@remit/web-client-dist 0.0.294 → 0.0.296
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-BNkTo3di.js → ComposeBody-DWkdEkqR.js} +2 -2
- package/assets/{ConfirmDialog-D7k6ug53.js → ConfirmDialog-BJo9D9jL.js} +1 -1
- package/assets/{ErrorState-Dzd1dG4I.js → ErrorState-CYMKMK-m.js} +1 -1
- package/assets/{OnboardingWizard-BpT-bh4F.js → OnboardingWizard-DiNp39Ly.js} +1 -1
- package/assets/{account-form-helpers-qliPkUSX.js → account-form-helpers-C6QgTBuy.js} +1 -1
- package/assets/{accounts-Dr5dvRkY.js → accounts-DrrxLu-A.js} +1 -1
- package/assets/{advanced-_VkDmMlU.js → advanced-ClKJ3X6O.js} +1 -1
- package/assets/{appearance-Dlq-rqJH.js → appearance-8lqa5Vua.js} +1 -1
- package/assets/{avatar-DLXozspI.js → avatar-VNDJ5A43.js} +1 -1
- package/assets/{browser-ponyfill-CQs4BAYO.js → browser-ponyfill-DvwMi_jg.js} +1 -1
- package/assets/{circle-check-D2h8K7Na.js → circle-check-pM99trgf.js} +1 -1
- package/assets/{download-C2ROFXkI.js → download-C3FtIMt9.js} +1 -1
- package/assets/{filters-BJI1dh_r.js → filters-Dux80wCX.js} +1 -1
- package/assets/{flagged-DRjvHDq-.js → flagged-BEsB_wRe.js} +1 -1
- package/assets/{folders-C7AH9iG6.js → folders-cKlRSWFA.js} +1 -1
- package/assets/{index-YsPo3AJf.css → index-Bp4WnjS6.css} +1 -1
- package/assets/{index-Z0KvXoPD.js → index-CFFTFBUh.js} +8 -8
- package/assets/{index-C9ePclcf.js → index-DZC9weAQ.js} +1 -1
- package/assets/index-bi7nSm8_.js +1 -0
- package/assets/{kbd-D5tq3erg.js → kbd-YJVHKonD.js} +1 -1
- package/assets/{labels-DydGRuJL.js → labels-AWXTmNVS.js} +1 -1
- package/assets/mail-KIW9IAGs.js +118 -0
- package/assets/move-options-D9t3Mojn.js +1 -0
- package/assets/{onboarding-Vs6qHdhJ.js → onboarding-BZ6X6xkU.js} +1 -1
- package/assets/{pencil-1bcPjRI2.js → pencil-X6z3x2NK.js} +1 -1
- package/assets/{senders-CGvgSCbU.js → senders-C1UIALFk.js} +1 -1
- package/assets/settings-B1pbwg2l.js +1 -0
- package/assets/{settings-screen-BEVDEgSL.js → settings-screen-CR4yq1NM.js} +1 -1
- package/assets/{shield-check-BHrnoPQT.js → shield-check-BSX7wD7V.js} +1 -1
- package/assets/{suggested-vips-CPWuzllJ.js → suggested-vips-2b3eZkLi.js} +1 -1
- package/assets/{useDebouncedValue-DRN7AoJj.js → useDebouncedValue-BD9ZdStj.js} +1 -1
- package/assets/{useFilters-BycxlYbK.js → useFilters-DyThnXyZ.js} +1 -1
- package/assets/{useLabels-C4ptFWUb.js → useLabels-CdFZ8p_J.js} +1 -1
- package/assets/{useSignature-D4dw99i4.js → useSignature-BQhyovyz.js} +1 -1
- package/index.html +2 -2
- package/package.json +1 -1
- package/assets/index-CBC27r1L.js +0 -1
- package/assets/mail-D_5lBTom.js +0 -118
- package/assets/move-options-D5dV78-q.js +0 -1
- package/assets/settings-CO9VbgjK.js +0 -1
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ComposeBody-DWkdEkqR.js","assets/index-CFFTFBUh.js","assets/index-Bp4WnjS6.css","assets/pencil-X6z3x2NK.js","assets/avatar-VNDJ5A43.js","assets/kbd-YJVHKonD.js","assets/shield-check-BSX7wD7V.js","assets/account-form-helpers-C6QgTBuy.js","assets/useSignature-BQhyovyz.js","assets/useDebouncedValue-BD9ZdStj.js","assets/useFilters-DyThnXyZ.js","assets/ErrorState-CYMKMK-m.js","assets/format-CKZmh-Ru.js","assets/move-options-D9t3Mojn.js","assets/download-C3FtIMt9.js","assets/useLabels-CdFZ8p_J.js","assets/ConfirmDialog-BJo9D9jL.js","assets/circle-check-pM99trgf.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{R as q,c as Bf,r as l,a as Fe,j as r,C as Qt,b as Ms,X as Nt,d as Q,B as oe,e as Ct,S as Xt,f as Dt,g as Pt,L as hs,h as Uf,i as Kf,k as Jl,l as mn,T as Lt,m as qf,u as nr,n as Hn,o as Zl,I as ec,F as Da,p as tc,q as Pa,s as Hf,A as La,D as Wf,t as hn,v as Vf,w as rr,O as Qf,M as Gf,x as Yf,y as sc,z as Xf,E as Jf,G as pn,H as Zf,J as em,K as tm,N as sm,P as nc,Q as ps,U as Fa,V as nm,W as rc,Y as rm,Z as am,_ as om,$ as $a,a0 as _a,a1 as Kt,a2 as ac,a3 as im,a4 as za,a5 as lm,a6 as cm,a7 as um,a8 as da,a9 as dm,aa as fm,ab as Ee,ac as mm,ad as hm,ae as pm,af as gm,ag as xm,ah as bm,ai as ei,aj as vm,ak as ym,al as wm,am as Ba,an as oc,ao as ic,ap as Jt,aq as Ve,ar as it,as as Ua,at as qe,au as ar,av as Wn,aw as De,ax as Ls,ay as Ft,az as lc,aA as cc,aB as Ka,aC as qa,aD as Ha,aE as Vn,aF as uc,aG as ve,aH as Wa,aI as dc,aJ as _e,aK as Sm,aL as km,aM as or,aN as ir,aO as fc,aP as mc,aQ as Cm,aR as $t,aS as tt,aT as jm,aU as ft,aV as hc,aW as ds,aX as lr,aY as Nm,aZ as cr,a_ as Va,a$ as Qa,b0 as ur,b1 as Zt,b2 as Em,b3 as Im,b4 as Rm,b5 as Tm,b6 as Mm,b7 as fa,b8 as Am,b9 as pc,ba as As,bb as Ga,bc as Ya,bd as Om,be as dr,bf as Dm,bg as Pm,bh as gc,bi as Xa,bj as Lm,bk as ti,bl as Fm,bm as $m,bn as _m,bo as zm,bp as qt,bq as ma,br as Bm,bs as Um,bt as Km,bu as xc,bv as qm,bw as Hm,bx as Wm,by as Vm,bz as si,bA as Qm,bB as Gm,bC as Ym,bD as Xm,bE as Ja,bF as ha,bG as pa,bH as Jm,bI as bc,bJ as Zm,bK as eh,bL as Za,bM as th,bN as sh,bO as nh,bP as rh,bQ as ah,bR as oh,bS as ih,bT as lh,bU as Bt,bV as At,bW as ch}from"./index-CFFTFBUh.js";import{P as uh}from"./pencil-X6z3x2NK.js";import{A as jt,M as fr,C as dh}from"./avatar-VNDJ5A43.js";import{K as Is}from"./kbd-YJVHKonD.js";import{S as gn,C as eo,R as fh}from"./shield-check-BSX7wD7V.js";import{M as vc,a as mh}from"./account-form-helpers-C6QgTBuy.js";import{R as hh,u as ph}from"./useSignature-BQhyovyz.js";import{u as mr}from"./useDebouncedValue-BD9ZdStj.js";import{D as yc,B as gh,u as es,a as ni,b as ri,c as xh,d as bh,e as vh,n as yh,o as wh,f as Sh,g as kh,S as Ch}from"./useFilters-DyThnXyZ.js";import{E as ts,f as wc}from"./ErrorState-CYMKMK-m.js";import{f as Sc,a as gt,b as kc,c as Gt,d as Qn,t as jh}from"./format-CKZmh-Ru.js";import{P as ai,u as to,a as Cc,b as so,f as no,C as Nh,M as ot,D as oi}from"./move-options-D9t3Mojn.js";import{D as Eh}from"./download-C3FtIMt9.js";import{u as ro}from"./useLabels-CdFZ8p_J.js";import{C as jc}from"./ConfirmDialog-BJo9D9jL.js";import{C as Ih}from"./circle-check-pM99trgf.js";function on(e){if(Rh())e.focus({preventScroll:!0});else{let t=Th(e);e.focus(),Mh(t)}}let Nn=null;function Rh(){if(Nn==null){Nn=!1;try{document.createElement("div").focus({get preventScroll(){return Nn=!0,!0}})}catch{}}return Nn}function Th(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 Mh(e){for(let{element:t,scrollTop:s,scrollLeft:n}of e)t.scrollTop=s,t.scrollLeft=n}const Wt=e=>e?.ownerDocument??document,Yt=e=>e&&"window"in e&&e.window===e?e:Wt(e).defaultView||window;function Ah(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&typeof e.nodeType=="number"}function Oh(e){return Ah(e)&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e}let Dh=!1;function Nc(){return Dh}function kt(e,t){if(!Nc())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:Oh(s)?s=s.host:s=s.parentNode}return!1}function Ge(e){if(Nc()&&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 Ph=typeof Element<"u"&&"checkVisibility"in Element.prototype;function Lh(e){const t=Yt(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}=Yt(e);let{display:i,visibility:c}=o(e);a=i!=="none"&&c!=="hidden"&&c!=="collapse"}return a}function Fh(e,t){return!e.hasAttribute("hidden")&&!e.hasAttribute("data-react-aria-prevent-focus")&&(e.nodeName==="DETAILS"&&t&&t.nodeName!=="SUMMARY"?e.hasAttribute("open"):!0)}function Ec(e,t){return Ph?e.checkVisibility({visibilityProperty:!0})&&!e.closest("[data-react-aria-prevent-focus]"):e.nodeName!=="#comment"&&Lh(e)&&Fh(e,t)&&(!e.parentElement||Ec(e.parentElement,e))}const Ic=["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"],$h=Ic.join(":not([hidden]),")+",[tabindex]:not([disabled]):not([hidden])";Ic.push('[tabindex]:not([tabindex="-1"]):not([disabled])');function _h(e,t){return e.matches($h)&&!zh(e)&&(t?.skipVisibilityCheck||Ec(e))}function zh(e){let t=e;for(;t!=null;){if(t instanceof Yt(t).HTMLElement&&t.inert)return!0;t=t.parentElement}return!1}const ao=typeof document<"u"?q.useLayoutEffect:()=>{};function Bh(e){let t=e;return t.nativeEvent=e,t.isDefaultPrevented=()=>t.defaultPrevented,t.isPropagationStopped=()=>t.cancelBubble,t.persist=()=>{},t}function Uh(e,t){Object.defineProperty(e,"target",{value:t}),Object.defineProperty(e,"currentTarget",{value:t})}function Kh(e){for(;e&&!_h(e,{skipVisibilityCheck:!0});)e=e.parentElement;let t=Yt(e),s=t.document.activeElement;if(!s||s===e)return;let n=!1,a=d=>{(Ge(d)===s||n)&&d.stopImmediatePropagation()},o=d=>{(Ge(d)===s||n)&&(d.stopImmediatePropagation(),!e&&!n&&(n=!0,on(s),u()))},i=d=>{(Ge(d)===e||n)&&d.stopImmediatePropagation()},c=d=>{(Ge(d)===e||n)&&(d.stopImmediatePropagation(),n||(n=!0,on(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 hr(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 oo(e){return typeof window<"u"&&window.navigator!=null?e.test(window.navigator.userAgentData?.platform||window.navigator.platform):!1}function ss(e){let t=null;return()=>(t==null&&(t=e()),t)}const Gn=ss(function(){return oo(/^Mac/i)}),qh=ss(function(){return oo(/^iPhone/i)}),Rc=ss(function(){return oo(/^iPad/i)||Gn()&&navigator.maxTouchPoints>1}),Tc=ss(function(){return qh()||Rc()}),Hh=ss(function(){return hr(/AppleWebKit/i)&&!Wh()}),Wh=ss(function(){return hr(/Chrome/i)}),Mc=ss(function(){return hr(/Android/i)}),Vh=ss(function(){return hr(/Firefox/i)});function Qh(e){return e.pointerType===""&&e.isTrusted?!0:Mc()&&e.pointerType?e.type==="click"&&e.buttons===1:e.detail===0&&!e.pointerType}function Gh(e){return!Mc()&&e.width===0&&e.height===0||e.width===1&&e.height===1&&e.pressure===0&&e.detail===0&&e.pointerType==="mouse"}function ln(e,t,s=!0){let{metaKey:n,ctrlKey:a,altKey:o,shiftKey:i}=t;Vh()&&window.event?.type?.startsWith("key")&&e.target==="_blank"&&(Gn()?n=!0:a=!0);let c=Hh()&&Gn()&&!Rc()?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});ln.isOpening=s,on(e),e.dispatchEvent(c),ln.isOpening=!1}ln.isOpening=!1;let Ht=new Map,ga=new Set;function ii(){if(typeof window>"u")return;function e(n){return"propertyName"in n}let t=n=>{let a=Ge(n);if(!e(n)||!a)return;let o=Ht.get(a);o||(o=new Set,Ht.set(a,o),a.addEventListener("transitioncancel",s,{once:!0})),o.add(n.propertyName)},s=n=>{let a=Ge(n);if(!e(n)||!a)return;let o=Ht.get(a);if(o&&(o.delete(n.propertyName),o.size===0&&(a.removeEventListener("transitioncancel",s),Ht.delete(a)),Ht.size===0)){for(let i of ga)i();ga.clear()}};document.body.addEventListener("transitionrun",t),document.body.addEventListener("transitionend",s)}typeof document<"u"&&(document.readyState!=="loading"?ii():document.addEventListener("DOMContentLoaded",ii));function Yh(){for(const[e]of Ht)"isConnected"in e&&!e.isConnected&&Ht.delete(e)}function Xh(e){requestAnimationFrame(()=>{Yh(),Ht.size===0?e():ga.add(e)})}function Ac(...e){return(...t)=>{for(let s of e)typeof s=="function"&&s(...t)}}let xa=new Map;typeof FinalizationRegistry<"u"&&new FinalizationRegistry(e=>{xa.delete(e)});function Jh(e,t){if(e===t)return e;let s=xa.get(e);if(s)return s.forEach(a=>a.current=t),t;let n=xa.get(t);return n?(n.forEach(a=>a.current=e),e):t}function Zh(...e){return e.length===1&&e[0]?e[0]:t=>{let s=!1;const n=e.map(a=>{const o=li(a,t);return s||=typeof o=="function",o});if(s)return()=>{n.forEach((a,o)=>{typeof a=="function"?a():li(e[o],null)})}}}function li(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Fs(...e){let t={...e[0]};for(let s=1;s<e.length;s++){let n=e[s];for(let a in n){let o=t[a],i=n[a];typeof o=="function"&&typeof i=="function"&&a[0]==="o"&&a[1]==="n"&&a.charCodeAt(2)>=65&&a.charCodeAt(2)<=90?t[a]=Ac(o,i):(a==="className"||a==="UNSAFE_className")&&typeof o=="string"&&typeof i=="string"?t[a]=Bf(o,i):a==="id"&&o&&i?t.id=Jh(o,i):a==="ref"&&o&&i?t.ref=Zh(o,i):t[a]=i!==void 0?i:o}}return t}function ep(e,t){ao(()=>{if(e&&e.ref&&t)return e.ref.current=t.current,()=>{e.ref&&(e.ref.current=null)}})}const tp=q.useInsertionEffect??ao;function zr(e){const t=l.useRef(null);return tp(()=>{t.current=e},[e]),l.useCallback((...s)=>{const n=t.current;return n?.(...s)},[])}let Es="default",ba="",_n=new WeakMap;function sp(e){if(Tc()){if(Es==="default"){const t=Wt(e);ba=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";_n.set(e,e.style[t]),e.style[t]="none"}}function ci(e){if(Tc()){if(Es!=="disabled")return;Es="restoring",setTimeout(()=>{Xh(()=>{if(Es==="restoring"){const t=Wt(e);t.documentElement.style.webkitUserSelect==="none"&&(t.documentElement.style.webkitUserSelect=ba||""),ba="",Es="default"}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&e&&_n.has(e)){let t=_n.get(e),s="userSelect"in e.style?"userSelect":"webkitUserSelect";e.style[s]==="none"&&(e.style[s]=t),e.getAttribute("style")===""&&e.removeAttribute("style"),_n.delete(e)}}function ui(e){return e?.defaultView?.__webpack_nonce__||globalThis.__webpack_nonce__||void 0}let Br=new WeakMap;function np(e){let t=e??(typeof document<"u"?document:void 0);if(!t)return ui(t);if(Br.has(t))return Br.get(t);let s=t.querySelector('meta[property="csp-nonce"]'),n=s&&s instanceof Yt(s).HTMLMetaElement&&(s.nonce||s.content)||ui(t)||void 0;return n!==void 0&&Br.set(t,n),n}const Oc=q.createContext({register:()=>{}});Oc.displayName="PressResponderContext";function Dc(){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 rp(e){let t=l.useContext(Oc);if(t){let{register:s,ref:n,...a}=t;e=Fs(a,e),s()}return ep(t,e.ref),e}class En{#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 di=Symbol("linkClicked"),fi="react-aria-pressable-style",mi="data-react-aria-pressable";function ap(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,...y}=rp(e),[g,p]=l.useState(!1),x=l.useRef({isPressed:!1,ignoreEmulatedMouseEvents:!1,didFirePressStart:!1,isTriggeringEvent:!1,activePointerId:null,target:null,isOverTarget:!1,pointerType:null,disposables:[]}),{addGlobalListener:b,removeAllGlobalListeners:S}=Dc(),w=l.useCallback((j,T)=>{let P=x.current;if(c||P.didFirePressStart)return!1;let I=!0;if(P.isTriggeringEvent=!0,n){let D=new En("pressstart",T,j);n(D),I=D.shouldStopPropagation}return s&&s(!0),P.isTriggeringEvent=!1,P.didFirePressStart=!0,p(!0),I},[c,n,s]),v=l.useCallback((j,T,P=!0)=>{let I=x.current;if(!I.didFirePressStart)return!1;I.didFirePressStart=!1,I.isTriggeringEvent=!0;let D=!0;if(a){let N=new En("pressend",T,j);a(N),D=N.shouldStopPropagation}if(s&&s(!1),p(!1),t&&P&&!c){let N=new En("press",T,j);t(N),D&&=N.shouldStopPropagation}return I.isTriggeringEvent=!1,D},[c,a,s,t]),k=zr(v),R=l.useCallback((j,T)=>{let P=x.current;if(c)return!1;if(o){P.isTriggeringEvent=!0;let I=new En("pressup",T,j);return o(I),P.isTriggeringEvent=!1,I.shouldStopPropagation}return!0},[c,o]),A=zr(R),C=l.useCallback(j=>{let T=x.current;if(T.isPressed&&T.target){T.didFirePressStart&&T.pointerType!=null&&v(os(T.target,j),T.pointerType,!1),T.isPressed=!1,T.isOverTarget=!1,T.activePointerId=null,T.pointerType=null,S(),f||ci(T.target);for(let P of T.disposables)P();T.disposables=[]}},[f,S,v]),M=zr(C);l.useEffect(()=>{c&&x.current.isPressed&&M({currentTarget:x.current.target,shiftKey:!1,ctrlKey:!1,metaKey:!1,altKey:!1})},[c]);let L=l.useCallback(j=>{d&&C(j)},[d,C]),E=l.useCallback(j=>{c||i?.(j)},[c,i]),F=l.useCallback((j,T)=>{if(!c&&i){let P=new MouseEvent("click",j);Uh(P,T),i(Bh(P))}},[c,i]),O=l.useMemo(()=>{let j=x.current,T={onKeyDown(I){if(Ur(I.nativeEvent,I.currentTarget)&&kt(I.currentTarget,Ge(I))){hi(Ge(I),I.key)&&I.preventDefault();let D=!0;!j.isPressed&&!I.repeat&&(j.target=I.currentTarget,j.isPressed=!0,j.pointerType="keyboard",D=w(I,"keyboard"));let N=I.currentTarget,G=W=>{Ur(W,N)&&!W.repeat&&kt(N,Ge(W))&&j.target&&A(os(j.target,W),"keyboard")};b(Wt(I.currentTarget),"keyup",Ac(G,P),!0),D&&I.stopPropagation(),I.metaKey&&Gn()&&j.metaKeyEvents?.set(I.key,I.nativeEvent)}else I.key==="Meta"&&(j.metaKeyEvents=new Map)},onClick(I){if(!(I&&!kt(I.currentTarget,Ge(I)))&&I&&I.button===0&&!j.isTriggeringEvent&&!ln.isOpening){let D=!0;if(c&&I.preventDefault(),!j.ignoreEmulatedMouseEvents&&!j.isPressed&&(j.pointerType==="virtual"||Qh(I.nativeEvent))){let N=w(I,"virtual"),G=A(I,"virtual"),W=k(I,"virtual");E(I),D=N&&G&&W}else if(j.isPressed&&j.pointerType!=="keyboard"){let N=j.pointerType||I.nativeEvent.pointerType||"virtual",G=A(os(I.currentTarget,I),N),W=k(os(I.currentTarget,I),N,!0);D=G&&W,j.isOverTarget=!1,E(I),M(I)}j.ignoreEmulatedMouseEvents=!1,D&&I.stopPropagation()}}},P=I=>{if(j.isPressed&&j.target&&Ur(I,j.target)){hi(Ge(I),I.key)&&I.preventDefault();let D=Ge(I),N=kt(j.target,D);k(os(j.target,I),"keyboard",N),N&&F(I,j.target),S(),I.key!=="Enter"&&io(j.target)&&kt(j.target,D)&&!I[di]&&(I[di]=!0,ln(j.target,I,!1)),j.isPressed=!1,j.metaKeyEvents?.delete(I.key)}else if(I.key==="Meta"&&j.metaKeyEvents?.size){let D=j.metaKeyEvents;j.metaKeyEvents=void 0;for(let N of D.values())j.target?.dispatchEvent(new KeyboardEvent("keyup",N))}};if(typeof PointerEvent<"u"){T.onPointerDown=N=>{if(N.button!==0||!kt(N.currentTarget,Ge(N)))return;if(Gh(N.nativeEvent)){j.pointerType="virtual";return}j.pointerType=N.pointerType;let G=!0;if(!j.isPressed){j.isPressed=!0,j.isOverTarget=!0,j.activePointerId=N.pointerId,j.target=N.currentTarget,f||sp(j.target),G=w(N,j.pointerType);let W=Ge(N);"releasePointerCapture"in W&&("hasPointerCapture"in W?W.hasPointerCapture(N.pointerId)&&W.releasePointerCapture(N.pointerId):W.releasePointerCapture(N.pointerId)),b(Wt(N.currentTarget),"pointerup",I,!1),b(Wt(N.currentTarget),"pointercancel",D,!1)}G&&N.stopPropagation()},T.onMouseDown=N=>{if(kt(N.currentTarget,Ge(N))&&N.button===0){if(m){let G=Kh(N.target);G&&j.disposables.push(G)}N.stopPropagation()}},T.onPointerUp=N=>{!kt(N.currentTarget,Ge(N))||j.pointerType==="virtual"||N.button===0&&!j.isPressed&&A(N,j.pointerType||N.pointerType)},T.onPointerEnter=N=>{N.pointerId===j.activePointerId&&j.target&&!j.isOverTarget&&j.pointerType!=null&&(j.isOverTarget=!0,w(os(j.target,N),j.pointerType))},T.onPointerLeave=N=>{N.pointerId===j.activePointerId&&j.target&&j.isOverTarget&&j.pointerType!=null&&(j.isOverTarget=!1,k(os(j.target,N),j.pointerType,!1),L(N))};let I=N=>{if(N.pointerId===j.activePointerId&&j.isPressed&&N.button===0&&j.target){if(kt(j.target,Ge(N))&&j.pointerType!=null){let G=!1,W=setTimeout(()=>{j.isPressed&&j.target instanceof HTMLElement&&(G?M(N):(on(j.target),j.target.click()))},80);b(N.currentTarget,"click",()=>G=!0,!0),j.disposables.push(()=>clearTimeout(W))}else M(N);j.isOverTarget=!1}},D=N=>{M(N)};T.onDragStart=N=>{kt(N.currentTarget,Ge(N))&&M(N)}}return T},[b,c,m,S,f,L,w,E,F]);return l.useEffect(()=>{if(!h)return;const j=Wt(h.current);if(!j||!j.head||j.getElementById(fi))return;const T=j.createElement("style");T.id=fi;let P=np(j);P&&(T.nonce=P),T.textContent=`
|
|
3
|
+
@layer {
|
|
4
|
+
[${mi}] {
|
|
5
|
+
touch-action: pan-x pan-y pinch-zoom;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
`.trim(),j.head.prepend(T)},[h]),l.useEffect(()=>{let j=x.current;return()=>{f||ci(j.target??void 0);for(let T of j.disposables)T();j.disposables=[]}},[f]),{isPressed:u||g,pressProps:Fs(y,O,{[mi]:!0})}}function io(e){return e.tagName==="A"&&e.hasAttribute("href")}function Ur(e,t){const{key:s,code:n}=e,a=t,o=a.getAttribute("role");return(s==="Enter"||s===" "||s==="Spacebar"||n==="Space")&&!(a instanceof Yt(a).HTMLInputElement&&!Pc(a,s)||a instanceof Yt(a).HTMLTextAreaElement||a.isContentEditable)&&!((o==="link"||!o&&io(a))&&s!=="Enter")}function os(e,t){let s=t.clientX,n=t.clientY;return{currentTarget:e,shiftKey:t.shiftKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,altKey:t.altKey,clientX:s,clientY:n,key:t.key}}function op(e){return e instanceof HTMLInputElement?!1:e instanceof HTMLButtonElement?e.type!=="submit"&&e.type!=="reset":!io(e)}function hi(e,t){return e instanceof HTMLInputElement?!Pc(e,t):op(e)}const ip=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);function Pc(e,t){return e.type==="checkbox"||e.type==="radio"?t===" ":ip.has(e.type)}let lp=0;const Kr=new Map;function cp(e){let[t,s]=l.useState();return ao(()=>{if(!e)return;let n=Kr.get(e);if(n)s(n.element.id);else{let a=`react-aria-description-${lp++}`;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},Kr.set(e,n)}return n.refCount++,()=>{n&&--n.refCount===0&&(n.element.remove(),Kr.delete(e))}},[e]),{"aria-describedby":e?t:void 0}}const up=500;function dp(e){let{isDisabled:t,onLongPressStart:s,onLongPressEnd:n,onLongPress:a,threshold:o=up,accessibilityDescription:i}=e;const c=l.useRef(void 0);let{addGlobalListener:u,removeGlobalListener:m}=Dc(),{pressProps:d}=ap({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})),Wt(h.target).activeElement!==h.target&&on(h.target),a&&a({...h,type:"longpress"}),c.current=void 0},o),h.pointerType==="touch")){let y=p=>{p.preventDefault()},g=Yt(h.target);u(h.target,"contextmenu",y,{once:!0}),u(g,"pointerup",()=>{setTimeout(()=>{m(h.target,"contextmenu",y)},30)},{once:!0})}},onPressEnd(h){c.current&&clearTimeout(c.current),n&&(h.pointerType==="mouse"||h.pointerType==="touch")&&n({...h,type:"longpressend"})}}),f=cp(a&&!t?i:void 0);return{longPressProps:Fs(d,f)}}const pr=Fe("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 Lc=Fe("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 fp=Fe("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 Fc=Fe("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 lo=Fe("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 $c=Fe("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]);const _c=Fe("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 zc=Fe("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 Bc=Fe("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 mp=Fe("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 gr=Fe("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 hp=Fe("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 pp=Fe("Minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);const xr=Fe("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 co=Fe("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 Uc=Fe("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=Fe("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 qc=Fe("Settings",[["path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z",key:"1qme2f"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);const $s=Fe("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 gp=Fe("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 xp=Fe("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 bp=Fe("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 vp=Fe("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"}]]),yp=({address:e,showTrustedBadge:t=!1})=>{const s=t?r.jsx(pr,{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]})},wp=({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(yp,{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(Qt,{className:"h-4 w-4"}):r.jsx(Ms,{className:"h-4 w-4"})})]})},Sp=({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(Nt,{className:"size-3"})})]}),kp={unknown:{label:"Unknown sender",tone:"neutral"},wellknown:{label:"Known sender",tone:"positive"},vip:{label:"VIP",tone:"accent"}};function ws({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 Cp({sender:e}){const t=kp[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(jt,{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(Ct,{tone:"danger",dot:!0,children:"Address couldn't be verified"}):r.jsx(Ct,{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 jp({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(gp,{className:"mt-0.5 size-4 shrink-0"}),r.jsx("p",{className:"text-xs leading-relaxed",children:e.summary})]});const s=e.addressUnreadable?"This sender can't be verified":"This message may be impersonating someone";return r.jsxs("div",{className:"rounded-md bg-danger-soft p-3",children:[r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx($s,{className:"mt-0.5 size-4 shrink-0 text-danger"}),r.jsxs("div",{className:"min-w-0",children:[r.jsx("p",{className:"text-sm font-semibold text-danger",children:s}),r.jsx("p",{className:"mt-1 text-xs leading-relaxed text-fg",children:e.summary}),!e.addressUnreadable&&e.dkimDomain&&r.jsxs("p",{className:"mt-1 text-2xs text-fg-muted",children:["Sent from"," ",r.jsx("code",{className:"rounded bg-surface px-1 py-0.5",children:e.dkimDomain}),", claims to be"," ",r.jsx("code",{className:"rounded bg-surface px-1 py-0.5",children:e.fromDomain})]})]})]}),e.similarCount!=null&&e.similarCount>0&&r.jsxs(oe,{variant:"secondary",size:"sm",className:"mt-2 w-full border-danger/30 text-danger hover:bg-danger-soft",onClick:t,children:[e.similarCount," similar messages"]})]})}function Ws({icon:e,label:t,active:s,danger:n,onClick:a,pending:o}){const i=a===void 0||o===!0;return r.jsxs("button",{type:"button",onClick:a,disabled:i,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",i&&"cursor-not-allowed opacity-50 hover:border-line"),children:[e,t]})}const Np={sender:"matched: sender",recipient:"matched: recipient",subject:"matched: subject",attachment:"matched: attachment",body:"matched: body",entities:"matched: entities"};function Hc({data:e,onClose:t,onShowSimilar:s,actions:n,similarState:a="ready",similarLinkComponent:o,className:i,hideCloseButton:c=!1,reportSpamPending:u=!1,notSpamPending:m=!1}){const{sender:d,authenticity:f,category:h,flags:y={},similar:g}=e,p=f.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(oe,{variant:"ghost",size:"sm",icon:r.jsx(Nt,{className:"size-3.5"}),onClick:t,"aria-label":"Collapse intelligence sidebar"})]}),r.jsx(ws,{label:"Sender",children:r.jsx(Cp,{sender:d})}),r.jsx(ws,{label:"Authenticity",children:r.jsx(jp,{auth:f,onShowSimilar:s})}),r.jsx(ws,{label:"Category",children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Ct,{tone:p?"danger":"neutral",children:h.value}),h.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.jsxs(ws,{label:"Quick actions",children:[r.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[r.jsx(Ws,{icon:r.jsx(Xt,{className:"size-3.5"}),label:"VIP",active:y.vip,onClick:n?.onToggleVip}),r.jsx(Ws,{icon:r.jsx(Lc,{className:"size-3.5"}),label:"Mute",active:y.muted,onClick:n?.onToggleMute}),n?.onNotSpam&&r.jsx(Ws,{icon:r.jsx(mp,{className:"size-3.5"}),label:m?"Undoing…":"Not spam",active:!0,onClick:n.onNotSpam,pending:m}),n?.onReportSpam&&r.jsx(Ws,{icon:r.jsx(xp,{className:"size-3.5"}),label:u?"Reporting…":"Report spam",danger:!0,onClick:n.onReportSpam,pending:u}),r.jsx(Ws,{icon:r.jsx(hp,{className:"size-3.5"}),label:"Unsubscribe",active:y.unsubscribed,onClick:n?.onToggleUnsubscribe})]}),n?.onNotSpam&&r.jsx("p",{className:"mt-1.5 text-2xs text-fg-subtle",children:"You reported this message as spam"})]}),(a!=="ready"||g.length>0)&&r.jsx(ws,{label:"Similar messages",children:a==="loading"?r.jsx("div",{className:"animate-pulse space-y-2",children:Array.from({length:3}).map((x,b)=>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"})]},b))}):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:g.map(x=>{const b="block w-full rounded-md px-1 py-1 text-left hover:bg-surface-sunken",S=`Open message from ${x.fromName||"unknown sender"}: ${x.subject}`,w=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:x.fromName}),r.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:x.timeLabel})]}),r.jsx("div",{className:"truncate text-xs text-fg-muted",children:x.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:Np[x.matched]})]});return r.jsx("li",{children:o?o({mailboxId:x.mailboxId,messageId:x.id,className:b,ariaLabel:S,children:w}):r.jsx("div",{className:b,children:w})},x.id)})})}),r.jsx(ws,{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(Dt,{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(Dt,{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 uo=[{action:"focusNext",keys:["j","k"],label:"navigate"},{action:"muteSender",keys:["m"],label:"mute"},{action:"help",keys:["?"],label:"all shortcuts"}];function Ep(e){return uo.filter(t=>e[t.action]!==void 0)}const Wc=[{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 Ip(e){for(const t of Wc){const s=t.hints.find(n=>n.action===e);if(s)return s.keys}}function Vc(e){const t=Ip(e);return!t||t.length===0?"":t.length===1?t[0]??"":t[0]==="g"?t.join(" then "):t.join("")}function Vs(e){const t=Vc(e);return t===""?"":`(${t})`}const Yn=e=>({shiftKey:e.shiftKey,metaKey:e.metaKey,ctrlKey:e.ctrlKey}),pi=e=>e.shiftKey||e.metaKey||e.ctrlKey,Rp=e=>e.shiftKey?"range":e.metaKey||e.ctrlKey?"toggle":"open",fo=(e,t)=>!t&&e>0,Tp=(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)},Mp=(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},Qc=(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]},Gc=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(x=>{const b=new Set(x);return b.has(p)?b.delete(p):b.add(p),b})},[]),c=l.useCallback(p=>{a(p),s(x=>{if(x.has(p))return x;const b=new Set(x);return b.add(p),b})},[]),u=l.useCallback(p=>{s(x=>{if(!x.has(p))return x;const b=new Set(x);return b.delete(p),b})},[]),m=l.useCallback(p=>{s(new Set(p))},[]),d=l.useCallback(()=>{a(void 0),s(new Set)},[]),f=l.useCallback(p=>{s(x=>p.every(S=>x.has(S))?new Set:new Set(p))},[]),h=l.useCallback(p=>{a(p)},[]),y=l.useCallback(p=>{s(x=>{if(x.size===0)return x;const b=Ap(x,p);return b.size===x.size?x:b})},[]),g=l.useCallback((p,x,b)=>{const S=Mp(p,n,b,x);s(w=>{const v=Tp(p,S,x);if(v.length===0)return w;const k=new Set(w);for(const R of v)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:y}};function Yc({hints:e=uo,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 Dp(){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 Pp({filter:e,scopeLabel:t,searchQuery:s}){const n=s?.trim();return e?r.jsxs(gi,{children:[r.jsx("p",{className:"font-medium text-fg",children:$p(e.label,t,n)}),r.jsx("p",{className:"mt-1 text-sm text-fg-muted",children:Lp[e.reach]}),r.jsx(oe,{variant:"secondary",size:"sm",className:"mt-4",onClick:e.onClear,children:"Clear filter"})]}):r.jsx(gi,{children:r.jsx("p",{className:"text-fg-muted",children:Fp(n,t)})})}const Lp={"whole-folder":"Every message in this folder was checked.","loaded-pages":"Only the messages loaded so far were checked."};function Fp(e,t){return e?"No messages match your search":t?`No messages in ${t}`:"No messages in this mailbox"}function $p(e,t,s){return s?`No results for “${s}” in ${e}`:t?`No ${e} mail in ${t}`:`No ${e} mail`}function gi({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 _p(){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(hs,{className:"size-4 animate-spin","aria-hidden":"true"}),r.jsx("span",{children:"Loading more…"})]})}function zp({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(Pt,{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(oe,{variant:"secondary",size:"sm",onClick:t,children:"Retry"}),s&&r.jsx(oe,{variant:"ghost",size:"sm",onClick:s,children:"Report a problem"})]})]})})}const Qs={action:null,nextPrefix:null,preventDefault:!1},Bp={b:"goBrief",i:"goInbox",s:"goSent",f:"goFlagged",",":"goSettings"},Up={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 Kp(e,t){const s=e.key.toLowerCase(),n=e.metaKey||e.ctrlKey;if(e.inEditable)return{...Qs,nextPrefix:t==="g"?null:t};if(e.onControl&&(s==="enter"||s===" "))return{...Qs,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{...Qs,nextPrefix:t==="g"?null:t};if(s==="escape")return{action:"back",nextPrefix:null,preventDefault:!1};if(t==="g"){const i=Bp[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=Up[s];if(a){const o=a.requireShift===!0,i=s.length===1&&!/[a-z0-9]/.test(s);return!o&&e.shiftKey&&!i?Qs:{action:a.action,nextPrefix:null,preventDefault:!0}}return Qs}function qp(e){if(!(e instanceof HTMLElement))return!1;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"||e.isContentEditable}const Xc="data-message-row",Hp='button, a[href], summary, [role="button"], [role="menuitem"], [role="tab"], [role="switch"], [role="checkbox"]';function Wp(e){if(!(e instanceof HTMLElement))return!1;const t=e.closest(Hp);return t?!t.hasAttribute(Xc):!1}const Jc="outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",Zc=({active:e,focused:t})=>Q("relative flex h-8 w-full items-center gap-2 px-row-inset text-left",Jc,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"),_s=({active:e,focused:t})=>Q("relative flex w-full items-start gap-3 py-2 pl-5 pr-row-inset text-left transition-colors",Jc,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 eu({thread:e}){const t=!e.isRead;return r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"flex w-4 shrink-0 items-center justify-center",children:e.suspicious?r.jsx($s,{className:"size-3.5 text-danger"}):e.starred?r.jsx(Xt,{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(xr,{className:"size-3 shrink-0 text-fg-subtle",role:"img","aria-label":"Has an attachment"}),r.jsx("span",{className:"w-11 shrink-0 text-right text-2xs text-fg-subtle tabular-nums",children:e.timeLabel})]})}function xi(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 cn({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:xi(e.subject,s)}),e.suspicious&&r.jsx($s,{className:"size-3.5 shrink-0 text-danger"}),e.starred&&r.jsx(Xt,{className:"size-3 shrink-0 fill-warning text-warning"}),e.hasAttachment&&r.jsx(xr,{className:"size-3 shrink-0 text-fg-subtle",role:"img","aria-label":"Has an attachment"})]}),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:xi(e.snippet,s)}),e.category&&e.category!=="personal"&&r.jsx(Ct,{tone:Uf[e.category],className:"shrink-0",children:e.category}),e.labels?.map(a=>r.jsx(Kf,{label:a,className:"max-w-20"},a.labelId)),t]})]})}function Vp({thread:e,selection:t}){if(!t)return r.jsx(jt,{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(jt,{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(mn,{className:"size-3"})})]})}function mo({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(Vp,{thread:e,selection:t}),r.jsx(cn,{thread:e,badge:s,highlightQuery:n})]})}const tu=e=>({...Jl,[Xc]:"","data-message-id":e.id});function Qp({thread:e,active:t,focused:s,tabIndex:n,onClick:a}){return r.jsx("button",{type:"button",...tu(e),tabIndex:n,onClick:a,className:Zc({active:t,focused:s}),children:r.jsx(eu,{thread:e})})}function Gp({thread:e,active:t,focused:s,tabIndex:n,selection:a,onClick:o}){return r.jsx("button",{type:"button",...tu(e),tabIndex:n,onClick:o,className:Q("group",_s({active:t,focused:s})),children:r.jsx(mo,{thread:e,selection:a})})}let Rs;const Yp=5e3;function su(e){e.preventDefault(),Xn()}function Xn(){Rs!==void 0&&(clearTimeout(Rs),Rs=void 0,document.removeEventListener("contextmenu",su,!0),document.removeEventListener("pointerup",Xn,!0))}function Xp(){Rs===void 0?(document.addEventListener("contextmenu",su,!0),document.addEventListener("pointerup",Xn,!0)):clearTimeout(Rs),Rs=setTimeout(Xn,Yp)}function nu({onLongPress:e,isDisabled:t,delayMs:s=500,accessibilityDescription:n}){const{longPressProps:a}=dp({isDisabled:t,threshold:s,accessibilityDescription:n,onLongPress:e}),o=l.useCallback(i=>{i.pointerType!=="touch"&&i.pointerType!=="pen"||Xp()},[]);return{longPressProps:Fs(a,{onPointerDown:o})}}const fs=72,bi=10,Jp=fs/2,vi="__swipeableRowAxisCancel";function yi(e){return e==="leading"?fs:e==="trailing"?-fs:0}function Zp(e){return e>=fs/2?"leading":e<=-fs/2?"trailing":"none"}function ru({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:y}=nu({onLongPress:c,isDisabled:t,accessibilityDescription:"Select message"}),g=E=>{const F=new PointerEvent("pointercancel",{bubbles:!0});F[vi]=!0,E.currentTarget.dispatchEvent(F)},w=Fs(y,{onPointerDown:E=>{d.current={startX:E.clientX,startY:E.clientY,axis:"none",escaped:!1}},onPointerMove:E=>{if(t)return;const F=d.current;if(!F)return;const O=E.clientX-F.startX,j=E.clientY-F.startY;if(F.axis==="none"&&(Math.abs(j)>bi&&Math.abs(j)>Math.abs(O)?F.axis="vertical":Math.abs(O)>bi&&Math.abs(O)>Math.abs(j)&&(F.axis="horizontal",E.currentTarget.setPointerCapture(E.pointerId))),F.axis==="none")return;const T=F.axis==="horizontal"?Math.abs(O):Math.abs(j);if(!F.escaped&&T>Jp&&(F.escaped=!0,g(E)),F.axis!=="horizontal")return;const P=yi(a),I=Math.max(-fs,Math.min(fs,P+O));h(I)},onPointerUp:E=>{const F=d.current;d.current=null;const O=f;if(h(null),!!F){if(F.axis!=="none"&&!F.escaped&&g(E),F.axis==="horizontal"){O!==null&&o(Zp(O));return}if(F.axis!=="vertical"){if(t){i();return}if(a!=="none"){o("none");return}u()}}},onPointerCancel:E=>{E.nativeEvent[vi]||(d.current=null,h(null))}}),v=f??yi(a),k=v>0?"leading":v<0?"trailing":"none",R=Q("relative touch-pan-y bg-surface","select-none",_s({active:s||n})),A={transform:v!==0?`translateX(${v}px)`:void 0,transition:f===null?"transform 150ms ease":"none",minHeight:44},C=!e.isRead,M=E=>E.stopPropagation(),L=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(mn,{className:"size-3.5"})}),r.jsx(cn,{thread:e})]}):r.jsxs(r.Fragment,{children:[C&&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:E=>{E.preventDefault(),E.stopPropagation(),c()},onKeyDown:E=>{E.key!=="Enter"&&E.key!==" "||(E.preventDefault(),E.stopPropagation(),c())},className:"-m-2 inline-flex size-11 shrink-0 items-center justify-center rounded-full",children:r.jsx(jt,{name:e.fromName,email:e.fromEmail,size:"sm"})}),r.jsx(cn,{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(vc,{className:"size-6"}):r.jsx(gr,{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(Lt,{className:"size-6"})}),r.jsx("button",{type:"button",role:t?"checkbox":void 0,"aria-checked":t?s:void 0,"data-message-row":!0,"data-message-id":e.id,...w,className:R,style:A,children:L})]})}function eg({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),[y,g]=l.useState(new Map),p=e.flatMap(w=>w.threads).filter(w=>!f.has(w.id)).map(w=>{const v=y.get(w.id);return v===void 0?w:{...w,isRead:v}}),[x,b]=l.useState(a&&a!=="none"&&p[1]?{id:p[1].id,side:a}:null),S=(w,v)=>{if(v==="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))}b(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(co,{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(ru,{thread:w,selectionMode:s,checked:n.has(w.id),active:w.id===t,peek:x?.id===w.id?x.side:"none",onPeek:v=>b(v==="none"?null:{id:w.id,side:v}),onToggleCheck:()=>o(w.id),onLongPress:()=>i(w.id),onOpen:()=>c(w.id),onAct:v=>S(w.id,v)})},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 tg=new Set;function au({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:y,density:g="comfortable",onSelectThread:p,onOpenNav:x,isDesktop:b,initialTouchState:S,selection:w,keyboard:v,selectionBar:k,paneOverlay:R,listBody:A,hideHeader:C=!1}){const M=g==="compact"?Qp:Gp,L=l.useRef(null),E=l.useRef(null),F=qf(v);nr({containerRef:L,itemSelector:Hn,enabled:!F});const O=F?v.focusedId:void 0,j=F?O??s[0]?.threads[0]?.id:void 0,T=l.useCallback(U=>j===void 0?void 0:U===j?0:-1,[j]);l.useEffect(()=>{if(O===void 0)return;const U=E.current;if(!U)return;const _=U.querySelector(`${Hn}[data-message-id="${O}"]`);!_||_===U.ownerDocument.activeElement||_.focus({preventScroll:!1})},[O]),l.useEffect(()=>{if(!F)return;const U=E.current;if(!U)return;const _=U.ownerDocument.activeElement;_!==null&&_!==U.ownerDocument.body||U.focus({preventScroll:!0})},[F]);const P=!b&&!n&&o==="ready",[I,D]=l.useState(!1),N=S==="peek-trailing"?"trailing":S==="peek-leading"?"leading":void 0,G=()=>{D(!0),setTimeout(()=>D(!1),1400)},W=w?.selectedIds??tg,ne=w?.onToggle,re=w?.onRowSelect,he=fo(W.size,b),te=l.useCallback(U=>{if(ne)return{checked:W.has(U),onToggle:_=>{_.preventDefault(),_.stopPropagation(),ne(U)}}},[W,ne]),ce=l.useCallback((U,_)=>re?.(U,Yn(_))?(_.preventDefault(),_.shiftKey&&window.getSelection()?.removeAllRanges(),!0):!1,[re]),ie=l.useCallback(({thread:U,active:_,onClick:ue})=>r.jsx(M,{thread:U,active:_,focused:U.id===O,tabIndex:T(U.id),selection:te(U.id),onClick:pe=>{ce(U.id,pe)||ue?.()}}),[M,te,ce,O,T]);return r.jsxs("section",{ref:U=>{E.current=U,v?.ref(U)},tabIndex:F?-1:void 0,className:"relative flex h-full w-full flex-col bg-surface outline-none",children:[k??(C?null:r.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[x&&r.jsx(oe,{variant:"ghost",size:"sm",icon:r.jsx(fr,{className:"size-4"}),onClick:x,"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(Dp,{})}):o==="empty"?r.jsx(Pp,{filter:c,scopeLabel:u,searchQuery:i}):o==="error"?r.jsx(zp,{message:m,onRetry:d,onReport:f}):n?r.jsx(Zl,{...h??{},sections:s,selectedThreadId:y,Row:ie,keyboard:v,onSelectThread:p}):A??(P?r.jsx(eg,{sections:s,selectedThreadId:y,selectionMode:he,checkedIds:W,initialPeek:N,onToggleCheck:U=>ne?.(U),onEnterSelection:U=>ne?.(U),onOpenThread:U=>p?.(U),onRefresh:G,refreshing:I}):r.jsx("div",{ref:L,className:"flex-1 overflow-y-auto",children:s.map(U=>r.jsxs("div",{children:[!a&&U.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:U.label}),r.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:U.threads.length})]}),r.jsx("div",{className:"divide-y divide-line",children:U.threads.map(_=>r.jsx(M,{thread:_,active:_.id===y,focused:_.id===O,tabIndex:T(_.id),selection:te(_.id),onClick:ue=>{ce(_.id,ue)||p?.(_.id)}},_.id))})]},U.id))})),b&&r.jsx(Yc,{hints:v?Ep(v.handlers):uo}),R]})}function ho({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 y=p=>{h.current&&!h.current.contains(p.target)&&f(!1)},g=p=>{p.key==="Escape"&&f(!1)};return document.addEventListener("mousedown",y),document.addEventListener("keydown",g),()=>{document.removeEventListener("mousedown",y),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(oe,{variant:"ghost",size:"sm",icon:t??r.jsx(_c,{className:"size-5"}),onClick:()=>f(y=>!y),"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(y=>r.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{f(!1),y.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:[y.icon&&r.jsx("span",{className:"shrink-0 text-fg-subtle",children:y.icon}),y.label]},y.key)),m]})]})}const Gs="min-h-11 min-w-11 px-0";function ou({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:y}){const g=(x,b)=>()=>{if(!e){f?.(x);return}b?.()},p=u?[{key:"toggle-read",label:c?"Mark as unread":"Mark as read",icon:c?r.jsx(vc,{className:"size-4"}):r.jsx(gr,{className:"size-4"}),onSelect:g("toggleRead",u)}]:[];return r.jsxs("div",{className:Q("relative",y),children:[r.jsxs("div",{className:"flex h-12 shrink-0 items-center gap-0.5 bg-canvas px-1",children:[t&&r.jsx(oe,{variant:"ghost",size:"sm",icon:r.jsx(Kc,{className:"size-5"}),onClick:g("reply",t),"aria-label":"Reply",title:"Reply",className:Gs}),s&&r.jsx(oe,{variant:"ghost",size:"sm",icon:r.jsx(Uc,{className:"size-5"}),onClick:g("replyAll",s),"aria-label":"Reply all",title:"Reply all",className:Gs}),n&&r.jsx(oe,{variant:"ghost",size:"sm",icon:r.jsx(zc,{className:"size-5"}),onClick:g("forward",n),"aria-label":"Forward",title:"Forward",className:Gs}),r.jsx("div",{className:"flex-1"}),o&&r.jsx(oe,{variant:"ghost",size:"sm",icon:r.jsx(Xt,{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:Gs}),m,i&&r.jsx(oe,{variant:"ghost",size:"sm",icon:r.jsx(Lt,{className:"size-5"}),onClick:g("delete",i),"aria-label":"Move to Trash",title:"Move to Trash",className:Gs}),r.jsx(ho,{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 sg({open:e=!1,enabled:t=!0,onToggle:s,className:n}){return r.jsx(oe,{variant:"ghost",size:"sm",icon:r.jsx(ec,{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 ng({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:y="Reply all (a)",forwardTitle:g="Forward (f)",deleteTitle:p="Move to Trash (#)",flagTitle:x="Star (s)",children:b,className:S}){const w=(v,k)=>()=>{if(!e){t?.(v);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(oe,{variant:"ghost",size:"sm",icon:r.jsx(Kc,{className:"size-4"}),title:h,"aria-label":"Reply",onClick:w("reply",o)}),r.jsx(oe,{variant:"ghost",size:"sm",icon:r.jsx(Uc,{className:"size-4"}),title:y,"aria-label":"Reply all",onClick:w("replyAll",i)}),r.jsx(oe,{variant:"ghost",size:"sm",icon:r.jsx(zc,{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(oe,{variant:"ghost",size:"sm",icon:r.jsx(Lt,{className:"size-4"}),title:p,"aria-label":"Move to Trash",onClick:w("delete",u)}),d??r.jsx(oe,{variant:"ghost",size:"sm",icon:r.jsx(Da,{className:"size-4"}),title:"Move to mailbox","aria-label":"Move to mailbox",onClick:w("move",f)}),r.jsx(oe,{variant:"ghost",size:"sm",icon:r.jsx(Xt,{className:Q("size-4",n&&"fill-warning text-warning")}),title:x,"aria-label":"Star",onClick:w("flag",m)})]}),r.jsx("div",{className:"flex-1"}),b]}),!e&&s&&r.jsx("p",{role:"status",className:"border-b border-line bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:s})]})}const rg=(e,t)=>{const n=e==="newsletter"||e==="marketing"||t;return{framed:n,isPlain:!n}},ag=()=>`
|
|
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
|
+
`,og=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,""))},ig=/^(none|transparent|inherit|initial|unset)\s*$/i,lg=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},cg=e=>{const t=/background(?:-color)?\s*:\s*([^;}\n]+)/gi;let s;for(s=t.exec(e);s!==null;){const n=s[1].trim();if(!ig.test(n))return!0;s=t.exec(e)}return!1},ug=e=>{if(/\bstyle\s*=\s*["'][^"']*background/i.test(e)||/\bbgcolor\s*=/i.test(e))return!0;for(const t of lg(e))if(cg(t))return!0;return!1},dg=["script","iframe","object","embed","form","input","button","textarea","select","meta","link","base"],fg=["onerror","onload","onclick","onmouseover","onmouseout","onfocus","onblur","onsubmit","onkeydown","onkeyup","formaction","xlink:href","data-bind"],mg="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
|
+
`),hg=e=>e.replace(/url\s*\([^)]*\)/gi,"none").replace(/expression\s*\([^)]*\)/gi,"").replace(/-moz-binding\s*:[^;]*/gi,""),pg=e=>e.replace(/@import[^;]*;/gi,"/* @import blocked */").replace(/url\s*\([^)]*\)/gi,"none").replace(/expression\s*\([^)]*\)/gi,"").replace(/-moz-binding\s*:[^;]*/gi,""),gg=(e={})=>{const t=tc(),s={FORBID_TAGS:dg,FORBID_ATTR:fg,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",mg),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",hg(a))}}),t.addHook("uponSanitizeElement",(n,a)=>{if(a.tagName==="style"){const o=n.textContent||"";n.textContent=pg(o)}}),n=>{const a=ug(n),o=t.sanitize(n,s);return{html:`<style>${ag()}</style>${o}`,hasAuthorBackground:a}}},xg='"Geist Variable", "Geist", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',wi={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)"}},bg=/prefers-color-scheme\s*:\s*dark|color-scheme\s*:\s*[^;}"']*\bdark\b/i,Si='<meta name="viewport" content="width=device-width, initial-scale=1">',vg=e=>{const t=e?wi.dark:wi.light;return`
|
|
54
|
+
/* Plain-email base: UI font-stack + theme-aware colors (#424) */
|
|
55
|
+
html, body {
|
|
56
|
+
font-family: ${xg};
|
|
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
|
+
`},yg=(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}",wg=(e,t,s)=>{if(t==="plain")return`${Si}<style>${vg(s)}</style>${e}`;const n=bg.test(e);return`${Si}<style>${yg(s,n)}</style>${e}`},Sg=5e4,kg=1e4,Cg="(max-width: 640px)",jg=.4,Ng="allow-same-origin allow-popups allow-popups-to-escape-sandbox",ki=(e,t,s)=>Math.min(Math.ceil(Math.max(e,t)),s),Eg=(e,t)=>e<=0||t<=0||e<=t?1:Math.max(jg,t/e),Ig=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},Rg=new Set(["Enter","Escape","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End"]),Tg=e=>e===" "?!1:e.length===1?!0:Rg.has(e),Ci=e=>{if(e.metaKey||e.ctrlKey||e.altKey||!Tg(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}))},ji=({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=Ig(Cg),y=l.useMemo(()=>wg(e,t,s),[e,t,s]);l.useEffect(()=>{const w=a.current;if(!w)return;const v=()=>f(R=>R===w.clientWidth?R:w.clientWidth);v();const k=new ResizeObserver(v);return k.observe(w),()=>k.disconnect()},[]),l.useEffect(()=>{const w=o.current;if(!w)return;const v=()=>{const C=w.contentDocument;if(!C?.body)return;const M=C.documentElement,L=ki(C.body.scrollHeight,M?.scrollHeight??0,Sg);c(F=>F===L?F:L);const E=ki(C.body.scrollWidth,M?.scrollWidth??0,kg);m(F=>F===E?F:E)};let k,R;const A=()=>{v();const C=w.contentDocument;C?.body&&(k=new ResizeObserver(v),k.observe(C.body),C.documentElement&&k.observe(C.documentElement),C.addEventListener("keydown",Ci),R=C)};return w.addEventListener("load",A),()=>{w.removeEventListener("load",A),R?.removeEventListener("keydown",Ci),k?.disconnect()}},[]);const g=h?Eg(u,d):1,p=g<1,x=p?`${u}px`:h?"100%":t==="framed"&&u>0?`max(100%, ${u}px)`:u===0?"100%":`${u}px`,b=i===0?"1px":`${i}px`,S=r.jsx("iframe",{ref:o,title:"Email content",sandbox:Ng,srcDoc:y,className:p?void 0:n,scrolling:"no",style:{width:x,maxWidth:p?"none":void 0,border:"none",display:"block",height:b,overflow:"hidden",transform:p?`scale(${g})`:void 0,transformOrigin:p?"top left":void 0,colorScheme:"normal"}});return r.jsx("div",{ref:a,className:p?n:void 0,children:p?r.jsx("div",{style:{width:"100%",height:`${Math.ceil(i*g)}px`,overflow:"hidden"},children:S}):S})},Ni=()=>r.jsx("p",{className:"text-fg-muted text-sm italic",children:"This message has no body content."}),iu=({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:gg({allowExternalImages:a,resolveCid:o})(e),[e,a,o]),m=u?.html??null,{framed:d,isPlain:f}=rg(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(Ni,{})}):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(ji,{html:m,variant:"framed",isDark:s})}):r.jsx("div",{className:"max-w-full overflow-x-auto lg:max-w-2xl",children:r.jsx(ji,{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(Ni,{})]})};function zs({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(Pa,{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 lu({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(jt,{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=>{Hf(c)&&(c.preventDefault(),t())},className:Q(i,"cursor-pointer"),children:o}):r.jsx("div",{className:i,children:o})}function cu({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(Qt,{className:"mt-1 size-3.5 shrink-0 text-fg-subtle"}),r.jsx(jt,{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($s,{className:"mt-0.5 size-4 shrink-0 text-danger"}),r.jsxs("div",{className:"text-sm text-fg",children:[r.jsx("span",{className:"font-semibold text-danger",children:"Caution: "}),t," ",r.jsx("button",{type:"button",className:"text-accent underline",children:"Why?"})]})]}),m&&r.jsx("div",{className:"mt-3 -mx-2 lg:-mx-4",children:m}),r.jsx("div",{className:"-mx-2 [&_.message-body-notice]:px-2 lg:mx-0 lg:[&_.message-body-notice]:px-0",children:d??r.jsx(iu,{className:"mt-3",html:e.bodyHtml,category:e.framed?"newsletter":"personal",allowImages:!0})})]})}function Mg({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,y=()=>{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(oe,{variant:"ghost",size:"sm",icon:r.jsx(La,{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(oe,{variant:"ghost",size:"sm",icon:r.jsx(ec,{className:"size-4"}),onClick:y,"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 x=b=>b?()=>b(p.id):void 0;return p.expanded?r.jsx(cu,{message:p,warning:e.warning,onHeaderClick:x(o?.onToggleExpand),actionBar:r.jsx(ou,{hasThread:!0,onReply:x(o?.onReply),onReplyAll:x(o?.onReplyAll),onForward:x(o?.onForward),onToggleStar:x(o?.onToggleStar),onDelete:x(o?.onDelete),onToggleRead:x(o?.onToggleRead),moveSlot:o?.moveSlot?.(p.id)})},p.id):r.jsx(lu,{message:p,onClick:x(o?.onToggleExpand)},p.id)})}),s&&!d&&r.jsx(Wf,{open:f,onClose:g,title:"Intelligence",anchor:"right",className:"p-0",children:r.jsx(Hc,{data:s,onClose:g,className:"h-full w-full border-l-0"})})]})}const Ag="button:not([disabled]), a[href]",us="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",us,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 Dg({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 rn({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(Dg,{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 Ei={inbox:0,flagged:1,drafts:2,sent:3,archive:4,all:5,junk:6,trash:7};function Pg(e){switch(e){case"inbox":return r.jsx(Pa,{className:"size-4"});case"flagged":return r.jsx(Xt,{className:"size-4"});case"drafts":return r.jsx(sc,{className:"size-4"});case"sent":return r.jsx(hn,{className:"size-4"});case"archive":return r.jsx(Yf,{className:"size-4"});case"all":return r.jsx(Gf,{className:"size-4"});case"junk":return r.jsx(Qf,{className:"size-4"});case"trash":return r.jsx(Lt,{className:"size-4"})}}const Ii=e=>e.role!=null,qr=8,Ri="remit.nav.folders.open.",Ti="remit.nav.account.open.";function Mi(e,t,s){if(typeof localStorage>"u")return s;const n=localStorage.getItem(e+t);return n===null?s:n!=="0"}function Ai(e,t,s){typeof localStorage>"u"||localStorage.setItem(e+t,s?"1":"0")}function Lg({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",us),children:[r.jsx(rr,{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",us),children:r.jsx(Nt,{className:"size-3.5"})})]})}function Fg({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",us),children:[r.jsx(fp,{className:"size-4 shrink-0"}),r.jsxs("span",{className:"min-w-0 flex-1 truncate",children:["Save “",t,"”"]})]}),e.map(o=>r.jsx(Lg,{query:o,onSelect:()=>s?.(o),onRemove:n?()=>n(o):void 0},o))]})}function $g({account:e,selectedNavId:t,onSelectNav:s,linkComponent:n}){const[a,o]=l.useState(()=>Mi(Ti,e.id,!0)),[i,c]=l.useState(()=>Mi(Ri,e.id,!0)),[u,m]=l.useState(!1),d=()=>{o(S=>{const w=!S;return Ai(Ti,e.id,w),w})},f=()=>{c(S=>{const w=!S;return Ai(Ri,e.id,w),w})},h=e.mailboxes.filter(Ii).sort((S,w)=>Ei[S.role]-Ei[w.role]),y=e.mailboxes.filter(S=>!Ii(S)),g=u||y.length<=qr?y:y.slice(0,qr),p=y.length-g.length,x=e.status??"ready",b=x==="ready"&&h.length===0&&y.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",us,e.muted&&"opacity-55"),children:[a?r.jsx(Qt,{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(Lc,{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:[x==="loading"&&r.jsx("div",{className:"px-2 py-1 text-sm text-fg-muted",children:"Loading…"}),x==="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(Pt,{className:"mt-0.5 size-4 shrink-0 text-danger","aria-hidden":"true"}),r.jsx("div",{className:"min-w-0 flex-1",children:r.jsx("p",{className:"font-medium text-danger",children:"Couldn't load mailboxes"})}),e.onRetry&&r.jsx("button",{type:"button",onClick:e.onRetry,className:"shrink-0 text-sm font-medium text-accent hover:underline",children:"Retry"})]}),b&&r.jsx("div",{className:"px-2 py-1 text-sm text-fg-muted",children:"No mailboxes"}),x==="ready"&&r.jsxs(r.Fragment,{children:[h.map(S=>r.jsx(rn,{navId:S.id,linkComponent:n,icon:Pg(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(rn,{navId:"outbox",linkComponent:n,icon:r.jsx(hn,{className:"size-4"}),label:"Outbox",ariaLabel:"Outbox",count:e.outboxPending>0?e.outboxPending:void 0,active:t==="outbox",dimmed:e.muted,onClick:()=>s?.("outbox")}),y.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",us),children:[i?r.jsx(Qt,{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:y.length})]}),i&&r.jsxs(r.Fragment,{children:[g.map(S=>r.jsx(rn,{navId:S.id,linkComponent:n,icon:r.jsx(Vf,{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)&&y.length>qr&&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",us),children:u?"Show less":`Show all (${y.length})`})]})]})]})]})]})}function _g({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);nr({containerRef:f,itemSelector:Ag});const h=a==="drawer",y=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(rn,{navId:"brief",linkComponent:o,icon:r.jsx(Dt,{className:"size-4"}),label:"Daily brief",ariaLabel:"Daily brief",count:s,active:t==="brief",onClick:()=>n?.("brief")}),r.jsx(rn,{navId:"flagged",linkComponent:o,icon:r.jsx(Xt,{className:"size-4"}),label:"Starred",ariaLabel:"Starred",active:t==="flagged",onClick:()=>n?.("flagged")}),r.jsx(Fg,{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($g,{account:g,selectedNavId:t,onSelectNav:n,linkComponent:o},g.id))]});return h?y:r.jsx("aside",{ref:f,className:"flex h-full w-full flex-col bg-surface-sunken",children:y})}function zg({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})]})}const Bg=/[\u0000-\u001f\u007f-\u009f\u061c\u200b-\u200f\u2028\u2029\u202a-\u202e\u2066-\u2069\ufeff]/g,Ug=/[<>:"|?*]/g,Kg=/^(con|prn|aux|nul|com[1-9]|lpt[1-9])(\.|$)/i,Oi=120,qg=12,Hg="attachment",Di=e=>{const t=[...e];if(t.length<=Oi)return e;const s=e.lastIndexOf("."),n=s>0&&[...e.slice(s)].length<=qg?e.slice(s):"",a=Oi-[...n].length;return t.slice(0,a).join("")+n},Wg=(e,t=Hg)=>{const n=e.replace(Bg,"").split(/[/\\]/),o=(n[n.length-1]??"").replace(Ug,"_").replace(/^[.\s]+/,"").replace(/[.\s]+$/,"");if(o.length===0)return Di(t);const i=Kg.test(o)?`_${o}`:o;return Di(i)},Pi=["KB","MB","GB","TB"],Vg=e=>{if(!Number.isFinite(e)||e<0)return"unknown size";const t=Math.round(e);if(t<1024)return t===1?"1 byte":`${t} bytes`;const s=1023.95;let n=t/1024,a=0;for(;n>=s&&a<Pi.length-1;)n/=1024,a+=1;return`${n.toFixed(1).replace(/\.0$/,"")} ${Pi[a]}`};function Qg({state:e,onRetry:t}){return r.jsxs("div",{role:"alert","data-testid":"attachment-error",className:"flex items-start gap-2 border-t border-danger/30 bg-danger-soft px-2 py-2 text-xs",children:[r.jsx(Pt,{className:"mt-0.5 size-3.5 shrink-0 text-danger","aria-hidden":!0}),r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsx("p",{className:"font-medium text-danger",children:e.title}),r.jsx("p",{className:"mt-0.5 text-fg-muted",children:e.detail})]}),r.jsxs("div",{className:"flex shrink-0 items-center gap-3",children:[r.jsx("button",{type:"button",onClick:t,className:"font-medium text-accent hover:underline",children:"Try again"}),e.reportUrl&&r.jsx("a",{href:e.reportUrl,target:"_blank",rel:"noreferrer",className:"font-medium text-accent hover:underline",children:"Report this"})]})]})}function Gg({attachments:e,onDownload:t,hasUnlistedAttachment:s=!1,className:n}){return e.length===0&&!s?null:r.jsxs("section",{"aria-label":"Attachments","data-testid":"attachment-list",className:Q("space-y-1.5",n),children:[r.jsxs("h3",{className:"flex items-center gap-1.5 text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:[r.jsx(xr,{className:"size-3","aria-hidden":!0}),e.length===0?"Attachment":e.length===1?"1 attachment":`${e.length} attachments`]}),e.length>0&&r.jsx("ul",{className:"overflow-hidden rounded-sm border border-line bg-surface",children:e.map(a=>{const o=a.download.status==="downloading";return r.jsxs("li",{className:"border-t border-line first:border-t-0",children:[r.jsxs("button",{type:"button",onClick:()=>t(a.attachmentId),disabled:o,"data-testid":"attachment-download","aria-label":`Download ${a.filename}`,className:"flex w-full items-center gap-2 px-2 py-2 text-left transition-colors hover:bg-surface-sunken disabled:cursor-progress disabled:opacity-60",children:[r.jsxs("span",{className:"min-w-0 flex-1",children:[r.jsx("bdi",{className:"block truncate text-sm text-fg",title:a.filename,children:a.filename}),r.jsxs("span",{className:"block truncate text-2xs text-fg-subtle",children:[a.typeLabel," ·"," ",Vg(a.sizeOctets)]})]}),o?r.jsx(hs,{className:"size-4 shrink-0 animate-spin text-fg-subtle","aria-hidden":!0}):r.jsx(Eh,{className:"size-4 shrink-0 text-fg-subtle","aria-hidden":!0})]}),a.download.status==="failed"&&r.jsx(Qg,{state:a.download,onRetry:()=>t(a.attachmentId)})]},a.attachmentId)})}),s&&r.jsx("p",{role:"alert","data-testid":"attachment-unlisted",className:"rounded-sm border border-line bg-surface px-2 py-2 text-xs text-fg-muted",children:"The mail server says this message carries an attachment, but none of its parts describe one. Re-sync the account from Settings; if the attachment still does not appear, the message is worth reporting."})]})}function Yg({label:e,onUndo:t,undoLabel:s="Undo",filtersHref:n,className:a}){return r.jsxs(Ct,{tone:"accent",className:Q("py-1 text-xs",a),children:[r.jsx(vp,{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 Xg({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(hs,{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:Jg(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(Dt,{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 Jg({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 Zg="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",Li="pointer-events-none absolute inset-0 m-auto size-3.5 text-accent-fg";function po({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:Zg,...i}),r.jsx(mn,{className:Q(Li,"hidden peer-checked:block"),"aria-hidden":!0}),r.jsx(pp,{className:Q(Li,"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 ex=({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 tx({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(oe,{variant:"primary",size:"md","aria-busy":s,title:n?void 0:o,className:"min-h-11 rounded-full px-4",icon:s?r.jsx(hs,{className:"size-4 animate-spin"}):r.jsx(hn,{className:"size-4"}),onClick:()=>{if(!s){if(!n){o&&i?.(o);return}e()}},children:"Send"}),r.jsx(ex,{status:a})]}),r.jsx(oe,{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(Lt,{className:"size-4"}),onClick:()=>{s||t()}})]})}function sx({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:"flex min-h-0 flex-1 flex-col overflow-auto","data-testid":"compose-body-area",children:[s,n&&r.jsx("div",{className:"shrink-0 px-3 pb-2",children:n})]}),a]})}function nx({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 rx({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 ax(e,t){const s=t-1;return s<=0?null:e<s?e:s-1}const ox=e=>e instanceof HTMLElement?e.tagName==="INPUT"||e.tagName==="TEXTAREA"||e.isContentEditable:!1,ix=({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 y=l.useId(),g=d??y,p=l.useRef(null),x=l.useRef([]),b=o??a,[S,w]=l.useState(null),v=l.useRef(void 0),[k,R]=l.useState(""),A=e.length>0;l.useEffect(()=>{w(T=>T!==null&&T>=e.length?null:T)},[e.length]),l.useEffect(()=>{const T=v.current;if(T!==void 0){if(v.current=void 0,T===null){p.current?.focus();return}x.current[T]?.focus()}});const C=l.useRef(void 0);l.useEffect(()=>{const T=f?.caret;if(!T||T===C.current)return;C.current=T;const P=p.current;!P||P.ownerDocument.activeElement!==P||(P.setSelectionRange(T.cursor,T.cursor),f?.onCaretChange(T.cursor))});const M=T=>{f?.onCaretChange(T.selectionStart??T.value.length)},L=l.useCallback(T=>{w(T),v.current=T},[]),E=l.useCallback(T=>{const P=e[T];P&&t&&(L(ax(T,e.length)),R(`${P.label} removed`),t(P.id))},[e,t,L]),F=l.useCallback(()=>{L(null),a()},[a,L]),O=l.useCallback(T=>{const P=T.currentTarget;if(f?.onKeyDown(T))return;const I=nx({key:T.key,shiftKey:T.shiftKey,repeat:T.repeat,caretAtStart:P.selectionStart===0&&P.selectionEnd===0,hasValue:s.length>0,chipCount:e.length});switch(I.type){case"focusChip":T.preventDefault(),L(I.index);return;case"clearQuery":b();return;case"blur":P.blur();return;case"none":return}},[e.length,s,b,L,f]),j=l.useCallback(T=>P=>{const I=rx({key:P.key,repeat:P.repeat,index:T,chipCount:e.length});switch(I.type!=="none"&&P.preventDefault(),I.type){case"removeChip":E(I.index);return;case"focusChip":L(I.index);return;case"focusInput":L(null);return;case"activateChip":return;case"none":return}},[e,E,L]);return l.useEffect(()=>{if(!c)return;const T=P=>{P.key!=="/"||P.metaKey||P.ctrlKey||P.altKey||ox(P.target)||(P.preventDefault(),p.current?.focus())};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[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(rr,{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((T,P)=>r.jsx(Xf,{ref:I=>{x.current[P]=I},label:T.label,tone:T.tone,focused:S===P,onFocusLabel:()=>w(P),onKeyDown:j(P),onRemove:()=>E(P)},T.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:T=>{n(T.target.value),M(T.target)},onKeyDown:O,onKeyUp:T=>M(T.currentTarget),onClick:T=>M(T.currentTarget),onFocus:T=>{w(null),f?.onFocusChange?.(!0),M(T.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(Nt,{className:Q("text-fg-muted",m==="lg"?"size-5":"size-4")})}),r.jsx("span",{role:"status","aria-live":"polite",className:"sr-only",children:k})]})},go=({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(ix,{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 lx(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 cx({result:e,onClick:t,query:s,showFolder:n=!0}){const a=n&&e.folder?Jf(e.folder):void 0;return r.jsx("button",{type:"button",onClick:t,className:Q("group",_s({}),"border-b border-line"),children:r.jsx(mo,{thread:lx(e),highlightQuery:s,badge:r.jsxs(r.Fragment,{children:[a&&r.jsx(Ct,{tone:"neutral",className:"shrink-0",children:a}),e.category&&r.jsx(Ct,{tone:e.category.tone??"neutral",className:"shrink-0",children:e.category.label}),e.matchedChunkLabel&&r.jsx(Ct,{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 ux=e=>e===1?"result":"results";function uu({count:e,onScopeToSpam:t}){return r.jsx(pn,{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})," ",`${ux(e)} from Spam`]}),r.jsx(oe,{variant:"ghost",size:"sm",onClick:t,className:"shrink-0 text-accent",children:"Go to Spam"})]})})}const Fi=6,dx={kind:"global"},fx=e=>e.kind==="folder"&&e.role==="junk",mx=e=>e.folder?.role==="junk";function xo(e){const t=[],s=[];for(const n of e)mx(n)?s.push(n):t.push(n);return{kept:t,spam:s}}function du({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(Zf,{className:"size-3.5 shrink-0","aria-hidden":"true"}),r.jsx("span",{children:"Make this a filter"})]}),t&&r.jsx(em,{id:s,reason:t,nudged:n,className:"px-2 pt-1 text-2xs text-warning"})]})}function hx({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>Fi,d=!i&&u?e.results.slice(0,Fi):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(Qt,{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(cx,{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(Qt,{className:"ml-1 size-3"})]})]})]})}function fu({value:e,recentSearches:t,onPickRecent:s,sections:n,loading:a,onSelectResult:o,tokens:i,scope:c=dx,makeFilter:u}){if(!(e.trim().length>0))return t&&t.length>0?r.jsxs("div",{className:"flex flex-col",children:[r.jsx("h3",{className:"px-row-inset pb-1 pt-3 text-2xs font-semibold uppercase tracking-wide text-fg-subtle",children:"Recent searches"}),t.map(v=>r.jsxs("button",{type:"button",onClick:()=>s?.(v),className:"flex w-full items-center gap-2.5 border-b border-line px-row-inset py-2.5 text-left transition-colors hover:bg-surface-sunken",children:[r.jsx(eo,{className:"size-4 shrink-0 text-fg-subtle"}),r.jsx("span",{className:"min-w-0 flex-1 truncate text-sm text-fg-muted",children:v})]},v))]}):r.jsx("p",{className:"px-row-inset py-6 text-center text-sm text-fg-subtle",children:"Search across your mail by sender, subject or words in the message."});const d=i&&i.length>0&&r.jsx(tm,{tokens:i}),f=u&&r.jsx(du,{...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(v=>r.jsxs("div",{className:"flex flex-col gap-1.5",children:[r.jsx("div",{className:"h-3 w-1/3 animate-pulse rounded bg-surface-sunken"}),r.jsx("div",{className:"h-3 w-2/3 animate-pulse rounded bg-surface-sunken"}),r.jsx("div",{className:"h-2.5 w-1/2 animate-pulse rounded bg-surface-sunken"})]},v))})]});const h=c.kind==="global",y=fx(c)||c.kind==="collection",g=h||c.kind==="collection",p=(n??[]).map(v=>{if(y)return{section:v,spam:[]};const{kept:k,spam:R}=xo(v.results);return{section:{...v,results:k},spam:R}}),x=p.map(v=>v.section),b=p.reduce((v,k)=>v+k.spam.length,0),S=c.kind==="global"&&b>0&&c.onScopeToSpam!==void 0?r.jsx(uu,{count:b,onScopeToSpam:c.onScopeToSpam}):void 0;return x.some(v=>v.results.length>0)?r.jsxs("div",{className:"flex flex-col",children:[f,d,S,x.filter(v=>v.results.length>0).map(v=>r.jsx(hx,{section:v,query:e,showFolder:g,onSelectResult:o},v.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 px({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:y,makeFilter:g,suggest:p,suggestList:x}){const b=r.jsx(fu,{value:e,recentSearches:o,onPickRecent:i,sections:c,loading:u,onSelectResult:m,tokens:d,scope:y,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(go,{value:e,onChange:t,onClear:s,chips:f,onRemoveChip:h,globalFocusKey:!1,showClearButton:!1,suggest:p})}),r.jsx(oe,{variant:"ghost",size:"sm",icon:r.jsx(Nt,{className:"size-4"}),onClick:n,"aria-label":"Clear and close search",className:"-mr-1 shrink-0"})]}),x,a&&e.trim().length===0?r.jsx(sm,{children:r.jsx(nc,{...a,children:b})}):r.jsx("div",{className:"flex-1 overflow-y-auto",children:b})]})}function gx(){const e=ps();if(!e)return null;const t=e.showNavPane?!e.navCollapsed:!1;return r.jsx(oe,{variant:"ghost",size:"sm",icon:r.jsx(fr,{className:"size-4"}),onClick:e.toggleNav,"aria-label":t?"Hide folders":"Show folders","aria-expanded":t,title:"Folders",className:"shrink-0"})}const xx={queued:{icon:eo,label:"Queued",className:"text-warning"},sending:{icon:hs,label:"Sending…",className:"text-accent-2",spin:!0},sent:{icon:lo,label:"Sent",className:"text-positive"},failed:{icon:Pt,label:"Failed",className:"text-danger"},blocked:{icon:Fa,label:"Blocked",className:"text-warning"}};function $i({status:e,iconOnly:t,className:s}){const n=xx[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 bx=(e,t)=>t?"bg-accent-2-soft":e==="failed"?"bg-danger-soft":e==="blocked"?"bg-warning/10":"";function vx({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",bx(n,o)),children:[r.jsxs("button",{type:"button",...Jl,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($i,{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($i,{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(hh,{actions:[...n==="failed"&&c?[{label:"Retry sending",iconOnly:!0,icon:r.jsx(fh,{className:"size-3.5"}),busy:u,onClick:c}]:[],{label:"Edit as draft",iconOnly:!0,icon:r.jsx(hn,{className:"size-3.5"}),onClick:m}],destructive:{label:"Delete message",iconOnly:!0,icon:r.jsx(Lt,{className:"size-3.5"}),busy:f,confirm:{prompt:"Delete this message?",confirmLabel:"Delete"},onClick:d}})})]})}const yx=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},wx=({children:e,onRefresh:t,isRefreshing:s})=>yx(yc)?e:r.jsx(nm,{onRefresh:t,isPullable:!s,children:e}),Sx=({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(Qt,{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))})]})};function bo({state:e,onRefresh:t,label:s,errorMessage:n,hasUpdate:a,size:o="sm",className:i}){const c=e==="refreshing",u=e==="error",m=e==="success",d=u?r.jsx(Pt,{className:"size-4 text-danger"}):m?r.jsx(lo,{className:"size-4 text-positive"}):r.jsx(co,{className:Q("size-4",c&&"animate-spin")}),f=u?`${s} — failed: ${n??"try again"}`:c?`${s} — refreshing`:m?`${s} — up to date`:a?`${s} — new mail`:s;return r.jsxs("div",{className:"relative inline-flex",children:[r.jsx(oe,{variant:"ghost",size:o,icon:d,onClick:t,disabled:c,"aria-label":f,"aria-busy":c||void 0,title:u?n:s,className:i}),e==="idle"&&a&&r.jsx("span",{"aria-hidden":"true",className:"absolute right-1 top-1 size-1.5 rounded-full bg-accent-2"})]})}const kx=e=>e===1?"message":"messages";function Cx({count:e,onReview:t,onDismiss:s,actionLabel:n="Review & rescue"}){return r.jsx(pn,{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} ${kx(e)} here`})," ","may not be spam — they're from senders we can verify."]})]}),r.jsx(oe,{variant:"primary",size:"sm",onClick:t,className:"self-start",children:n})]})})}const jx=(e,t)=>e==="vip"?"vip":e==="unknown"&&t==="md"?"unknown-pill":"hidden",mu=({senderTrust:e,size:t="sm",className:s})=>{const n=jx(e,t);return n==="vip"?r.jsx(Dt,{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 Nx({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(po,{className:"mt-0.5",checked:t,onChange:s,"aria-label":`${t?"Deselect":"Select"} ${n?i:`message from ${a}`}`}),!n&&r.jsx(jt,{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(mu,{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(Ct,{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 Ex=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)},Ix=(e,t)=>{const s=e.messages.filter(n=>t.has(n.id)).length;return s===0?"none":s===e.messages.length?"all":"some"},_i=e=>e===1?"message":"messages";function Rx({group:e,selected:t,onToggleGroup:s,onToggleMessage:n}){const[a,o]=l.useState(!1),i=Ix(e,t),c=e.messages.length,u=a?Qt: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(po,{className:"mt-0.5",checked:i==="all",indeterminate:i==="some",onChange:()=>s(e,i!=="all"),"aria-label":`${i==="all"?"Deselect":"Select"} all ${c} ${_i(c)} from ${e.senderName}`}),r.jsx(jt,{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(mu,{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(Ct,{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} ${_i(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(Nx,{candidate:m,selected:t.has(m.id),onToggle:()=>n(m.id),hideSender:!0},m.id))})]})}const vo=e=>e===1?"message":"messages",Tx=(e,t)=>`Moves ${e===1?"this message":`these ${e} ${vo(e)}`} out of Spam to ${t} now. Nothing later.`,va=(e,t)=>e.find(s=>s.id===t)?.label??"Inbox";function Mx(){return r.jsx(pn,{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 Ax({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(()=>Ex(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(oe,{variant:"ghost",size:"sm",icon:r.jsx(dh,{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(Mx,{})})]}),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(oe,{variant:"ghost",size:"sm",onClick:a,children:"Select all"}),r.jsx(oe,{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(Rx,{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(oe,{variant:"primary",onClick:i,className:"h-11 w-full font-semibold",children:`Continue with ${d} ${vo(d)}`}),r.jsx(oe,{variant:"ghost",onClick:c,className:"h-11 w-full",children:"Cancel"})]})]})}function Ox({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(rc,{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:va(t,n)}),r.jsx(oe,{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:Tx(e,va(t,n))}),r.jsx(oe,{variant:"primary",onClick:o,className:"h-11 w-full font-semibold",children:`Move ${e} out of Spam`}),r.jsx(oe,{variant:"ghost",onClick:i,className:"h-11 w-full",children:"Back"})]})]})}function Dx({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(Ih,{className:"size-10 text-positive","aria-hidden":!0}),r.jsx("p",{className:"text-base font-semibold text-fg",children:`Moved ${e} ${vo(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(oe,{variant:"primary",onClick:s,className:"h-11 w-full font-semibold",children:"Done"})})]})}function Px({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(v=>v.id)):new Set),[f,h]=l.useState(s),[y,g]=l.useState(0),p=l.useRef(!1);l.useEffect(()=>{e&&!p.current&&(u("review"),d(new Set(t.map(v=>v.id))),h(s),g(0)),p.current=e},[e,t,s]);const x=m.size,b=v=>{d(k=>{const R=new Set(k);return R.has(v)?R.delete(v):R.add(v),R})},S=(v,k)=>{d(R=>{const A=new Set(R);for(const C of v.messages)k?A.add(C.id):A.delete(C.id);return A})},w=()=>{const v=Array.from(m);g(v.length),o(v,f),u("done")};return r.jsxs(gh,{open:e,onClose:i,dismissLabel:"Close rescue",children:[c==="review"&&r.jsx(Ax,{candidates:t,selected:m,onToggle:b,onToggleGroup:S,onSelectAll:()=>d(new Set(t.map(v=>v.id))),onSelectNone:()=>d(new Set),onContinue:()=>u("destination"),onCancel:i}),c==="destination"&&r.jsx(Ox,{count:x,folders:n,delimiter:a,destination:f,onPick:h,onMove:w,onBack:()=>u("review")}),c==="done"&&r.jsx(Dx,{count:y,destinationLabel:va(n,f),onClose:i})]})}const Lx={html:"",text:""},zi=e=>e.toLocaleString();function Bi({selectAll:e,selecting:t,className:s}){return r.jsx(po,{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 yo({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:y,isBusy:g=!1,isCounting:p=!1,selectAll:x,statusLabel:b,progress:S,notice:w}){const v=t>0||p,k=x?.checked?`All ${zi(t)} loaded selected`:`${zi(t)} ${t===1?"message":"messages"} selected`,R=[];return i&&!g&&!p&&R.push({key:"junk",label:"Junk",icon:r.jsx($s,{className:"size-4"}),onSelect:i}),c&&!g&&!p&&R.push({key:"mark-read",label:"Mark read",icon:r.jsx(gr,{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:[v?r.jsx(oe,{variant:"ghost",size:"touch",icon:r.jsx(La,{className:"size-5"}),onClick:s,"aria-label":"Cancel selection",className:"-ml-2 shrink-0"}):u,x&&r.jsx(Bi,{selectAll:x,selecting:v,className:"hidden shrink-0 pr-2 md:flex"}),v?r.jsx("span",{"data-selection-count":"",className:"min-w-0 flex-1 truncate px-1 text-sm font-medium text-fg",role:"status","aria-live":"polite",children:b??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]}),v&&!p&&r.jsxs(r.Fragment,{children:[r.jsx(oe,{variant:"ghost",size:"touch",icon:g?r.jsx(hs,{className:"size-5 animate-spin"}):r.jsx(Lt,{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(oe,{variant:"ghost",size:"touch",icon:r.jsx(Da,{className:"size-5"}),onClick:a,"aria-label":"Move selected messages",className:"shrink-0"}),!g&&o&&r.jsx(oe,{variant:"ghost",size:"touch",icon:r.jsx(Dt,{className:"size-5"}),onClick:o,"aria-label":"Organize selected messages",className:"shrink-0"})]}),v&&r.jsx(ho,{triggerLabel:"More actions",items:R,className:"shrink-0",children:!g&&!p&&y})]}),!v&&h,v&&x&&r.jsx("div",{"data-selection-bar-row":"select-all",className:"px-row-inset pb-2 md:hidden",children:r.jsx(Bi,{selectAll:x,selecting:v,className:"w-full"})}),S&&r.jsx("div",{className:"px-row-inset pb-2",children:r.jsx(rm,{value:S.value,max:S.max,tone:S.tone})}),w&&r.jsx(pn,{"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(oe,{variant:"ghost",size:"md",onClick:w.action.onClick,className:"-my-1 min-h-11 shrink-0",children:w.action.label})]})})]})}const Fx={global:"Search all mail",pending:"Search mail",scoped:"Search this folder"};function $x({search:e,onCompose:t,onReportBug:s,onOpenSettings:n,composeShortcut:a,refreshControl:o,account:i}){return r.jsx(zg,{leading:r.jsx(gx,{}),search:r.jsx(go,{value:e.value,onChange:e.onChange,onClear:e.onClear,onClearQuery:e.onClearQuery,chips:e.chips,onRemoveChip:e.onRemoveChip,placeholder:Fx[e.scope]}),actions:r.jsxs(r.Fragment,{children:[r.jsx(oe,{variant:"ghost",size:"sm",icon:r.jsx(bp,{className:"size-4"}),title:a?`Compose (${a})`:"Compose","aria-label":"Compose",onClick:t}),r.jsx(oe,{variant:"ghost",size:"sm",icon:r.jsx(Fc,{className:"size-4"}),title:"Report a bug","aria-label":"Report a bug",onClick:s}),r.jsx(oe,{variant:"ghost",size:"sm",icon:r.jsx(qc,{className:"size-4"}),title:"Settings","aria-label":"Settings",onClick:n}),o,i]})})}const wo=[{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"}],hu={id:"unread",label:"Unread"},_x={id:"flagged",label:"Starred"},pu={id:"attachment",label:"Has attachment"};function zx(e){if(!(e.length<=1))return e.map(t=>({id:t.id,label:t.label,count:t.count,active:t.active}))}function Bx(e=[]){return{categories:[...wo],filters:am,sources:zx(e)}}function gu(){return{categories:[...wo],filters:[hu,_x,pu]}}function Ux(){return{categories:[...wo],filters:[hu,pu]}}const Kx=["p","br","div","h1","h2","h3","h4","h5","h6","strong","b","em","i","u","s","ul","ol","li","blockquote","pre","code","hr","table","thead","tbody","tr","th","td","a","img"],qx=["href","src","alt","colspan","rowspan"],Hx=/^(?:https?:|mailto:)/i,Wx=/^(?:https:|data:image\/)/i,Vx=e=>{const t=tc();if(!t.isSupported)throw new Error("adopted HTML cannot be sanitized: no DOM is available");return t.addHook("afterSanitizeAttributes",s=>{if(s.tagName==="A"){Hx.test(s.getAttribute("href")??"")||s.removeAttribute("href"),e==="quoted"&&(s.setAttribute("target","_blank"),s.setAttribute("rel","noopener noreferrer nofollow"));return}if(s.tagName==="IMG"){if(e==="quoted"){s.remove();return}Wx.test(s.getAttribute("src")??"")||s.remove()}}),t},Ui=new Map,Qx=e=>{const t=Ui.get(e);if(t)return t;const s=Vx(e);return Ui.set(e,s),s},xu=(e,t)=>Qx(t).sanitize(e,{ALLOWED_TAGS:Kx,ALLOWED_ATTR:qx,ALLOW_DATA_ATTR:!1,ALLOW_ARIA_ATTR:!1}),TN=e=>xu(e,"outgoing"),Gx=e=>xu(e,"quoted");function Yx(e,t){return e.endsWith(t)?e.length===t.length||e[e.length-t.length-1]===".":!1}function Xx(e,t){const s=e.length-t.length-2,n=e.lastIndexOf(".",s);return n===-1?e:e.slice(n+1)}function Jx(e,t,s){if(s.validHosts!==null){const a=s.validHosts;for(const o of a)if(Yx(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:Xx(t,e)}const Hr=/[\t\n\r]/g;let ya=!1;function Ki(e){return e>=97&&e<=122||e>=48&&e<=57||e>127||e>=65&&e<=90||e===45||e===95}function qi(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 an(e,t,s=!1){let n=0,a=e.length,o=!1,i=!1;if(ya=!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 x=e.indexOf(":/",n);if(x!==-1){const b=qi(e,n,x);if(b===1)for(i=!0,n=x+2;e.charCodeAt(n)===47||e.charCodeAt(n)===92;)n+=1;else if(b===2){i=!0,n=x+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<x;S+=1){const w=e.charCodeAt(S)|32;if(!(w>=97&&w<=122||w>=48&&w<=57||w===46||w===45||w===43)){const v=e.charCodeAt(S);return v===9||v===10||v===13?an(e.replace(Hr,""),t,s):null}}if(e.charCodeAt(x+2)===47)n=x+3;else return null}}else if(e.charCodeAt(n)!==91){let b=-1;for(let S=n;S<a;S+=1){const w=e.charCodeAt(S);if(w===9||w===10||w===13)return an(e.replace(Hr,""),t,s);if(w===58){b=S;break}if(w===47||w===92||w===63||w===35)break}if(b!==-1){let S=!1;for(let w=b+1;w<a;w+=1){const v=e.charCodeAt(w);if(v===47||v===92||v===63||v===35)break;if(v===64){S=!0;break}}if(!S){let w=!0,v=b+1;for(;v<a;v+=1){const k=e.charCodeAt(v);if(k===47||k===92||k===63||k===35)break;if(k<48||k>57){w=!1;break}}if(v===b+1&&(w=!1),!w){const k=qi(e,n,b);if(k===0){let R=!1;for(let A=b+1;A<a;A+=1){const C=e.charCodeAt(A);if(C===47||C===92||C===63||C===35)break;if(C===58){R=!0;break}}if(!R)return null}else if(i=!0,n=b+1,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,y=s,g=n-1,p=-1;if(s&&n<a){const x=e.charCodeAt(n);(!(Ki(x)||x===46||x===95)||x===45)&&(y=!1)}for(let x=n;x<a;x+=1){const b=e.charCodeAt(x);if(b<64)if(b===47||b===35||b===63){a=x;break}else b===58?(f===-1&&(f=x),d=x):b===9||b===10||b===13?h=!0:s&&(b===46?((x-g>64||p===46||p===45)&&(y=!1),g=x):(b<48||b>57)&&(b!==45||p===46)&&(y=!1));else if(i&&b===92){a=x;break}else b===64?(u=x,f=-1):b===93?m=x:b>=65&&b<=90?o=!0:s&&!Ki(b)&&(y=!1);s&&(p=b)}if(h)return an(e.replace(Hr,""),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&&y&&u===-1&&d===-1&&m===-1&&e.charCodeAt(a-1)!==46&&a-n<=255&&a-g-1<=63&&p!==45&&(ya=!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 Zx(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 eb(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 tb(e){return eb(e)||Zx(e)}function Hi(e){return e>=97&&e<=122||e>=48&&e<=57||e>127}function Wi(e){if(e.length>255||e.length===0||!Hi(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(!(Hi(o)||o===45||o===95)||o===45&&s===46)return!1;s=o}return n-t-1<=63&&s!==45}function sb({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 nb=sb({});function rb(e){return nb}function ab(){return{domain:null,domainWithoutSuffix:null,hostname:null,isIcann:null,isIp:null,isPrivate:null,isSpecialUse:null,publicSuffix:null,subdomain:null}}function ob(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 ib(e,t,s,n,a){const o=rb();if(typeof e!="string")return a;let i=!1;return o.extractHostname?o.mixedInputs?(i=Wi(e),a.hostname=an(e,i,o.validateHostname)):a.hostname=an(e,!1,o.validateHostname):a.hostname=e,o.detectIp&&a.hostname!==null&&(a.isIp=tb(a.hostname),a.isIp)?a:o.validateHostname&&o.extractHostname&&a.hostname!==null&&!(i&&a.hostname===e)&&!ya&&!Wi(a.hostname)?(a.hostname=null,a):(a.hostname===null||(s(a.hostname,o,a),a.publicSuffix===null)||(a.domain=Jx(a.publicSuffix,a.hostname,o)),a)}const Vi=ab();function lb(e,t){return ob(Vi),ib(e,3,om,t,Vi).domain}const br=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},cb=e=>{const t=e.lastIndexOf("@");return t>=0?e.slice(t+1):e},bu=e=>lb(cb(e.trim())),ub=e=>{const t=br(e);if(t.length<2)return null;let s=null;for(const n of t){const a=bu(n);if(a===null)return null;if(s===null)s=a;else if(s!==a)return null}return s},vr=e=>{const t=ub(e);return t!==null?[{field:"FromDomain",value:t}]:br(e).map(s=>({field:"From",value:s}))},db=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},vu=e=>e.displayName?.trim()||e.normalizedEmail,fb=/^\s*(?:(?:re|aw|fwd?|vs|sv|antw|res|enc|tr)\s*(?:\[\d+\])?\s*:|\[[^\]]{1,32}\])\s*/i,mb=e=>{let t=e.replace(/\s+/g," ").trim();for(;;){const s=t.replace(fb,"");if(s===t)return t.trim();t=s}},hb=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"]),pb=3,Wr=e=>e.split(" ").filter(t=>t!==""),Qi=e=>e.length===0||e.join(" ").length<pb?!1:e.some(t=>!hb.has(t.toLowerCase())),gb=(e,t)=>e.findIndex((s,n)=>t.every((a,o)=>e[n+o]?.toLowerCase()===a.toLowerCase())),xb=e=>{const t=e.map(mb).filter(o=>o!=="");if(t.length===0)return;const[s,...n]=t;if(n.length===0)return Qi(Wr(s))?s:void 0;const a=Wr(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(Qi(c)&&n.every(u=>gb(Wr(u),c)>=0))return c.join(" ")}},bb=(e,t)=>{const s=vr(e);if(br(e).length===1||s.length===1&&s[0].field==="FromDomain")return s;const n=xb(t);return n!==void 0?[{field:"Subject",value:n}]:s},vb=({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}`:""},yb=e=>e.clauses.length>0,wb=e=>({scopedOutFolder:e.scopedOut?.label,droppedFacets:e.droppedFacets.map(t=>t.label),droppedSemantic:e.droppedSemantic}),Sb=({orderedIds:e,isDesktop:t,initialFocusedId:s,initialSelectedIds:n,onExitSelection:a})=>{const[o,i]=l.useState(s),[c,u]=l.useState(),m=l.useCallback(I=>{u(D=>D===I?D:void 0),i(I)},[]),d=Gc({initialSelectedIds:n}),{selectedCount:f,toggle:h,clearSelection:y,selectRange:g,setAnchor:p,selectAll:x}=d,b=fo(f,t),S=l.useRef(null),w=l.useRef(!1),v=l.useCallback(()=>{a?.(),y()},[y,a]),k=l.useMemo(()=>o?e.indexOf(o):-1,[e,o]),R=l.useCallback(I=>{if(I<0||I>=e.length)return;const D=e[I];if(b){h(D);return}S.current=D,w.current=!1,u(D),i(D)},[e,b,h]),A=l.useCallback(()=>{e.length!==0&&R(k<0?0:Math.min(k+1,e.length-1))},[e.length,k,R]),C=l.useCallback(()=>{e.length!==0&&R(k<=0?0:k-1)},[e.length,k,R]),M=l.useCallback(()=>R(0),[R]),L=l.useCallback(()=>R(e.length-1),[R,e.length]),E=l.useCallback(()=>{o&&h(o)},[o,h]),F=l.useCallback((I,D)=>{const N=Rp(D);return N==="range"?(g(e,I,o),!0):N==="toggle"?(h(I),!0):(v(),p(I),!1)},[e,o,g,h,v,p]),O=l.useCallback(I=>{const D=Qc(e,o,I);D!==void 0&&(g(e,D),S.current=D,w.current=!1,u(void 0),i(D))},[e,o,g]),j=l.useCallback(()=>O(-1),[O]),T=l.useCallback(()=>O(1),[O]),P=l.useCallback(()=>{e.length>0&&x(e)},[e,x]);return{focusedMessageId:o,setFocusedMessageId:m,keyboardFocusedMessageId:c,focusIndex:k,pendingDomFocusRef:S,cursorMovedByPointerRef:w,selection:d,isMultiSelectMode:b,exitSelection:v,moveFocusToIndex:R,focusNext:A,focusPrevious:C,focusFirst:M,focusLast:L,toggleFocusedSelection:E,extendRangeUp:j,extendRangeDown:T,selectAllLoaded:P,handleRowSelect:F}};function kb({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=Kp({key:d.key,shiftKey:d.shiftKey,metaKey:d.metaKey,ctrlKey:d.ctrlKey,altKey:d.altKey,inEditable:qp(d.target),onControl:Wp(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 Vt(e,t,{checkForDefaultPrevented:s=!0}={}){return function(a){if(e?.(a),s===!1||!a||!a.defaultPrevented)return t?.(a)}}function Gi(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Cb(...e){return t=>{let s=!1;const n=e.map(a=>{const o=Gi(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():Gi(e[a],null)}}}}function gs(...e){return l.useCallback(Cb(...e),e)}function jb(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:y,...g}=f,p=h?.[e]?.[u]||c,x=l.useMemo(()=>g,Object.values(g));return r.jsx(p.Provider,{value:x,children:y})};m.displayName=o+"Provider";function d(f,h,y={}){const{optional:g=!1}=y,p=h?.[e]?.[u]||c,x=l.useContext(p);if(x)return x;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,Nb(a,...t)]}function Nb(...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 un=globalThis?.document?l.useLayoutEffect:()=>{},Eb=$a[" useInsertionEffect ".trim().toString()]||un;function Ib({prop:e,defaultProp:t,onChange:s=()=>{},caller:n}){const[a,o,i]=Rb({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=Tb(d)?d(e):d;f!==e&&i.current?.(f)}else o(d)},[c,e,o,i]);return[u,m]}function Rb({defaultProp:e,onChange:t}){const[s,n]=l.useState(e),a=l.useRef(s),o=l.useRef(t);return Eb(()=>{o.current=t},[t]),l.useEffect(()=>{a.current!==s&&(o.current?.(s),a.current=s)},[s,a]),[s,n,o]}function Tb(e){return typeof e=="function"}function yu(e){const t=l.forwardRef((s,n)=>{let{children:a,...o}=s,i=null,c=!1;const u=[];Yi(a)&&typeof In=="function"&&(a=In(a._payload)),l.Children.forEach(a,h=>{if(Pb(h)){c=!0;const y=h;let g="child"in y.props?y.props.child:y.props.children;Yi(g)&&typeof In=="function"&&(g=In(g._payload)),i=Ab(y,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?Db(i):void 0,d=gs(n,m);if(!i){if(a||a===0)throw new Error(c?_b(e):$b(e));return a}const f=Ob(o,i.props??{});return i.type!==l.Fragment&&(f.ref=n?d:m),l.cloneElement(i,f)});return t.displayName=`${e}.Slot`,t}var Mb=Symbol.for("radix.slottable"),Ab=(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 Ob(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 Db(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 Pb(e){return l.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===Mb}var Lb=Symbol.for("react.lazy");function Yi(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===Lb&&"_payload"in e&&Fb(e._payload)}function Fb(e){return typeof e=="object"&&e!==null&&"then"in e}var $b=e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,_b=e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,In=$a[" use ".trim().toString()],zb=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],_t=zb.reduce((e,t)=>{const s=yu(`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 Bb(e,t){e&&_a.flushSync(()=>e.dispatchEvent(t))}function dn(e){const t=l.useRef(e);return l.useEffect(()=>{t.current=e}),l.useMemo(()=>((...s)=>t.current?.(...s)),[])}var Ub="DismissableLayer",wa="dismissableLayer.update",Kb="dismissableLayer.pointerDownOutside",qb="dismissableLayer.focusOutside",Xi,So=l.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),wu=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(So),[f,h]=l.useState(null),y=f?.ownerDocument??globalThis?.document,[,g]=l.useState({}),p=gs(t,h),x=Array.from(d.layers),[b]=[...d.layersWithOutsidePointerEventsDisabled].slice(-1),S=b?x.indexOf(b):-1,w=f?x.indexOf(f):-1,v=d.layersWithOutsidePointerEventsDisabled.size>0,k=w>=S,R=l.useRef(!1),A=Gb(E=>{o?.(E),c?.(E),E.defaultPrevented||u?.()},{ownerDocument:y,deferPointerDownOutside:n,isDeferredPointerDownOutsideRef:R,dismissableSurfaces:d.dismissableSurfaces,shouldHandlePointerDownOutside:l.useCallback(E=>{if(!(E instanceof Node))return!1;const F=[...d.branches].some(O=>O.contains(E));return k&&!F},[d.branches,k])}),C=Yb(E=>{if(n&&R.current)return;const F=E.target;[...d.branches].some(j=>j.contains(F))||(i?.(E),c?.(E),E.defaultPrevented||u?.())},y),M=f?w===x.length-1:!1,L=dn(E=>{E.key==="Escape"&&(a?.(E),!E.defaultPrevented&&u&&(E.preventDefault(),u()))});return l.useEffect(()=>{if(M)return y.addEventListener("keydown",L,{capture:!0}),()=>y.removeEventListener("keydown",L,{capture:!0})},[y,M,L]),l.useEffect(()=>{if(f)return s&&(d.layersWithOutsidePointerEventsDisabled.size===0&&(Xi=y.body.style.pointerEvents,y.body.style.pointerEvents="none"),d.layersWithOutsidePointerEventsDisabled.add(f)),d.layers.add(f),Ji(),()=>{s&&(d.layersWithOutsidePointerEventsDisabled.delete(f),d.layersWithOutsidePointerEventsDisabled.size===0&&(y.body.style.pointerEvents=Xi))}},[f,y,s,d]),l.useEffect(()=>()=>{f&&(d.layers.delete(f),d.layersWithOutsidePointerEventsDisabled.delete(f),Ji())},[f,d]),l.useEffect(()=>{const E=()=>g({});return document.addEventListener(wa,E),()=>document.removeEventListener(wa,E)},[]),r.jsx(_t.div,{...m,ref:p,style:{pointerEvents:v?k?"auto":"none":void 0,...e.style},onFocusCapture:Vt(e.onFocusCapture,C.onFocusCapture),onBlurCapture:Vt(e.onBlurCapture,C.onBlurCapture),onPointerDownCapture:Vt(e.onPointerDownCapture,A.onPointerDownCapture)})});wu.displayName=Ub;var Hb="DismissableLayerBranch",Wb=l.forwardRef((e,t)=>{const s=l.useContext(So),n=l.useRef(null),a=gs(t,n);return l.useEffect(()=>{const o=n.current;if(o)return s.branches.add(o),()=>{s.branches.delete(o)}},[s.branches]),r.jsx(_t.div,{...e,ref:a})});Wb.displayName=Hb;function Vb(){const e=l.useContext(So),[t,s]=l.useState(null);return l.useEffect(()=>{if(t)return e.dismissableSurfaces.add(t),()=>{e.dismissableSurfaces.delete(t)}},[t,e.dismissableSurfaces]),s}var Qb=()=>!0;function Gb(e,t){const{ownerDocument:s=globalThis?.document,deferPointerDownOutside:n=!1,isDeferredPointerDownOutsideRef:a,dismissableSurfaces:o,shouldHandlePointerDownOutside:i=Qb}=t,c=dn(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 y(){return Array.from(d.current.values()).some(Boolean)}function g(w){if(!m.current)return;const v=w.target;v instanceof Node&&[...o].some(R=>R.contains(v))||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 x=w=>{if(w.target&&!u.current){let v=function(){s.removeEventListener("click",f.current);const R=y();h(),R||Su(Kb,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?v():(s.removeEventListener("click",f.current),f.current=v,s.addEventListener("click",f.current,{once:!0}))}else s.removeEventListener("click",f.current),h();u.current=!1},b=["pointerup","mousedown","mouseup","touchstart","touchend","click"];for(const w of b)s.addEventListener(w,g,!0),s.addEventListener(w,p);const S=window.setTimeout(()=>{s.addEventListener("pointerdown",x)},0);return()=>{window.clearTimeout(S),s.removeEventListener("pointerdown",x),s.removeEventListener("click",f.current);for(const w of b)s.removeEventListener(w,g,!0),s.removeEventListener(w,p)}},[s,c,n,a,o,i]),{onPointerDownCapture:()=>u.current=!0}}function Yb(e,t=globalThis?.document){const s=dn(e),n=l.useRef(!1);return l.useEffect(()=>{const a=o=>{o.target&&!n.current&&Su(qb,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 Ji(){const e=new CustomEvent(wa);document.dispatchEvent(e)}function Su(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?Bb(a,o):a.dispatchEvent(o)}var Rn=0,Ss=null;function Xb(){l.useEffect(()=>{Ss||(Ss={start:Zi(),end:Zi()});const{start:e,end:t}=Ss;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==t&&document.body.insertAdjacentElement("beforeend",t),Rn++,()=>{Rn===1&&(Ss?.start.remove(),Ss?.end.remove(),Ss=null),Rn=Math.max(0,Rn-1)}},[])}function Zi(){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 Vr="focusScope.autoFocusOnMount",Qr="focusScope.autoFocusOnUnmount",el={bubbles:!1,cancelable:!0},Jb="FocusScope",ku=l.forwardRef((e,t)=>{const{loop:s=!1,trapped:n=!1,onMountAutoFocus:a,onUnmountAutoFocus:o,...i}=e,[c,u]=l.useState(null),m=dn(a),d=dn(o),f=l.useRef(null),h=gs(t,u),y=l.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;l.useEffect(()=>{if(n){let p=function(w){if(y.paused||!c)return;const v=w.target;c.contains(v)?f.current=v:Ut(f.current,{select:!0})},x=function(w){if(y.paused||!c)return;const v=w.relatedTarget;v!==null&&(c.contains(v)||Ut(f.current,{select:!0}))},b=function(w){if(document.activeElement===document.body)for(const k of w)k.removedNodes.length>0&&Ut(c)};document.addEventListener("focusin",p),document.addEventListener("focusout",x);const S=new MutationObserver(b);return c&&S.observe(c,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",p),document.removeEventListener("focusout",x),S.disconnect()}}},[n,c,y.paused]),l.useEffect(()=>{if(c){sl.add(y);const p=document.activeElement;if(!c.contains(p)){const b=new CustomEvent(Vr,el);c.addEventListener(Vr,m),c.dispatchEvent(b),b.defaultPrevented||(Zb(rv(Cu(c)),{select:!0}),document.activeElement===p&&Ut(c))}return()=>{c.removeEventListener(Vr,m),setTimeout(()=>{const b=new CustomEvent(Qr,el);c.addEventListener(Qr,d),c.dispatchEvent(b),b.defaultPrevented||Ut(p??document.body,{select:!0}),c.removeEventListener(Qr,d),sl.remove(y)},0)}}},[c,m,d,y]);const g=l.useCallback(p=>{if(!s&&!n||y.paused)return;const x=p.key==="Tab"&&!p.altKey&&!p.ctrlKey&&!p.metaKey,b=document.activeElement;if(x&&b){const S=p.currentTarget,[w,v]=ev(S);w&&v?!p.shiftKey&&b===v?(p.preventDefault(),s&&Ut(w,{select:!0})):p.shiftKey&&b===w&&(p.preventDefault(),s&&Ut(v,{select:!0})):b===S&&p.preventDefault()}},[s,n,y.paused]);return r.jsx(_t.div,{tabIndex:-1,...i,ref:h,onKeyDown:g})});ku.displayName=Jb;function Zb(e,{select:t=!1}={}){const s=document.activeElement;for(const n of e)if(Ut(n,{select:t}),document.activeElement!==s)return}function ev(e){const t=Cu(e),s=tl(t,e),n=tl(t.reverse(),e);return[s,n]}function Cu(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 tl(e,t){const s=typeof t.checkVisibility=="function"&&t.checkVisibility({checkVisibilityCSS:!0});for(const n of e)if(!(s?!n.checkVisibility({checkVisibilityCSS:!0}):tv(n,{upTo:t})))return n}function tv(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 sv(e){return e instanceof HTMLInputElement&&"select"in e}function Ut(e,{select:t=!1}={}){if(e&&e.focus){const s=document.activeElement;e.focus({preventScroll:!0}),e!==s&&sv(e)&&t&&e.select()}}var sl=nv();function nv(){let e=[];return{add(t){const s=e[0];t!==s&&s?.pause(),e=nl(e,t),e.unshift(t)},remove(t){e=nl(e,t),e[0]?.resume()}}}function nl(e,t){const s=[...e],n=s.indexOf(t);return n!==-1&&s.splice(n,1),s}function rv(e){return e.filter(t=>t.tagName!=="A")}var av=$a[" useId ".trim().toString()]||(()=>{}),ov=0;function Gr(e){const[t,s]=l.useState(av());return un(()=>{s(n=>n??String(ov++))},[e]),e||(t?`radix-${t}`:"")}var iv="Portal",ju=l.forwardRef((e,t)=>{const{container:s,...n}=e,[a,o]=l.useState(!1);un(()=>o(!0),[]);const i=s||a&&globalThis?.document?.body;return i?_a.createPortal(r.jsx(_t.div,{...n,ref:t}),i):null});ju.displayName=iv;function lv(e,t){return l.useReducer((s,n)=>t[s][n]??s,e)}var yr=e=>{const{present:t,children:s}=e,n=cv(t),a=typeof s=="function"?s({present:n.isPresent}):l.Children.only(s),o=uv(n.ref,dv(a));return typeof s=="function"||n.isPresent?l.cloneElement(a,{ref:o}):null};yr.displayName="Presence";function cv(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]=lv(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??Ys(n.current),i.current=void 0):o.current="none"},[u]),un(()=>{const d=n.current,f=a.current;if(f!==e){const y=o.current,g=Ys(d);e?(i.current=g,m("MOUNT")):g==="none"||d?.display==="none"?m("UNMOUNT"):m(f&&y!==g?"ANIMATION_OUT":"UNMOUNT"),a.current=e}},[e,m]),un(()=>{if(t){let d;const f=t.ownerDocument.defaultView??window,h=g=>{const x=Ys(n.current).includes(CSS.escape(g.animationName));if(g.target===t&&x&&(m("ANIMATION_END"),!a.current)){const b=t.style.animationFillMode;t.style.animationFillMode="forwards",d=f.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=b)})}},y=g=>{g.target===t&&(o.current=Ys(n.current))};return t.addEventListener("animationstart",y),t.addEventListener("animationcancel",h),t.addEventListener("animationend",h),()=>{f.clearTimeout(d),t.removeEventListener("animationstart",y),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=Ys(f)}else n.current=null;s(d)},[])}}function rl(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function uv(...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=rl(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():rl(n[i],null)}}},[])}function Ys(e){return e?.animationName||"none"}function dv(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 fv=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},ks=new WeakMap,Tn=new WeakMap,Mn={},Yr=0,Nu=function(e){return e&&(e.host||Nu(e.parentNode))},mv=function(e,t){return t.map(function(s){if(e.contains(s))return s;var n=Nu(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})},hv=function(e,t,s,n){var a=mv(t,Array.isArray(e)?e:[e]);Mn[s]||(Mn[s]=new WeakMap);var o=Mn[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 y=h.getAttribute(n),g=y!==null&&y!=="false",p=(ks.get(h)||0)+1,x=(o.get(h)||0)+1;ks.set(h,p),o.set(h,x),i.push(h),p===1&&g&&Tn.set(h,!0),x===1&&h.setAttribute(s,"true"),g||h.setAttribute(n,"true")}catch(b){console.error("aria-hidden: cannot operate on ",h,b)}})};return d(t),c.clear(),Yr++,function(){i.forEach(function(f){var h=ks.get(f)-1,y=o.get(f)-1;ks.set(f,h),o.set(f,y),h||(Tn.has(f)||f.removeAttribute(n),Tn.delete(f)),y||f.removeAttribute(s)}),Yr--,Yr||(ks=new WeakMap,ks=new WeakMap,Tn=new WeakMap,Mn={})}},pv=function(e,t,s){s===void 0&&(s="data-aria-hidden");var n=Array.from(Array.isArray(e)?e:[e]),a=fv(e);return a?(n.push.apply(n,Array.from(a.querySelectorAll("[aria-live], script"))),hv(n,a,s,"aria-hidden")):function(){return null}},zn="right-scroll-bar-position",Bn="width-before-scroll-bar",gv="with-scroll-bars-hidden",xv="--removed-body-scroll-bar-size";function Xr(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function bv(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 vv=typeof window<"u"?l.useLayoutEffect:l.useEffect,al=new WeakMap;function yv(e,t){var s=bv(null,function(n){return e.forEach(function(a){return Xr(a,n)})});return vv(function(){var n=al.get(s);if(n){var a=new Set(n),o=new Set(e),i=s.current;a.forEach(function(c){o.has(c)||Xr(c,null)}),o.forEach(function(c){a.has(c)||Xr(c,i)})}al.set(s,e)},[e]),s}function wv(e){return e}function Sv(e,t){t===void 0&&(t=wv);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 kv(e){e===void 0&&(e={});var t=Sv(null);return t.options=Kt({async:!0,ssr:!1},e),t}var Eu=function(e){var t=e.sideCar,s=ac(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,Kt({},s))};Eu.isSideCarExport=!0;function Cv(e,t){return e.useMedium(t),Eu}var Iu=kv(),Jr=function(){},wr=l.forwardRef(function(e,t){var s=l.useRef(null),n=l.useState({onScrollCapture:Jr,onWheelCapture:Jr,onTouchMoveCapture:Jr}),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,y=e.noRelative,g=e.noIsolation,p=e.inert,x=e.allowPinchZoom,b=e.as,S=b===void 0?"div":b,w=e.gapMode,v=ac(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),k=h,R=yv([s,t]),A=Kt(Kt({},v),a);return l.createElement(l.Fragment,null,d&&l.createElement(k,{sideCar:Iu,removeScrollBar:m,shards:f,noRelative:y,noIsolation:g,inert:p,setCallbacks:o,allowPinchZoom:!!x,lockRef:s,gapMode:w}),i?l.cloneElement(l.Children.only(c),Kt(Kt({},A),{ref:R})):l.createElement(S,Kt({},A,{className:u,ref:R}),c))});wr.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};wr.classNames={fullWidth:Bn,zeroRight:zn};var jv=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Nv(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=jv();return t&&e.setAttribute("nonce",t),e}function Ev(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Iv(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Rv=function(){var e=0,t=null;return{add:function(s){e==0&&(t=Nv())&&(Ev(t,s),Iv(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Tv=function(){var e=Rv();return function(t,s){l.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&s])}},Ru=function(){var e=Tv(),t=function(s){var n=s.styles,a=s.dynamic;return e(n,a),null};return t},Mv={left:0,top:0,right:0,gap:0},Zr=function(e){return parseInt(e||"",10)||0},Av=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[Zr(s),Zr(n),Zr(a)]},Ov=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Mv;var t=Av(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])}},Dv=Ru(),Ts="data-scroll-locked",Pv=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(gv,` {
|
|
77
|
+
overflow: hidden `).concat(n,`;
|
|
78
|
+
padding-right: `).concat(c,"px ").concat(n,`;
|
|
79
|
+
}
|
|
80
|
+
body[`).concat(Ts,`] {
|
|
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(zn,` {
|
|
94
|
+
right: `).concat(c,"px ").concat(n,`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.`).concat(Bn,` {
|
|
98
|
+
margin-right: `).concat(c,"px ").concat(n,`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.`).concat(zn," .").concat(zn,` {
|
|
102
|
+
right: 0 `).concat(n,`;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.`).concat(Bn," .").concat(Bn,` {
|
|
106
|
+
margin-right: 0 `).concat(n,`;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
body[`).concat(Ts,`] {
|
|
110
|
+
`).concat(xv,": ").concat(c,`px;
|
|
111
|
+
}
|
|
112
|
+
`)},ol=function(){var e=parseInt(document.body.getAttribute(Ts)||"0",10);return isFinite(e)?e:0},Lv=function(){l.useEffect(function(){return document.body.setAttribute(Ts,(ol()+1).toString()),function(){var e=ol()-1;e<=0?document.body.removeAttribute(Ts):document.body.setAttribute(Ts,e.toString())}},[])},Fv=function(e){var t=e.noRelative,s=e.noImportant,n=e.gapMode,a=n===void 0?"margin":n;Lv();var o=l.useMemo(function(){return Ov(a)},[a]);return l.createElement(Dv,{styles:Pv(o,!t,a,s?"":"!important")})},Sa=!1;if(typeof window<"u")try{var An=Object.defineProperty({},"passive",{get:function(){return Sa=!0,!0}});window.addEventListener("test",An,An),window.removeEventListener("test",An,An)}catch{Sa=!1}var Cs=Sa?{passive:!1}:!1,$v=function(e){return e.tagName==="TEXTAREA"},Tu=function(e,t){if(!(e instanceof Element))return!1;var s=window.getComputedStyle(e);return s[t]!=="hidden"&&!(s.overflowY===s.overflowX&&!$v(e)&&s[t]==="visible")},_v=function(e){return Tu(e,"overflowY")},zv=function(e){return Tu(e,"overflowX")},il=function(e,t){var s=t.ownerDocument,n=t;do{typeof ShadowRoot<"u"&&n instanceof ShadowRoot&&(n=n.host);var a=Mu(e,n);if(a){var o=Au(e,n),i=o[1],c=o[2];if(i>c)return!0}n=n.parentNode}while(n&&n!==s.body);return!1},Bv=function(e){var t=e.scrollTop,s=e.scrollHeight,n=e.clientHeight;return[t,s,n]},Uv=function(e){var t=e.scrollLeft,s=e.scrollWidth,n=e.clientWidth;return[t,s,n]},Mu=function(e,t){return e==="v"?_v(t):zv(t)},Au=function(e,t){return e==="v"?Bv(t):Uv(t)},Kv=function(e,t){return e==="h"&&t==="rtl"?-1:1},qv=function(e,t,s,n,a){var o=Kv(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 y=Au(e,c),g=y[0],p=y[1],x=y[2],b=p-x-o*g;(g||b)&&Mu(e,c)&&(f+=b,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},On=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},ll=function(e){return[e.deltaX,e.deltaY]},cl=function(e){return e&&"current"in e?e.current:e},Hv=function(e,t){return e[0]===t[0]&&e[1]===t[1]},Wv=function(e){return`
|
|
113
|
+
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
114
|
+
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
115
|
+
`)},Vv=0,js=[];function Qv(e){var t=l.useRef([]),s=l.useRef([0,0]),n=l.useRef(),a=l.useState(Vv++)[0],o=l.useState(Ru)[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=im([e.lockRef.current],(e.shards||[]).map(cl),!0).filter(Boolean);return p.forEach(function(x){return x.classList.add("allow-interactivity-".concat(a))}),function(){document.body.classList.remove("block-interactivity-".concat(a)),p.forEach(function(x){return x.classList.remove("allow-interactivity-".concat(a))})}}},[e.inert,e.lockRef.current,e.shards]);var c=l.useCallback(function(p,x){if("touches"in p&&p.touches.length===2||p.type==="wheel"&&p.ctrlKey)return!i.current.allowPinchZoom;var b=On(p),S=s.current,w="deltaX"in p?p.deltaX:S[0]-b[0],v="deltaY"in p?p.deltaY:S[1]-b[1],k,R=p.target,A=Math.abs(w)>Math.abs(v)?"h":"v";if("touches"in p&&A==="h"&&R.type==="range")return!1;var C=window.getSelection(),M=C&&C.anchorNode,L=M?M===R||M.contains(R):!1;if(L)return!1;var E=il(A,R);if(!E)return!0;if(E?k=A:(k=A==="v"?"h":"v",E=il(A,R)),!E)return!1;if(!n.current&&"changedTouches"in p&&(w||v)&&(n.current=k),!k)return!0;var F=n.current||k;return qv(F,x,p,F==="h"?w:v)},[]),u=l.useCallback(function(p){var x=p;if(!(!js.length||js[js.length-1]!==o)){var b="deltaY"in x?ll(x):On(x),S=t.current.filter(function(k){return k.name===x.type&&(k.target===x.target||x.target===k.shadowParent)&&Hv(k.delta,b)})[0];if(S&&S.should){x.cancelable&&x.preventDefault();return}if(!S){var w=(i.current.shards||[]).map(cl).filter(Boolean).filter(function(k){return k.contains(x.target)}),v=w.length>0?c(x,w[0]):!i.current.noIsolation;v&&x.cancelable&&x.preventDefault()}}},[]),m=l.useCallback(function(p,x,b,S){var w={name:p,delta:x,target:b,should:S,shadowParent:Gv(b)};t.current.push(w),setTimeout(function(){t.current=t.current.filter(function(v){return v!==w})},1)},[]),d=l.useCallback(function(p){s.current=On(p),n.current=void 0},[]),f=l.useCallback(function(p){m(p.type,ll(p),p.target,c(p,e.lockRef.current))},[]),h=l.useCallback(function(p){m(p.type,On(p),p.target,c(p,e.lockRef.current))},[]);l.useEffect(function(){return js.push(o),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:h}),document.addEventListener("wheel",u,Cs),document.addEventListener("touchmove",u,Cs),document.addEventListener("touchstart",d,Cs),function(){js=js.filter(function(p){return p!==o}),document.removeEventListener("wheel",u,Cs),document.removeEventListener("touchmove",u,Cs),document.removeEventListener("touchstart",d,Cs)}},[]);var y=e.removeScrollBar,g=e.inert;return l.createElement(l.Fragment,null,g?l.createElement(o,{styles:Wv(a)}):null,y?l.createElement(Fv,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Gv(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const Yv=Cv(Iu,Qv);var Ou=l.forwardRef(function(e,t){return l.createElement(wr,Kt({},e,{ref:t,sideCar:Yv}))});Ou.classNames=wr.classNames;var Xv=class extends za{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:cm(t,s.data),hasPreviousPage:lm(t,s.data),isFetchNextPageError:m,isFetchingNextPage:d,isFetchPreviousPageError:f,isFetchingPreviousPage:h,isRefetchError:c&&!m&&!f,isRefetching:o&&!d&&!h}}};function ul(e,t){const s=new Set(t);return e.filter(n=>!s.has(n))}function Jv(e,t,s){const n=e.slice(0);return n[t]=s,n}var Zv=class extends um{#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,da.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||!dm(d,h)});!u&&!m||(u&&(this.#c=n,this.#t=a),this.#e=o,this.hasListeners()&&(u&&(ul(s,a).forEach(d=>{d.destroy()}),ul(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=fm(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 za(this.#s,a);s.push({defaultedQueryOptions:a,observer:i})}),s}#m(e,t){const s=this.#t.indexOf(e);s!==-1&&(this.#e=Jv(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)&&da.batch(()=>{this.listeners.forEach(a=>{a(this.#e)})})}}};function mt({queries:e,...t},s){const n=Ee(),a=mm(),o=hm(),i=l.useMemo(()=>e.map(p=>{const x=n.defaultQueryOptions(p);return x._optimisticResults=a?"isRestoring":"optimistic",x}),[e,n,a]);i.forEach(p=>{pm(p);const x=n.getQueryCache().get(p.queryHash);gm(p,o,x)}),xm(o);const[c]=l.useState(()=>new Zv(n,i,t)),[u,m,d]=c.getOptimisticResult(i,t.combine),f=!a&&t.subscribed!==!1;l.useSyncExternalStore(l.useCallback(p=>f?c.subscribe(da.batchCalls(p)):bm,[c,f]),()=>c.getCurrentResult(),()=>c.getCurrentResult()),l.useEffect(()=>{c.setQueries(i,t)},[i,t,c]);const y=u.some((p,x)=>ei(i[x],p))?u.flatMap((p,x)=>{const b=i[x];if(b&&ei(b,p)){const S=new za(n,b);return vm(b,S,o)}return[]}):[];if(y.length>0)throw Promise.all(y);const g=u.find((p,x)=>{const b=i[x];return b&&ym({result:p,errorResetBoundary:o,throwOnError:b.throwOnError,query:n.getQueryCache().get(b.queryHash),suspense:b.suspense})});if(g?.error)throw g.error;return m(d())}function Du(e,t){return wm(e,Xv)}function ey(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 Pu(e,t){const{shouldBlockFn:s,enableBeforeUnload:n=!0,disabled:a=!1,withResolver:o=!1}=ey(e),i=Ba(),{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(b){const S=i.parseLocation(b),w=i.getMatchedRoutes(S.pathname);return w.foundRoute===void 0?{routeId:"__notFound__",fullPath:S.pathname,pathname:S.pathname,params:w.routeParams,search:i.options.parseSearch(b.search)}:{routeId:w.foundRoute.id,fullPath:w.foundRoute.fullPath,pathname:S.pathname,params:w.routeParams,search:i.options.parseSearch(b.search)}}const y=h(f.currentLocation),g=h(f.nextLocation);if(y.routeId==="__notFound__"&&g.routeId!=="__notFound__")return!1;const p=await s({action:f.action,current:y,next:g});if(!o)return p;if(!p)return!1;const x=await new Promise(b=>{m({status:"blocked",current:y,next:g,action:f.action,proceed:()=>b(!1),reset:()=>b(!0)})});return m({status:"idle",current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0}),x};return a?void 0:c.block({blockerFn:d,enableBeforeUnload:n})},[s,n,a,o,c,i]),u}function Ot(e){const t=Ba({warn:e?.router===void 0}),s=e?.router||t;return oc(s.stores.__store,ic(e,s))}function Sr(e){const t=Ba();return oc(t.stores.location,ic(e,t))}const ty=new Set(["outbox","flagged"]),sy=e=>{const[,t,s]=e.split(/[?#]/)[0].split("/");return t!=="mail"||!s?!1:!ty.has(s)};function ny(e){const t=mt({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=Ua(n.folderAppointments);return(o.find(u=>i.get(u.mailboxId)==="inbox")??o[0])?.mailboxId}}function Lu(e){const{openCompose:t}=Jt(),s=Ve(),n=Sr(),a=ny(e);return l.useCallback(()=>{if(sy(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 ry=e=>e.startsWith("/mail")||e.startsWith("/settings"),ay=({accounts:e})=>{const{state:t}=Jt(),s=Sr(),n=Lu(e),a=s.search,o=typeof a?.selectedMessageId=="string"&&a.selectedMessageId.length>0;return!ry(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(uh,{className:"size-6"})})},Fu=({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:qe("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:qe("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})]})},nn=({onClick:e,disabled:t,destructive:s,children:n})=>r.jsx("button",{type:"button",onClick:a=>{a.stopPropagation(),t||e()},disabled:t,className:qe("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}),$u=()=>r.jsx("div",{className:"my-1 h-px bg-line"}),_u=({children:e})=>{const{Account:t}=ar();return r.jsx(t,{children:e})},oy=({email:e,onSignOut:t})=>{const s=e??"Account";return r.jsxs(Fu,{trigger:r.jsx(jt,{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($u,{})]}),r.jsxs(nn,{onClick:t,children:[r.jsx(Bc,{className:"size-4"}),"Sign out"]})]})},iy=()=>r.jsx(_u,{children:({email:e,signOut:t})=>r.jsx(oy,{email:e,onSignOut:t})}),ly=new Set(["discovering_mailboxes","syncing_inbox","syncing_others"]);function ko(e){return!!e&&ly.has(e)}const zu=3e3,cy=zu*2,dl={syncing:!1,resolved:!1,synced:0,total:0};function uy(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),cy);return()=>clearTimeout(g)},[s,t]);const c=mt({queries:e.map(g=>({...Wn({path:{accountId:g}}),enabled:t&&!n,refetchInterval:zu,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(ko(g.data?.syncPhase)){d=!0;for(const p of g.data?.mailboxes??[])f+=p.messagesSynced,h+=p.messagesTotal}const y=t&&m&&!d;return l.useEffect(()=>{y&&a(!0)},[y]),!t||!m?dl:{syncing:d,resolved:!0,synced:f,total:h}}const fl=6e4,dy=new Set(["sent","drafts","trash","archive"]),ml=(e,t)=>{const s=new Map;for(const n of e){const a=t.get(n.mailboxId)?.role;a&&dy.has(a)||s.set(n.mailboxId,n.messagesTotal)}return s},fy=(e,t)=>{for(const[s,n]of t)if(n>(e.get(s)??0))return!0;return!1},Bu=l.createContext(null),kr=()=>{const e=l.useContext(Bu);if(!e)throw new Error("useMailFreshness must be used inside <MailFreshnessProvider>");return e};function my({accountIds:e,children:t}){const s=Ee(),{resultFolderIndex:n}=De(),a=l.useRef(new Map),o=l.useRef(new Set),[i,c]=l.useState(new Set),u=mt({queries:e.map(g=>({...Wn({path:{accountId:g}}),refetchInterval:fl,staleTime:fl,meta:{softError:!0}}))}),m=u.map(g=>g.dataUpdatedAt).join(","),d=e.join(",");l.useEffect(()=>{let g=!1;const p=new Set(i);e.forEach((x,b)=>{const S=u[b]?.data;if(!S)return;const w=ml(S.mailboxes??[],n);if(!o.current.has(x)){o.current.add(x),a.current.set(x,w);return}if(p.has(x))return;const v=a.current.get(x)??new Map;fy(v,w)&&(p.add(x),g=!0)}),g&&c(p)},[d,m]);const f=l.useCallback(g=>g.some(p=>i.has(p)),[i]),h=l.useCallback(g=>{c(p=>{if(g.every(b=>!p.has(b)))return p;const x=new Set(p);for(const b of g)x.delete(b);return x});for(const p of g){const x=s.getQueryData(Wn({path:{accountId:p}}).queryKey);a.current.set(p,ml(x?.mailboxes??[],n)),o.current.add(p)}},[s,n]),y=l.useMemo(()=>({hasNewMail:f,acknowledge:h}),[f,h]);return r.jsx(Bu.Provider,{value:y,children:t})}const hy=2e3,py=45e3,gy=e=>new Promise(t=>setTimeout(t,e)),ka=e=>e instanceof Error&&e.message?e.message:"Something went wrong",xy=e=>{cc(e,{softError:!0})&&Ka(e)},Uu=e=>e.reduce((t,s)=>Math.max(t,s.lastSyncedAt??0),0),Ku=(e,t)=>e.fetchQuery({...Wn({path:{accountId:t}}),staleTime:0}),by=async(e,t,s,n)=>{let a=!1;for(;;){const o=await Ku(e,t).then(u=>({ok:!0,data:u})).catch(u=>({ok:!1,error:u}));if(!o.ok)return{accountId:t,message:ka(o.error)};const{syncPhase:i,mailboxes:c}=o.data;if(ko(i))a=!0;else if(a||Uu(c??[])>s)return i==="error"?{accountId:t,message:"Sync failed for this account"}:void 0;if(Date.now()>=n)return{accountId:t,message:"Refresh is taking longer than usual"};await gy(hy)}},vy=async(e,t,s,n)=>{const a=await Ku(e,s).then(c=>({ok:!0,maxLastSynced:Uu(c.mailboxes??[])})).catch(c=>({ok:!1,error:c}));if(!a.ok)return{accountId:s,enqueued:!1,ok:!1,message:ka(a.error)};const o=await lc({path:{accountId:s},throwOnError:!0}).then(()=>({ok:!0})).catch(c=>({ok:!1,error:c}));if(!o.ok)return xy(o.error),{accountId:s,enqueued:!1,ok:!1,message:ka(o.error)};t.recordEvent("sync.triggered");const i=await by(e,s,a.maxLastSynced,n);return i?{accountId:s,enqueued:!0,ok:!1,message:i.message}:{accountId:s,enqueued:!0,ok:!0}},Co=(e,t={})=>{const s=Ee(),n=Ls(),{acknowledge:a}=kr(),[o,i]=l.useState("idle"),[c,u]=l.useState(),m=l.useRef(0),d=l.useRef(e);d.current=e;const f=l.useRef(t);f.current=t,l.useEffect(()=>{if(o!=="success")return;const y=setTimeout(()=>i("idle"),2e3);return()=>clearTimeout(y)},[o]);const h=l.useCallback(()=>{const y=d.current;if(y.length===0){i("error"),u("Nothing to refresh yet");return}const g=++m.current;i("refreshing"),u(void 0),(async()=>{const p=Date.now()+py,x=await Promise.all(y.map(w=>vy(s,n,w,p)));if(m.current!==g)return;const b=x.filter(w=>w.enqueued).map(w=>w.accountId);for(const w of b)s.invalidateQueries({queryKey:Ft({path:{accountId:w}})});b.length>0&&(f.current.onSettled?.(),a(b));const S=x.filter(w=>!w.ok);S.length===0?i("success"):(i("error"),u(S[0]?.message))})()},[a,s,n]);return{state:o,errorMessage:c,refresh:h}},qu="/mail/",jo="/mail/$mailboxId",Hu="/mail/outbox",Wu="/mail/flagged";function No(e){return e.some(t=>t.routeId===qu)}function xn(e){return e.some(t=>t.routeId===Wu)}function Cr(e){return e.some(t=>t.routeId===Hu)}function Vu(e){return e.some(t=>t.routeId===jo)}function yy(e){const t=e.find(s=>s.params?.mailboxId)?.params?.mailboxId;return t?`${jo}:${t}`:xn(e)?Wu:Cr(e)?Hu:No(e)?qu:""}const Un="search-scope";function wy(e){const t=e.trim().replace(/\s+/g," ").toLowerCase();return/\s/.test(t)?`in:"${t}"`:`in:${t}`}function Qu(e){return xn(e)||Cr(e)||Vu(e)}function Gu(e){return e.find(t=>t.routeId===jo)?.params?.mailboxId}function Sy(e){const t=Gu(e.matches);return t||(Qu(e.matches)?e.callerMailboxId:e.callerMailboxId??e.inTokenMailboxId)}function ky(e,t){return No(e)?{kind:"global"}:xn(e)?{kind:"scoped",chip:{id:Un,label:"is:starred"}}:Cr(e)?{kind:"scoped",chip:{id:Un,label:"in:outbox"}}:Vu(e)?t?{kind:"scoped",chip:{id:Un,label:wy(t)}}:{kind:"pending"}:{kind:"global"}}function Cy(e,t,s){return t.kind==="global"?{kind:"global"}:xn(e)?{kind:"collection"}:{kind:"folder",...s?{role:s}:{}}}const Yu=({accounts:e})=>{const t=qa({strict:!1}),s=Sr(),n=t.mailboxId,{t:a}=Ha("mail",{useSuspense:!1}),o=l.useCallback((c,u)=>a(c,{defaultValue:u}),[a]),i=mt({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=Ua(e[c].folderAppointments);return Vn(m,d.get(n),o)}return null},jy=({accounts:e})=>{const s=qa({strict:!1}).mailboxId,n=mt({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 Xu(e){const t=Ve(),{searchInput:s}=De(),n=Yu({accounts:e}),a=Ot({select:c=>c.matches}),o=ky(a,n),i=l.useCallback(c=>{c===Un&&t({to:"/mail",search:{q:s||void 0,selectedMessageId:void 0}})},[t,s]);return{scope:o,clearScope:i}}function Ny({accounts:e}){const{searchInput:t,onSearchChange:s,onSearchClear:n,onSearchClearQuery:a}=De(),o=Ve(),i=Lu(e),{scope:c,clearScope:u}=Xu(e),m=c.kind==="scoped"?[{id:c.chip.id,label:c.chip.label,tone:"scope"}]:void 0,d=l.useMemo(()=>e.map(p=>p.accountId),[e]),{hasNewMail:f}=kr(),{state:h,errorMessage:y,refresh:g}=Co(d);return r.jsx($x,{search:{value:t,scope:c.kind,chips:m,onChange:s,onClear:n,onClearQuery:a,onRemoveChip:u},onCompose:i,onReportBug:uc,onOpenSettings:()=>o({to:"/settings/accounts"}),composeShortcut:Vc("compose"),refreshControl:r.jsx(bo,{state:h,onRefresh:g,label:"Refresh all accounts",errorMessage:y,hasUpdate:f(d)}),account:r.jsx(iy,{})})}const Eo=({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:qe("safe-area-frame 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(Nt,{className:"size-5"})})}),r.jsx("div",{className:"flex-1 overflow-y-auto",children:s})]})]})},Ey=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},Ca={all:["messages"],detail:e=>[...Ca.all,"detail",e],body:e=>[...Ca.detail(e),"body"]};class cs 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 Iy=e=>{const t=Number.parseInt(e??"",10);return!Number.isFinite(t)||t<=0?1:Math.min(t,30)},Ry=8,Ty="x-remit-403-reason",Ju=(e,t)=>{const s=t?.trim()??"";return e===401?"auth":e===403?s.length>0?"auth":"body-missing":e===404?"body-missing":"generic"},My=(e,t)=>(t??"").toLowerCase().startsWith("text/html")?/<div\s+id=["']root["']/i.test(e):!1,Ay=(e,t)=>{const s=(t??"").toLowerCase();return!!(e==="text"&&s.startsWith("text/html"))},Oy=async(e,t,s=async()=>null)=>{const n={},a=await s();a&&(n.Authorization=`Bearer ${a}`);const o=await dc(e,{headers:n});if(o.status===202)throw new cs("not-ready","Message body is still syncing",202,Iy(o.headers.get("Retry-After")));if(!o.ok){const u=o.headers.get(Ty),m=Ju(o.status,u);throw new cs(m,`Failed to load message body (${o.status} ${o.statusText})`,o.status)}const i=o.headers.get("content-type");if(Ay(t,i))throw new cs("content-type-mismatch",`Refusing to render message body — expected ${t}, got Content-Type ${i}`);const c=await o.text();if(My(c,i))throw new cs("spa-shell-leak","Refusing to render message body — response looks like the SPA shell (CloudFront 403/404 fallback leaked through to /content/*)");return c},Dy=async(e,t)=>(t.isRetryAfterNotReady&&await e.refetchDescribeMessage(),e.fetchContent(t.contentUrl,t.kind)),Zu=({messageId:e,bodyParts:t,enabled:s=!0})=>{const n=t?Ey(t):null,a=Ls(),{getToken:o}=ar(),i=l.useRef(null),c=Ee(),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?[...Ca.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,Dy({fetchContent:(p,x)=>Oy(p,x,o),refetchDescribeMessage:()=>c.refetchQueries({queryKey:Wa({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 cs&&p.reason==="not-ready"?g<Ry:g<1,retryDelay:(g,p)=>p instanceof cs&&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 y=f.data&&n?{kind:n.kind,body:f.data}:void 0;return{picked:n,data:y,isLoading:h,isError:f.isError,error:f.error,refetch:f.refetch}},Py=e=>e.then(()=>{},()=>{}),Ly=({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=Ee(),m=l.useRef(e),d=l.useRef(e);m.current!==e&&(m.current=e,d.current=e);const f=_e(Sm()),h=_e(km()),y=l.useCallback(async w=>{n("saving"),o(null);const v=d.current;if(v){const R=await h.mutateAsync({path:{outboxMessageId:v},body:{toAddresses:w.toAddresses,ccAddresses:w.ccAddresses,bccAddresses:w.bccAddresses,subject:w.subject,textBody:w.textBody,htmlBody:w.htmlBody,inReplyTo:w.inReplyTo,references:w.references}});return n("saved"),R}const k=await f.mutateAsync({body:{...w,sendImmediately:!1}});return d.current=k.outboxMessageId,t(k.outboxMessageId),n("saved"),u.invalidateQueries({queryKey:or().queryKey}),k},[f,h,t,u]),g=l.useRef(Promise.resolve()),p=l.useCallback(w=>{const v=g.current.then(()=>y(w));return g.current=Py(v),v},[y]),x=l.useCallback(w=>{i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{const v=d.current;v&&c.current.has(v)||p(w).catch(k=>{o(k),n("error")})},2e3)},[p]),b=l.useCallback(w=>(i.current&&clearTimeout(i.current),p(w).then(v=>({outcome:"saved",outboxMessageId:v.outboxMessageId})).catch(v=>(n("error"),{outcome:"failed",error:v}))),[p]),S=l.useCallback(w=>{i.current&&clearTimeout(i.current),w&&c.current.add(w)},[]);return{saveStatus:s,saveError:a,saveDraft:x,saveImmediately:b,stopAutoSave:S}},Fy=["Tab",","],hl=e=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.trim()),$y=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(hl(a))return{email:a,displayName:n}}if(hl(t))return{email:t}},ea=({label:e,addresses:t,onChange:s,placeholder:n})=>{const[a,o]=l.useState(""),i=l.useRef(null),c=mr(a,200),{data:u}=ve({...ir({query:{q:c,limit:8}}),enabled:c.length>=2}),m=u?.items??[],d=new Set(t.map(v=>v.email.toLowerCase())),f=a.length>=2?m.filter(v=>!d.has(v.normalizedEmail.toLowerCase())):[],h=l.useCallback(v=>{d.has(v.email.toLowerCase())||(s([...t,v]),o(""))},[t,d,s]),y=l.useCallback(v=>{s(t.filter((k,R)=>R!==v))},[t,s]),g=l.useCallback(v=>{h({email:v.normalizedEmail,displayName:v.displayName}),i.current?.focus()},[h]),p=l.useCallback(()=>{const v=$y(a);v&&h(v)},[a,h]),x=fc({count:f.length,acceptKeys:Fy,onAccept:v=>g(f[v])}),b=l.useMemo(()=>f.map(v=>({value:v.normalizedEmail,label:v.displayName??v.normalizedEmail,...v.displayName?{hint:v.normalizedEmail}:{}})),[f]),S=l.useCallback(v=>{if(v.key==="Backspace"&&a===""&&t.length>0){y(t.length-1);return}x.handleKeyDown(v)||(v.key==="Enter"||v.key==="Tab"||v.key===",")&&a.trim()&&(v.preventDefault(),p())},[a,t.length,y,x.handleKeyDown,p]),w=l.useCallback(()=>{setTimeout(()=>{p(),x.dismiss()},150)},[p,x.dismiss]);return r.jsxs("div",{className:"relative",children:[r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsxs("label",{htmlFor:`address-field-${e}`,className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:[e,":"]}),r.jsxs("div",{className:"flex-1 flex flex-wrap items-center gap-1 min-h-[36px] px-2 py-1 border rounded-md bg-canvas cursor-text",onClick:()=>i.current?.focus(),onKeyDown:v=>{(v.key==="Enter"||v.key===" ")&&i.current?.focus()},children:[t.map((v,k)=>r.jsx(Sp,{email:v.email,displayName:v.displayName,onRemove:()=>y(k)},v.email)),r.jsx("input",{ref:i,id:`address-field-${e}`,type:"text",value:a,onChange:v=>{x.reopen(),o(v.target.value)},onKeyDown:S,onBlur:w,placeholder:t.length===0?n:"",className:"flex-1 min-w-[120px] bg-transparent outline-none text-sm py-0.5",autoComplete:"off",...x.comboboxProps})]})]}),x.open&&r.jsx(mc,{id:x.listId,suggestions:b,activeIndex:x.activeIndex,optionId:x.optionId,onPick:v=>{const k=f.find(R=>R.normalizedEmail===v.value);k&&g(k)},onHighlight:x.setActiveIndex,label:`${e} suggestions`,className:"absolute left-12 right-0 z-50 mt-1 max-h-[200px] shadow-lg"})]})},_y=({accountId:e})=>{const t=Ve();return r.jsxs("div",{role:"alert","data-testid":"compose-smtp-missing-banner",className:"flex items-start gap-3 border-b border-warning/50 bg-warning/10 px-3 py-2",children:[r.jsx(Fa,{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(Cm,{className:"size-3","aria-hidden":"true"})]})]})]})},pl=150,zy=()=>{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>pl}});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>pl})};return n(),s.addEventListener("resize",n),()=>s.removeEventListener("resize",n)},[]),e},By=({selectedAccountId:e,onSelect:t})=>{const{data:s}=ve({...$t(),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))})]})},Uy=({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})]}),Ky=l.lazy(()=>Nm(()=>import("./ComposeBody-DWkdEkqR.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17])).then(e=>({default:e.ComposeBody}))),qy=()=>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"})]}),Hy=e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),ed=e=>e.split(`
|
|
116
|
+
`).map(t=>`<p>${Hy(t)}</p>`).join(""),gl=e=>e?`<p></p><p>-- </p>${ed(e)}`:"",Wy=e=>e?/^re:\s/i.test(e)?e:`Re: ${e}`:"Re: ",Vy=e=>e?/^fwd?:\s/i.test(e)?e:`Fwd: ${e}`:"Fwd: ",Qy=(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}},Gy=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}},Yy=(e,t,s,n,a)=>e.length===0&&t.length===0&&s.length===0&&n.trim()===""&&a.text.trim()==="",Xy=({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:y})=>{const g=es(),{isKeyboardOpen:p}=zy();if(!g&&p){const b=[];return s.length>0&&b.push(`To: ${s.map(S=>S.displayName??S.email).join(", ")}`),a.length>0&&b.push(`Cc: ${a.length}`),i.length>0&&b.push(`Bcc: ${i.length}`),h&&b.push(h),r.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-line overflow-hidden","data-testid":"compose-header-collapsed",children:[r.jsx("span",{className:"truncate text-xs text-fg-muted",children:b.length>0?b.join(" · "):"…"}),r.jsx("span",{className:"shrink-0 inline-flex items-center justify-center rounded bg-surface-sunken px-1.5 py-0.5 text-2xs text-fg-muted",children:"…"})]})}return r.jsxs("div",{className:"space-y-1 px-3 py-2 border-b border-line",children:[r.jsx(By,{selectedAccountId:e,onSelect:t}),r.jsx(ea,{label:"To",addresses:s,onChange:n,placeholder:"Recipients"}),u?r.jsx(ea,{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(ea,{label:"Bcc",addresses:i,onChange:c}),r.jsx(Uy,{value:h,onChange:y})]})},Io=({mode:e,account:t,sourceMessage:s,onClose:n,onAccountChange:a})=>{const{state:o,setOutboxMessageId:i,startSendPolling:c}=Jt(),{pushError:u}=tt(),{outboxMessageId:m}=o,[d,f]=l.useState([]),[h,y]=l.useState([]),[g,p]=l.useState([]),[x,b]=l.useState(""),[S,w]=l.useState(!1),[v,k]=l.useState(!1),[R,A]=l.useState(t?.accountId),[C,M]=l.useState(!1),L=l.useRef(m);l.useEffect(()=>{const me=L.current;me!==m&&(L.current=m,!(!m||me===void 0)&&(f([]),y([]),p([]),b(""),w(!1),k(!1),T(""),I(Lx),O(K=>K+1),M(!1)))},[m]);const{signature:E}=ph(R),[F,O]=l.useState(0),[j,T]=l.useState(()=>gl(E.plainText)),[P,I]=l.useState(()=>({html:gl(E.plainText),text:E.plainText})),{data:D}=ve({...jm({path:{outboxMessageId:m??""}}),enabled:!!m&&!C});l.useEffect(()=>{if(!D||C)return;f(D.toAddresses.map(K=>({email:K,displayName:void 0}))),D.ccAddresses&&D.ccAddresses.length>0&&(y(D.ccAddresses.map(K=>({email:K,displayName:void 0}))),w(!0)),D.bccAddresses&&D.bccAddresses.length>0&&(p(D.bccAddresses.map(K=>({email:K,displayName:void 0}))),k(!0)),D.subject&&b(D.subject);const me=D.htmlBody||ed(D.textBody??"");T(me),I({html:me,text:D.textBody??""}),O(K=>K+1),A(D.accountId),M(!0)},[D,C]),l.useEffect(()=>{if(s){if(e==="reply"||e==="reply_all"){const{to:me,cc:K}=Qy(s,e,t?.email);f(me),y(K),K.length>0&&w(!0),b(Wy(s.envelope.subject))}e==="forward"&&b(Vy(s.envelope.subject))}},[e,s,t?.email]);const N=e==="reply"||e==="reply_all"||e==="forward",{data:G}=Zu({messageId:s?.message.messageId,bodyParts:s?.bodyParts,enabled:N&&!!s}),W=G?.kind==="text"?G.body:"",ne=G?.kind==="html"?Gx(G.body):void 0,re=s?.envelope.from[0]?.displayName??s?.envelope.from[0]?.normalizedEmail,he=l.useCallback(me=>{M(!0),i(me)},[i]),{saveStatus:te,saveError:ce,saveDraft:ie,saveImmediately:U,stopAutoSave:_}=Ly({outboxMessageId:m,onDraftCreated:he});l.useEffect(()=>{ce&&u({title:"Couldn't save draft",detail:ft(ce)??"Saving the draft failed.",error:ce})},[ce,u]);const ue=_e(hc()),pe=_e({...lr(),onError:me=>{u(ds("Couldn't discard draft","The draft wasn't discarded.",me))}}),{data:ye}=ve({...$t(),staleTime:1/0}),Se=ye?.accounts.find(me=>me.accountId===R),H=Se?mh(Se):!1,we=l.useRef(!1),[xe,Ie]=l.useState(!1),de=d.length>0&&!!R&&!H;l.useEffect(()=>{if(!R||m&&!C||Yy(d,h,g,x,P))return;const{html:me,text:K}=P;ie({accountId:R,toAddresses:d.map(Te=>Te.email),ccAddresses:h.length>0?h.map(Te=>Te.email):void 0,bccAddresses:g.length>0?g.map(Te=>Te.email):void 0,subject:x||void 0,textBody:K||void 0,htmlBody:me||void 0})},[R,m,C,d,h,g,x,P,ie]);const se=l.useCallback(async()=>{if(!we.current&&!(!R||d.length===0)){we.current=!0,Ie(!0);try{_();const me=s&&(e==="reply"||e==="reply_all")?Gy(s):{},{html:K,text:Te}=P,Ne=!m,Pe=await U({accountId:R,toAddresses:d.map(J=>J.email),ccAddresses:h.length>0?h.map(J=>J.email):void 0,bccAddresses:g.length>0?g.map(J=>J.email):void 0,subject:x||void 0,textBody:Te||void 0,htmlBody:K||void 0,...me});if(Pe.outcome==="failed"){u({title:"Couldn't send message",detail:ft(Pe.error)??"Saving the message failed, so nothing was sent. Try again.",error:Pe.error});return}const $=Pe.outboxMessageId;if(await ue.mutateAsync({path:{outboxMessageId:$}}).catch(J=>(u({title:"Couldn't send message",detail:ft(J)??(Ne?"The draft was saved but the send request failed. Try again from the Outbox.":"The send request failed. Try again."),error:J}),null))===null)return;_($),c($),n()}finally{we.current=!1,Ie(!1)}}},[R,d,h,g,x,P,e,s,m,U,ue,_,c,u,n]),be=l.useCallback(()=>{_(m),m&&pe.mutate({path:{outboxMessageId:m}}),n()},[_,m,pe,n]),Be=l.useCallback(me=>{A(me.accountId),a?.(me)},[a]);return r.jsx(sx,{banner:Se&&H?r.jsx(_y,{accountId:Se.accountId}):void 0,header:r.jsx(Xy,{selectedAccountId:R,onAccountChange:Be,toAddresses:d,setToAddresses:f,ccAddresses:h,setCcAddresses:y,bccAddresses:g,setBccAddresses:p,showCc:S,setShowCc:w,showBcc:v,setShowBcc:k,subject:x,setSubject:b}),quoted:W||ne?r.jsx(Sx,{text:W,html:ne,senderName:re}):void 0,actionBar:r.jsx(tx,{onSend:se,onDiscard:be,sending:xe,canSend:de,saveStatus:te,unavailableReason:H?"SMTP not configured":void 0,onUnavailable:me=>u({title:"Can't send yet",detail:me})}),children:r.jsx(l.Suspense,{fallback:r.jsx(qy,{}),children:r.jsx(Ky,{initialHtml:j,onChange:I,onSubmit:se,autoFocus:e==="new"},F)})})},xl=({mode:e,account:t,sourceMessage:s,onClose:n})=>r.jsx("div",{className:"border-t border-line bg-canvas max-h-[min(400px,60dvh)] flex flex-col",children:r.jsx(Io,{mode:e,account:t,sourceMessage:s,onClose:n})}),td=({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})]}),Ro=({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])},To=e=>{const{data:t,isLoading:s}=ve({...$t(),staleTime:1/0}),n=l.useMemo(()=>(t?.accounts??[]).map(c=>c.accountId),[t?.accounts]),a=mt({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}},Jy=100,ja=async e=>e.then(t=>({ok:!0,value:t}),t=>({ok:!1,error:t})),Zy=(e,t=Jy)=>{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},sd=async(e,t,s,n)=>{const a=Zy(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 ja(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}},Os=async(e,t)=>{await sd(e,async s=>(await t(s),{successCount:s.length,failureCount:0}),()=>{},()=>!1)},e0=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 ja(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 ja(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}},t0=e=>({done:e.done,total:Math.max(e.total,e.done)}),nd=e=>typeof e=="object"&&e!==null&&Array.isArray(e.pages),rd=e=>typeof e=="object"&&e!==null&&Array.isArray(e.items),ad=(e,t)=>e===void 0?e:nd(e)?{...e,pages:e.pages.map(s=>({...s,items:t(s.items)}))}:rd(e)?{...e,items:t(e.items)}:e,Et=e=>{const t=[];for(const s of new Set(e))t.push(cr({path:{mailboxId:s}})),t.push(Va({path:{mailboxId:s}}));return t.push(Qa()),t},bn=(e,t)=>Promise.all(t.map(s=>e.cancelQueries({queryKey:s}))),vn=(e,t)=>t.flatMap(s=>e.getQueriesData({queryKey:s})).filter(s=>s[1]!==void 0).map(([s,n])=>({queryKey:s,data:n})),yn=(e,t,s)=>{const n=a=>ad(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)},It=(e,t)=>{for(const s of t)e.invalidateQueries({queryKey:s})},s0=3e3,n0=(e,t,s)=>{if(e.length===0)return()=>{};const n=setTimeout(()=>s(e),t);return()=>clearTimeout(n)},jr=(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]},Jn=(e,t,s)=>e.map(n=>t.has(n.messageId)?{...n,isRead:s}:n),r0=(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),a0=({messages:e,expandedIds:t,threadId:s,mailboxId:n,accountId:a})=>{const o=Ee(),{pushError:i}=tt(),c=l.useRef(new Set),u=l.useRef(new Set),{mutate:m}=_e({...ur(),onMutate:async h=>{const y=new Set(h.body.messageIds??[]),g=h.body.isRead??!0,p=Zt({path:{threadId:s}}),x=Et(jr(y,e,n));await Promise.all([o.cancelQueries({queryKey:p}),bn(o,x)]);const b=o.getQueriesData({queryKey:p}).filter(w=>w[1]!==void 0).map(([w,v])=>({queryKey:w,data:v})),S=vn(o,x);return o.setQueriesData({queryKey:p},w=>w&&{...w,items:Jn(w.items,y,g)}),yn(o,x,w=>Jn(w,y,g)),{threadMessagesPrefix:p,listPrefixes:x,previousThreadMessages:b,previousThreadsList:S}},onSuccess:(h,y)=>{const g=y.body.messageIds??[];for(const p of g)c.current.add(p),u.current.delete(p)},onError:(h,y,g)=>{const p=y.body.messageIds??[];for(const b of p)u.current.delete(b);if(g){for(const b of g.previousThreadMessages)o.setQueryData(b.queryKey,b.data);wn(o,g.previousThreadsList)}const x=y.body.isRead??!0;i({title:x?"Couldn't mark as read":"Couldn't mark as unread",detail:ft(h),error:h})},onSettled:(h,y,g,p)=>{p&&(o.invalidateQueries({queryKey:p.threadMessagesPrefix}),It(o,p.listPrefixes),a&&o.invalidateQueries({queryKey:Ft({path:{accountId:a}})}))}}),d=l.useCallback(h=>{const y=h.filter(g=>!c.current.has(g)&&!u.current.has(g));if(y.length!==0){for(const g of y)u.current.add(g);m({body:{messageIds:y,isRead:!0}})}},[m]),f=l.useMemo(()=>r0(e,t,c.current,u.current),[e,t]);l.useEffect(()=>n0(f,s0,d),[f,d]),l.useEffect(()=>{c.current.clear(),u.current.clear()},[s])},Nr=e=>{const{mailboxId:t,accountId:s,messages:n}=e,a=Ee(),{pushError:o}=tt(),{mutateAsync:i,isPending:c}=_e({...ur(),onError:(m,d)=>{const f=d.body.isRead??!0;o({title:f?"Couldn't mark as read":"Couldn't mark as unread",detail:ft(m),error:m})},onSettled:(m,d,f)=>{It(a,Et(jr(f.body.messageIds??[],n??[],t))),s&&a.invalidateQueries({queryKey:Ft({path:{accountId:s}})})}});return{toggleReadFor:l.useCallback((m,d)=>{m.length!==0&&Os(m,f=>i({body:{messageIds:f,isRead:d}}))},[i]),isPending:c}},o0=60,i0=1.5,l0=(e,t,s)=>{const n=Math.abs(e),a=Math.abs(t);return n<s?{direction:null}:n<a*i0?{direction:null}:{direction:e<0?"left":"right"}},c0=({onSwipeLeft:e,onSwipeRight:t,thresholdPx:s=o0})=>{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}=l0(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}}},u0=(e,t,s)=>t?.find(n=>n.messageId===e)?.mailboxId??s,bl=(e,t,s)=>e.map(n=>n.messageId===t?{...n,hasStars:s}:n),Mo=({threadId:e,mailboxId:t,messages:s})=>{const n=Ee(),{pushError:a}=tt(),{mutate:o,isPending:i,variables:c}=_e({...Em(),onMutate:async m=>{const d=m.path.messageId,f=m.body.isStarred??!1,h=Zt({path:{threadId:e}}),y=Et([u0(d,s,t)]);await Promise.all([n.cancelQueries({queryKey:h}),bn(n,y)]);const g=n.getQueriesData({queryKey:h}).filter(x=>x[1]!==void 0).map(([x,b])=>({queryKey:x,data:b})),p=vn(n,y);return n.setQueriesData({queryKey:h},x=>ad(x,b=>bl(b,d,f))),yn(n,y,x=>bl(x,d,f)),{threadMessagesPrefix:h,listPrefixes:y,previousThreadMessages:g,previousThreadsList:p}},onError:(m,d,f)=>{if(f){for(const y of f.previousThreadMessages)n.setQueryData(y.queryKey,y.data);wn(n,f.previousThreadsList)}const h=d.body.isStarred??!1;a({title:h?"Couldn't star message":"Couldn't unstar message",detail:ft(m),error:m})},onSettled:(m,d,f,h)=>{h&&(n.invalidateQueries({queryKey:h.threadMessagesPrefix}),It(n,h.listPrefixes))}});return{toggleStar:(m,d)=>{o({path:{messageId:m},body:{isStarred:!d}})},isPending:i,pendingMessageId:i?c?.path.messageId:void 0}};function Er(e){return e===void 0?"uncategorized":e}const d0={inbox:"Inbox",junk:"Junk"},Ao=e=>e.destinationMailboxId!==void 0,f0=(e,t)=>{if(Ao(e))return`Moved from ${t??"another folder"} by Remit`;const s=e.fromPlacement??"";return`Moved from ${d0[s]??"another folder"} by Remit`},m0=(e,t)=>{if(e===ai.MoveToInbox)return t.inboxMailboxId;if(e===ai.MoveToJunk)return t.junkMailboxId},h0=(e,t,s)=>{if(!e||!t)return!1;const n=Ao(e)?e.destinationMailboxId:m0(e.action,s);return n!==void 0&&n===t},p0="Reported as spam",g0=(e,t)=>{if(e){if(Ao(e))return e.fromMailboxId;if(e.fromPlacement==="inbox")return t.inboxMailboxId;if(e.fromPlacement==="junk")return t.junkMailboxId}},Ir=(e,t)=>{const{data:s,isLoading:n}=ve({...$t(),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}},x0=e=>{const{mailboxId:t,isLoading:s}=Ir(e,"Archive");return{archiveMailboxId:t,isLoading:s}},b0=e=>{const{mailboxId:t,isLoading:s}=Ir(e,"Drafts");return{draftsMailboxId:t,isLoading:s}},od=e=>{const{mailboxId:t,isLoading:s}=Ir(e,"Inbox");return{inboxMailboxId:t,isLoading:s}},Sn=e=>{const{mailboxId:t,isLoading:s}=Ir(e,"Junk");return{junkMailboxId:t,isLoading:s}},Oo=e=>{const{data:t}=ve({...$t(),staleTime:1/0,enabled:!!e});return l.useMemo(()=>t?.accounts.find(s=>s.accountId===e)?.folderAppointments??[],[t,e])},vl=(e,t)=>e.filter(s=>!t.has(s.messageId)),Ds=({mailboxId:e,threadId:t,accountId:s,onAfterOptimisticRemove:n})=>{const a=Ee(),{pushError:o}=tt(),{mutateAsync:i,isPending:c,isError:u}=_e({...Im(),onMutate:async d=>{const f=new Set(d.body.messageIds??[]),h=t?Zt({path:{threadId:t}}):[],y=Et([e,d.body.destinationMailboxId]);await Promise.all([...t?[a.cancelQueries({queryKey:h})]:[],bn(a,y)]);const g=t?a.getQueriesData({queryKey:h}).filter(x=>x[1]!==void 0).map(([x,b])=>({queryKey:x,data:b})):[],p=vn(a,y);return t&&a.setQueriesData({queryKey:h},x=>x&&{...x,items:vl(x.items,f)}),yn(a,y,x=>vl(x,f)),n?.(Array.from(f)),{threadMessagesPrefix:h,listPrefixes:y,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 y=f.body.messageIds?.length??0;o({title:y>1?`Couldn't move ${y} messages`:"Couldn't move this message",detail:ft(d),error:d})},onSettled:(d,f,h,y)=>{y&&(t&&a.invalidateQueries({queryKey:y.threadMessagesPrefix}),It(a,y.listPrefixes),s&&a.invalidateQueries({queryKey:Ft({path:{accountId:s}})}))}});return{moveMessages:l.useCallback((d,f)=>{d.length!==0&&Os(d,h=>i({body:{messageIds:h,destinationMailboxId:f}}))},[i]),isPending:c,isError:u}},v0="This message could not be processed. Please try again.",y0=(e,t)=>e.replace(`Message ${t}'s`,"This message's"),yl=e=>{if(e.failureCount===0)return;const t=e.failures?.[0],s=t?.reason??v0,n=t?y0(s,t.messageId):s;throw new Mm(n,422)};function id({mailboxId:e,threadId:t,accountId:s,onAfterOptimisticRemove:n}){const a=Ee(),{pushError:o}=tt(),i=Et([e]),c=t?Zt({path:{threadId:t}}):[],u=()=>{t&&a.invalidateQueries({queryKey:c}),It(a,i),s&&a.invalidateQueries({queryKey:Ft({path:{accountId:s}})})},m=()=>(p,x)=>{u(),n?.(x.body.messageIds)},d=p=>(x,b)=>{o({title:p(b.body.messageIds.length),detail:ft(x),error:x})},f=_e({mutationFn:async p=>{const{data:x}=await Rm({...p,throwOnError:!0});return yl(x),x},meta:{softError:!0},onSuccess:m(),onError:d(p=>p>1?`Couldn't report ${p} messages as spam`:"Couldn't report this message as spam")}),h=_e({mutationFn:async p=>{const{data:x}=await Tm({...p,throwOnError:!0});return yl(x),x},meta:{softError:!0},onSuccess:m(),onError:d(p=>p>1?`Couldn't undo the spam report for ${p} messages`:"Couldn't undo the spam report")}),y=l.useCallback(p=>{p.length!==0&&Os(p,x=>f.mutateAsync({body:{messageIds:x}}))},[f.mutateAsync]),g=l.useCallback(p=>{p.length!==0&&Os(p,x=>h.mutateAsync({body:{messageIds:x}}))},[h.mutateAsync]);return{reportSpam:y,notSpam:g,isReporting:f.isPending,isRestoring:h.isPending}}const w0=({accountId:e,messageId:t,threadId:s,mailboxId:n,autoMoved:a,spamReport:o})=>{const{inboxMailboxId:i}=od(e),{junkMailboxId:c}=Sn(e),{moveMessages:u,isPending:m}=Ds({mailboxId:n,threadId:s,accountId:e}),{notSpam:d,isRestoring:f}=id({mailboxId:n,threadId:s,accountId:e}),{data:h}=ve({...it({path:{accountId:e??""}}),staleTime:1/0,enabled:!!e&&a?.fromMailboxId!==void 0}),y={inboxMailboxId:i,junkMailboxId:c},g=g0(a,y),p=l.useCallback(()=>{g&&u([t],g)},[u,t,g]),x=l.useCallback(()=>{d([t])},[d,t]);if(o)return{show:!0,label:p0,onUndo:x,isUndoing:f};if(!h0(a,n,y)||!a)return{show:!1,label:"",isUndoing:!1};const S=a.fromMailboxId?h?.items.filter(w=>w.mailboxId===a.fromMailboxId).map(w=>fa(w.fullPath))[0]:void 0;return{show:!0,label:f0(a,S),onUndo:g?p:void 0,isUndoing:m,...a.filterId?{filtersHref:"/settings/filters"}:{}}};function S0({accountId:e,messageId:t,threadId:s,mailboxId:n,autoMoved:a,spamReport:o}){const i=w0({accountId:e,messageId:t,threadId:s,mailboxId:n,autoMoved:a,spamReport:o});return i.show?r.jsx(Yg,{label:i.label,onUndo:i.onUndo,undoLabel:i.isUndoing?"Undoing…":"Undo",filtersHref:i.filtersHref}):null}const wl=(e,t)=>e.filter(s=>!t.has(s.messageId)),k0=e=>e.filter(t=>t.isDeleted!==!0),ms=({mailboxId:e,threadId:t,accountId:s,messages:n,onAfterOptimisticRemove:a})=>{const o=Ee(),{pushError:i}=tt(),{mutateAsync:c,isPending:u}=_e({...Am(),onMutate:async d=>{const f=new Set(d.body.messageIds??[]),h=t?Zt({path:{threadId:t}}):[],y=Et(jr(f,n??[],e));await Promise.all([o.cancelQueries({queryKey:h}),bn(o,y)]);const g=t?o.getQueriesData({queryKey:h}).filter(x=>x[1]!==void 0).map(([x,b])=>({queryKey:x,data:b})):[],p=vn(o,y);return t&&o.setQueriesData({queryKey:h},x=>x&&{...x,items:wl(x.items,f)}),yn(o,y,x=>wl(x,f)),a?.(Array.from(f)),{threadMessagesPrefix:h,listPrefixes:y,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 y=f.body.messageIds?.length??0;i({title:y>1?`Couldn't delete ${y} messages`:"Couldn't delete this message",detail:ft(d),error:d})},onSettled:(d,f,h,y)=>{y&&(t&&o.invalidateQueries({queryKey:y.threadMessagesPrefix}),It(o,y.listPrefixes),s&&o.invalidateQueries({queryKey:Ft({path:{accountId:s}})}))}});return{deleteMessages:l.useCallback(d=>{d.length!==0&&Os(d,f=>c({body:{messageIds:f}}))},[c]),isPending:u}},ld=(e,t=Date.now())=>({value:e,setAt:t}),C0=(e,t,s,n)=>{if(e.addressId!==t)return e;const a={...e.flags??{}};return s?a.trusted=ld(!0,n):delete a.trusted,{...e,flags:a}},j0=(e,t,s,n)=>{const a=o=>o.map(i=>C0(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)}}},Do=({messageId:e})=>{const t=Ee(),{pushError:s}=tt(),{mutate:n,isPending:a,error:o,reset:i}=_e({...pc(),onMutate:async u=>{const m=u.path.addressId,f=u.body.flags?.trusted?.value===!0,h=Wa({path:{messageId:e}});await t.cancelQueries({queryKey:h});const y=t.getQueriesData({queryKey:h}).filter(g=>g[1]!==void 0).map(([g,p])=>({queryKey:g,data:p}));return t.setQueriesData({queryKey:h},g=>g&&j0(g,m,f)),{describePrefix:h,previous:y}},onError:(u,m,d)=>{if(d)for(const f of d.previous)t.setQueryData(f.queryKey,f.data);s(ds("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:ld(!m)}}})},isPending:a,error:o,reset:i}};var Rr="Dialog",[cd]=jb(Rr),[N0,xt]=cd(Rr),ud=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]=Ib({prop:n,defaultProp:a??!1,onChange:o,caller:Rr});return r.jsx(N0,{scope:t,triggerRef:c,contentRef:u,contentId:Gr(),titleId:Gr(),descriptionId:Gr(),open:m,onOpenChange:d,onOpenToggle:l.useCallback(()=>d(f=>!f),[d]),modal:i,children:s})};ud.displayName=Rr;var dd="DialogTrigger",E0=l.forwardRef((e,t)=>{const{__scopeDialog:s,...n}=e,a=xt(dd,s),o=gs(t,a.triggerRef);return r.jsx(_t.button,{type:"button","aria-haspopup":"dialog","aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":Lo(a.open),...n,ref:o,onClick:Vt(e.onClick,a.onOpenToggle)})});E0.displayName=dd;var Po="DialogPortal",[I0,fd]=cd(Po,{forceMount:void 0}),md=e=>{const{__scopeDialog:t,forceMount:s,children:n,container:a}=e,o=xt(Po,t);return r.jsx(I0,{scope:t,forceMount:s,children:l.Children.map(n,i=>r.jsx(yr,{present:s||o.open,children:r.jsx(ju,{asChild:!0,container:a,children:i})}))})};md.displayName=Po;var Zn="DialogOverlay",hd=l.forwardRef((e,t)=>{const s=fd(Zn,e.__scopeDialog),{forceMount:n=s.forceMount,...a}=e,o=xt(Zn,e.__scopeDialog);return o.modal?r.jsx(yr,{present:n||o.open,children:r.jsx(T0,{...a,ref:t})}):null});hd.displayName=Zn;var R0=yu("DialogOverlay.RemoveScroll"),T0=l.forwardRef((e,t)=>{const{__scopeDialog:s,...n}=e,a=xt(Zn,s),o=Vb(),i=gs(t,o);return r.jsx(Ou,{as:R0,allowPinchZoom:!0,shards:[a.contentRef],children:r.jsx(_t.div,{"data-state":Lo(a.open),...n,ref:i,style:{pointerEvents:"auto",...n.style}})})}),Ps="DialogContent",pd=l.forwardRef((e,t)=>{const s=fd(Ps,e.__scopeDialog),{forceMount:n=s.forceMount,...a}=e,o=xt(Ps,e.__scopeDialog);return r.jsx(yr,{present:n||o.open,children:o.modal?r.jsx(M0,{...a,ref:t}):r.jsx(A0,{...a,ref:t})})});pd.displayName=Ps;var M0=l.forwardRef((e,t)=>{const s=xt(Ps,e.__scopeDialog),n=l.useRef(null),a=gs(t,s.contentRef,n);return l.useEffect(()=>{const o=n.current;if(o)return pv(o)},[]),r.jsx(gd,{...e,ref:a,trapFocus:s.open,disableOutsidePointerEvents:s.open,onCloseAutoFocus:Vt(e.onCloseAutoFocus,o=>{o.preventDefault(),s.triggerRef.current?.focus()}),onPointerDownOutside:Vt(e.onPointerDownOutside,o=>{const i=o.detail.originalEvent,c=i.button===0&&i.ctrlKey===!0;(i.button===2||c)&&o.preventDefault()}),onFocusOutside:Vt(e.onFocusOutside,o=>o.preventDefault())})}),A0=l.forwardRef((e,t)=>{const s=xt(Ps,e.__scopeDialog),n=l.useRef(!1),a=l.useRef(!1);return r.jsx(gd,{...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()}})}),gd=l.forwardRef((e,t)=>{const{__scopeDialog:s,trapFocus:n,onOpenAutoFocus:a,onCloseAutoFocus:o,...i}=e,c=xt(Ps,s);return Xb(),r.jsx(r.Fragment,{children:r.jsx(ku,{asChild:!0,loop:!0,trapped:n,onMountAutoFocus:a,onUnmountAutoFocus:o,children:r.jsx(wu,{role:"dialog",id:c.contentId,"aria-describedby":c.descriptionId,"aria-labelledby":c.titleId,"data-state":Lo(c.open),...i,ref:t,deferPointerDownOutside:!0,onDismiss:()=>c.onOpenChange(!1)})})})}),xd="DialogTitle",bd=l.forwardRef((e,t)=>{const{__scopeDialog:s,...n}=e,a=xt(xd,s);return r.jsx(_t.h2,{id:a.titleId,...n,ref:t})});bd.displayName=xd;var vd="DialogDescription",O0=l.forwardRef((e,t)=>{const{__scopeDialog:s,...n}=e,a=xt(vd,s);return r.jsx(_t.p,{id:a.descriptionId,...n,ref:t})});O0.displayName=vd;var yd="DialogClose",D0=l.forwardRef((e,t)=>{const{__scopeDialog:s,...n}=e,a=xt(yd,s);return r.jsx(_t.button,{type:"button",...n,ref:t,onClick:Vt(e.onClick,()=>a.onOpenChange(!1))})});D0.displayName=yd;function Lo(e){return e?"open":"closed"}function P0(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 wd=q.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}),kn=()=>{const e=q.useContext(wd);if(!e)throw new Error("useDrawerContext must be used within a Drawer.Root");return e};P0(`[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 L0(){const e=navigator.userAgent;return typeof window<"u"&&(/Firefox/.test(e)&&/Mobile/.test(e)||/FxiOS/.test(e))}function F0(){return Fo(/^Mac/)}function $0(){return Fo(/^iPhone/)}function Sl(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function _0(){return Fo(/^iPad/)||F0()&&navigator.maxTouchPoints>1}function Sd(){return $0()||_0()}function Fo(e){return typeof window<"u"&&window.navigator!=null?e.test(window.navigator.platform):void 0}const z0=24,B0=typeof window<"u"?l.useLayoutEffect:l.useEffect;function kl(...e){return(...t)=>{for(let s of e)typeof s=="function"&&s(...t)}}const ta=typeof document<"u"&&window.visualViewport;function Cl(e){let t=window.getComputedStyle(e);return/(auto|scroll)/.test(t.overflow+t.overflowX+t.overflowY)}function kd(e){for(Cl(e)&&(e=e.parentElement);e&&!Cl(e);)e=e.parentElement;return e||document.scrollingElement||document.documentElement}const U0=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);let Dn=0,sa;function K0(e={}){let{isDisabled:t}=e;B0(()=>{if(!t)return Dn++,Dn===1&&Sd()&&(sa=q0()),()=>{Dn--,Dn===0&&sa?.()}},[t])}function q0(){let e,t=0,s=f=>{e=kd(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,y=e.scrollTop,g=e.scrollHeight-e.clientHeight;g!==0&&((y<=0&&h>t||y>=g&&h<t)&&f.preventDefault(),t=h)},a=f=>{let h=f.target;Na(h)&&h!==document.activeElement&&(f.preventDefault(),h.style.transform="translateY(-2000px)",h.focus(),requestAnimationFrame(()=>{h.style.transform=""}))},o=f=>{let h=f.target;Na(h)&&(h.style.transform="translateY(-2000px)",requestAnimationFrame(()=>{h.style.transform="",ta&&(ta.height<window.innerHeight?requestAnimationFrame(()=>{jl(h)}):ta.addEventListener("resize",()=>jl(h),{once:!0}))}))},i=()=>{window.scrollTo(0,0)},c=window.pageXOffset,u=window.pageYOffset,m=kl(H0(document.documentElement,"paddingRight",`${window.innerWidth-document.documentElement.clientWidth}px`));window.scrollTo(0,0);let d=kl(Xs(document,"touchstart",s,{passive:!1,capture:!0}),Xs(document,"touchmove",n,{passive:!1,capture:!0}),Xs(document,"touchend",a,{passive:!1,capture:!0}),Xs(document,"focus",o,!0),Xs(window,"scroll",i));return()=>{m(),d(),window.scrollTo(c,u)}}function H0(e,t,s){let n=e.style[t];return e.style[t]=s,()=>{e.style[t]=n}}function Xs(e,t,s,n){return e.addEventListener(t,s,n),()=>{e.removeEventListener(t,s,n)}}function jl(e){let t=document.scrollingElement||document.documentElement;for(;e&&e!==t;){let s=kd(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+z0;o>i&&(s.scrollTop+=a-n)}e=s.parentElement}}function Na(e){return e instanceof HTMLInputElement&&!U0.has(e.type)||e instanceof HTMLTextAreaElement||e instanceof HTMLElement&&e.isContentEditable}function W0(e,t){typeof e=="function"?e(t):e!=null&&(e.current=t)}function V0(...e){return t=>e.forEach(s=>W0(s,t))}function Cd(...e){return l.useCallback(V0(...e),e)}const jd=new WeakMap;function We(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&&jd.set(e,n)}function Q0(e,t){if(!e||!(e instanceof HTMLElement))return;let s=jd.get(e);s&&(e.style[t]=s[t])}const Ke=e=>{switch(e){case"top":case"bottom":return!0;case"left":case"right":return!1;default:return e}};function Pn(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(", ")[Ke(t)?13:12]):(a=n.match(/^matrix\((.+)\)$/),a?parseFloat(a[1].split(", ")[Ke(t)?5:4]):null)}function G0(e){return 8*(Math.log(e+1)-2)}function na(e,t){if(!e)return()=>{};const s=e.style.cssText;return Object.assign(e.style,t),()=>{e.style.cssText=s}}function Y0(...e){return(...t)=>{for(const s of e)typeof s=="function"&&s(...t)}}const Le={DURATION:.5,EASE:[.32,.72,0,1]},Nd=.4,X0=.25,J0=100,Ed=8,is=16,Ea=26,ra="vaul-dragging";function Id(e){const t=q.useRef(e);return q.useEffect(()=>{t.current=e}),q.useMemo(()=>(...s)=>t.current==null?void 0:t.current.call(t,...s),[])}function Z0({defaultProp:e,onChange:t}){const s=q.useState(e),[n]=s,a=q.useRef(n),o=Id(t);return q.useEffect(()=>{a.current!==n&&(o(n),a.current=n)},[n,a,o]),s}function Rd({prop:e,defaultProp:t,onChange:s=()=>{}}){const[n,a]=Z0({defaultProp:t,onChange:s}),o=e!==void 0,i=o?e:n,c=Id(s),u=q.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 ew({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,y]=q.useState(typeof window<"u"?{innerWidth:window.innerWidth,innerHeight:window.innerHeight}:void 0);q.useEffect(()=>{function A(){y({innerWidth:window.innerWidth,innerHeight:window.innerHeight})}return window.addEventListener("resize",A),()=>window.removeEventListener("resize",A)},[]);const g=q.useMemo(()=>d===s?.[s.length-1]||null,[s,d]),p=q.useMemo(()=>{var A;return(A=s?.findIndex(C=>C===d))!=null?A:null},[s,d]),x=s&&s.length>0&&(o||o===0)&&!Number.isNaN(o)&&s[o]===d||!s,b=q.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 C;return(C=s?.map(M=>{const L=typeof M=="string";let E=0;if(L&&(E=parseInt(M,10)),Ke(c)){const O=L?E:h?M*A.height:0;return h?c==="bottom"?A.height-O:-A.height+O:O}const F=L?E:h?M*A.width:0;return h?c==="right"?A.width-F:-A.width+F:F}))!=null?C:[]},[s,h,u]),S=q.useMemo(()=>p!==null?b?.[p]:null,[b,p]),w=q.useCallback(A=>{var C;const M=(C=b?.findIndex(L=>L===A))!=null?C:null;i(M),We(n.current,{transition:`transform ${Le.DURATION}s cubic-bezier(${Le.EASE.join(",")})`,transform:Ke(c)?`translate3d(0, ${A}px, 0)`:`translate3d(${A}px, 0, 0)`}),b&&M!==b.length-1&&o!==void 0&&M!==o&&M<o?We(a.current,{transition:`opacity ${Le.DURATION}s cubic-bezier(${Le.EASE.join(",")})`,opacity:"0"}):We(a.current,{transition:`opacity ${Le.DURATION}s cubic-bezier(${Le.EASE.join(",")})`,opacity:"1"}),f(s?.[Math.max(M,0)])},[n.current,s,b,o,a,f]);q.useEffect(()=>{if(d||e){var A;const C=(A=s?.findIndex(M=>M===e||M===d))!=null?A:-1;b&&C!==-1&&typeof b[C]=="number"&&w(b[C])}},[d,e,s,b,w]);function v({draggedDistance:A,closeDrawer:C,velocity:M,dismissible:L}){if(o===void 0)return;const E=c==="bottom"||c==="right"?(S??0)-A:(S??0)+A,F=p===o-1,O=p===0,j=A>0;if(F&&We(a.current,{transition:`opacity ${Le.DURATION}s cubic-bezier(${Le.EASE.join(",")})`}),!m&&M>2&&!j){L?C():w(b[0]);return}if(!m&&M>2&&j&&b&&s){w(b[s.length-1]);return}const T=b?.reduce((I,D)=>typeof I!="number"||typeof D!="number"?I:Math.abs(D-E)<Math.abs(I-E)?D:I),P=Ke(c)?window.innerHeight:window.innerWidth;if(M>Nd&&Math.abs(A)<P*.4){const I=j?1:-1;if(I>0&&g&&s){w(b[s.length-1]);return}if(O&&I<0&&L&&C(),p===null)return;w(b[p+I]);return}w(T)}function k({draggedDistance:A}){if(S===null)return;const C=c==="bottom"||c==="right"?S-A:S+A;(c==="bottom"||c==="right")&&C<b[b.length-1]||(c==="top"||c==="left")&&C>b[b.length-1]||We(n.current,{transform:Ke(c)?`translate3d(0, ${C}px, 0)`:`translate3d(${C}px, 0, 0)`})}function R(A,C){if(!s||typeof p!="number"||!b||o===void 0)return null;const M=p===o-1;if(p>=o&&C)return 0;if(M&&!C)return 1;if(!x&&!M)return null;const E=M?p+1:p-1,F=M?b[E]-b[E-1]:b[E+1]-b[E],O=A/Math.abs(F);return M?1-O:O}return{isLastSnapPoint:g,activeSnapPoint:d,shouldFade:x,getPercentageDragged:R,setActiveSnapPoint:f,activeSnapPointIndex:p,onRelease:v,onDrag:k,snapPointsOffset:b}}const tw=()=>()=>{};function sw(){const{direction:e,isOpen:t,shouldScaleBackground:s,setBackgroundColorOnScale:n,noBodyStyles:a}=kn(),o=q.useRef(null),i=l.useMemo(()=>document.body.style.backgroundColor,[]);function c(){return(window.innerWidth-Ea)/window.innerWidth}q.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;Y0(n&&!a?na(document.body,{background:"black"}):tw,na(u,{transformOrigin:Ke(e)?"top":"left",transitionProperty:"transform, border-radius",transitionDuration:`${Le.DURATION}s`,transitionTimingFunction:`cubic-bezier(${Le.EASE.join(",")})`}));const m=na(u,{borderRadius:`${Ed}px`,overflow:"hidden",...Ke(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")},Le.DURATION*1e3)}}},[t,s,i])}let Js=null;function nw({isOpen:e,modal:t,nested:s,hasBeenOpened:n,preventScrollRestoration:a,noBodyStyles:o}){const[i,c]=q.useState(()=>typeof window<"u"?window.location.href:""),u=q.useRef(0),m=q.useCallback(()=>{if(Sl()&&Js===null&&e&&!o){Js={position:document.body.style.position,top:document.body.style.top,left:document.body.style.left,height:document.body.style.height,right:"unset"};const{scrollX: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 y=h-window.innerHeight;y&&u.current>=h&&(document.body.style.top=`${-(u.current+y)}px`)}),300)}},[e]),d=q.useCallback(()=>{if(Sl()&&Js!==null&&!o){const f=-parseInt(document.body.style.top,10),h=-parseInt(document.body.style.left,10);Object.assign(document.body.style,Js),window.requestAnimationFrame(()=>{if(a&&i!==window.location.href){c(window.location.href);return}window.scrollTo(h,f)}),Js=null}},[i]);return q.useEffect(()=>{function f(){u.current=window.scrollY}return f(),window.addEventListener("scroll",f),()=>{window.removeEventListener("scroll",f)}},[]),q.useEffect(()=>{if(t)return()=>{typeof document>"u"||document.querySelector("[data-vaul-drawer]")||d()}},[t,d]),q.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 rw({open:e,onOpenChange:t,children:s,onDrag:n,onRelease:a,snapPoints:o,shouldScaleBackground:i=!1,setBackgroundColorOnScale:c=!0,closeThreshold:u=X0,scrollLockTimeout:m=J0,dismissible:d=!0,handleOnly:f=!1,fadeFromIndex:h=o&&o.length-1,activeSnapPoint:y,setActiveSnapPoint:g,fixed:p,modal:x=!0,onClose:b,nested:S,noBodyStyles:w=!1,direction:v="bottom",defaultOpen:k=!1,disablePreventScroll:R=!0,snapToSequentialPoint:A=!1,preventScrollRestoration:C=!1,repositionInputs:M=!0,onAnimationEnd:L,container:E,autoFocus:F=!1}){var O,j;const[T=!1,P]=Rd({defaultProp:k,prop:e,onChange:V=>{t?.(V),!V&&!S&&$(),setTimeout(()=>{L?.(V)},Le.DURATION*1e3),V&&!x&&typeof window<"u"&&window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"}),V||(document.body.style.pointerEvents="auto")}}),[I,D]=q.useState(!1),[N,G]=q.useState(!1),[W,ne]=q.useState(!1),re=q.useRef(null),he=q.useRef(null),te=q.useRef(null),ce=q.useRef(null),ie=q.useRef(null),U=q.useRef(!1),_=q.useRef(null),ue=q.useRef(0),pe=q.useRef(!1),ye=q.useRef(!k),Se=q.useRef(0),H=q.useRef(null),we=q.useRef(((O=H.current)==null?void 0:O.getBoundingClientRect().height)||0),xe=q.useRef(((j=H.current)==null?void 0:j.getBoundingClientRect().width)||0),Ie=q.useRef(0),de=q.useCallback(V=>{o&&V===K.length-1&&(he.current=new Date)},[]),{activeSnapPoint:se,activeSnapPointIndex:be,setActiveSnapPoint:Be,onRelease:me,snapPointsOffset:K,onDrag:Te,shouldFade:Ne,getPercentageDragged:Pe}=ew({snapPoints:o,activeSnapPointProp:y,setActiveSnapPointProp:g,drawerRef:H,fadeFromIndex:h,overlayRef:re,onSnapPointChange:de,direction:v,container:E,snapToSequentialPoint:A});K0({isDisabled:!T||N||!x||W||!I||!M||!R});const{restorePositionSetting:$}=nw({isOpen:T,modal:x,nested:S??!1,hasBeenOpened:I,preventScrollRestoration:C,noBodyStyles:w});function le(){return(window.innerWidth-Ea)/window.innerWidth}function J(V){var fe,ae;!d&&!o||H.current&&!H.current.contains(V.target)||(we.current=((fe=H.current)==null?void 0:fe.getBoundingClientRect().height)||0,xe.current=((ae=H.current)==null?void 0:ae.getBoundingClientRect().width)||0,G(!0),te.current=new Date,Sd()&&window.addEventListener("touchend",()=>U.current=!1,{once:!0}),V.target.setPointerCapture(V.pointerId),ue.current=Ke(v)?V.pageY:V.pageX)}function ge(V,fe){var ae;let Z=V;const ke=(ae=window.getSelection())==null?void 0:ae.toString(),Oe=H.current?Pn(H.current,v):null,$e=new Date;if(Z.tagName==="SELECT"||Z.hasAttribute("data-vaul-no-drag")||Z.closest("[data-vaul-no-drag]"))return!1;if(v==="right"||v==="left")return!0;if(he.current&&$e.getTime()-he.current.getTime()<500)return!1;if(Oe!==null&&(v==="bottom"?Oe>0:Oe<0))return!0;if(ke&&ke.length>0)return!1;if(ie.current&&$e.getTime()-ie.current.getTime()<m&&Oe===0||fe)return ie.current=$e,!1;for(;Z;){if(Z.scrollHeight>Z.clientHeight){if(Z.scrollTop!==0)return ie.current=new Date,!1;if(Z.getAttribute("role")==="dialog")return!0}Z=Z.parentNode}return!0}function Me(V){if(H.current&&N){const fe=v==="bottom"||v==="right"?1:-1,ae=(ue.current-(Ke(v)?V.pageY:V.pageX))*fe,Z=ae>0,ke=o&&!d&&!Z;if(ke&&be===0)return;const Oe=Math.abs(ae),$e=document.querySelector("[data-vaul-drawer-wrapper]"),Qe=v==="bottom"||v==="top"?we.current:xe.current;let Ue=Oe/Qe;const Ce=Pe(Oe,Z);if(Ce!==null&&(Ue=Ce),ke&&Ue>=1||!U.current&&!ge(V.target,Z))return;if(H.current.classList.add(ra),U.current=!0,We(H.current,{transition:"none"}),We(re.current,{transition:"none"}),o&&Te({draggedDistance:ae}),Z&&!o){const ze=G0(ae),lt=Math.min(ze*-1,0)*fe;We(H.current,{transform:Ke(v)?`translate3d(0, ${lt}px, 0)`:`translate3d(${lt}px, 0, 0)`});return}const Xe=1-Ue;if((Ne||h&&be===h-1)&&(n?.(V,Ue),We(re.current,{opacity:`${Xe}`,transition:"none"},!0)),$e&&re.current&&i){const ze=Math.min(le()+Ue*(1-le()),1),lt=8-Ue*8,Je=Math.max(0,14-Ue*14);We($e,{borderRadius:`${lt}px`,transform:Ke(v)?`scale(${ze}) translate3d(0, ${Je}px, 0)`:`scale(${ze}) translate3d(${Je}px, 0, 0)`,transition:"none"},!0)}if(!o){const ze=Oe*fe;We(H.current,{transform:Ke(v)?`translate3d(0, ${ze}px, 0)`:`translate3d(${ze}px, 0, 0)`})}}}q.useEffect(()=>{window.requestAnimationFrame(()=>{ye.current=!0})},[]),q.useEffect(()=>{var V;function fe(){if(!H.current||!M)return;const ae=document.activeElement;if(Na(ae)||pe.current){var Z;const ke=((Z=window.visualViewport)==null?void 0:Z.height)||0,Oe=window.innerHeight;let $e=Oe-ke;const Qe=H.current.getBoundingClientRect().height||0,Ue=Qe>Oe*.8;Ie.current||(Ie.current=Qe);const Ce=H.current.getBoundingClientRect().top;if(Math.abs(Se.current-$e)>60&&(pe.current=!pe.current),o&&o.length>0&&K&&be){const Xe=K[be]||0;$e+=Xe}if(Se.current=$e,Qe>ke||pe.current){const Xe=H.current.getBoundingClientRect().height;let ze=Xe;Xe>ke&&(ze=ke-(Ue?Ce:Ea)),p?H.current.style.height=`${Xe-Math.max($e,0)}px`:H.current.style.height=`${Math.max(ze,ke-Ce)}px`}else L0()||(H.current.style.height=`${Ie.current}px`);o&&o.length>0&&!pe.current?H.current.style.bottom="0px":H.current.style.bottom=`${Math.max($e,0)}px`}}return(V=window.visualViewport)==null||V.addEventListener("resize",fe),()=>{var ae;return(ae=window.visualViewport)==null?void 0:ae.removeEventListener("resize",fe)}},[be,o,K]);function Ye(V){Ze(),b?.(),V||P(!1),setTimeout(()=>{o&&Be(o[0])},Le.DURATION*1e3)}function He(){if(!H.current)return;const V=document.querySelector("[data-vaul-drawer-wrapper]"),fe=Pn(H.current,v);We(H.current,{transform:"translate3d(0, 0, 0)",transition:`transform ${Le.DURATION}s cubic-bezier(${Le.EASE.join(",")})`}),We(re.current,{transition:`opacity ${Le.DURATION}s cubic-bezier(${Le.EASE.join(",")})`,opacity:"1"}),i&&fe&&fe>0&&T&&We(V,{borderRadius:`${Ed}px`,overflow:"hidden",...Ke(v)?{transform:`scale(${le()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`,transformOrigin:"top"}:{transform:`scale(${le()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)`,transformOrigin:"left"},transitionProperty:"transform, border-radius",transitionDuration:`${Le.DURATION}s`,transitionTimingFunction:`cubic-bezier(${Le.EASE.join(",")})`},!0)}function Ze(){!N||!H.current||(H.current.classList.remove(ra),U.current=!1,G(!1),ce.current=new Date)}function Ae(V){if(!N||!H.current)return;H.current.classList.remove(ra),U.current=!1,G(!1),ce.current=new Date;const fe=Pn(H.current,v);if(!V||!ge(V.target,!1)||!fe||Number.isNaN(fe)||te.current===null)return;const ae=ce.current.getTime()-te.current.getTime(),Z=ue.current-(Ke(v)?V.pageY:V.pageX),ke=Math.abs(Z)/ae;if(ke>.05&&(ne(!0),setTimeout(()=>{ne(!1)},200)),o){me({draggedDistance:Z*(v==="bottom"||v==="right"?1:-1),closeDrawer:Ye,velocity:ke,dismissible:d}),a?.(V,!0);return}if(v==="bottom"||v==="right"?Z>0:Z<0){He(),a?.(V,!0);return}if(ke>Nd){Ye(),a?.(V,!1);return}var Oe;const $e=Math.min((Oe=H.current.getBoundingClientRect().height)!=null?Oe:0,window.innerHeight);var Qe;const Ue=Math.min((Qe=H.current.getBoundingClientRect().width)!=null?Qe:0,window.innerWidth),Ce=v==="left"||v==="right";if(Math.abs(fe)>=(Ce?Ue:$e)*u){Ye(),a?.(V,!1);return}a?.(V,!0),He()}q.useEffect(()=>(T&&(We(document.documentElement,{scrollBehavior:"auto"}),he.current=new Date),()=>{Q0(document.documentElement,"scrollBehavior")}),[T]);function nt(V){const fe=V?(window.innerWidth-is)/window.innerWidth:1,ae=V?-is:0;_.current&&window.clearTimeout(_.current),We(H.current,{transition:`transform ${Le.DURATION}s cubic-bezier(${Le.EASE.join(",")})`,transform:Ke(v)?`scale(${fe}) translate3d(0, ${ae}px, 0)`:`scale(${fe}) translate3d(${ae}px, 0, 0)`}),!V&&H.current&&(_.current=setTimeout(()=>{const Z=Pn(H.current,v);We(H.current,{transition:"none",transform:Ke(v)?`translate3d(0, ${Z}px, 0)`:`translate3d(${Z}px, 0, 0)`})},500))}function st(V,fe){if(fe<0)return;const ae=(window.innerWidth-is)/window.innerWidth,Z=ae+fe*(1-ae),ke=-is+fe*is;We(H.current,{transform:Ke(v)?`scale(${Z}) translate3d(0, ${ke}px, 0)`:`scale(${Z}) translate3d(${ke}px, 0, 0)`,transition:"none"})}function Re(V,fe){const ae=Ke(v)?window.innerHeight:window.innerWidth,Z=fe?(ae-is)/ae:1,ke=fe?-is:0;fe&&We(H.current,{transition:`transform ${Le.DURATION}s cubic-bezier(${Le.EASE.join(",")})`,transform:Ke(v)?`scale(${Z}) translate3d(0, ${ke}px, 0)`:`scale(${Z}) translate3d(${ke}px, 0, 0)`})}return q.useEffect(()=>{x||window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"})},[x]),q.createElement(ud,{defaultOpen:k,onOpenChange:V=>{!d&&!V||(V?D(!0):Ye(!0),P(V))},open:T},q.createElement(wd.Provider,{value:{activeSnapPoint:se,snapPoints:o,setActiveSnapPoint:Be,drawerRef:H,overlayRef:re,onOpenChange:t,onPress:J,onRelease:Ae,onDrag:Me,dismissible:d,shouldAnimate:ye,handleOnly:f,isOpen:T,isDragging:N,shouldFade:Ne,closeDrawer:Ye,onNestedDrag:st,onNestedOpenChange:nt,onNestedRelease:Re,keyboardIsOpen:pe,modal:x,snapPointsOffset:K,activeSnapPointIndex:be,direction:v,shouldScaleBackground:i,setBackgroundColorOnScale:c,noBodyStyles:w,container:E,autoFocus:F}},s))}const Td=q.forwardRef(function({...e},t){const{overlayRef:s,snapPoints:n,onRelease:a,shouldFade:o,isOpen:i,modal:c,shouldAnimate:u}=kn(),m=Cd(t,s),d=n&&n.length>0;if(!c)return null;const f=q.useCallback(h=>a(h),[a]);return q.createElement(hd,{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})});Td.displayName="Drawer.Overlay";const Md=q.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:y,direction:g,snapPoints:p,container:x,handleOnly:b,shouldAnimate:S,autoFocus:w}=kn(),[v,k]=q.useState(!1),R=Cd(a,o),A=q.useRef(null),C=q.useRef(null),M=q.useRef(!1),L=p&&p.length>0;sw();const E=(O,j,T=0)=>{if(M.current)return!0;const P=Math.abs(O.y),I=Math.abs(O.x),D=I>P,N=["bottom","right"].includes(j)?1:-1;if(j==="left"||j==="right"){if(!(O.x*N<0)&&I>=0&&I<=T)return D}else if(!(O.y*N<0)&&P>=0&&P<=T)return!D;return M.current=!0,!0};q.useEffect(()=>{L&&window.requestAnimationFrame(()=>{k(!0)})},[]);function F(O){A.current=null,M.current=!1,c(O)}return q.createElement(pd,{"data-vaul-drawer-direction":g,"data-vaul-drawer":"","data-vaul-delayed-snap-points":v?"true":"false","data-vaul-snap-points":y&&L?"true":"false","data-vaul-custom-container":x?"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=>{b||(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(C.current=O,b||(n.onPointerMove==null||n.onPointerMove.call(n,O),!A.current))return;const j=O.pageY-A.current.y,T=O.pageX-A.current.x,P=O.pointerType==="touch"?10:2;E({x:T,y:j},g,P)?u(O):(Math.abs(T)>P||Math.abs(j)>P)&&(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(C.current)},onContextMenu:O=>{n.onContextMenu==null||n.onContextMenu.call(n,O),C.current&&F(C.current)}})});Md.displayName="Drawer.Content";const aw=250,ow=120,Ad=q.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:y}=kn(),g=q.useRef(null),p=q.useRef(!1);function x(){if(p.current){w();return}window.setTimeout(()=>{b()},ow)}function b(){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},aw)}function w(){g.current&&window.clearTimeout(g.current),p.current=!1}return q.createElement("div",{onClick:x,onPointerCancel:w,onPointerDown:v=>{d&&h(v),S()},onPointerMove:v=>{d&&y(v)},ref:n,"data-vaul-drawer-visible":f?"true":"false","data-vaul-handle":"","aria-hidden":"true",...s},q.createElement("span",{"data-vaul-handle-hitarea":"","aria-hidden":"true"},t))});Ad.displayName="Drawer.Handle";function iw(e){const t=kn(),{container:s=t.container,...n}=e;return q.createElement(md,{container:s,...n})}const dt={Root:rw,Content:Md,Overlay:Td,Portal:iw,Handle:Ad,Title:bd},Od="inline-flex items-center justify-center transition-colors",lw=qe(Od,"min-h-11 min-w-11 rounded hover:bg-surface-raised"),cw=qe(Od,"min-h-11 gap-1.5 px-3 rounded text-sm font-medium hover:bg-surface-raised"),$o=({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=es(),h=l.useRef(null),y=i??"Move to folder",g=l.useId(),{t:p}=Ha("mail",{useSuspense:!1}),x=to(),{data:b,isLoading:S,isError:w,error:v,refetch:k}=ve({...it({path:{accountId:e}}),staleTime:1/0,enabled:c}),R=Oo(e),{createFolderIn:A}=Cc(e),C=l.useMemo(()=>so({mailboxes:b?.items??[],folderAppointments:R,currentMailboxId:t,translator:x}),[b?.items,R,t,x]),M=no(b?.items??[]),L=C.find(I=>I.id===m),E=l.useCallback(()=>{u(!1),d(void 0)},[]),F=l.useCallback(()=>{L&&(E(),s(L.id))},[L,E,s]);l.useEffect(()=>{if(!c||!f)return;const I=N=>{h.current&&!h.current.contains(N.target)&&E()},D=N=>{N.key==="Escape"&&E()};return document.addEventListener("mousedown",I),document.addEventListener("keydown",D),()=>{document.removeEventListener("mousedown",I),document.removeEventListener("keydown",D)}},[c,f,E]);const O=n||!!a,j=r.jsxs("button",{type:"button",onClick:I=>{I.stopPropagation(),!O&&u(D=>!D)},"aria-label":y,"aria-haspopup":f?"tree":"dialog","aria-expanded":c,"aria-controls":c?g:void 0,title:a,className:o==="icon-only"?lw:cw,children:[r.jsx(Da,{className:o==="icon-only"?"size-5":"size-4"}),o==="compact"&&r.jsx("span",{className:"hidden sm:inline",children:"Move"})]}),T=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(ts,{variant:"inline",title:"Couldn't load folders",error:v,onRetry:()=>k()})}):r.jsx(rc,{folders:C,selectedId:m,delimiter:M,onSelect:d,onCreateFolder:A,onCancel:E,labels:{filterPlaceholder:p("move_picker_filter_placeholder",{defaultValue:"Filter folders…"}),filterAriaLabel:p("move_picker_filter_label",{defaultValue:"Filter folders"})}}),P=L&&r.jsx("div",{className:"shrink-0 border-t border-line p-2",children:r.jsx(oe,{variant:"primary",onClick:F,className:"h-11 w-full font-semibold",children:`Move to ${L.label}`})});return f?r.jsxs("div",{ref:h,className:"relative inline-block",children:[j,c&&r.jsxs("div",{id:g,className:qe("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:[T,P]})]}):r.jsxs(r.Fragment,{children:[j,r.jsx(dt.Root,{open:c,onOpenChange:I=>I?u(!0):E(),children:r.jsxs(dt.Portal,{children:[r.jsx(dt.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),r.jsxs(dt.Content,{className:"fixed inset-x-0 bottom-0 z-50 flex flex-col rounded-t-lg bg-canvas pb-[env(safe-area-inset-bottom,0px)]",style:{maxHeight:"85dvh"},id:g,children:[r.jsx(dt.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-subtle/30"}),r.jsx(dt.Title,{className:"px-4 py-2 text-base font-semibold border-b border-line",children:"Move to folder"}),r.jsx("div",{className:"flex min-h-0 flex-1 overflow-hidden",children:T}),P]})]})})]})},uw=({messageId:e,threadId:t,mailboxId:s,isRead:n,accountId:a,fromAddressId:o,isTrusted:i=!1,showRaw:c=!1,onToggleRaw:u})=>{const m=Ee(),d=Ve(),{pushError:f}=tt(),{selectedMessageId:h}=As({strict:!1}),{mutate:y,isPending:g}=_e({...ur(),onMutate:async T=>{const P=T.body.isRead??!0,I=new Set(T.body.messageIds??[]),D=Zt({path:{threadId:t}}),N=Et([s]);await Promise.all([m.cancelQueries({queryKey:D}),bn(m,N)]);const G=m.getQueriesData({queryKey:D}).filter(ne=>ne[1]!==void 0).map(([ne,re])=>({queryKey:ne,data:re})),W=vn(m,N);return m.setQueriesData({queryKey:D},ne=>ne&&{...ne,items:Jn(ne.items,I,P)}),yn(m,N,ne=>Jn(ne,I,P)),{threadMessagesPrefix:D,listPrefixes:N,previousThreadMessages:G,previousThreadsList:W}},onError:(T,P,I)=>{if(I){for(const N of I.previousThreadMessages)m.setQueryData(N.queryKey,N.data);wn(m,I.previousThreadsList)}const D=P.body.isRead??!0;f({title:D?"Couldn't mark as read":"Couldn't mark as unread",detail:ft(T),error:T})},onSettled:(T,P,I,D)=>{D&&(m.invalidateQueries({queryKey:D.threadMessagesPrefix}),It(m,D.listPrefixes))}}),p=l.useCallback(T=>{h&&T.includes(h)&&d({to:"/mail/$mailboxId",params:{mailboxId:s},search:P=>({...P,selectedMessageId:void 0})})},[h,s,d]),{deleteMessages:x,isPending:b}=ms({mailboxId:s,threadId:t,onAfterOptimisticRemove:p}),{moveMessages:S,isPending:w}=Ds({mailboxId:s,threadId:t,accountId:a,onAfterOptimisticRemove:p}),{toggleTrusted:v,isPending:k,error:R,reset:A}=Do({messageId:e}),C=()=>{y({body:{messageIds:[e],isRead:!1}})},M=()=>{x([e])},L=()=>{o&&v(o,i)},E=g||b||w||k,F=E||!o,O=l.useCallback(T=>{S([e],T)},[S,e]),j=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($o,{accountId:a,currentMailboxId:s,onMove:O,disabled:E,label:"Move this message"}),r.jsxs(Fu,{trigger:r.jsx(_c,{className:"size-4"}),children:[r.jsxs(nn,{onClick:L,disabled:F,children:[i?r.jsx(pr,{className:"size-4 text-positive"}):r.jsx(mn,{className:"size-4 opacity-0"}),r.jsx("span",{title:j,children:"Trusted sender"})]}),n&&r.jsxs(nn,{onClick:C,disabled:E,children:[r.jsx(gr,{className:"size-4"}),"Mark as unread"]}),u&&r.jsxs(nn,{onClick:u,children:[r.jsx($c,{className:"size-4"}),c?"Show formatted":"Show raw email"]}),r.jsx($u,{}),r.jsxs(nn,{onClick:M,disabled:E,destructive:!0,children:[r.jsx(Lt,{className:"size-4"}),"Delete"]})]})]}),R&&r.jsx("div",{className:"w-64",children:r.jsx(ts,{variant:"inline",title:"Couldn't update trust",error:R,onRetry:()=>{A(),L()}})})]})},dw=e=>e==="link-expired"||e==="not-ready";class Ia extends Error{reason;status;constructor(t,s,n){super(s),this.name="AttachmentFetchError",this.reason=t,this.status=n}}const fw="x-remit-403-reason",mw="expired",hw=(e,t)=>{if(t?.trim()===mw)return"link-expired";const s=Ju(e,t);return s==="auth"?"auth":s==="body-missing"?"missing":"generic"},pw=300*1e3,Nl=async(e,t)=>{const s={},n=await t();n&&(s.Authorization=`Bearer ${n}`);const a=await dc(e,{headers:s,signal:AbortSignal.timeout(pw)});if(a.status===202)throw new Ia("not-ready","Attachment is still being fetched from the mail server",202);if(!a.ok)throw new Ia(hw(a.status,a.headers.get(fw)),`Failed to download attachment (${a.status} ${a.statusText})`,a.status);return a.blob()},gw=(e,t,s)=>{switch(e){case"auth":return{title:"Your session expired",detail:`Sign in again, then download ${t} once more. Other parts of the app may also stop responding until you do.`};case"link-expired":return{title:"This download link expired and could not be renewed",detail:`Reload the page, then download ${t} again. If that keeps failing, this is worth reporting.`};case"missing":return{title:"This attachment is missing from storage",detail:"Remit has the message but not the file. Re-sync the account from Settings, then try again."};case"not-ready":return{title:"Still fetching this attachment",detail:"Remit is downloading it from the mail server now. Try again in a few seconds."};default:return{title:"Couldn't download this attachment",detail:s}}},El=e=>e instanceof Ia?e.reason:"generic",xw=e=>e instanceof Error?e.message:typeof e=="string"?e:"An unexpected error occurred while downloading this attachment.",bw=(e,t,s)=>{if(e!=="auth")return Ga(Ya({title:`Bug: attachment download failed (${e})`,errorMessage:`Downloading "${t}" failed: ${s}`}))},vw=(e,t)=>{const s=URL.createObjectURL(e),n=document.createElement("a");n.href=s,n.download=t,n.rel="noopener",document.body.append(n),n.click(),n.remove(),setTimeout(()=>URL.revokeObjectURL(s),0)},yw=e=>{const t=e.toUpperCase();return t==="OCTET-STREAM"?"FILE":t},ww=e=>{const t=e.toLowerCase().replace(/[^a-z0-9]/g,"");return t.length>0?`attachment.${t}`:"attachment"},Il=e=>e.filter(t=>!t.isMultipart&&t.disposition===Nh.Attachment&&t.contentUrl.length>0).map(t=>({bodyPartId:t.bodyPartId,filename:Wg(t.dispositionFilename??"",ww(t.mediaSubtype)),typeLabel:yw(t.mediaSubtype),sizeOctets:t.sizeOctets,contentUrl:t.contentUrl})),Rl={status:"idle"},Sw=({messageId:e,bodyParts:t,hasAttachment:s=!1,className:n})=>{const{getToken:a}=ar(),o=Ee(),[i,c]=l.useState({}),u=l.useMemo(()=>Il(t??[]),[t]),m=Wa({path:{messageId:e}}),d=g=>Nl(g.contentUrl,a).catch(p=>{if(!dw(El(p)))throw p;return o.refetchQueries({queryKey:m}).then(()=>{const x=o.getQueryData(m),b=x?Il(x.bodyParts).find(S=>S.bodyPartId===g.bodyPartId):void 0;return Nl(b?.contentUrl??g.contentUrl,a)})}),f=(g,p)=>c(x=>({...x,[g]:p})),h=g=>{const p=u.find(x=>x.bodyPartId===g);if(!p)throw new Error(`No attachment part ${g} on message ${e}`);f(g,{status:"downloading"}),d(p).then(x=>{vw(x,p.filename),f(g,Rl)}).catch(x=>{const b=El(x),S=xw(x),{title:w,detail:v}=gw(b,p.filename,S);f(g,{status:"failed",title:w,detail:v,reportUrl:bw(b,p.filename,S)})})},y=s&&t!==void 0&&u.length===0;return r.jsx(Gg,{className:n,attachments:u.map(g=>({attachmentId:g.bodyPartId,filename:g.filename,typeLabel:g.typeLabel,sizeOctets:g.sizeOctets,download:i[g.bodyPartId]??Rl})),onDownload:h,hasUnlistedAttachment:y})},kw=()=>{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},Cw=({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"})]})]}),jw=(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}}},Nw=e=>e instanceof cs?e.reason:"generic",Ew=e=>e instanceof Error?e.message:typeof e=="string"?e:"An unexpected error occurred while loading the message body.",Iw=({error:e,onRetry:t})=>{const s=Nw(e),n=Ew(e),{title:a,detail:o}=jw(s,n),[i,c]=l.useState(!1),{Account:u}=ar();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(Pt,{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(Nt,{className:"size-4","aria-hidden":"true"})})]})]})},Rw=()=>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"})]}),Tl=()=>r.jsx("p",{className:"text-fg-muted text-sm italic",children:"This message has no body content."}),Dd=({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=kw(),{toggleTrusted:h,isPending:y}=Do({messageId:a??""}),g=!!e&&e.length>0,{picked:p,data:x,isLoading:b,isError:S,error:w,refetch:v}=Zu({messageId:a,bodyParts:e,enabled:g}),k=l.useMemo(()=>og(e??[]),[e]),R=g&&x?.kind==="html"?x.body:t,A=g&&x?.kind==="text"?x.body:s;if(g){if(b)return r.jsx("div",{className:qe("message-body",c),children:r.jsx(Rw,{})});if(S)return r.jsx("div",{className:qe("message-body",c),children:r.jsx(Iw,{error:w,onRetry:()=>v()})});if(!p)return r.jsx("div",{className:qe("message-body",c),children:r.jsx(Tl,{})})}else if(!t&&!s)return r.jsx("div",{className:qe("message-body",c),children:r.jsx(Tl,{})});const C=!!(o&&a),M=()=>{!o||y||(m(!0),h(o,!1))};return r.jsx(iu,{className:c,html:R,text:A,isDark:f,category:i,allowImages:d,resolveCid:k,renderBlockedNotice:L=>r.jsx(Cw,{blockedImageCount:L,canAlwaysTrust:C,isTrustPending:y,onLoadOnce:()=>m(!0),onAlwaysTrust:M})})},Tw=({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:y})=>{const g=Ee(),{deleteMessages:p}=ms({mailboxId:s,threadId:t}),{moveMessages:x}=Ds({mailboxId:s,threadId:t,accountId:n}),{toggleTrusted:b}=Do({messageId:e}),{mutate:S}=_e({...ur(),onSettled:()=>{g.invalidateQueries({queryKey:Zt({path:{threadId:t}})}),It(g,Et([s]))}}),w=l.useCallback(A=>{x([e],A)},[x,e]),v=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(pr,{className:"size-4 text-positive"}):r.jsx(mn,{className:"size-4"}),onSelect:()=>b(c,u)}),d&&R.push({key:"raw",label:m?"Show formatted":"Show raw email",icon:r.jsx($c,{className:"size-4"}),onSelect:d}),r.jsx(ou,{hasThread:!0,onReply:f,onReplyAll:h,onForward:y,isStarred:o,onToggleStar:i,onDelete:v,isRead:a,onToggleRead:k,overflowItems:R,moveSlot:n?r.jsx($o,{accountId:n,currentMailboxId:s,onMove:w,label:"Move this message"}):void 0})},Mw=()=>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"})]}),Aw=({messageId:e,enabled:t=!0})=>{const{data:s,isLoading:n,isError:a,error:o,refetch:i}=ve({...Om({path:{messageId:e}}),enabled:t});if(n)return r.jsx("div",{className:"message-body",children:r.jsx(Mw,{})});if(a)return r.jsx("div",{className:"message-body",children:r.jsx(ts,{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})})},Ow=()=>r.jsx(pr,{className:"inline-block size-4 ml-1 -mt-0.5 text-positive align-middle","aria-label":"Trusted sender","data-testid":"trusted-sender-badge"}),Pd=(e,t)=>({id:e.messageId,fromName:e.fromName??e.fromEmail??"?",fromEmail:e.fromEmail??"",toLabel:"",dateLabel:t,snippet:e.snippet||"",bodyHtml:""}),Ld=({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:qe("shrink-0 p-0.5 rounded transition-colors",e?"text-warning":qe("text-fg-subtle hover:text-warning",n&&"opacity-0 group-hover:opacity-100 focus:opacity-100"),s&&"opacity-50"),children:r.jsx(Xt,{className:qe("size-3.5",e&&"fill-current")})}),Dw=({threadMessage:e,isFocused:t,onToggle:s,onToggleStar:n,isStarPending:a})=>{const o=Sc(e.sentDate,"datetime"),i=Pd(e,o);return r.jsx(lu,{message:i,onClick:s,isFocused:t,isUnread:!e.isRead,trailing:r.jsxs(r.Fragment,{children:[e.hasAttachment&&r.jsx(xr,{className:"size-3 shrink-0 text-fg-subtle",role:"img","aria-label":"Has an attachment"}),r.jsx(Ld,{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})]})})},Pw=({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:y,onReply:g,onReplyAll:p,onForward:x})=>{const b=Sc(e.sentDate,"long"),S=!e.isRead,w=t?.envelope.from[0]?.flags?.trusted?.value===!0,v=t?.envelope.from[0]?.addressId,k=Pd(e,b),R=e.autoMoved||e.spamReport?r.jsx(S0,{accountId:d,messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,autoMoved:e.autoMoved,spamReport:e.spamReport}):null;return r.jsx(cu,{message:k,isFocused:y?!1:i,onHeaderClick:c,senderBadge:w?r.jsx(Ow,{}):void 0,trailing:r.jsx("span",{"data-testid":"message-date",className:"text-2xs text-fg-subtle",children:b}),to:t?r.jsx(wp,{label:"To",addresses:t.envelope.to}):null,indicators:R||!y?r.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mt-0.5",children:[R,!y&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"flex items-center justify-end gap-1",children:r.jsx(Ld,{isStarred:e.hasStars,onToggleStar:u,isStarPending:m})}),S&&r.jsx("span",{className:"size-1.5 rounded-full bg-accent","aria-label":"Unread"})]})]}):void 0,actionMenu:y?void 0:r.jsx(uw,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,isRead:e.isRead,accountId:d,fromAddressId:v,isTrusted:w,showRaw:f,onToggleRaw:h}),actionBar:y?r.jsx(Tw,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,accountId:d,isRead:e.isRead,isStarred:e.hasStars,onToggleStar:u,fromAddressId:v,isTrusted:w,showRaw:f,onToggleRaw:h,onReply:g,onReplyAll:p,onForward:x}):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&&Dm(a)?r.jsx("div",{className:"mt-3",children:r.jsx(td,{message:"This message has been deleted"})}):n?r.jsx("div",{className:"mt-3",children:r.jsx(ts,{variant:"inline",title:"Couldn't load this message",error:a,onRetry:o})}):f?r.jsx("div",{className:"mt-3",children:r.jsx(Aw,{messageId:e.messageId})}):r.jsxs("div",{className:"mt-3",children:[r.jsx(Dd,{bodyParts:t?.bodyParts,messageId:e.messageId,fromAddressId:t?.envelope.from[0]?.addressId,isTrusted:w,category:Er(e.category)}),r.jsx(Sw,{messageId:e.messageId,bodyParts:t?.bodyParts,hasAttachment:e.hasAttachment,className:"mt-4 px-2 lg:px-0"})]})})},Lw=({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:y,isLoading:g,isError:p,error:x,refetch:b}=ve({...dr({path:{messageId:e.messageId}}),enabled:t,meta:{softError:!0}});return t?r.jsx(Pw,{threadMessage:e,messageData:y,isLoading:g,isError:p,error:x,onRetry:()=>b(),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(Dw,{threadMessage:e,isFocused:s,onToggle:n,onToggleStar:a,isStarPending:o})},Fw=()=>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 Ml({authenticity:e,onOpenIntelligence:t}){return e.dkimMismatch?r.jsxs("div",{className:"flex items-start gap-2 rounded-none border-b border-danger/20 bg-danger-soft px-5 py-2.5 text-sm",children:[r.jsx($s,{className:"mt-0.5 size-4 shrink-0 text-danger"}),r.jsxs("p",{className:"flex-1 leading-snug text-fg",children:["This message claims to be from"," ",r.jsx("span",{className:"font-semibold",children:e.fromDomain})," but was sent",e.dkimDomain?` via ${e.dkimDomain}`:" from a different domain","."]}),t&&r.jsx("button",{type:"button",onClick:t,className:"shrink-0 text-2xs font-medium text-danger hover:underline",children:"Why?"})]}):null}const Bs=({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=es(),{handlers:y}=c0({onSwipeLeft:m,onSwipeRight:d}),{accountId:g}=To(t),{data:p,isLoading:x,isError:b,error:S,refetch:w}=ve({...Pm({path:{threadId:e}})}),v=l.useMemo(()=>p?.items??[],[p?.items]),k=v[v.length-1],R=l.useRef(new Map),[A,C]=l.useState(new Set),[M,L]=l.useState(null),[E,F]=l.useState(0);l.useEffect(()=>{if(v.length>0&&e!==M){L(e);const de=new Set([v[v.length-1].threadMessageId]);if(n){const se=v.find(be=>be.messageId===n);se&&de.add(se.threadMessageId)}C(de),F(v.length-1)}},[e,v,M,n]);const O=l.useCallback(de=>{C(se=>{const be=new Set(se);return be.has(de)?be.delete(de):be.add(de),be})},[]),j=l.useCallback(de=>{const se=v[de];if(!se)return;R.current.get(se.threadMessageId)?.scrollIntoView({behavior:"smooth",block:"nearest"})},[v]),T=l.useCallback(()=>{if(v.length===0)return;const de=Math.min(E+1,v.length-1);F(de),j(de)},[v.length,E,j]),P=l.useCallback(()=>{if(v.length===0)return;const de=Math.max(E-1,0);F(de),j(de)},[v.length,E,j]),I=l.useCallback(()=>{const de=v[E];de&&O(de.threadMessageId)},[v,E,O]),{data:D}=ve({...$t(),staleTime:1/0}),N=D?.accounts?.[0];a0({messages:v,expandedIds:A,threadId:e,mailboxId:t,accountId:N?.accountId});const{toggleStar:G,isPending:W,pendingMessageId:ne}=Mo({threadId:e,mailboxId:t,messages:v}),[re,he]=l.useState(null),[te,ce]=l.useState(0),ie=l.useCallback(de=>{he(de),ce(se=>se+1)},[]);l.useEffect(()=>{c&&c!=="new"&&(ie(c),u?.())},[c,u,ie]);const{data:U}=ve({...dr({path:{messageId:k?.messageId??""}}),enabled:!!k&&re!==null}),_=l.useCallback(()=>ie("reply"),[ie]),ue=l.useCallback(()=>ie("reply_all"),[ie]),pe=l.useCallback(()=>ie("forward"),[ie]),ye=l.useCallback(()=>{he(null),u?.()},[u]),Se=l.useRef(null);if(l.useEffect(()=>{if(re===null||te===0)return;const de=Se.current;if(!de)return;const se=()=>de.scrollIntoView({behavior:"smooth",block:"end"});if(se(),typeof ResizeObserver>"u")return;const be=new ResizeObserver(se);return be.observe(de),()=>be.disconnect()},[te,re]),Ro({enabled:!x&&v.length>0&&re===null,bindings:[{key:"j",handler:T,preventDefault:!0},{key:"ArrowDown",handler:T,preventDefault:!0},{key:"k",handler:P,preventDefault:!0},{key:"ArrowUp",handler:P,preventDefault:!0},{key:"Enter",handler:I,preventDefault:!0},{key:"o",handler:I,preventDefault:!0},{key:"r",handler:_,preventDefault:!0},{key:"R",handler:ue,noModifiers:!1,preventDefault:!0},{key:"f",handler:pe,preventDefault:!0}]}),x)return r.jsx(Fw,{});if(b)return r.jsx("div",{className:"flex h-full items-center justify-center",children:r.jsx(ts,{title:"Couldn't load this conversation",error:S,onRetry:()=>w()})});if(v.length===0)return r.jsx("div",{className:"flex h-full items-center justify-center",children:r.jsx(td,{message:"No messages in this thread"})});const H=s||v[0]?.subject||"(No subject)",we=v.length,xe=de=>r.jsx("div",{children:v.map((se,be)=>r.jsx("div",{ref:Be=>{Be&&R.current.set(se.threadMessageId,Be)},children:r.jsx(Lw,{threadMessage:se,isExpanded:A.has(se.threadMessageId),isFocused:be===E,onToggle:()=>O(se.threadMessageId),onToggleStar:()=>G(se.messageId,se.hasStars),isStarPending:W&&ne===se.messageId,accountId:g,mobile:de,onReply:de?_:void 0,onReplyAll:de?ue:void 0,onForward:de?pe:void 0})},se.threadMessageId))}),Ie=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:H}),r.jsxs("p",{className:"mt-1 text-2xs text-fg-subtle",children:[we," ",we===1?"message":"messages"]})]});return h?r.jsxs("article",{className:"h-full flex flex-col",children:[Ie,a?.dkimMismatch&&r.jsx(Ml,{authenticity:a,onOpenIntelligence:o}),r.jsx("div",{className:"flex-1 overflow-auto",children:xe(!1)}),re!==null&&r.jsx(xl,{mode:re,account:N,sourceMessage:U,onClose:ye})]}):r.jsxs(Mg,{thread:{subject:H,messages:[]},onBack:i??(()=>{}),intelligenceOpen:f,onToggleIntelligence:o,touchHandlers:y,children:[a?.dkimMismatch&&r.jsx(Ml,{authenticity:a,onOpenIntelligence:o}),xe(!0),re!==null&&r.jsx("div",{ref:Se,children:r.jsx(xl,{mode:re,account:N,sourceMessage:U,onClose:ye})})]})};function xs(){const{mailboxNameIndex:e,accountNameIndex:t}=De();return{...Ot({select:n=>Qu(n.matches)})?{}:{mailboxesByName:e},accountsByName:t}}const _o=e=>e.trim().toLocaleLowerCase(),Fd={personal:"Personal",uncategorized:"Unclassified",transactional:"Transactional",newsletter:"Newsletter",marketing:"Marketing",social:"Social",automated:"Automated"},$w=Object.values(ot).map(e=>({value:e,label:Fd[e]})),_w={unclassified:"uncategorized"},Ra=[{name:"from",label:"Sender",values:"contact"},{name:"subject",label:"Subject",values:"text"},{name:"category",label:"Category",values:"fixed",options:$w},{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"}],zw=new Map(Ra.map(e=>[e.name,e])),$d=e=>zw.get(e.toLowerCase()),Bw=/^\d{4}-\d{2}-\d{2}$/,Uw=e=>/[\s"]/.test(e),Kw=e=>Uw(e)?`"${e.replace(/"/g,"")}"`:e,_d=(e,t)=>`${e}:${Kw(t)}`,qw=e=>{if(!e.startsWith('"'))return e;const t=e.slice(1);return t.endsWith('"')?t.slice(0,-1):t};function zo(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 zd(e){const t=e.indexOf(":");if(t<=0)return;const s=e.slice(t+1);return{name:e.slice(0,t).toLowerCase(),value:qw(s),rawValue:s}}function Hw(e,t,s){if(!Bw.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 Ww(e){const t=e.toLowerCase(),s=_w[t];return s||Object.values(ot).find(a=>a===t)}function Vw(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 Qw(e,t){const s=zd(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=Ww(a);return o?{type:"category",raw:e,value:a,category:o}:void 0}case"is":return Vw(e,a);case"has":return a.toLowerCase()==="attachment"?{type:"hasAttachment",raw:e}:void 0;case"before":case"after":return Hw(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 Us(e,t={}){const s=[],n=[];for(const a of zo(e)){const o=Qw(a.raw,t);o?s.push(o):n.push(a.raw)}return{freeText:n.join(" "),tokens:s}}function Gw(e,t){return zo(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: ${Fd[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 Yw=20,Xw=new Set(Object.values(ot)),Jw=e=>e!==void 0&&Xw.has(e)?e:void 0,Zw=e=>{if(e.some(t=>t.type==="isUnread"))return!1;if(e.some(t=>t.type==="isRead"))return!0};function Ud({mailboxId:e,filterCategory:t}={}){const{searchQuery:s}=De(),n=xs(),a=Ot({select:v=>v.matches}),o=_o(s),{freeText:i,tokens:c}=Us(o,n),u=i.length>0,m=c.find(v=>v.type==="category"),d=Jw(t)??m?.category,f=c.some(v=>v.type==="hasAttachment")?!0:void 0,h=c.some(v=>v.type==="isStarred")?!0:void 0,y=Zw(c),g=c.find(v=>v.type==="after"),p=c.find(v=>v.type==="before"),x=c.find(v=>v.type==="in"),b=Sy({matches:a,callerMailboxId:e,inTokenMailboxId:x?.mailboxId}),{data:S,isLoading:w}=ve({...gc({query:{query:i,mailboxId:b,limit:Yw,...d!==void 0?{category:d}:{},...f!==void 0?{hasAttachment:f}:{},...h!==void 0?{hasStars:h}:{},...y!==void 0?{isRead:y}:{},...g?{sentDateFrom:g.epochSeconds}:{},...p?{sentDateTo:p.epochSeconds}:{}}}),enabled:u,staleTime:6e4});return{hits:S?.items??[],isLoading:u&&w}}const eS=(e,t)=>e.createdAt!==t.createdAt?e.createdAt-t.createdAt:e.accountId.localeCompare(t.accountId),tS=e=>[...e].sort(eS);function er(e){const t=e.authenticity?.dkimMismatch===!0;return{id:e.messageId,accountId:e.accountId,mailboxId:e.mailboxId,threadId:e.threadId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:gt(e.sentDate),sentDate:e.sentDate,isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Er(e.category),suspicious:t}}function Al(e){return e.filter(t=>t.muted!==!0)}function sS(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 Ol=[{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 nS(e){const t=new Map(Ol.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 Ol){const a=t.get(n.category);a&&a.length>0&&s.push({id:n.id,label:n.label,threads:a})}return s}function Kd(e,t){return e.fromName.toLowerCase().includes(t)||e.fromEmail.toLowerCase().includes(t)||e.subject.toLowerCase().includes(t)||e.snippet.toLowerCase().includes(t)}function Bo(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 qd="This account has no Junk folder appointed, so there is nowhere to file these. Appoint one under Settings › Folders.",rS="These are already in Junk, so there is nowhere to file them.",Tr=(e,t)=>e!==void 0&&e!==t?e:void 0,aS=(e,t)=>{if(Tr(e,t)===void 0)return e===void 0?qd:rS},oS={sender:"sender",recipient:"recipient",subject:"subject",attachment:"attachment",body:"body",entities:"entities"};function iS(e){return oS[e]??e}function lS(e,t){const{folder:s}=Xa(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:gt(e.sentDate),unread:!e.isRead,flagged:e.hasStars===!0,threadId:e.threadId,mailboxId:e.mailboxId,...s?{folder:s}:{}}}function Kn(e,t){const{folder:s}=Xa(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.threadId?{threadId:e.threadId}:{},...e.mailboxId?{mailboxId:e.mailboxId}:{},...s?{folder:s}:{}}}function cS(e,t){const{mailboxId:s,folder:n}=Xa(t,e.mailboxIds);return{id:e.messageId,sender:e.fromName??"Unknown",subject:e.subject??"(No subject)",snippet:"",date:e.sentDate!=null?gt(e.sentDate*1e3):"",threadId:e.threadId,matchedChunkLabel:iS(e.matchedChunkType),score:e.score,...s?{mailboxId:s}:{},...n?{folder:n}:{}}}function Hd(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(cS(o,s)));return a}function Wd(e){const{spam:t}=xo([...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 uS=e=>{const{mailboxId:t,messages:s}=e,n=Ee(),{pushError:a}=tt(),{mutateAsync:o,isPending:i}=_e({...Lm(),onError:(u,m)=>{a({title:m.body.action==="Remove"?"Couldn't remove label":"Couldn't apply label",detail:ft(u),error:u})},onSettled:(u,m,d)=>{It(n,Et(jr(d.body.messageIds??[],s??[],t)))}});return{applyLabel:l.useCallback((u,m,d)=>{u.length!==0&&Os(u,f=>o({body:{messageIds:f,labelId:m,action:d}}))},[o]),isPending:i}};function Vd({accountId:e,mailboxId:t,messageIds:s}){const{labels:n}=ro(e),{applyLabel:a}=uS({mailboxId:t}),o=l.useMemo(()=>n.map(i=>({key:i.labelId,label:i.name,icon:r.jsx("span",{className:`size-2.5 rounded-full ${Fm(i.color)?ti[i.color]:ti.Default}`}),onSelect:()=>a(s,i.labelId,"Apply")})),[n,s,a]);return o.length===0?null:r.jsx(ho,{triggerLabel:"Apply label to selected messages",triggerIcon:r.jsx($m,{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 dS=768,Qd=e=>e!=="desktop",Mr=()=>{const e=ni(`(min-width: ${dS}px)`);return ni(yc)?"desktop":e?"tablet":"phone"},Gd=8;function Uo(e,t){const s=Math.max(0,Math.min(t,e.length)),n=zo(e).find(o=>s>=o.start&&s<=o.end);if(!n)return{start:s,end:s,raw:""};const a=zd(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 fS(e,t){const s=Uo(e,t);if(s.name===void 0)return{kind:"token",query:s.raw};const n=$d(s.name);if(n)return{kind:"value",token:n.name,source:n.values,query:s.value??""}}const mS={mailbox:"mailboxes",account:"accounts",contact:"contacts"},hS=(e,t)=>{if(e.values==="fixed")return e.options??[];const s=mS[e.values];return s?t[s]??[]:[]},pS=(e,t)=>{if(t==="")return 1;const s=e.toLowerCase();return s.startsWith(t)?0:s.includes(t)?1:-1},Ta=(e,...t)=>{let s=-1;for(const n of t){if(n===void 0)continue;const a=pS(n,e);a<0||(s<0||a<s)&&(s=a)}return s},Yd=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,Gd).map(s=>s.suggestion)},Dl=e=>({value:`${e.name}:`,label:`${e.name}:`,hint:e.label});function gS(e){const t=e.trim().toLowerCase();if(t==="")return Ra.map(Dl);const s=[];for(const n of Ra)if(s.push({rank:Ta(t,`${n.name}:`,n.label),suggestion:Dl(n)}),n.values==="fixed")for(const a of n.options??[]){const o=_d(n.name,a.value);s.push({rank:Ta(t,o,a.label),suggestion:{value:o,label:a.label??o,hint:o}})}return Yd(s)}function xS(e,t,s){const n=t.trim().toLowerCase(),a=hS(e,s).map(o=>({rank:Ta(n,o.value,o.label),suggestion:{value:_d(e.name,o.value),label:o.label??o.value,...o.hint?{hint:o.hint}:{}}}));return Yd(a)}function bS(e,t,s={}){const n=Uo(e,t);if(n.name===void 0)return gS(n.raw);const a=$d(n.name);return a?xS(a,n.value??"",s):[]}function vS(e,t,s){const n=Uo(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 yS=e=>({value:e.normalizedEmail,...e.displayName?{label:e.displayName,hint:e.normalizedEmail}:{}});function wS(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 SS(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 kS(e,t=[]){const s=e.flat().filter(o=>o.fullPath),n=new Map;for(const o of s){const i=fa(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=fa(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 CS(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 jS=250,NS=2;function ES({query:e,cursor:t,enabled:s}){const{accounts:n}=De(),{mailboxesByName:a}=xs(),o=a!==void 0,i=s?fS(e,t):void 0,c=i?.source==="contact"?i.query.trim():"",u=mr(c,jS),{data:m}=ve({...ir({query:{q:u,limit:Gd}}),enabled:u.length>=NS}),d=mt({queries:n.map(g=>({...it({path:{accountId:g.accountId}}),staleTime:1/0}))}),f=l.useMemo(()=>o?kS(d.map(g=>g.data?.items??[]),n):[],[o,d,n]),h=l.useMemo(()=>CS(n),[n]),y=l.useMemo(()=>(m?.items??[]).map(yS),[m]);return l.useMemo(()=>{if(!s)return[];const g=bS(e,t,{mailboxes:f,accounts:h,contacts:y});return o?g:g.filter(p=>p.value!=="in:")},[s,e,t,f,h,y,o])}const IS={title:"",navSlot:null,titleMeta:null,searchSlot:null,searchField:null,searchResults:null,makeFilterSlot:null},Ma=l.createContext(IS),Ar=()=>l.useContext(Ma),RS=new Set(["hasAttachment","isUnread","isRead","isStarred","category","before","after"]),TS=e=>RS.has(e),MS=(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}TS(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}},AS=(e,t,s)=>e.targetAccountId??t??s[0]?.accountId,Xd="remit.recentSearches",OS=5;function Aa(){try{const e=localStorage.getItem(Xd);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}catch{return[]}}function Pl(e){const t=e.trim();if(!t)return Aa();const s=[t,...Aa().filter(n=>n!==t)].slice(0,OS);try{localStorage.setItem(Xd,JSON.stringify(s))}catch{return s}return s}const DS=e=>e.tier!=="phone"&&e.hasLiveInput&&!(e.bodyRendersCommittedResults&&e.hasCommittedQuery);function Jd({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:y="Related",searchResultsInBody:g=!1,refreshControl:p}){const{accounts:x,resultFolderIndex:b,searchQuery:S,searchInput:w,onSearchChange:v,onSearchClear:k,searchViewKey:R}=De(),A=xs(),C=Ve(),M=ps(),L=Mr(),[E,F]=l.useState(!1),[O,j]=l.useState(Aa),T=_m(),P=l.useRef(R);l.useEffect(()=>{P.current!==R&&(P.current=R,F(!1))},[R]);const[I,D]=l.useState(0),[N,G]=l.useState(!1),[W,ne]=l.useState(void 0),re=ES({query:w,cursor:I,enabled:N&&w.trim().length>0}),he=l.useCallback(ae=>{const Z=vS(w,I,ae);v(Z.query),ne({cursor:Z.cursor})},[w,I,v]),te=fc({count:re.length,onAccept:ae=>{const Z=re[ae];Z&&he(Z)}}),{comboboxProps:ce,handleKeyDown:ie}=te,U=l.useMemo(()=>({comboboxProps:ce,onKeyDown:ie,onCaretChange:D,onFocusChange:G,...W?{caret:W}:{}}),[ce,ie,W]),_=te.open?r.jsx(mc,{id:te.listId,suggestions:re,activeIndex:te.activeIndex,optionId:te.optionId,onPick:he,onHighlight:te.setActiveIndex,label:"Search suggestions",className:"mx-row-inset mt-1 shrink-0"}):null,ue=w.trim().length>0,{mailboxesByName:pe,accountsByName:ye}=A,Se=l.useMemo(()=>Us(w,{mailboxesByName:pe,accountsByName:ye}),[w,pe,ye]),H=Se.tokens.map(ae=>({label:Bd(ae),onRemove:()=>v(Gw(w,ae))})),we=c??[],xe=m??[],Ie=ue?[{id:"top",label:h,results:we},{id:"related",label:y,results:xe}]:[],se=!(we.length+xe.length>0)&&(u===!0||d===!0),{scope:be}=Xu(x),Be=Ot({select:ae=>ae.matches}),me=Gu(Be),K=Cy(Be,be,me?b.get(me)?.role:void 0),Te=K.kind==="global"?Wd([...we,...xe]):void 0,Ne=Te?{kind:"global",onScopeToSpam:()=>C({to:"/mail/$mailboxId",params:{mailboxId:Te.mailboxId},search:{q:S||void 0,selectedMessageId:void 0,selectedThreadId:void 0}})}:K,Pe=xe.length>0,$=l.useMemo(()=>MS(Se,{searchHadSemanticReach:Pe}),[Se,Pe]),le=ue?$:void 0,J=ue?{onClick:()=>{F(!1),T("properties","search")},blockedReason:yb($)?void 0:"Add a sender or words to filter on"}:void 0,ge=J?r.jsx(du,{...J}):null,Me=DS({tier:L,hasLiveInput:ue,hasCommittedQuery:S.trim().length>0,bodyRendersCommittedResults:g}),Ye=ae=>{j(Pl(w)),f?.(ae)},He=r.jsx(fu,{value:w,sections:Ie,loading:se,onSelectResult:Ye,tokens:H,scope:Ne}),Ze=n===void 0,Ae=Me?r.jsx("div",{className:"h-full overflow-y-auto",children:He}):null,nt=Ae&&!Ze?Ae:s,st=Ae&&Ze?Ae:null,Re=Qd(L),V=Re&&(E||ue),fe=l.useMemo(()=>({title:e,searchResults:st,makeFilterSlot:ge,searchConversion:le,navSlot:M&&!M.showNavPane&&r.jsx(oe,{variant:"ghost",size:"touch",icon:r.jsx(fr,{className:"size-5"}),onClick:()=>M.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(zm,{}),p]}),searchSlot:Re&&!V&&r.jsx(oe,{variant:"ghost",size:"touch",icon:r.jsx(rr,{className:"size-5"}),onClick:()=>F(!0),"aria-label":"Search",className:"shrink-0"}),searchField:V&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"min-w-0 flex-1",children:r.jsx(go,{value:w,onChange:v,onClear:k,globalFocusKey:!1,showClearButton:!1,suggest:U})}),r.jsx(oe,{variant:"ghost",size:"touch",icon:r.jsx(Nt,{className:"size-5"}),onClick:()=>{k(),F(!1)},"aria-label":"Close search",className:"shrink-0"})]})}),[e,t,M,Re,V,w,v,k,U,st,ge,le,p]);if(L==="phone"&&E){const ae=Z=>{j(Pl(w)),F(!1),f?.(Z)};return r.jsxs(Ma.Provider,{value:fe,children:[r.jsx(px,{value:w,onChange:v,onClear:k,onCancel:()=>{F(!1),k()},filter:i,recentSearches:O,onPickRecent:v,makeFilter:J,sections:Ie,loading:se,onSelectResult:ae,tokens:H,scope:Ne,suggest:U,suggestList:_}),a]})}return r.jsx(Ma.Provider,{value:fe,children:r.jsxs("section",{className:"relative flex h-full w-full flex-col bg-surface",children:[n?.(fe),_,r.jsx("div",{className:"min-h-0 flex-1",children:nt}),o,a]})})}const PS=120,Zd=({keyboardFocusedMessageId:e,openMessageId:t,enabled:s,open:n,delayMs:a=PS})=>{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 ef(e,t){if(e.length!==0)return t!==void 0&&e.includes(t)?t:e[0]}const Ko=l.createContext(null),LS=e=>{const t=l.useContext(Ko);return t?t.rowInteraction(e):null},qo=()=>{const e=l.useContext(Ko);if(!e)throw new Error("useThreadListSelection must be used inside <ThreadListInteraction>");return e},FS="[data-message-id]",$S=e=>Array.from(e.querySelectorAll(FS)).map(t=>t.dataset.messageId).filter(t=>t!==void 0),_S=(e,t)=>e.length===t.length&&e.every((s,n)=>s===t[n]),zS=e=>{const[t,s]=l.useState([]);return l.useEffect(()=>{const n=e.current;if(!n)return;const a=()=>{const i=$S(n);s(c=>_S(c,i)?c:i)};a();const o=new MutationObserver(a);return o.observe(n,{childList:!0,subtree:!0}),()=>o.disconnect()},[e]),t};function tf({selectedMessageId:e,onOpen:t,onDeleteMessages:s,onSelectionVerb:n,wizardOpen:a=!1,isDeleting:o=!1,commandsRef:i,onTriageContextChange:c,children:u}){const m=es(),d=l.useRef(null),f=zS(d),h=Sb({orderedIds:f,isDesktop:m,initialFocusedId:e}),{focusedMessageId:y,setFocusedMessageId:g,pendingDomFocusRef:p,cursorMovedByPointerRef:x,selection:b,isMultiSelectMode:S,exitSelection:w,handleRowSelect:v}=h,{selectedIds:k,selectedCount:R,isSelected:A,toggle:C,select:M,toggleAll:L}=b,E=f.length>0&&f.every(_=>k.has(_)),F=l.useCallback(()=>{f.length>0&&L(f)},[f,L]),{intersectWith:O}=b;l.useEffect(()=>{O(f)},[O,f]),l.useEffect(()=>{const _=p.current;_!==null&&(p.current=null,d.current?.querySelector(`[data-message-id="${_}"]`)?.focus())});const j=l.useCallback(_=>{x.current=!0,g(_)},[x,g]),T=l.useCallback(_=>{m||M(_)},[m,M]),P=l.useCallback(()=>{y&&t(y)},[y,t]),I=l.useCallback(_=>t(_,{replace:!0}),[t]);Zd({keyboardFocusedMessageId:h.keyboardFocusedMessageId,openMessageId:e,enabled:m&&R===0,open:I});const[D,N]=l.useState(null),G=l.useCallback(_=>D!==null?!0:R>0?(n(_),!0):_!=="delete"||!y?!1:(N([y]),!0),[D,R,n,y]),W=l.useCallback(()=>{D!==null&&(s(D),N(null),w())},[D,s,w]),ne=l.useCallback(()=>N(null),[]),re=l.useCallback(()=>R===0?!1:(w(),!0),[R,w]),he=f.length>0;l.useEffect(()=>{if(i){if(!he){i.current=null;return}return i.current={focusNext:h.focusNext,focusPrevious:h.focusPrevious,focusFirst:h.focusFirst,focusLast:h.focusLast,openFocused:P,toggleSelect:h.toggleFocusedSelection,extendSelectDown:h.extendRangeDown,extendSelectUp:h.extendRangeUp,selectAll:h.selectAllLoaded,clearSelection:re,requestVerb:G,toggleDensity:()=>{}},()=>{i.current=null}}},[i,he,h.focusNext,h.focusPrevious,h.focusFirst,h.focusLast,h.toggleFocusedSelection,h.extendRangeDown,h.extendRangeUp,h.selectAllLoaded,P,re,G]);const te=l.useMemo(()=>Array.from(k),[k]),ce=D!==null;l.useEffect(()=>{c?.({focusedMessageId:y,selectedIds:te,orderedIds:f,hasList:he,blocksKeyboard:ce||a})},[c,y,te,f,he,ce,a]);const ie=ef(f,y),U=l.useMemo(()=>({selectedIds:k,selectedCount:R,exitSelection:w,startSelectionVerb:n,orderedIds:f,allSelected:E,toggleAllLoaded:F,rowInteraction:_=>({focused:_===y,isTabStop:_===ie,isDesktop:m,onFocusRow:j,selection:{isChecked:A(_),onToggleCheck:C,onRowSelect:v,isMultiSelectMode:S,onLongPress:T}})}),[k,R,w,n,f,E,F,y,ie,m,j,A,C,v,S,T]);return r.jsxs(Ko.Provider,{value:U,children:[r.jsx("div",{ref:d,className:"contents",children:u}),r.jsx(jc,{isOpen:ce,title:kc(D?.length??0),description:"You can restore them from Trash later.",confirmLabel:"Move to Trash",destructive:!0,isBusy:o,onConfirm:W,onCancel:ne})]})}function BS({title:e,isDeleting:t}){const s=Ar(),{selectedCount:n,exitSelection:a,startSelectionVerb:o,orderedIds:i,allSelected:c,toggleAllLoaded:u}=qo();return r.jsx(yo,{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 aa=e=>{e.preventDefault(),e.stopPropagation()},sf=(e,t)=>{const s=l.useRef(!1),n=l.useCallback(i=>{if(s.current=!1,i.button!==0)return;const c=Yn(i);pi(c)&&t?.(e,c)&&(aa(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,aa(i),!0;const c=Yn(i);return!pi(c)||!t?.(e,c)?!1:(aa(i),c.shiftKey&&window.getSelection()?.removeAllRanges(),!0)},[t,e]);return{onMouseDown:n,onContextMenu:a,claimClick:o}},US=({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=Ee(),y=e.id,g=LS(y),p=s??g?.focused??!1,x=n??g?.isTabStop??!1,b=c??g?.selection,S=f??g?.onFocusRow,w=o??g?.isDesktop??!0,v=b?.isChecked??!1,k=b?.isMultiSelectMode??!1,R=b?.onToggleCheck,A=b?.onRowSelect,C=b?.onLongPress,M=l.useCallback(N=>{N.preventDefault(),N.stopPropagation(),R?.(y)},[R,y]),L=sf(y,A),E=l.useCallback(N=>{if(!L.claimClick(N)){if(!w){if(k){N.preventDefault(),N.stopPropagation(),R?.(y);return}d?.();return}A?.(y,Yn(N)),d?.()}},[L,w,k,R,A,d,y]),F=l.useCallback(()=>{C?.(y)},[C,y]),{longPressProps:O}=nu({onLongPress:F,accessibilityDescription:v?"Deselect message":"Select message"}),j=l.useCallback(()=>{h.prefetchQuery(dr({path:{messageId:y}}))},[h,y]),T=l.useCallback(()=>{j(),S?.(y)},[j,S,y]),P=Fs({"data-list-row":"","data-message-row":!0,"data-message-id":y,...u?{role:"option","aria-selected":v}:{},tabIndex:x?0:-1,onClick:E,onMouseDown:L.onMouseDown,onContextMenu:L.onContextMenu,onMouseEnter:j,onFocus:T},w||!b?{}:O),I=qe(a==="compact"?Zc({active:t,focused:p}):qe("group",_s({active:t,focused:p})),"outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-inset",v&&"bg-accent-soft",!w&&"min-h-11 select-none [-webkit-touch-callout:none]"),D=a==="compact"?r.jsx(eu,{thread:e}):r.jsx(mo,{thread:e,badge:i,selection:b?{checked:v,alwaysVisible:k,onToggle:M}:void 0});return m===void 0?r.jsx("button",{type:"button",...P,className:I,children:D}):r.jsx(qt,{to:"/mail/$mailboxId",params:{mailboxId:m},search:N=>({...N,selectedMessageId:y}),...P,className:I,children:D})},Ho=l.memo(US),nf=8,rf=e=>e==="From"||e==="FromDomain",KS=e=>({value:e.email,label:e.displayName??e.email,...e.displayName?{hint:e.email}:{},...e.fromSelection?{source:"selected"}:{}}),qS=e=>{const t=bu(e.email);if(t!==null)return{value:t,...e.fromSelection?{source:"selected"}:{}}},HS=(e,t)=>e.value.toLowerCase().includes(t)||(e.label??"").toLowerCase().includes(t),WS=(e,t,s)=>{if(!rf(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"?KS(i):qS(i);if(!c)continue;const u=c.value.toLowerCase();if(!(u===""||a.has(u))&&(a.add(u),u!==n&&!(n!==""&&!HS(c,n))&&(o.push(c),o.length===nf)))break}return o},VS=250,QS=2,GS=(e,t,s)=>{const n=t.trim(),a=mr(n,VS),o=e!==void 0&&rf(e),{data:i}=ve({...ir({query:{q:a,limit:nf}}),enabled:o&&a.length>=QS});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 WS(e,n,c)},YS={delete:(e,t)=>`Deleting ${e} of ${t}…`,move:(e,t)=>`Moving ${e} of ${t}…`,markRead:(e,t)=>`Marking ${e} of ${t} as read…`},af={delete:"moved to Trash",move:"moved",markRead:"marked as read"},XS={delete:"couldn't be deleted",move:"couldn't be moved",markRead:"couldn't be marked as read"},JS={delete:"Couldn't delete these messages",move:"Couldn't move these messages",markRead:"Couldn't mark these messages as read"},ZS={delete:"The delete didn't finish.",move:"The move didn't finish.",markRead:"The update didn't finish."},ek=(e,t,s)=>YS[e](Gt(t),Gt(s)),Ll=(e,t)=>`${Gt(t)} ${af[e]}. Your mail server is still catching up.`,tk=e=>`Stopped after ${Gt(e)}`,sk=(e,t,s)=>`${Gt(t)} of ${Gt(s)} ${af[e]}. Nothing was sent for the rest, so they are untouched.`,nk=(e,t)=>t>0?`Stopped after ${Gt(t)} — some messages ${XS[e]}`:JS[e],rk=e=>ZS[e],ak=e=>e==="delete"?"danger":"info",ok=100,ik=(e,t)=>e.kind==="move"?[t,e.destinationMailboxId]:[t],of=({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),y=Ee(),{pushError:g}=tt();l.useEffect(()=>{h.current||(f.current=!0),i({kind:"idle"})},[s,n]);const p=l.useRef(a);p.current=a;const x=l.useCallback(C=>async M=>{const{data:L}=await ma({path:{mailboxId:e},query:{...C,continuationToken:M,limit:ok},throwOnError:!0});return{ids:(L.items??[]).map(E=>E.messageId),continuationToken:L.continuationToken}},[e]),b=l.useCallback(async()=>{const{data:C}=await ma({path:{mailboxId:e},query:{...p.current,count:!0,results:!1},throwOnError:!0});if(C.count===void 0)throw new Error("the search returned no count for the selection");return C.count},[e]),S=l.useCallback(C=>async M=>{if(C.kind==="move"){const{data:E}=await Bm({body:{messageIds:M,destinationMailboxId:C.destinationMailboxId},throwOnError:!0});return E}if(C.kind==="markRead"){const{data:E}=await Um({body:{messageIds:M,isRead:!0},throwOnError:!0});return E}const{data:L}=await Km({body:{messageIds:M},throwOnError:!0});return L},[]),w=l.useCallback(C=>{It(y,Et(ik(C,e))),t&&y.invalidateQueries({queryKey:Ft({path:{accountId:t}})})},[y,e,t]),v=l.useCallback(()=>{f.current=!1,i({kind:"counting"}),b().then(C=>{if(f.current){i({kind:"idle"});return}i({kind:"escalated",total:C})},C=>{g(ds("Couldn't count matching messages","The count didn't finish.",C)),i({kind:"idle"})})},[b,g]),k=l.useCallback(()=>{f.current=!0},[]),R=l.useCallback(()=>{h.current||(f.current=!0,i({kind:"idle"}))},[]),A=l.useCallback(async(C,M)=>{f.current=!1,h.current=!0,u(C);const L=j=>d(t0(j)),E=S(C),F=x(p.current);let O;try{O=M!==void 0?await sd(M,E,L,()=>f.current):await e0(F,o.kind==="escalated"?o.total:0,E,L,()=>f.current)}finally{h.current=!1}return u(void 0),d(void 0),i({kind:"idle"}),O.error&&g(ds(nk(C.kind,O.done),rk(C.kind),O.error)),O.done>0&&w(C),O},[S,x,o,g,w]);return{phase:o,escalate:v,stop:k,clear:R,isRunning:c!==void 0,runningAction:c,progress:m,runAction:A}},lf=12,lk=e=>{const{envelope:t}=e,s=t.from[0];return{id:t.messageId,sender:s?vu({normalizedEmail:s.normalizedEmail,displayName:s.displayName}):"Unknown",subject:t.subject??"(No subject)",date:gt(t.date)}},ck=(e,t)=>{const s=e!==void 0&&t!==void 0,{data:n,isLoading:a}=ve({...xc({path:{mailboxId:e??""},query:{...t,limit:lf}}),enabled:s,staleTime:3e4});return{messages:(n?.items??[]).map(uk),isPending:s&&a}},uk=e=>({id:e.messageId,sender:e.fromName||e.fromEmail||"Unknown",subject:e.subject??"(No subject)",date:gt(e.sentDate)}),dk=e=>mt({queries:e.slice(0,lf).map(t=>({...dr({path:{messageId:t}}),staleTime:Number.POSITIVE_INFINITY})),combine:t=>({messages:t.map(s=>s.data).filter(s=>s!==void 0).map(lk),isPending:t.some(s=>s.isPending)})}),fk=e=>({matchOperator:"Or",literalClauses:vr(e)}),mk=(e,t,s)=>{const n=_e(qm()),{mutate:a,reset:o}=n,[i,c]=l.useState(!1),u=l.useMemo(()=>br(s),[s]),m=l.useCallback(()=>{!e||!t||(c(!1),a({path:{accountId:e},body:ri({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:ri(fk(u))}))},[h,e,u,a]);const y=i||(f?.semanticUnavailable??!1),g=n.isPending||h,p=i?{matchOperator:"Or",literalClauses:vr(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:y,senderFallback:i,senders:u,matchPredicate:p,isPending:g,isError:n.isError,error:n.error}},hk=()=>[cr({path:{mailboxId:""}}),Va({path:{mailboxId:""}}),Qa()].map(e=>[{_id:e[0]._id}]),pk=e=>nd(e)?e.pages:rd(e)?[e]:[],gk=e=>typeof e=="object"&&e!==null&&typeof e.messageId=="string",xk=(e,t)=>{const s=new Set(t),n=new Map;for(const a of e)for(const o of pk(a))for(const i of o.items){if(!gk(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)},bk=e=>{const t=Ee(),s=e.join("\0");return l.useMemo(()=>{const n=hk().flatMap(a=>t.getQueriesData({queryKey:a}).map(([,o])=>o));return xk(n,e)},[t,s])},vk=({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",yk={clauses:[],matchOperator:"any"},wk={clauses:[],matchOperator:"all",droppedFacets:[],keptTerms:!1,droppedSemantic:!1},Sk=[],ls={state:"saving",matched:0,applied:0,failed:0,failures:[]},oa=(e,t)=>e.map((s,n)=>({...s,id:`${t}-${n}`})),Fl=(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},ia=e=>e==="move"||e==="junk"||e==="organize",$l=e=>e==="junk"?qd:"No destination was chosen, so there is nowhere to file these. Go back and pick a folder.";function kk({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:y}){const[g]=l.useState(()=>c),[p]=l.useState(()=>o),x=g!==void 0,[b,S]=l.useState(x?"properties":"selected"),w=p?"escalated":b,[v,k]=l.useState(()=>g?{clauses:oa(g.clauses,"search"),matchOperator:g.matchOperator}:yk),[R,A]=l.useState(void 0),[C,M]=l.useState(void 0),[L,E]=l.useState(!1),[F,O]=l.useState(void 0),[j,T]=l.useState(void 0),[P,I]=l.useState(),D=l.useRef(!1),N=l.useRef(!1),G=l.useMemo(()=>n.map(B=>B.id),[n]),W=l.useMemo(()=>n.map(B=>B.email).filter(Boolean),[n]),ne=G[0],re=bk(G),{junkMailboxId:he}=Sn(t),te=mk(p?void 0:t,ne,W),{preview:ce}=te;l.useEffect(()=>{ce()},[ce]);const ie=w==="similar"||w==="properties",U=l.useMemo(()=>({matchOperator:v.matchOperator==="all"?"And":"Or",literalClauses:v.clauses.map(B=>({field:B.field,value:B.value}))}),[v.clauses,v.matchOperator]),_=w==="similar"?te.matchPredicate:U,{count:ue,matchedIds:pe}=xh(ie?t:void 0,_),ye=dk(ie?pe:[]),Se=ck(p?s:void 0,p?.searchQuery),H=p?{status:"ready",count:p.total}:ie?ue:{status:"ready",count:n.length},{data:we}=ve({...it({path:{accountId:t??""}}),enabled:!!t,staleTime:Number.POSITIVE_INFINITY}),xe=Oo(t),Ie=to(),de=l.useMemo(()=>so({mailboxes:we?.items??[],folderAppointments:xe,currentMailboxId:s,translator:Ie}),[we?.items,xe,s,Ie]),{createFolderIn:se}=Cc(t),be=de.find(B=>B.id===v.moveMailboxId)?.label,Be=db(n.map(B=>({normalizedEmail:B.email,displayName:B.sender}))),me=vb({match:w==="properties"&&v.clauses[0]?.value.trim()||void 0,sender:Be?vu(Be):void 0,folder:be}),K=l.useMemo(()=>({...v,name:v.name??me}),[v,me]),Te=GS(R?.draft.field,R?.draft.value??"",W),Ne=bh(t),Pe=vh(t),$=of({mailboxId:s??"",accountId:t,enabled:!1,predicateKey:"selection-wizard",searchQuery:{}}),{runAction:le}=$,J=Vm({verb:e,mode:w,scope:v.scope,fromSearch:x}),ge=J[si(J,d)],Me=!a&&!!t,Ye=Me?void 0:Ym,He=Me?void 0:Xm,Ae=(B=>{if(B==="folder")return He;if(B==="rule")return K.scope==="standing"||K.scope==="until"?Ye:void 0})(ge)??Qm(ge,K,H),nt=l.useCallback(()=>oa(bb(W,re),"seed"),[W,re]),st=l.useCallback(B=>{S(B),k(X=>({...X,widen:B==="similar"&&ne?{anchorCount:Math.max(n.length,1)}:void 0,...B==="properties"&&X.clauses.length===0?{clauses:nt()}:{}}))},[ne,n.length,nt]),Re=l.useCallback(()=>{E(!0),S("properties"),k(B=>({...B,widen:void 0,clauses:oa(vr(W),"sender"),matchOperator:"any"})),f("properties")},[W,f]),V=te.semanticUnavailable||te.isError;l.useEffect(()=>{ge==="match"&&(w!=="similar"||!V||L||Re())},[ge,w,V,L,Re]);const fe=l.useCallback(()=>{A({mode:"add",draft:{field:"From",value:""}})},[]),ae=l.useCallback(B=>{const X=v.clauses.find(je=>je.id===B);X&&A({mode:"edit",clauseId:B,draft:{field:X.field,value:X.value}})},[v.clauses]),Z=l.useCallback(B=>{k(X=>({...X,clauses:X.clauses.filter(je=>je.id!==B)}))},[]),ke=l.useCallback(B=>{A(X=>X&&{...X,draft:B})},[]),Oe=l.useCallback(()=>{A(B=>{if(!B)return;const X=yh(B.draft.field,B.draft.value),je={...B.draft,value:X};k(pt=>({...pt,clauses:B.clauseId?pt.clauses.map(yt=>yt.id===B.clauseId?{...yt,...je}:yt):[...pt.clauses,{id:crypto.randomUUID(),...je}]}))})},[]),$e=l.useCallback(()=>{if(Ae){M(ge);return}M(void 0);const B=J[si(J,ge)+1];B&&f(B)},[Ae,ge,J,f]),Qe=l.useCallback(async B=>{const X=Fl(e,K.moveMailboxId,he);if(!X){T({matched:B.length,failureReason:$l(e)});return}T({matched:B.length});const je=await le(X,[...B]);T({matched:B.length,outcome:je}),N.current&&m?.(X.kind,B.length,je)},[e,K.moveMailboxId,he,le,m]),Ue=l.useCallback(async()=>{if(!p)return;const B=Fl(e,K.moveMailboxId,he);if(!B){T({matched:p.total,failureReason:$l(e)});return}T({matched:p.total});const X=await p.run(B);T({matched:p.total,outcome:X}),N.current&&m?.(B.kind,p.total,X)},[p,e,K.moveMailboxId,he,m]),{start:Ce}=Ne,{createFilterAsync:Xe}=Pe,ze=l.useCallback(()=>{if(p){Ue();return}const B=wh({mode:b,ruleScope:K.scope}),X=Sh({mode:b,ruleScope:K.scope,anchorMessageId:ne,clauses:K.clauses,matchOperator:K.matchOperator,moveMailboxId:K.moveMailboxId,until:K.until});if(O(B),B==="standing"||B==="temporary"){const je=kh(X)?X:void 0;I(je),Xe(X,B,(K.name??"").trim()).then(pt=>{pt&&je&&Ce(je)});return}if(B==="all-like-these"&&ia(e)){Ce(X);return}Qe(B==="just-these"?G:pe)},[p,Ue,b,K,ne,e,G,pe,Xe,Ce,Qe]),lt=l.useCallback(()=>{if(Ae){M(ge);return}D.current||(D.current=!0,f("run"),ze())},[Ae,ge,f,ze]),Je=l.useCallback(B=>{const X=Ne.progress,je=vk({failure:Ne.failure,isStarting:Ne.isStarting,isRunning:Ne.isRunning,isDone:Ne.isDone,failedCount:X.failedCount,ruleSaved:B});return je==="saving"||je==="commitFailed"||je==="backApplyStartFailed"?{...ls,state:je}:{state:je,matched:X.matchedCount,applied:X.appliedCount,failed:je==="backApplyFailed"||je==="backApplyRestartFailed"?X.failedCount:0,failures:[]}},[Ne]),zt=l.useMemo(()=>{const B=new Map;for(const X of[...n,...ye.messages,...Se.messages])B.set(X.id,X);return B},[n,ye.messages,Se.messages]),Rt=p?i:$.progress,ns=l.useCallback(()=>{if(!j)return ls;const{matched:B,outcome:X,failureReason:je}=j;if(je!==void 0)return{...ls,state:"commitFailed",failureReason:je};if(!X){const wt=Rt?.done??0;return{state:"backApplyRunning",matched:Math.max(B,wt),applied:wt,failed:0,failures:[]}}if(!(X.cancelled||X.error!==void 0))return{state:"backApplyComplete",matched:Math.max(B,X.done),applied:X.done,failed:0,failures:[]};if(X.done===0)return{...ls,state:"commitFailed"};const yt=X.failedIds.map(wt=>zt.get(wt)).filter(wt=>wt!==void 0),vs=X.failedIds.length>0?X.failedIds.length:Math.max(B-X.done,1);return{state:"runStopped",matched:Math.max(B,X.done),applied:X.done,failed:vs,failures:yt}},[j,Rt,zt]),rt=p?ns():F==="standing"||F==="temporary"?Pe.isError?{...ls,state:"commitFailed"}:Pe.isSuccess?P?Je(!0):{...ls,state:"filterSaved"}:ls:F==="all-like-these"&&ia(e)?Je(!1):ns(),Tt=()=>{if(rt.state==="statusUnknown"){Ne.refreshStatus();return}if(p){Ue();return}if(F==="standing"||F==="temporary"){if(Pe.isError){Pe.reset(),ze();return}P&&Ce(P);return}if(F==="all-like-these"&&ia(e)){ze();return}const B=j?.outcome?.failedIds??[];Qe(B.length>0?B:G)},bt=l.useCallback(()=>{y(J,ge)},[y,J,ge]),vt=l.useCallback(()=>{N.current=!0,y(J,ge),u()},[y,J,ge,u]),{stop:ht}=$,rs=j!==void 0&&j.outcome===void 0&&j.failureReason===void 0,qs=l.useCallback(()=>{if(p){p.stop();return}ht()},[p,ht]);Pu({shouldBlockFn:({action:B})=>B!=="BACK"?!1:(vt(),!0),enableBeforeUnload:!1,disabled:ge!=="run"});const ct={messages:p?Se.messages:ie?ye.messages:n,count:H,label:w==="selected"?"Your selection":"A sample of what matches",emptyReason:w==="similar"&&V?"notIndexed":"noMatch",loading:p?Se.isPending:ie&&(H.status==="loading"||ye.isPending)};return r.jsx(Gm,{verb:e,steps:J,step:ge,blockedReason:Ae,nudged:C===ge,onBack:h,onExit:ge==="run"?vt:bt,onContinue:$e,onCommit:lt,match:{selectedCount:n.length,mode:w,onModeChange:st,semanticUnavailable:V,semanticErrorDetail:te.error instanceof Error?te.error.message:void 0,semanticFallbackTaken:L,onSemanticFallback:Re,escalatedScope:p?.scope,sample:ct},properties:{clauses:K.clauses,matchOperator:K.matchOperator,onMatchOperatorChange:B=>k(X=>({...X,matchOperator:B})),clauseEdit:R,onStartAddClause:fe,onStartEditClause:ae,onRemoveClause:Z,onChangeDraft:ke,onSubmitClause:Oe,onCancelClause:()=>A(void 0),clauseFields:Ch,clauseSuggestions:Te,conversionNotice:g?wb(g):void 0,semanticFallbackTaken:L,sample:{...ct,label:"What this matches"}},folder:{folders:de,mailboxId:K.moveMailboxId,delimiter:no(we?.items??[]),onSelect:B=>k(X=>({...X,moveMailboxId:B})),onCreateFolder:t?se:void 0,restriction:He},rule:{draft:K,onScopeChange:B=>k(X=>({...X,scope:B})),onUntilChange:B=>k(X=>({...X,until:B})),restriction:Ye},name:{name:K.name??"",onNameChange:B=>k(X=>({...X,name:B})),nudged:C===ge},review:{verb:e,mode:w,selectedCount:n.length,clauses:K.clauses,matchOperator:K.matchOperator,folder:be,scope:K.scope,until:K.until,ruleName:J.includes("name")?K.name:void 0,escalatedScope:p?.scope,sample:ct},run:{state:rt.state,verb:e,scope:K.scope,matched:rt.matched,applied:rt.applied,failedCount:rt.failed,failures:rt.failures,failureReason:rt.failureReason,onRetry:Tt,onDismiss:vt,onCancelRun:rs?qs:void 0}})}function Wo(e){const t=Hm()==="search",{searchConversion:s}=Ar(),{accounts:n}=De(),{step:a,goToStep:o,goBack:i,closeWizard:c}=Wm(t?"properties":"match");if(!a)return null;const u=t?s??wk:void 0;return r.jsx(kk,{...e,...u?{verb:"organize",accountId:AS(u,e.accountId,n),selection:Sk,crossAccount:!1,escalated:void 0,searchConversion:u}:{},step:a,goToStep:o,goBack:i,closeWizard:c})}const Ck=200,_l=()=>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))}),jk=({accountEmail:e})=>{const t=Ve();return r.jsxs("div",{className:"flex items-center gap-2 px-row-inset py-2 border-b border-line bg-danger-soft/40 text-xs text-danger",children:[r.jsx(Pt,{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"})]})},Nk=(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 Ek({header:e,rows:t,wizard:s,children:n}){const{selectedIds:a,selectedCount:o,exitSelection:i,orderedIds:c,allSelected:u,toggleAllLoaded:m}=qo(),d=l.useMemo(()=>Nk(t,a),[t,a]),{junkMailboxId:f}=Sn(d.accountId),{labels:h}=ro(d.accountId),y=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=Tr(f,d.mailboxId),x=l.useMemo(()=>c.length>0?{checked:u,indeterminate:o>0&&!u,onChange:m}:void 0,[c.length,u,o,m]),b=d.moveDisabledHint?{tone:"warning",text:d.moveDisabledHint}:void 0,S=w=>r.jsx(yo,{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(Vd,{accountId:d.accountId,mailboxId:d.mailboxId,messageIds:y}):void 0,selectAll:x,notice:b});return r.jsx(Jd,{...e,selectionBar:S,paneOverlay:r.jsx(Wo,{verb:s.verb,accountId:d.accountId,mailboxId:d.mailboxId,selection:g,crossAccount:d.moveDisabledHint!==void 0,onFinished:i}),children:n})}function Ik({accounts:e,selectedMessageId:t,onSelectMessage:s,onSelectSearchResult:n,commandsRef:a,onTriageContextChange:o,onDeleteMessages:i}){const{searchQuery:c,searchInput:u,resultFolderIndex:m}=De(),d=xs(),f=es(),h=Ja(),y=Ve(),g=l.useMemo(()=>tS(e.filter($=>!$.muted?.value)),[e]),[p,x]=l.useState("all"),[b,S]=l.useState("all"),[w,v]=l.useState(new Set),[k,R]=l.useState(!1),A=l.useCallback($=>{v(le=>{const J=new Set(le);return J.has($)?J.delete($):J.add($),J})},[]),C=l.useCallback(()=>v(new Set),[]),M=u.trim().length>0,{data:L,isLoading:E,isError:F,refetch:O}=ve({...ha(),staleTime:6e4}),j=mt({queries:g.map($=>({...it({path:{accountId:$.accountId}}),staleTime:1/0,meta:{softError:!0}}))}),T=l.useMemo(()=>{const $=new Map;for(let le=0;le<g.length;le++){const J=g[le].accountId,Me=(j[le]?.data?.items??[]).reduce((Ye,He)=>Ye+(He.unseenCount??0),0);$.set(J,Me)}return $},[g,j]),P=l.useMemo(()=>g.filter(($,le)=>{const J=j[le];return J?.isError?!pa(J.error):!1}),[g,j]),{freeText:I,tokens:D}=Us(c.trim().toLowerCase(),d),{data:N,isFetching:G}=ve({...ha({query:{query:I,limit:Ck}}),enabled:I.length>0,staleTime:3e4}),W=l.useMemo(()=>{const $=Al(L?.items??[]).map(er);return(I?sS($.filter(J=>Kd(J,I)),Al(N?.items??[]).map(er)):$).filter(J=>(p==="all"||J.accountId===p)&&Bo(J,D))},[L,N,p,I,D]),{bodyRows:ne,briefSpamOffer:re}=l.useMemo(()=>{if(!I)return{bodyRows:W,briefSpamOffer:void 0};const $=W.map(ge=>Kn(ge,m)),{spam:le}=xo($);if(le.length===0)return{bodyRows:W,briefSpamOffer:void 0};const J=new Set(le.map(ge=>ge.id));return{bodyRows:W.filter(ge=>!J.has(ge.id)),briefSpamOffer:Wd($)}},[W,I,m]),he=l.useMemo(()=>nS(ne),[ne]),te=l.useCallback(($,le)=>{const J=I?ne.find(ge=>ge.id===$):void 0;if(J?.threadId&&J.mailboxId&&n){n(Kn(J,m),le);return}s?.($,le)},[I,ne,m,n,s]),ce=l.useMemo(()=>g.length<=1?[]:[{id:"all",label:"All",active:p==="all"},...g.map($=>({id:$.accountId,label:$.email.split("@")[0]??$.email,count:T.get($.accountId),active:p===$.accountId}))],[g,T,p]),ie=l.useMemo(()=>e.filter($=>$.muted?.value).length,[e]),U=l.useMemo(()=>Array.from(T.values()).reduce(($,le)=>$+le,0),[T]),_=l.useMemo(()=>g.map($=>$.accountId),[g]),{hasNewMail:ue}=kr(),{state:pe,errorMessage:ye,refresh:Se}=Co(_,{onSettled:()=>O()}),H=l.useMemo(()=>r.jsx(bo,{state:pe,onRefresh:Se,label:"Refresh daily brief",errorMessage:ye,hasUpdate:ue(_)}),[pe,Se,ye,ue,_]),we=l.useMemo(()=>W.filter($=>(b==="all"||$.category===b)&&Jm($,w)).map($=>Kn($,m)),[W,b,w,m]),{hits:xe,isLoading:Ie}=Ud(),de=l.useMemo(()=>{const $=new Map;for(const J of L?.items??[])$.set(J.messageId,J.threadId);const le=we.map(J=>$.get(J.id)).filter(J=>J!=null);return Hd(xe,le,m)},[xe,we,L,m]),se=l.useMemo(()=>{const $=Bx(ce.map(le=>({id:le.id,label:le.label,count:le.count,active:le.active})));return{categories:$.categories,filters:$.filters,sources:$.sources,sourcesNote:ie>0?`+${ie} muted`:void 0,selectedCategory:b,activeFilters:w,expanded:k,onExpandedChange:R,onSelectCategory:le=>S(le),onSelectSource:x,onToggleFilter:le=>A(le),onClear:()=>{S("all"),x("all"),C()}}},[ce,ie,b,w,k,A,C]),be=he.length===0&&p==="all"&&I.length===0&&D.length===0,Be=l.useMemo(()=>g.map($=>$.accountId),[g]),me=l.useMemo(()=>g.some($=>ko($.syncPhase)),[g]),K=uy(Be,be||me),Te=r.jsxs("div",{className:"h-full overflow-y-auto",children:[r.jsx(_l,{}),r.jsx(_l,{})]}),Ne=!E&&!F&&!be,Pe=Ne?r.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[re&&r.jsx(uu,{count:re.count,onScopeToSpam:()=>y({to:"/mail/$mailboxId",params:{mailboxId:re.mailboxId},search:{q:c||void 0,selectedMessageId:void 0,selectedThreadId:void 0}})}),r.jsx("div",{className:"min-h-0 flex-1",children:r.jsx(Zl,{sections:he,briefCategory:b,Row:Ho,selectedThreadId:t,onSelectThread:te,onSelectBriefCategory:S,sources:ce,sourcesNote:ie>0?`+${ie} muted`:void 0,onSelectSource:x,activeFilters:w,onToggleFilter:A,onClearFilters:C,hideChrome:M})})]}):E?Te: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(Pt,{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(co,{className:"size-3.5"}),"Try again"]})]}):K.resolved?r.jsx(Xg,{sync:K.syncing?{synced:K.synced,total:K.total}:void 0}):Te;return r.jsx(bc,{hasSheet:Ne&&!M,children:r.jsx(tf,{selectedMessageId:t,onOpen:te,onDeleteMessages:i,onSelectionVerb:h.start,wizardOpen:h.isOpen,commandsRef:a,onTriageContextChange:o,children:r.jsx(Ek,{wizard:h,header:{title:"Daily brief",unreadCount:U,footer:f?r.jsx(Yc,{}):void 0,searchFilter:se,searchResults:we,searchLoading:E||G,relatedResults:de,relatedLoading:Ie,onSelectSearchResult:n,searchResultsInBody:!0,refreshControl:H},rows:W,children:r.jsxs("div",{className:"flex h-full flex-col",children:[P.map($=>r.jsx(jk,{accountEmail:$.email,accountId:$.accountId},$.accountId)),r.jsx("div",{className:"min-h-0 flex-1",children:Pe})]})})})})}const Rk=10,cf=e=>({q:e?.toLowerCase()??"",limit:Rk}),Tk=(e,t)=>{if(!t)return;const s=t.toLowerCase();return e?.find(n=>n.normalizedEmail===s)};function Mk(e){const t=new Date(e),s=new Date;return t.toDateString()===s.toDateString()?"today":Qn(t,{month:"short",year:"numeric"})}function uf(e){if(!e)return!0;const[,t]=e.split("@");return t?!t.includes("."):!0}const Ak="We can't verify the sender of this email, which could mean it's from an insecure source.",Ok="We couldn't read this sender's address, so we can't confirm who really sent this message.";function Dk(e,t){return{name:e.fromName??e.fromEmail??"Unknown",email:e.fromEmail??"",trust:e.senderTrust,firstSeenLabel:t?Mk(t.createdAt):"unknown",inboundCount:t?.inboundCount,replyCount:t?.replyCount,addressUnverified:uf(e.fromEmail)}}function Pk(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 zl(e){if(e.fromName&&e.fromName!==e.fromEmail)return e.fromName}function Lk(e){return e.length===1?e[0]:`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function Fk(e,t){const s=[],n=e.displayNameCorrespondence;t&&(n===oi.Unrelated?s.push(`The name it shows, "${t}", has nothing to do with ${e.fromDomain}.`):n===oi.Lookalike&&s.push(`The name it shows, "${t}", only looks like ${e.fromDomain}.`));const a=$k(e.offDomainLinkDomains);return a.length>0&&s.push(`Its links go to ${Lk(a.slice(0,3))}.`),s}function $k(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&t.length>0):[]}function _k(e,t){const s=t>0?t:void 0;if(uf(e.fromEmail))return{verdict:"mismatch",fromDomain:"",addressUnreadable:!0,summary:Ok,similarCount:s};const n=e.authenticity;if(!n)return{verdict:"caution",fromDomain:e.fromEmail?.split("@")[1]??"",summary:Ak};if(!n.dkimMismatch){const m=zl(e),d=Fk(n,m);return d.length>0?{verdict:"caution",fromDomain:n.fromDomain,dkimDomain:n.dkimDomain,claimedBrand:m,summary:d.join(" ")}:{verdict:"aligned",fromDomain:n.fromDomain,dkimDomain:n.dkimDomain,summary:n.dkimDomain?`This message was signed by ${n.dkimDomain}.`:"Nothing looks unusual about this sender."}}const a=n.fromDomain,o=n.dkimDomain,i=zl(e),c=o?`it was actually sent from ${o}`:"its signature failed to verify",u=i?`The display name claims "${i}", but ${c}${o?` — not ${a}`:""}. Real senders use their own address.`:`This message claims to be from ${a}, but ${c}.`;return{verdict:"mismatch",fromDomain:a,dkimDomain:o,claimedBrand:i,summary:u,similarCount:s}}function df(e,t){const s=e?.fromEmail??null,n=e?.subject??"",{data:a,error:o}=ve({...ir({query:cf(s??void 0)}),enabled:!!s,staleTime:3e4}),i=Tk(a?.items,s??void 0),c=[n,s].filter(Boolean).join(" "),{data:u,isLoading:m,error:d}=ve({...gc({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(b=>b.messageId!==e.messageId).map(b=>({id:b.messageId,mailboxId:t!=null&&b.mailboxIds.includes(t)?t:b.mailboxIds[0]??"",fromName:b.fromName??"",subject:b.subject??"(No subject)",timeLabel:b.sentDate!=null?gt(b.sentDate*1e3):"",matched:b.matchedChunkType})),y=Dk(e,i),g=_k(e,h.length),p={value:e.category??"personal",overridden:i?.flags?.category?.value!=null&&i.flags.category.value!==e.category},x=Pk(i);return{sender:y,authenticity:g,category:p,flags:x,similar:h}},[e,i,u,t]),isSimilarLoading:m,similarError:d,similarErrorIsFatal:pa(d),addressErrorIsFatal:pa(o),addressId:i?.addressId,address:i}}function zk(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 ff({addressId:e,senderEmail:t}){const s=Ee(),{pushError:n}=tt(),a=Zm({query:cf(t)}),{mutate:o,isPending:i}=_e({...pc(),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:zk(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:ft(u),error:u})},onSettled:()=>{s.invalidateQueries({queryKey:a})}});return{updateFlags:l.useCallback(u=>{if(!e){Ka(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 Bk=e=>e==="vip"?"A sender you know":e==="wellknown"?"You've emailed them before":"Passed authentication",mf=e=>e.senderTrust!=="vip"&&e.senderTrust!=="wellknown"?!1:e.authenticity?.dkimMismatch!==!0;function Uk(e,t){e.recordEvent("rescue.candidates_surfaced",{count:String(t)})}function Kk(e,t){e.recordEvent("rescue.flow_opened",{count:String(t)})}function qk(e,t){e.recordEvent("rescue.committed",{selected:String(t.selected),total:String(t.total),destination:t.toInbox?"inbox":"other"})}function hf(e,t){e.recordEvent("rescue.sent_to_junk",{count:String(t.count),senderTrust:t.senderTrust,wasRescuable:String(t.wasRescuable)})}const Hk=["personal","newsletter","marketing","automated","transactional","social"],Wk=e=>e.spamReport?"notSpam":"reportSpam",Vk=e=>{const{similarError:t,similarErrorIsFatal:s,isSimilarLoading:n}=e;return t&&!s?"error":n?"loading":"ready"};function Qk(){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(Dt,{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 Gk({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:Hk.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 Yk({thread:e,onClose:t,mailboxId:s,accountId:n,hideCloseButton:a,onAfterOptimisticRemove:o}){const{data:i,addressId:c,isSimilarLoading:u,similarError:m,similarErrorIsFatal:d}=df(e,s),[f,h]=l.useState(!1),y=e.fromEmail??void 0,{updateFlags:g}=ff({addressId:c,senderEmail:y}),{reportSpam:p,notSpam:x,isReporting:b,isRestoring:S}=id({mailboxId:e.mailboxId,threadId:e.threadId,accountId:n,onAfterOptimisticRemove:o}),w=Ls(),v=Wk(e),k=l.useCallback(()=>{x([e.messageId])},[x,e.messageId]),R=l.useCallback(()=>{hf(w,{count:1,senderTrust:e.senderTrust,wasRescuable:mf(e)}),p([e.messageId])},[p,e,w]),A=l.useCallback(()=>{},[]),C=l.useCallback(()=>{const P=i?.flags?.vip!==!0;g({vip:{value:P}})},[i?.flags?.vip,g]),M=l.useCallback(()=>{const P=i?.flags?.muted!==!0;g({muted:{value:P}})},[i?.flags?.muted,g]),L=l.useCallback(()=>{const P=i?.flags?.unsubscribed!==!0;g({unsubscribed:{value:P}})},[i?.flags?.unsubscribed,g]),E=l.useCallback(P=>{h(!1),g({category:{value:P}})},[g]),F=c!==void 0,O={onToggleVip:F?C:void 0,onToggleMute:F?M:void 0,onToggleUnsubscribe:F?L:void 0,onReclassify:F?()=>h(!0):void 0,onNotSpam:v==="notSpam"?k:void 0,onReportSpam:v==="reportSpam"?R:void 0},j=({mailboxId:P,messageId:I,className:D,ariaLabel:N,children:G})=>r.jsx(qt,{to:"/mail/$mailboxId",params:{mailboxId:P},search:W=>({...W,selectedMessageId:I}),className:D,"aria-label":N,children:G});if(!i)return r.jsx(Qk,{});const T=Vk({similarError:m,similarErrorIsFatal:d,isSimilarLoading:u});return r.jsxs(r.Fragment,{children:[r.jsx(Hc,{data:i,onClose:t,hideCloseButton:a,onShowSimilar:A,actions:O,similarState:T,similarLinkComponent:j,reportSpamPending:b,notSpamPending:S,className:"border-l-0 h-full w-full"}),r.jsx(Gk,{isOpen:f,current:i.category.value,onSelect:E,onCancel:()=>h(!1)})]})}const Ks=({onClose:e,thread:t,mailboxId:s,accountId:n,hideCloseButton:a,onAfterOptimisticRemove:o})=>t?r.jsx(Yk,{thread:t,onClose:e,mailboxId:s,accountId:n,hideCloseButton:a,onAfterOptimisticRemove:o}):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(Dt,{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(Dt,{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."})]})]}),la="Open a message first",Vo=({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,y]=l.useState(null),g=u??e,p=x=>()=>y(x);return r.jsx(ng,{hasThread:e,isStarred:d,onUnavailable:x=>y(la),unavailableHint:h,replyTitle:`Reply ${Vs("reply")}`,replyAllTitle:`Reply all ${Vs("replyAll")}`,forwardTitle:`Forward ${Vs("forward")}`,deleteTitle:`Move to Trash ${Vs("delete")}`,flagTitle:`Star ${Vs("toggleStar")}`,onReply:a,onReplyAll:o,onForward:i,onDelete:g?c:p(la),onToggleStar:m,onMove:p(la),moveSlot:f?r.jsx($o,{accountId:f.accountId,currentMailboxId:f.currentMailboxId,onMove:f.onMove,label:"Move to mailbox"}):void 0,children:r.jsx(sg,{open:t,enabled:s,onToggle:n})})},pf=()=>{const e=Ee();return l.useCallback(t=>{const s=Zt({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])},fn=({thread:e,mailboxId:t,accountId:s,onAfterOptimisticRemove:n})=>{const a=t??e?.mailboxId,o=s??e?.accountId,{accountId:i}=To(o?void 0:a),c=o??i,u=pf(),{deleteMessages:m}=ms({mailboxId:a??"",threadId:e?.threadId,accountId:c,onAfterOptimisticRemove:n}),{moveMessages:d}=Ds({mailboxId:a??"",threadId:e?.threadId,accountId:c,onAfterOptimisticRemove:n}),{toggleStar:f}=Mo({threadId:e?.threadId??"",mailboxId:a??""}),h=l.useCallback(()=>{e&&m(u(e))},[e,u,m]),y=l.useCallback(S=>{e&&d(u(e),S)},[e,u,d]),g=l.useCallback(()=>{e&&f(e.messageId,e.hasStars)},[e,f]),[p,x]=l.useState(null),b=l.useCallback(()=>x(null),[]);return{mailboxId:a,accountId:c,isStarred:e?.hasStars,deleteThread:h,moveThread:y,toggleStar:g,composeRequest:p,requestCompose:x,clearComposeRequest:b}},Bl=(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]},Qo=()=>{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}},Go=({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 kb({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:Bl(t,s,"next")??void 0,previousMessageId:Bl(t,s,"previous")??void 0}};function Xk(e){return{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,messageId:e.messageId,authenticity:e.authenticity}}function gf(e,t){if(e)return Xk(e);if(t.messageId&&t.threadId&&t.mailboxId)return{threadId:t.threadId,mailboxId:t.mailboxId,messageId:t.messageId}}const xf=l.createContext(null);function Or(){const e=l.useContext(xf);if(!e)throw new Error("BriefPane.* must be used inside <BriefPane>");return e}function Jk({selectedMessageId:e,children:t}){const s=Ve(),{searchInput:n}=De(),{selectedThreadId:a,selectedMailboxId:o}=As({strict:!1}),{data:i}=ve({...ha(),staleTime:6e4}),c=l.useMemo(()=>{if(e)return i?.items.find(M=>M.messageId===e)},[i,e]),u=l.useMemo(()=>gf(c,{messageId:e,threadId:a,mailboxId:o}),[c,e,a,o]),m=l.useCallback((M,L)=>{s({to:"/mail",search:E=>({...E,selectedMessageId:M,selectedThreadId:void 0,selectedMailboxId:void 0}),replace:L?.replace})},[s]),d=l.useCallback((M,L)=>{s({to:"/mail",replace:L?.replace,search:E=>({...E,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:L=>({...L,selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0})})},[e,s]),h=fn({thread:c,onAfterOptimisticRemove:f}),y=l.useCallback(()=>{s({to:"/mail",search:M=>({...M,selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0})})},[s]),g=Qo(),p=l.useMemo(()=>i?.items??[],[i]),{deleteMessages:x}=ms({mailboxId:c?.mailboxId??"",messages:p,onAfterOptimisticRemove:f}),{toggleReadFor:b}=Nr({mailboxId:c?.mailboxId??"",messages:p}),S=g.focusedMessageId,v=l.useMemo(()=>i?.items.find(M=>M.messageId===S),[i,S])??c,k=fn({thread:v}),{nextMessageId:R,previousMessageId:A}=Go({context:g,orderedIds:g.orderedIds,selectedMessageId:e,onClose:y,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")||v&&b([v.messageId],!v.isRead)},goFlagged:()=>s({to:"/mail/flagged"}),goSettings:()=>s({to:"/settings"})}}),C={selectedMessageId:e,selectedThread:c,conversation:u,onSelectMessage:m,onSelectSearchResult:d,onCloseThread:y,actions:h,triage:g,onDeleteMessages:x,nextMessageId:R,previousMessageId:A,handleDeselectIfRemoved:f};return r.jsx(xf.Provider,{value:C,children:t})}function bf(){const{selectedMessageId:e,onSelectMessage:t,onSelectSearchResult:s,triage:n,onDeleteMessages:a}=Or(),{accounts:o}=De();return r.jsx(Ik,{accounts:o,selectedMessageId:e,onSelectMessage:t,onSelectSearchResult:s,commandsRef:n.listCommandsRef,onTriageContextChange:n.onTriageContextChange,onDeleteMessages:a})}function Zk(){const{conversation:e,actions:t}=Or(),{intelligenceOpen:s,onToggleIntelligence:n}=De(),a=ps()?.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(Vo,{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(Bs,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,selectedMessageId:e.messageId,authenticity:e.authenticity,composeRequest:t.composeRequest,onComposeClose:t.clearComposeRequest}):r.jsx(zs,{})})]})}function eC(){const{selectedThread:e,handleDeselectIfRemoved:t}=Or(),{onToggleIntelligence:s}=De();return r.jsx(Ks,{onClose:s,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId,onAfterOptimisticRemove:t})}function tC(){const{selectedThread:e,conversation:t,onSelectMessage:s,onCloseThread:n,nextMessageId:a,previousMessageId:o,handleDeselectIfRemoved:i}=Or(),{intelligenceOpen:c,onToggleIntelligence:u}=De();return t?r.jsxs(r.Fragment,{children:[r.jsx(Bs,{threadId:t.threadId,mailboxId:t.mailboxId,subject:t.subject,selectedMessageId:t.messageId,authenticity:t.authenticity,onBack:n,onOpenIntelligence:u,onSwipeNext:a?()=>s(a):void 0,onSwipePrevious:o?()=>s(o):void 0,mobileIntelligenceOpen:c}),r.jsx(Eo,{isOpen:c,onClose:u,ariaLabel:"Message details",side:"right",children:r.jsx(Ks,{onClose:u,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId,hideCloseButton:!0,onAfterOptimisticRemove:i})})]}):r.jsx("div",{className:"h-full",children:r.jsx(bf,{})})}const Zs=Object.assign(Jk,{List:bf,Reading:Zk,Intelligence:eC,Phone:tC}),sC=()=>Qa({query:{starred:!0,order:"desc"}});function vf(){const{data:e,isLoading:t,isError:s,error:n,refetch:a,fetchNextPage:o,hasNextPage:i,isFetchingNextPage:c}=Du({queryKey:sC(),queryFn:async({pageParam:m})=>{const{data:d}=await eh({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 nC=e=>{const t=new Set;return e.filter(s=>t.has(s.threadId)?!1:(t.add(s.threadId),!0))};function yf({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:y,relatedLoading:g,onSelectSearchResult:p,searchResultsLabel:x,relatedResultsLabel:b,searchResultsInBody:S,refreshControl:w}){const{searchInput:v}=De(),k=v.trim().length>0,R={categories:s.categories,filters:s.filters,sources:s.sources,selectedCategory:n,activeFilters:a,onSelectCategory:o,onSelectSource:c,onToggleFilter:i,onClear:u};return r.jsx(bc,{hasSheet:!k,children:r.jsx(Jd,{title:e,unreadCount:t,footer:d,searchFilter:R,searchResults:f,searchLoading:h,relatedResults:y,relatedLoading:g,onSelectSearchResult:p,searchResultsLabel:x,relatedResultsLabel:b,searchResultsInBody:S,refreshControl:w,children:r.jsx(nc,{...R,hideChrome:k,children:m})})})}const rC={unread:e=>!e.isRead,attachment:e=>e.hasAttachment===!0};function aC({rows:e,verb:t}){const{selectedIds:s,exitSelection:n}=qo(),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(Wo,{verb:t,selection:a,crossAccount:!0,onFinished:n})}function oC({selectedMessageId:e,onSelectMessage:t,commandsRef:s,onTriageContextChange:n,onDeleteMessages:a}){const{searchQuery:o,resultFolderIndex:i}=De(),c=xs(),u=es(),m=Ja(),[d,f]=l.useState("all"),[h,y]=l.useState(new Set),g=l.useCallback(D=>{y(N=>{const G=new Set(N);return G.has(D)?G.delete(D):G.add(D),G})},[]),p=l.useCallback(()=>{f("all"),y(new Set)},[]),{threads:x,isLoading:b,isError:S,error:w,refetch:v,fetchNextPage:k,hasNextPage:R,isFetchingNextPage:A}=vf(),{freeText:C,tokens:M}=Us(o.trim().toLowerCase(),c),L=l.useMemo(()=>{const D=Array.from(h).map(N=>rC[N]).filter(N=>N!=null);return nC(x).map(er).filter(N=>(d==="all"||N.category===d)&&D.every(G=>G(N))&&(!C||Kd(N,C))&&Bo(N,M))},[x,d,h,C,M]),E=l.useMemo(()=>Ux(),[]),F=l.useMemo(()=>L.map(D=>Kn(D,i)),[L,i]),O=l.useMemo(()=>L.filter(D=>!D.isRead).length,[L]),j=b?"loading":S?"error":L.length===0?"empty":"ready",T=l.useCallback(()=>{const D=Ga(Ya());window.open(D,"_blank","noopener,noreferrer")},[]),P=Ar(),I=r.jsx("div",{className:"flex h-full min-h-0 flex-col",children:r.jsxs("div",{className:"flex-1 overflow-y-auto",children:[r.jsx("div",{className:"divide-y divide-line",children:L.map(D=>r.jsx(Ho,{thread:D,active:D.id===e,onClick:()=>t?.(D.id)},D.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(yf,{title:"Starred",unreadCount:O,preset:E,selectedCategory:d,activeFilters:h,onSelectCategory:f,onToggleFilter:g,onClearFilters:p,searchResults:F,searchLoading:b,onSelectSearchResult:D=>t?.(D.id),searchResultsInBody:!0,children:r.jsxs(tf,{selectedMessageId:e,onOpen:(D,N)=>t?.(D,N),onDeleteMessages:a,onSelectionVerb:m.start,wizardOpen:m.isOpen,commandsRef:s,onTriageContextChange:n,children:[r.jsx(au,{listTitle:"Starred",sections:[{id:"flagged",threads:L}],flatList:!0,hideHeader:!0,listState:P.searchResults?"ready":j,searchQuery:C?o:void 0,errorMessage:S?wc(w):void 0,onRetry:()=>v(),onReportError:T,selectedThreadId:e,onSelectThread:t,isDesktop:u,selectionBar:r.jsx(BS,{title:"Starred"}),listBody:P.searchResults??(j==="ready"?I:void 0)}),r.jsx(aC,{rows:L,verb:m.verb})]})})}const wf=l.createContext(null);function Dr(){const e=l.useContext(wf);if(!e)throw new Error("FlaggedPane.* must be used inside <FlaggedPane>");return e}function iC({selectedMessageId:e,children:t}){const s=Ve(),{threads:n}=vf(),a=l.useMemo(()=>{if(e)return n.find(w=>w.messageId===e)},[n,e]),o=l.useCallback((w,v)=>{s({to:"/mail/flagged",search:k=>({...k,selectedMessageId:w}),replace:v?.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=fn({thread:a,onAfterOptimisticRemove:c}),m=Qo(),{deleteMessages:d}=ms({mailboxId:a?.mailboxId??"",messages:n,onAfterOptimisticRemove:c}),{toggleReadFor:f}=Nr({mailboxId:a?.mailboxId??"",messages:n}),h=m.focusedMessageId,g=l.useMemo(()=>n.find(w=>w.messageId===h),[n,h])??a,p=fn({thread:g}),{nextMessageId:x,previousMessageId:b}=Go({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:x,previousMessageId:b,handleDeselectIfRemoved:c};return r.jsx(wf.Provider,{value:S,children:t})}function Sf(){const{selectedMessageId:e,onSelectMessage:t,triage:s,onDeleteMessages:n}=Dr();return r.jsx(oC,{selectedMessageId:e,onSelectMessage:t,commandsRef:s.listCommandsRef,onTriageContextChange:s.onTriageContextChange,onDeleteMessages:n})}function lC(){const{selectedThread:e,actions:t}=Dr(),{intelligenceOpen:s,onToggleIntelligence:n}=De(),a=ps()?.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(Vo,{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(Bs,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,authenticity:e.authenticity,composeRequest:t.composeRequest,onComposeClose:t.clearComposeRequest}):r.jsx(zs,{})})]})}function cC(){const{selectedThread:e,handleDeselectIfRemoved:t}=Dr(),{onToggleIntelligence:s}=De();return r.jsx(Ks,{onClose:s,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId,onAfterOptimisticRemove:t})}function uC(){const{selectedThread:e,onCloseThread:t,onSelectMessage:s,nextMessageId:n,previousMessageId:a,handleDeselectIfRemoved:o}=Dr(),{intelligenceOpen:i,onToggleIntelligence:c}=De();return e?r.jsxs(r.Fragment,{children:[r.jsx(Bs,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,authenticity:e.authenticity,onBack:t,onOpenIntelligence:c,onSwipeNext:n?()=>s(n):void 0,onSwipePrevious:a?()=>s(a):void 0,mobileIntelligenceOpen:i}),r.jsx(Eo,{isOpen:i,onClose:c,ariaLabel:"Message details",side:"right",children:r.jsx(Ks,{onClose:c,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId,hideCloseButton:!0,onAfterOptimisticRemove:o})})]}):r.jsx("div",{className:"h-full",children:r.jsx(Sf,{})})}const en=Object.assign(iC,{List:Sf,Reading:lC,Intelligence:cC,Phone:uC}),dC={reply:"Reply",reply_all:"Reply All",forward:"Forward",new:"New Message"},fC=()=>{const e=l.useRef(!1);return l.useCallback(()=>{const s=document.querySelector("[data-subject-field]")?.value??"",o=(document.querySelector('[data-testid="compose-body"]')?.textContent??"").replace(/--\s*/g,"").trim();return e.current=s.trim().length>0||o.length>0,e.current},[])},mC=()=>{const{state:e,closeCompose:t}=Jt(),s=fC(),[n,a]=l.useState(!1),{isError:o,error:i,refetch:c}=ve({...$t(),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=dC[e.mode]??"New Message";return r.jsxs(dt.Root,{open:e.isOpen,onOpenChange:u,children:[r.jsxs(dt.Portal,{children:[r.jsx(dt.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),r.jsxs(dt.Content,{className:"fixed inset-x-0 bottom-0 z-50 flex flex-col rounded-t-lg bg-canvas pb-[env(safe-area-inset-bottom,0px)]",style:{height:"95dvh"},children:[r.jsx(dt.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-muted/30"}),r.jsx(dt.Title,{className:"px-4 py-2 text-base font-semibold border-b border-line",children:f}),o?r.jsx("div",{className:"flex-1 flex items-center justify-center p-4",children:r.jsx(ts,{title:"Couldn't load compose",error:i,onRetry:()=>{c()}})}):r.jsx("div",{className:"flex-1 overflow-hidden",children:r.jsx(Io,{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"})]})]})})]})},hC={reply:"Reply",reply_all:"Reply All",forward:"Forward",new:"New Message"},kf=()=>{const{state:e,closeCompose:t}=Jt(),s=es(),{isError:n,error:a,refetch:o}=ve({...$t(),staleTime:1/0});if(!s)return r.jsx(mC,{});if(!e.isOpen)return null;const i=hC[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(Nt,{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(ts,{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(Io,{mode:e.mode,account:e.account,sourceMessage:e.sourceMessage,onClose:t},e.outboxMessageId??"new")})]})};function pC(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:gt(e.updatedAt),isRead:!0}}function gC(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:gt(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0}}function xC({outboxMessages:e,accountId:t,imapThreads:s}){const n=e.filter(i=>i.status==="draft"&&i.accountId===t).map(pC),a=s.map(gC),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 Yo(){const e=ps();return!e||e.showNavPane?null:r.jsx(oe,{variant:"ghost",size:"sm",icon:r.jsx(fr,{className:"size-4"}),onClick:e.openNav,"aria-label":"Open folders",className:"-ml-1 shrink-0"})}const bC=({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})]}),vC=({row:e,isSelected:t,onOpen:s,onDelete:n,isDeleting:a})=>r.jsxs("button",{type:"button",onClick:()=>s(e.id),className:Q("group",_s({active:t})),children:[r.jsx(sc,{className:"size-7 shrink-0 text-fg-muted mt-0.5"}),r.jsx(cn,{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(Lt,{className:"size-3.5"})})})]}),yC=({row:e,isSelected:t,onOpen:s})=>{const n=!e.isRead;return r.jsxs("button",{type:"button",onClick:()=>s(e.id),className:Q("group",_s({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(jt,{name:e.fromName,email:e.fromEmail,size:"sm"}),r.jsx(cn,{thread:e})]})};function wC({mailboxId:e,accountId:t,selectedMessageId:s,imapThreads:n,title:a,unreadCount:o}){const{openCompose:i,state:c}=Jt(),u=Ve(),m=Ee(),{data:d}=ve(or()),f=l.useMemo(()=>xC({outboxMessages:d?.items??[],accountId:t,imapThreads:n}),[d?.items,t,n]),h=_e({...lr(),onSuccess:()=>{m.invalidateQueries({queryKey:Za()})}}),y=b=>{h.mutate({path:{outboxMessageId:b}})},g=b=>{s&&u({to:"/mail/$mailboxId",params:{mailboxId:e},search:{selectedMessageId:void 0}}),i({mode:"new",outboxMessageId:b})},p=b=>{u({to:"/mail/$mailboxId",params:{mailboxId:e},search:{selectedMessageId:b}})},x=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(Yo,{}),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:x?r.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-2 text-center px-4",children:[r.jsx(Pa,{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(b=>r.jsxs("div",{children:[b.label&&r.jsx(bC,{label:b.label,count:b.threads.length}),r.jsx("div",{className:"divide-y divide-line",children:b.threads.map(S=>b.id==="remit-drafts"?r.jsx(vC,{row:S,isSelected:c.isOpen&&S.id===c.outboxMessageId,onOpen:g,onDelete:y,isDeleting:h.isPending},S.id):r.jsx(yC,{row:S,isSelected:S.id===s,onOpen:p},S.id))})]},b.id))})]})}function SC(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 Ul(e,t){if(e===void 0)throw new Error("Unexpected undefined");return e}const kC=(e,t)=>Math.abs(e-t)<1.01,CC=(e,t,s)=>{let n;return function(...a){e.clearTimeout(n),n=e.setTimeout(()=>t.apply(this,a),s)}};let tn;const ca=()=>{if(tn!==void 0)return tn;if(typeof navigator>"u")return tn=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return tn=!0;const e=navigator.maxTouchPoints;return tn=navigator.platform==="MacIntel"&&e!==void 0&&e>0},Kl=e=>{const{offsetWidth:t,offsetHeight:s}=e;return{width:t,height:s}},jC=e=>e,NC=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},EC=(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(Kl(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(Kl(s))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(c):c()});return o.observe(s,{box:"border-box"}),()=>{o.unobserve(s)}},tr={passive:!0},IC=typeof window>"u"?!0:"onscrollend"in window,RC=(e,t,s)=>{const n=e.scrollElement;if(!n)return;const a=e.targetWindow;if(!a)return;const o=e.options.useScrollendEvent&&IC;let i=0;const c=o?null:CC(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,tr),o&&n.addEventListener("scrollend",d,tr),()=>{n.removeEventListener("scroll",m),o&&n.removeEventListener("scrollend",d)}},TC=(e,t)=>RC(e,t,s=>{const{horizontal:n,isRtl:a}=e.options;return n?s.scrollLeft*(a&&-1||1):s.scrollTop}),MC=(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"]},AC=(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})},OC=AC;class DC{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:jC,rangeExtractor:NC,onChange:()=>{},measureElement:MC,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 y=s[h];y!==void 0&&(o[h]=y)}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,y=o.count,g=this.getMeasurements(),p=h>0?((n=g[0])==null?void 0:n.key)??i.getItemKey(0):null,x=h>0?((a=g[h-1])==null?void 0:a.key)??i.getItemKey(h-1):null;if(y!==h||h>0&&y>0&&(o.getItemKey(0)!==p||o.getItemKey(y-1)!==x)){m=!0;const w=h>0?this.getVirtualItemForOffset(this.getScrollOffset())??g[0]:null;w&&(c=[w.key,this.getScrollOffset()-w.start]);const v=o.followOnAppend===!0?"auto":o.followOnAppend||null;v&&y>h&&this.isAtEnd(i.scrollEndThreshold)&&(h===0||o.getItemKey(y-1)!==x)&&(u=v)}}this.options=o,m&&(this.pendingMin=0,this.itemSizeCacheVersion++);let d=!1,f=0;if(c&&this.scrollOffset!==null){const[h,y]=c,g=this.getMeasurements(),{count:p,getItemKey:x}=this.options;let b=0;for(;b<p&&x(b)!==h;)b++;if(b<p){const S=g[b];if(S){const w=S.start+y;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,!(!ca()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};o.addEventListener("touchstart",i,tr),o.addEventListener("touchend",c,tr),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&&(ca()&&(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 b of this.laneAssignments.keys())b>=s&&this.laneAssignments.delete(b);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMin=null),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(b=>{this.itemSizeCache.set(b.key,b.size)}));const h=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===s&&(this.lanesSettling=!1),c===1){const b=s*2;let S=this._flatMeasurements;if(!S||S.length<b){const k=new Float64Array(b);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),C=typeof A=="number"?A:this.options.estimateSize(k);S[k*2]=w,S[k*2+1]=C,w+=C+m}const v=SC(s,S,o);return this.measurementsCache=v,v}const y=this.measurementsCache.slice(0,h),g=new Array(c).fill(void 0),p=new Float64Array(c);let x=0;for(let b=0;b<h;b++){const S=y[b];S&&(g[S.lane]===void 0&&x++,g[S.lane]=b,p[S.lane]=S.end)}for(let b=h;b<s;b++){const S=o(b),w=this.laneAssignments.get(b);let v,k;const R=u==="estimate"||f.has(S);if(w!==void 0&&this.options.lanes>1){v=w;const L=g[v],E=L!==void 0?y[L]:void 0;k=E?E.end+m:n+a}else if(x===c){let L=0,E=p[0],F=g[0];for(let O=1;O<c;O++){const j=p[O];(j<E||j===E&&g[O]<F)&&(L=O,E=j,F=g[O])}v=L,k=E+m,R&&this.laneAssignments.set(b,v)}else v=b%this.options.lanes,k=n+a,R&&this.laneAssignments.set(b,v);const A=f.get(S),C=typeof A=="number"?A:this.options.estimateSize(b),M=k+C;y[b]={index:b,start:k,size:C,end:M,key:S,lane:v},g[v]===void 0&&x++,g[v]=b,p[v]=M}return this.measurementsCache=y,y},{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=LC(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,y=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()-y):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=Cf(0,n.length-1,o?c=>a[c*2]:c=>Ul(n[c]).start,s);return Ul(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&&(ca()&&(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&&kC(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 Cf=(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 PC(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 LC(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=PC(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=Cf(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 ua=typeof document<"u"?l.useLayoutEffect:l.useEffect;function FC({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 b=m.options.horizontal?"width":"height";d.container.style[b]=`${f}px`}const h=!!m.options.horizontal,y=d.mode==="transform",g=h?"left":"top",p=m.options.scrollMargin,x=m.getVirtualItems();for(const b of x){const S=b.start-p,w=m.elementsCache.get(b.key);w&&d.lastPositions.get(w)!==S&&(d.lastPositions.set(w,S),y?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 y=!0;if(h.enabled){i(m);const g=m.range,p=h.prevRange;y=!p||p.isScrolling!==m.isScrolling||p.startIndex!==g?.startIndex||p.endIndex!==g?.endIndex,y&&(h.prevRange=g?{startIndex:g.startIndex,endIndex:g.endIndex,isScrolling:m.isScrolling}:null)}y&&(e&&d?_a.flushSync(a):a()),(f=n.onChange)==null||f.call(n,m,d)}},[u]=l.useState(()=>{const m=new DC(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 y=m.options.horizontal?"width":"height";d.style[y]=`${h}px`}}})});return u.setOptions(c),ua(()=>u._didMount(),[]),ua(()=>u._willUpdate()),ua(()=>{i(u)}),u}function $C(e){return FC({observeElementRect:EC,observeElementOffset:TC,scrollToFn:OC,...e})}const Xo=e=>e.query?`matching "${e.query}"`:e.from?`from "${e.from}"`:"matching your search",_C=e=>`Select all ${Xo(e)}`,zC=(e,t)=>`All ${Gt(t)} ${Xo(e)} selected`,BC=({verb:e,confirmingDelete:t,hasSelection:s,junkMailboxId:n,currentMailboxId:a,deletableMessageId:o})=>{if(t)return{kind:"withheld"};if(e==="junk"){const i=aS(n,a);if(i!==void 0)return{kind:"unavailable",reason:i}}return s?{kind:"openWizard"}:e!=="delete"||o===void 0?{kind:"declined"}:{kind:"confirmDelete",messageId:o}},UC=(e,t,s)=>e==="BACK"&&t&&s===void 0,KC=(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:gt(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Er(e.category),messageCount:t,suspicious:e.authenticity?.dkimMismatch===!0,labels:e.labels}),qC=({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:y})=>r.jsx(Ho,{thread:KC(e,m),linkMailboxId:t,inListbox:!0,active:s,focused:n,isTabStop:a,density:y,isDesktop:h,onFocusRow:o,selection:{isChecked:i,onToggleCheck:c,onRowSelect:u,isMultiSelectMode:d,onLongPress:f}}),HC=l.memo(qC),WC=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:gt(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Er(e.category),suspicious:t}},VC=({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:y,density:g})=>{const[p,x]=l.useState("none"),b=Ve(),S=l.useCallback(A=>{navigator.vibrate?.(10),A==="trailing"?h(e.messageId):y(e.messageId,e.isRead),x("none")},[h,y,e.messageId,e.isRead]),w=l.useCallback(()=>{d(e.messageId)},[d,e.messageId]),v=l.useCallback(()=>{c(e.messageId)},[c,e.messageId]),k=l.useCallback(()=>{b({to:"/mail/$mailboxId",params:{mailboxId:t},search:A=>({...A,selectedMessageId:e.messageId})})},[b,t,e.messageId]),R=sf(e.messageId,u);return f||m?r.jsx(HC,{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("div",{role:"presentation",onPointerDownCapture:R.onMouseDown,onClickCapture:R.claimClick,onContextMenu:R.onContextMenu,children:r.jsx(ru,{thread:WC(e),selectionMode:!1,checked:!1,active:s,peek:p,onPeek:x,onToggleCheck:v,onLongPress:w,onOpen:k,onAct:S})})},QC=72,GC=32,YC=5,jf="remit:list-density",XC=()=>{try{const e=localStorage.getItem(jf);if(e==="compact"||e==="comfortable")return e}catch{}return"comfortable"},JC=({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(rr,{className:"size-4 text-fg-muted"}),r.jsxs("span",{className:"text-sm text-fg-muted",children:["Results for “",e,"”"]})]}),ZC=({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:y=!1,isLoadingMore:g=!1,accountId:p,listTitle:x,listMeta:b,listFilter:S,listScopeLabel:w,onTriageContextChange:v,commandsRef:k,hideHeader:R=!1})=>{const A=l.useRef(null),C=Ve(),M=es(),L=Ja(),{verb:E,start:F,startFromSearch:O}=L,j=th(),T=!!c?.trim(),P=Ar(),{labels:I}=ro(p),{pushError:D}=tt(),[N,G]=l.useState(s),[W,ne]=l.useState(),re=l.useCallback(z=>{ne(Y=>Y===z?Y:void 0),G(z)},[]),[he,te]=l.useState(XC),ce=l.useCallback(()=>{te(z=>{const Y=z==="comfortable"?"compact":"comfortable";try{localStorage.setItem(jf,Y)}catch{}return Y})},[]),{toggleReadFor:ie}=Nr({mailboxId:e}),{junkMailboxId:U}=Sn(p),_=Tr(U,e),{selectedIds:ue,selectedCount:pe,hasSelection:ye,isSelected:Se,toggle:H,select:we,clearSelection:xe,selectRange:Ie,setAnchor:de,selectAll:se,toggleAll:be,intersectWith:Be}=Gc(),me=fo(pe,M),[K,Te]=l.useState(null),Ne=T&&!!u,Pe=`${e}|${JSON.stringify(u??{})}`,$=of({mailboxId:e,accountId:p,enabled:Ne,predicateKey:Pe,searchQuery:u??{}}),le=l.useCallback((z,Y,St)=>{if(St.error===void 0){if(St.cancelled){D({severity:"warning",title:tk(St.done),detail:sk(z,St.done,Y)});return}D({severity:"info",title:Ll(z,St.done)})}},[D]),J=$.phase.kind,ge=$.clear,Me=l.useCallback(()=>{J==="escalated"&&ge(),xe()},[xe,ge,J]),[Ye,He]=l.useState(null),Ze=l.useRef(null),Ae=l.useRef(!1),nt=l.useRef(null),st=!n&&t.length>0,Re=K!==null,V=$C({count:t.length,getScrollElement:()=>A.current,estimateSize:()=>he==="compact"?GC:QC,overscan:YC}),fe=s?t.findIndex(z=>z.messageId===s):-1,ae=N?t.findIndex(z=>z.messageId===N):-1,Z=l.useCallback(z=>{if(z<0||z>=t.length)return;const Y=t[z];if(me){H(Y.messageId);return}Ze.current=Y.messageId,Ae.current=!1,ne(Y.messageId),G(Y.messageId)},[t,me,H]),ke=l.useCallback(()=>{if(t.length===0)return;const z=ae<0?0:Math.min(ae+1,t.length-1);Z(z)},[t.length,ae,Z]),Oe=l.useCallback(()=>{if(t.length===0)return;const z=ae<=0?0:ae-1;Z(z)},[t.length,ae,Z]),$e=l.useCallback(()=>Z(0),[Z]),Qe=l.useCallback(()=>Z(t.length-1),[Z,t.length]),Ue=l.useCallback(()=>{N&&H(N)},[N,H]),Ce=l.useMemo(()=>t.map(z=>z.messageId),[t]),Xe=l.useMemo(()=>{const z=[];for(const Y of t)ue.has(Y.messageId)&&z.push({id:Y.messageId,sender:Y.fromName??Y.fromEmail??"Unknown",email:Y.fromEmail??"",subject:Y.subject??"(No subject)",date:gt(Y.sentDate)});return z},[t,ue]),ze=l.useCallback((z,Y)=>Y.shiftKey?(Ie(Ce,z,N),!0):Y.metaKey||Y.ctrlKey?(H(z),!0):(Me(),de(z),!1),[Ce,N,Ie,H,Me,de]),lt=l.useCallback(z=>{!m||z.length===0||(nt.current=N??null,Te(z))},[m,N]),Je=l.useCallback(z=>{const Y=Qc(Ce,N,z);Y!==void 0&&(Ie(Ce,Y),Ze.current=Y,Ae.current=!1,ne(void 0),G(Y))},[Ce,N,Ie]),zt=l.useCallback(()=>Je(-1),[Je]),Rt=l.useCallback(()=>Je(1),[Je]),ns=l.useCallback(()=>{Ce.length>0&&se(Ce)},[Ce,se]),bs=l.useCallback(z=>{const Y=BC({verb:z,confirmingDelete:K!==null,hasSelection:ye,junkMailboxId:U,currentMailboxId:e,deletableMessageId:m?N:void 0});return Y.kind==="openWizard"?(F(z),!0):Y.kind==="confirmDelete"?(lt([Y.messageId]),!0):Y.kind==="unavailable"?(D({severity:"warning",title:Y.reason}),!0):Y.kind==="withheld"},[K,m,ye,U,e,F,N,lt,D]),rt=l.useCallback(()=>{N&&C({to:"/mail/$mailboxId",params:{mailboxId:e},search:z=>({...z,selectedMessageId:N})})},[N,C,e]),Tt=l.useCallback(z=>{C({to:"/mail/$mailboxId",params:{mailboxId:e},search:Y=>({...Y,selectedMessageId:z}),replace:!0})},[C,e]);Zd({keyboardFocusedMessageId:W,openMessageId:s,enabled:M&&pe===0,open:Tt});const bt=$.phase.kind==="escalated"?{scope:Xo(u??{}),total:$.phase.total,searchQuery:u??{},run:z=>$.runAction(z),stop:$.stop}:void 0,vt=l.useCallback(()=>{if(!K)return;const z=K;if(z.length===0){Te(null);return}const Y=new Set(z),St=t.findIndex(et=>Y.has(et.messageId));let Mt;for(let et=St+1;et<t.length;et++)if(!Y.has(t[et].messageId)){Mt=t[et].messageId;break}if(Mt===void 0){for(let et=St-1;et>=0;et--)if(!Y.has(t[et].messageId)){Mt=t[et].messageId;break}}m?.(z),Me(),nt.current=null,Te(null),Mt!==void 0&&(Ze.current=Mt,Ae.current=!1,re(Mt),M&&C({to:"/mail/$mailboxId",params:{mailboxId:e},search:et=>({...et,selectedMessageId:Mt}),replace:!0})),M||He(Ll("delete",z.length))},[K,t,m,Me,C,e,M,re]),ht=l.useCallback(()=>{const z=nt.current;nt.current=null,Te(null),z!==null&&(Ze.current=z,Ae.current=!1,re(z))},[re]),rs=l.useMemo(()=>{if(pe===0)return;const z=new Set;for(const Y of t)ue.has(Y.messageId)&&z.add(Y.accountConfigId);if(z.size>1)return"Move only works within one account — clear selection or pick messages from a single account"},[pe,ue,t]),qs=l.useCallback(()=>{if(bt){O();return}F("organize")},[bt,O,F]),Cn=l.useCallback(z=>{m?.([z])},[m]),ct=l.useCallback((z,Y)=>{ie([z],!Y)},[ie]),B=l.useCallback(z=>{M||we(z)},[M,we]),X=l.useCallback(()=>{if($.isRunning||$.phase.kind==="counting"){$.stop();return}Me()},[$,Me]),je=l.useCallback(()=>{$.clear()},[$]);l.useEffect(()=>{if(Ae.current||!M&&s)return;const z=ae>=0?ae:fe;z>=0&&V.scrollToIndex(z,{align:"auto"})},[ae,fe,V,M,s]),l.useEffect(()=>{s&&(Ae.current=!1,re(s))},[s,re]),l.useEffect(()=>{N&&(t.some(z=>z.messageId===N)||re(t[0]?.messageId))},[t,N,re]),l.useEffect(()=>{v?.({focusedMessageId:N,selectedIds:Array.from(ue),hasList:st,blocksKeyboard:Re||L.isOpen})},[N,ue,st,Re,L.isOpen,v]);const pt=l.useRef(v);pt.current=v,l.useEffect(()=>()=>pt.current?.({focusedMessageId:void 0,selectedIds:[],hasList:!1,blocksKeyboard:!1}),[]),l.useEffect(()=>{$.phase.kind!=="idle"||$.isRunning||Be(t.map(z=>z.messageId))},[t,Be,$.phase,$.isRunning]);const yt=l.useRef(e);l.useEffect(()=>{yt.current!==e&&(yt.current=e,Me())},[e,Me]),Pu({shouldBlockFn:({action:z})=>UC(z,ye,j)?(Me(),!0):!1,enableBeforeUnload:!1,disabled:!ye||j!==void 0}),l.useEffect(()=>{const z=A.current;if(!z||!y||!h)return;const Y=()=>{if(g)return;const{scrollTop:St,scrollHeight:Mt,clientHeight:et}=z;St+et>=Mt-200&&h()};return z.addEventListener("scroll",Y,{passive:!0}),Y(),()=>z.removeEventListener("scroll",Y)},[y,g,h]),l.useEffect(()=>{const z=Ze.current;if(!z)return;const Y=A.current?.querySelector(`[data-message-id="${z}"]`);Y&&(Ze.current=null,Y.focus({preventScroll:!0}))}),l.useEffect(()=>{if(k){if(!st){k.current=null;return}return k.current={focusNext:ke,focusPrevious:Oe,focusFirst:$e,focusLast:Qe,openFocused:rt,toggleSelect:Ue,extendSelectDown:Rt,extendSelectUp:zt,selectAll:ns,clearSelection:()=>ye?(Me(),!0):!1,requestVerb:bs,toggleDensity:ce},()=>{k.current=null}}},[k,st,ke,Oe,$e,Qe,rt,Ue,Rt,zt,ns,ye,Me,bs,ce]);const vs=n?"loading":a?"error":t.length===0?"empty":"ready",wt=a?wc(o):void 0,as=l.useCallback(()=>{const z=Ga(Ya());window.open(z,"_blank","noopener,noreferrer")},[]),jn=[{id:"inbox",threads:[]}],ys=Ce.length>0&&Ce.every(z=>ue.has(z)),Lr=Ne&&y&&ys&&!d&&!f&&$.phase.kind==="idle"&&!$.isRunning,Fr=d||f||$.isRunning,Hs=$.phase.kind==="escalated"?$.phase.total:pe,$r=$.runningAction?ek($.runningAction.kind,$.progress?.done??0,$.progress?.total??Hs):$.phase.kind==="counting"?"Counting matches…":$.phase.kind==="escalated"?zC(u??{},$.phase.total):void 0,_r=$.phase.kind!=="escalated"&&Ce.length>0?{checked:ys,indeterminate:pe>0&&!ys,onChange:()=>be(Ce)}:void 0,ee=$.runningAction?{value:$.progress?.done??0,max:$.progress?.total??Hs,tone:ak($.runningAction.kind)}:void 0,at=($.phase.kind==="counting"?{tone:"info",text:"",action:{label:"Stop",onClick:$.stop}}:$.phase.kind==="escalated"&&!$.isRunning?{tone:"info",text:"",action:{label:"Clear selection",onClick:je}}:Lr?{tone:"info",text:"",action:{label:_C(u??{}),onClick:$.escalate}}:void 0)??(rs?{tone:"warning",text:rs}:void 0),Ff=r.jsx(yo,{title:P.title||x,navSlot:P.navSlot,titleMeta:P.titleMeta,searchSlot:P.searchSlot,searchField:P.searchField,idleSlot:P.makeFilterSlot,count:Hs,onCancel:X,onDelete:()=>F("delete"),onMove:()=>F("move"),onOrganize:qs,onJunk:_?()=>F("junk"):void 0,onMarkRead:()=>F("markRead"),overflowSlot:p&&e&&pe>0&&I.length>0?r.jsx(Vd,{accountId:p,mailboxId:e,messageIds:Array.from(ue)}):void 0,isBusy:Fr,isCounting:$.phase.kind==="counting",selectAll:_r,statusLabel:$r,progress:ee,notice:at}),$f=ef(Ce,N),_f=l.useCallback(z=>{Ae.current=!0,re(z)},[re]),zf=r.jsxs(r.Fragment,{children:[T&&c&&r.jsx(JC,{query:c}),r.jsxs("div",{ref:A,role:"listbox","aria-multiselectable":!0,"aria-label":x,className:"flex-1 overflow-y-auto",children:[r.jsx("div",{role:"presentation",className:"relative w-full",style:{height:`${V.getTotalSize()}px`},children:V.getVirtualItems().map(z=>{const Y=t[z.index];return r.jsx("div",{role:"presentation","data-index":z.index,ref:V.measureElement,className:qe("absolute left-0 top-0 w-full border-b border-line",$.isRunning&&"pointer-events-none opacity-50"),style:{transform:`translateY(${z.start}px)`},children:r.jsx(VC,{thread:Y,mailboxId:e,isSelected:s===Y.messageId,isFocused:N===Y.messageId,isTabStop:$f===Y.messageId,onFocusRow:_f,isChecked:Se(Y.messageId),onToggleCheck:H,onRowSelect:ze,isMultiSelectMode:me,onLongPress:B,isDesktop:M,onDelete:Cn,onToggleRead:ct,density:he})},z.key)})}),g&&r.jsx(_p,{})]})]});return r.jsxs(r.Fragment,{children:[Ye&&!M&&r.jsx(pn,{tone:"success",variant:"soft",className:"m-2 rounded-md",onDismiss:()=>He(null),children:Ye}),r.jsx(au,{listTitle:x,listMeta:b,sections:jn,flatList:!0,listState:P.searchResults?"ready":vs,searchQuery:T?c:void 0,listFilter:S,listScopeLabel:w,errorMessage:wt,onRetry:i,onReportError:as,density:he,selectedThreadId:s,onSelectThread:z=>C({to:"/mail/$mailboxId",params:{mailboxId:e},search:Y=>({...Y,selectedMessageId:z})}),isDesktop:M,hideHeader:R,selectionBar:Ff,listBody:P.searchResults??(vs==="ready"?zf:void 0)}),r.jsx(jc,{isOpen:K!==null,title:kc(K?.length??0),description:"You can restore them from Trash later.",confirmLabel:"Move to Trash",destructive:!0,isBusy:d,onConfirm:vt,onCancel:ht}),r.jsx(Wo,{verb:E,accountId:p,mailboxId:e,selection:Xe,crossAccount:rs!==void 0,escalated:bt,escalatedProgress:$.progress,onFinished:Me,onRunEnded:le})]})},ej=e=>Ft({path:{accountId:e}}),tj=e=>{const t=Ee(),s=Ls(),n=_e({...sh(),onSuccess:()=>{s.recordEvent("sync.triggered"),t.invalidateQueries({queryKey:ej(e)})}});return{trigger:()=>{n.mutate({path:{accountId:e}})},triggerAsync:()=>n.mutateAsync({path:{accountId:e}}),isPending:n.isPending,error:n.error,reset:n.reset}},sj=({accountId:e,children:t})=>{const{triggerAsync:s,isPending:n}=tj(e);return r.jsx(wx,{onRefresh:s,isRefreshing:n,children:t})};function nj({accountId:e,currentMailboxId:t,candidates:s,onMove:n,children:a}){const[o,i]=l.useState(!1),c=Ls(),u=to(),{inboxMailboxId:m}=od(e),d=Oo(e),{data:f}=ve({...it({path:{accountId:e}}),staleTime:1/0}),h=l.useMemo(()=>so({mailboxes:f?.items??[],folderAppointments:d,currentMailboxId:t,translator:u}),[f?.items,d,t,u]),y=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,Uk(c,s.length))},[c,s.length]);const p=l.useCallback(()=>{Kk(c,s.length),i(!0)},[c,s.length]),x=l.useCallback((b,S)=>{qk(c,{selected:b.length,total:s.length,toInbox:S===m}),n(b,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(Cx,{count:s.length,onReview:p})}),r.jsx("div",{className:"min-h-0 flex-1",children:a}),r.jsx(Px,{open:o,candidates:s,defaultDestinationId:y,availableFolders:h,delimiter:no(f?.items??[]),onConfirmMove:x,onCancel:()=>i(!1)})]})}const rj="We can verify this sender";function aj(e){const{data:t}=ve({...xc({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:rj,trustSubReason:Bk(n.senderTrust),senderTrust:n.senderTrust}))}}const oj=e=>{const t=new Set,s=[];for(const n of e)t.has(n.threadMessageId)||(t.add(n.threadMessageId),s.push(n));return s},ij={unread:"unread",flagged:"starred",attachment:"attachments"},lj=new Set(Object.values(ot)),Nf=e=>lj.has(e),cj=e=>Nf(e.category)||e.attributes.size>0,uj=e=>{const t={};Nf(e.category)&&(t.category=[e.category]);for(const s of e.attributes){const n=ij[s];n&&(t[n]=!0)}return t},dj=e=>(e.senderTrust?.length??0)>0||e.dkimMismatch!==void 0?"loaded-pages":"whole-folder",fj=["category","unread","starred","attachments"],ql=e=>JSON.stringify(fj.map(t=>e?.[t]??null)),mj=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},hj=(e,t)=>{const s=mj(e);return s?ql(s)===ql(t):!1},Ef="remit:intelligence-open";function pj(){try{return localStorage.getItem(Ef)!=="closed"}catch{return!0}}function Hl(e){try{localStorage.setItem(Ef,e?"open":"closed")}catch{}}const gj=(e,t)=>e!==t,xj=(e,t,s)=>{if(!(s||!t))return e.find(n=>n.messageId===t)},bj=(e,t,s,n)=>{if(e)return e;if(!(n||!s))return t?.messageId===s?t:void 0},Ln=e=>e[0],vj=e=>{const t=Ln(e.filter(c=>c.type==="from").map(c=>c.value)),s=Ln(e.filter(c=>c.type==="subject").map(c=>c.value)),n=Ln(e.filter(c=>c.type==="category").map(c=>c.category)),a=Ln(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}:{}}},yj=(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 wj(e,t={}){const s=vj(e),n={...s,...t};return{params:s,residual:e.filter(a=>!yj(n,a))}}function Sj(e,t,s){if(t.length===0)return e;const n=[...t];return e.filter(a=>{const o=er(a);return Bo({...o,accountId:o.accountId??s},n)})}const kj=50,Cj=new Map(gu().categories.filter(e=>e.id!=="all").map(e=>[e.id,e.label])),If=l.createContext(null);function Pr(){const e=l.useContext(If);if(!e)throw new Error("MailboxPane.* must be used inside <MailboxPane>");return e}function jj({mailboxId:e,selectedMessageId:t,children:s}){const n=Ve(),o=Mr()==="desktop",i=Ls(),{accounts:c,searchQuery:u,searchInput:m,intelligenceOpen:d,onToggleIntelligence:f,onSetIntelligenceOpen:h}=De(),y=xs(),g=_o(u),p=g.length>0,{freeText:x,tokens:b}=Us(g,y),[S,w]=l.useState("all"),[v,k]=l.useState(new Set),R=l.useMemo(()=>({category:S,attributes:v}),[S,v]),A=l.useMemo(()=>uj(R),[R]),C=p||cj(R),{params:M,residual:L}=wj(b,A),E={order:"desc",limit:kj,...x?{query:x}:{},...M,...A},F={category:E.category,unread:E.unread,starred:E.starred,attachments:E.attachments},O=C?Va({path:{mailboxId:e},query:E}):cr({path:{mailboxId:e},query:{order:"desc"}}),{data:j,isLoading:T,isError:P,error:I,refetch:D,fetchNextPage:N,hasNextPage:G,isFetchingNextPage:W}=Du({queryKey:O,queryFn:async({pageParam:ee})=>{if(C){const{data:at}=await ma({path:{mailboxId:e},query:{...E,continuationToken:ee},throwOnError:!0});return at}const{data:ut}=await nh({path:{mailboxId:e},query:{order:"desc",continuationToken:ee},throwOnError:!0});return ut},initialPageParam:void 0,getNextPageParam:ee=>ee.continuationToken,placeholderData:(ee,ut)=>hj(ut?.queryKey,F)?ee:void 0}),ne=l.useCallback(ee=>{t&&ee.includes(t)&&n({to:"/mail/$mailboxId",params:{mailboxId:e},search:ut=>({...ut,selectedMessageId:void 0,selectedThreadId:void 0})})},[t,e,n]),{deleteMessages:re,isPending:he}=ms({mailboxId:e,onAfterOptimisticRemove:ne}),{accountId:te}=To(e),ce=Yu({accounts:c}),{moveMessages:ie,isPending:U}=Ds({mailboxId:e,accountId:te,onAfterOptimisticRemove:ne}),_=Sj(k0(oj(j?.pages.flatMap(ee=>ee.items??[])??[])),L,te),ue=l.useCallback(ee=>{w(ee)},[]),pe=l.useCallback(ee=>{k(ut=>{const at=new Set(ut);return at.has(ee)?at.delete(ee):at.add(ee),at})},[]),ye=l.useCallback(()=>{w("all"),k(new Set)},[]),Se=Cj.get(S),H=Se?{label:Se,reach:L.length>0?"loaded-pages":dj(E),onClear:ye}:void 0,we=gj(m,u),xe=xj(_,t,we),[Ie,de]=l.useState(void 0);l.useEffect(()=>{xe&&de(xe)},[xe]);const se=bj(xe,Ie,t,we),{selectedThreadId:be}=As({strict:!1}),Be=l.useMemo(()=>gf(se,{messageId:t,threadId:we?void 0:be,mailboxId:e}),[se,t,be,we,e]),me=Qo(),{listCommandsRef:K,onTriageContextChange:Te,focusedMessageId:Ne,selectedIds:Pe}=me,$=_.find(ee=>ee.messageId===Ne)??se,le=l.useRef(null);l.useEffect(()=>{const ee=se?.messageId??null;ee&&le.current!==ee&&se?.authenticity?.dkimMismatch&&(le.current=ee,d||f())},[se?.messageId,se?.authenticity?.dkimMismatch,d,f]);const J=l.useRef(!1);l.useEffect(()=>{J.current||o&&se?.messageId&&(J.current=!0,pj()&&!d&&h(!0))},[o,se?.messageId,d,h]);const ge=jy({accounts:c})??0,Me=Ee(),{pushError:Ye}=tt(),He=fn({thread:se,mailboxId:e,accountId:te,onAfterOptimisticRemove:ne}),{draftsMailboxId:Ze}=b0(te),Ae=Ze!==void 0&&Ze===e,{archiveMailboxId:nt}=x0(te),st=pf(),{requestCompose:Re}=He,V=l.useCallback(()=>{Re("reply")},[Re]),fe=l.useCallback(()=>{Re("reply_all")},[Re]),ae=l.useCallback(()=>{Re("forward")},[Re]),{state:Z,openCompose:ke,closeCompose:Oe}=Jt(),$e=l.useCallback(()=>{ke({mode:"new"})},[ke]),Qe=_e({...lr(),onError:ee=>{Ye(ds("Couldn't discard draft","The draft wasn't deleted.",ee))}}),Ue=l.useCallback(()=>{const ee=Z.outboxMessageId;ee&&(Qe.mutate({path:{outboxMessageId:ee}}),Me.invalidateQueries({queryKey:Za()}),Oe())},[Z.outboxMessageId,Qe,Me,Oe]),Ce=l.useCallback(()=>{n({to:"/mail/$mailboxId",params:{mailboxId:e},search:ee=>({...ee,selectedMessageId:void 0,selectedThreadId:void 0})})},[e,n]),Xe=l.useCallback(ee=>ee?st(ee):[],[st]),{toggleStar:ze}=Mo({threadId:$?.threadId??"",mailboxId:e}),{toggleReadFor:lt}=Nr({mailboxId:e,accountId:te}),{junkMailboxId:Je}=Sn(te),zt=Je!=null&&Je===e,Rt=Tr(Je,e),{candidates:ns}=aj(zt?Je:void 0),{moveMessages:bs}=Ds({mailboxId:e,threadId:$?.threadId,accountId:te,onAfterOptimisticRemove:ne}),{deleteMessages:rt}=ms({mailboxId:e,threadId:$?.threadId,onAfterOptimisticRemove:ne}),{addressId:Tt,address:bt}=df($),{updateFlags:vt}=ff({addressId:Tt,senderEmail:$?.fromEmail??void 0}),ht=l.useCallback(()=>t||!Ne?!1:(n({to:"/mail/$mailboxId",params:{mailboxId:e},search:ee=>({...ee,selectedMessageId:Ne})}),!0),[t,Ne,e,n]),rs=l.useCallback(()=>{ht()||se&&Re("reply")},[ht,se,Re]),qs=l.useCallback(()=>{ht()||se&&Re("reply_all")},[ht,se,Re]),Cn=l.useCallback(()=>{ht()||se&&Re("forward")},[ht,se,Re]),ct=l.useCallback(()=>Xe($),[Xe,$]),B=l.useCallback(()=>{if(K.current?.requestVerb("delete"))return;const ee=ct();ee.length>0&&rt(ee)},[K,ct,rt]),X=l.useCallback(()=>{if(K.current?.requestVerb("junk")||!Rt)return;const ee=ct();ee.length!==0&&(hf(i,{count:ee.length,senderTrust:$?.senderTrust??"unknown",wasRescuable:$?mf($):!1}),bs(ee,Rt))},[K,Rt,ct,bs,i,$]),je=l.useCallback(()=>{if(Pe.length>0){const ee=!($?.hasStars??!1),ut=new Set(Pe);for(const at of _)ut.has(at.messageId)&&at.hasStars!==ee&&ze(at.messageId,at.hasStars);return}$&&ze($.messageId,$.hasStars)},[Pe,_,$,ze]),pt=l.useCallback(()=>{if(K.current?.requestVerb("markRead"))return;const ee=ct();if(ee.length===0)return;const ut=!($?.isRead??!1);lt(ee,ut)},[K,ct,$,lt]),yt=l.useCallback(()=>{if(!Tt)return;const ee=bt?.flags?.muted?.value!==!0;vt({muted:{value:ee}})},[Tt,bt,vt]),vs=l.useCallback(()=>{if(!Tt)return;const ee=bt?.flags?.vip?.value!==!0;vt({vip:{value:ee}})},[Tt,bt,vt]),wt=l.useCallback(()=>{d||f()},[d,f]),as=l.useCallback(ee=>{n({to:ee})},[n]),jn=Ae?"drafts":nt===e?"archive":Je===e?"junk":"inbox",ys=l.useRef("");l.useEffect(()=>{const ee=ys.current;ys.current=g,g.length>0&&ee.length===0&&i.recordEvent("search.submitted",{mailboxType:jn})},[g,jn,i]);const Lr=Ae&&Z.isOpen&&!!Z.outboxMessageId&&!se,{goBack:Fr,nextMessageId:Hs,previousMessageId:$r}=Go({context:me,orderedIds:_.map(ee=>ee.messageId),selectedMessageId:t,enabled:!Z.isOpen,onClose:Ce,handlers:{reply:rs,replyAll:qs,forward:Cn,delete:B,toggleStar:je,toggleRead:pt,muteSender:yt,blockSender:wt,vipSender:vs,markJunk:X,toggleIntelligence:se?f:void 0,compose:$e,goBrief:()=>as("/mail"),goInbox:()=>as("/mail"),goSent:()=>as("/mail"),goFlagged:()=>as("/mail/flagged"),goSettings:()=>as("/settings")}});Ro({enabled:Z.isOpen,bindings:[{key:"Escape",handler:Oe,preventDefault:!0}]});const _r={mailboxId:e,selectedMessageId:t,selectedThread:se,conversation:Be,threads:_,isLoading:T,isError:P,error:I,mailboxAccountId:te,mailboxName:ce,unreadCount:ge,isDraftsMailbox:Ae,isSpamFolder:zt,rescueCandidates:ns,filterCategory:S,filterAttributes:v,onSelectFilterCategory:ue,onToggleFilterAttribute:pe,onClearFilters:ye,listFilter:H,intelligenceOpen:d,onToggleIntelligence:f,handleDeselectIfRemoved:ne,searchPredicate:p&&L.length===0?E:void 0,onDeleteMessages:re,onMoveMessages:ie,isDeleting:he,isMoving:U,onLoadMore:N,hasMore:G,isLoadingMore:W,onTriageContextChange:Te,listCommandsRef:K,onRetry:()=>D(),toolbarComposeRequest:He.composeRequest,onToolbarReply:V,onToolbarReplyAll:fe,onToolbarForward:ae,onClearComposeRequest:He.clearComposeRequest,onToolbarDelete:He.deleteThread,onToolbarStar:He.toggleStar,onToolbarDiscardDraft:Ue,onToolbarMove:He.moveThread,composeState:Z,closeCompose:Oe,hasRemitDraftOpen:Lr,onBack:Fr,nextMessageId:Hs,previousMessageId:$r};return r.jsx(If.Provider,{value:_r,children:s})}function Rf(){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:y,mailboxName:g,unreadCount:p,isDraftsMailbox:x,isSpamFolder:b,rescueCandidates:S,onTriageContextChange:w,listCommandsRef:v,onRetry:k,filterCategory:R,filterAttributes:A,onSelectFilterCategory:C,onToggleFilterAttribute:M,onClearFilters:L,listFilter:E,searchPredicate:F}=Pr(),{searchQuery:O,searchInput:j,accounts:T,resultFolderIndex:P}=De(),I=Mr(),D=Ve(),N=g??"Inbox",G=l.useMemo(()=>gu(),[]),W=l.useMemo(()=>y?[y]:[],[y]),{hasNewMail:ne}=kr(),{state:re,errorMessage:he,refresh:te}=Co(W,{onSettled:k}),ce=l.useMemo(()=>r.jsx(bo,{state:re,onRefresh:te,label:`Refresh ${N}`,errorMessage:he,hasUpdate:ne(W)}),[re,te,N,he,ne,W]),ie=l.useMemo(()=>s.map(xe=>lS(xe,P)),[s,P]),{hits:U,isLoading:_}=Ud({mailboxId:e,filterCategory:R}),ue=l.useMemo(()=>Hd(U,s.map(xe=>xe.threadId),P),[U,s,P]),pe=l.useCallback(xe=>D({to:"/mail/$mailboxId",params:{mailboxId:xe.mailboxId??e},search:Ie=>({...Ie,q:j||void 0,selectedMessageId:xe.id,selectedThreadId:xe.threadId})}),[e,D,j]);if(x&&y)return r.jsx(wC,{mailboxId:e,accountId:y,selectedMessageId:t,imapThreads:s,title:g??"Drafts",unreadCount:p??void 0});const ye=r.jsx(ZC,{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:y,listTitle:N,listFilter:E,listScopeLabel:N,hideHeader:!0,onTriageContextChange:w,commandsRef:v}),Se=T[0]?.accountId,H=I==="phone"&&Se?r.jsx(sj,{accountId:Se,children:ye}):ye,we=b&&S.length>0&&y?r.jsx(nj,{accountId:y,currentMailboxId:e,candidates:S,onMove:c,children:H}):H;return r.jsx(yf,{title:N,unreadCount:p,preset:G,selectedCategory:R,activeFilters:A,onSelectCategory:C,onToggleFilter:M,onClearFilters:L,searchResults:ie,searchLoading:n,relatedResults:ue,relatedLoading:_,onSelectSearchResult:pe,searchResultsInBody:!0,refreshControl:ce,children:we})}function Nj(){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:y,onToolbarDiscardDraft:g,onToolbarMove:p,composeState:x}=Pr(),b=ps()?.showIntelligencePane??!1,S=!!n,w=b&&S,v=x.isOpen&&!n?r.jsx(kf,{}):n?r.jsx(Bs,{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(zs,{});return r.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[r.jsx(Vo,{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?y:void 0,isStarred:s?.hasStars,moveContext:S&&t?{accountId:t,currentMailboxId:e,onMove:p}:void 0}),r.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:v})]})}function Ej(){const{mailboxId:e,mailboxAccountId:t,selectedThread:s,onToggleIntelligence:n,handleDeselectIfRemoved:a}=Pr();return r.jsx(Ks,{onClose:n,thread:s,mailboxId:e,accountId:t,onAfterOptimisticRemove:a})}function Ij(){const{mailboxId:e,mailboxAccountId:t,selectedThread:s,conversation:n,intelligenceOpen:a,onToggleIntelligence:o,onBack:i,nextMessageId:c,previousMessageId:u,composeState:m,handleDeselectIfRemoved:d}=Pr(),f=Ve();if(n){const h=y=>f({to:"/mail/$mailboxId",params:{mailboxId:e},search:g=>({...g,selectedMessageId:y,selectedThreadId:void 0})});return r.jsxs(r.Fragment,{children:[r.jsx(Bs,{threadId:n.threadId,mailboxId:n.mailboxId,subject:n.subject,selectedMessageId:n.messageId,authenticity:n.authenticity,onBack:i,onOpenIntelligence:o,onSwipeNext:c?()=>h(c):void 0,onSwipePrevious:u?()=>h(u):void 0,mobileIntelligenceOpen:a}),r.jsx(Eo,{isOpen:a,onClose:o,ariaLabel:"Message details",side:"right",children:r.jsx(Ks,{onClose:o,thread:s,mailboxId:e,accountId:t,hideCloseButton:!0,onAfterOptimisticRemove:d})})]})}return m.isOpen?r.jsx("div",{className:"h-full",children:r.jsx(kf,{})}):r.jsx(Rf,{})}const sn=Object.assign(jj,{List:Rf,Reading:Nj,Intelligence:Ej,Phone:Ij}),Tf=e=>e==="failed"||e==="blocked",Mf=e=>e!=="draft"&&e!=="sent",Jo="remit.savedSearches",Rj=25;function sr(){try{const e=localStorage.getItem(Jo);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}catch{return[]}}function Tj(e){const t=e.trim();if(!t)return sr();const s=[t,...sr().filter(n=>n!==t)].slice(0,Rj);try{localStorage.setItem(Jo,JSON.stringify(s))}catch{return s}return s}function Mj(e){const t=sr().filter(s=>s!==e);try{localStorage.setItem(Jo,JSON.stringify(t))}catch{return t}return t}const Wl=e=>/^\d/.test(e),Aj=(e,t)=>{const s=Wl(e),n=Wl(t);return s&&!n?-1:!s&&n?1:e.localeCompare(t,void 0,{sensitivity:"base",numeric:!0})};function Oj(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)=>Aj(Vn(o,void 0,s),Vn(i,void 0,s))),{system:n,labels:a}}function Dj(e,t,s){const n=rh(t)&&e.unseenCount>0;return{id:e.mailboxId,name:Vn(e,t,s),unseen:n?e.unseenCount:void 0,role:t,fullPath:e.fullPath}}function Pj(){const e=Sr(),t=qa({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 Vl({accounts:e,onMailboxSelect:t,variant:s="desktop"}){const n=Ee(),a=Ve(),o=Pj(),{searchInput:i,onSearchChange:c}=De(),[u,m]=l.useState(sr),{t:d}=Ha("mail",{useSuspense:!1}),f=l.useCallback((C,M)=>d(C,{defaultValue:M}),[d]),h=mt({queries:e.map(C=>({...it({path:{accountId:C.accountId}}),staleTime:1/0}))}),{data:y}=ve(or()),g=l.useMemo(()=>(y?.items??[]).filter(C=>Mf(C.status)).length,[y?.items]),p=l.useMemo(()=>e.map((C,M)=>{const L=h[M],E=L?.data?.items??[],F=Ua(C.folderAppointments),{system:O,labels:j}=Oj(E,F,f),T=L?.isError?"error":L?.isLoading?"loading":"ready";return{id:C.accountId,label:C.email,email:C.email,muted:!!C.muted,outboxPending:g,status:T,onRetry:()=>L?.refetch(),mailboxes:[...O,...j].map(P=>Dj(P,F.get(P.mailboxId),f))}}),[e,h,g,f]),x=C=>{n.invalidateQueries({queryKey:cr({path:{mailboxId:C},query:{order:"desc"}})})},b=({navId:C,className:M,ariaLabel:L,title:E,children:F,onClick:O})=>C==="brief"?r.jsx(qt,{to:"/mail",search:{q:void 0,selectedMessageId:void 0},onClick:()=>O?.(),className:M,"aria-label":L,title:E,children:F}):C==="outbox"?r.jsx(qt,{to:"/mail/outbox",search:{q:void 0,selectedOutboxMessageId:void 0},onClick:()=>O?.(),className:M,"aria-label":L,title:E,children:F}):C==="flagged"?r.jsx(qt,{to:"/mail/flagged",search:{q:void 0,selectedMessageId:void 0},onClick:()=>O?.(),className:M,"aria-label":L,title:E,children:F}):C==="settings"?r.jsx(qt,{to:"/settings/accounts",onClick:()=>O?.(),className:M,"aria-label":L,title:E,children:F}):r.jsx(qt,{to:"/mail/$mailboxId",params:{mailboxId:C},search:{q:void 0,selectedMessageId:void 0},onClick:()=>{x(C),O?.()},className:M,"aria-label":L,title:E,children:F}),S=()=>{c(""),t?.()},w=i.trim(),v=w.length>0&&!u.includes(w)?w:void 0,k=l.useCallback(()=>{v&&m(Tj(v))},[v]),R=l.useCallback(C=>{m(Mj(C))},[]),A=l.useCallback(C=>{c(C),a({to:"/mail",search:{q:C,selectedMessageId:void 0}}),t?.()},[c,a,t]);return r.jsx(_g,{accounts:p,selectedNavId:o,onSelectNav:S,linkComponent:b,variant:s,savedSearches:u,saveableQuery:v,onSaveCurrentSearch:k,onSelectSavedSearch:A,onRemoveSavedSearch:R})}function Lj(){return r.jsxs("button",{type:"button",onClick:uc,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(Fc,{className:"size-4 shrink-0"}),r.jsx("span",{className:"flex-1 truncate text-left",children:"Report a bug"})]})}function Fj({accounts:e,onMailboxSelect:t}){return ps()?.showNavPane??!0?r.jsx(Vl,{accounts:e}):r.jsxs("div",{className:"flex h-full flex-col",children:[r.jsx("div",{className:"flex-1 overflow-y-auto",children:r.jsx(Vl,{accounts:e,onMailboxSelect:t,variant:"drawer"})}),r.jsxs("div",{className:"border-t border-line px-2 py-2",children:[r.jsxs(qt,{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(qc,{className:"size-4 shrink-0"}),r.jsx("span",{className:"flex-1 truncate text-left",children:"Settings"})]}),r.jsx(Lj,{}),r.jsx(_u,{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(Bc,{className:"size-4 shrink-0"}),r.jsx("span",{className:"flex-1 truncate text-left",children:"Sign out"})]})})]})]})}function $j(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 _j(e){return e.tokens.length>0&&e.freeText.trim().length===0}const Af={queued:{icon:eo,label:"Queued",className:"text-warning"},sending:{icon:hs,label:"Sending…",className:"text-accent-2"},sent:{icon:lo,label:"Sent",className:"text-positive"},failed:{icon:Pt,label:"Failed",className:"text-danger"},blocked:{icon:Fa,label:"Blocked",className:"text-warning"}},zj=e=>jh(e).toDateString()===new Date().toDateString()?Qn(e,{hour:"numeric",minute:"2-digit"}):Qn(e,{month:"short",day:"numeric"}),Ql=e=>Qn(e,{dateStyle:"medium",timeStyle:"short"}),Bj=e=>{const t=e.toAddresses??[];return t.length===0?"No recipients":t.length===1?t[0]:`${t[0]} +${t.length-1}`},Of=(e,t)=>t?"The outbox cannot filter on those terms":e?"No matching outbox messages":"No outbox messages",Df=l.createContext(null);function Zo(){const e=l.useContext(Df);if(!e)throw new Error("OutboxPane.* must be used inside <OutboxPane>");return e}function Uj({children:e}){const t=Ve(),{selectedOutboxMessageId:s}=As({strict:!1}),{data:n,isLoading:a}=ve(or()),{searchQuery:o}=De(),i=xs(),c=_o(o),u=Us(c,i),m=c.length>0,d=_j(u),f=l.useMemo(()=>d?[]:(n?.items??[]).filter(p=>Mf(p.status)).filter(p=>$j(p,u.freeText)),[n,u.freeText,d]),h=l.useMemo(()=>f.find(p=>p.outboxMessageId===s),[f,s]),y=l.useCallback(p=>{t({to:"/mail/outbox",search:x=>({...x,selectedOutboxMessageId:p})})},[t]),g={messages:f,hasQuery:m,unsupportedQuery:d,isLoading:a,selectedMessageId:s,selectedMessage:h,onSelectMessage:y};return r.jsx(Df.Provider,{value:g,children:e})}function Pf({message:e,isSelected:t,onSelect:s}){const n=Ee(),{openCompose:a}=Jt(),{pushError:o}=tt(),i=l.useCallback(()=>{n.invalidateQueries({queryKey:Za()})},[n]),c=_e({...hc(),onSuccess:i,onError:f=>{o(ds("Couldn't resend message","The message wasn't sent.",f))}}),u=_e({...lr(),onSuccess:i,onError:f=>{o(ds("Couldn't delete message","The message wasn't deleted.",f))}}),m=e.status;if(!Af[m])return null;const d=Tf(e.status);return r.jsx(vx,{recipients:Bj(e),subject:e.subject||"",time:zj(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 Lf({message:e,onBack:t}){const s=e.status,n=Af[s],a=n?.icon??hn,o=e.sentAt?Ql(e.sentAt):Ql(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(La,{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:qe("size-4",n.className,s==="sending"&&"animate-spin")}),r.jsx("span",{className:qe("text-xs font-medium",n.className),children:n.label}),Tf(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(Dd,{html:e.htmlBody,text:e.textBody})})]})}function Kj(){const{messages:e,hasQuery:t,unsupportedQuery:s,isLoading:n,selectedMessageId:a,onSelectMessage:o}=Zo(),i=l.useRef(null);return nr({containerRef:i,itemSelector:Hn}),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(zs,{message:Of(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(Yo,{}),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(Pf,{message:c,isSelected:a===c.outboxMessageId,onSelect:()=>o(c.outboxMessageId)},c.outboxMessageId))})]})}function qj(){const{selectedMessage:e}=Zo();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(Lf,{message:e}):r.jsx(zs,{message:"Select a message to read",showHints:!1})})]})}function Hj(){const{messages:e,hasQuery:t,unsupportedQuery:s,isLoading:n,selectedMessageId:a,selectedMessage:o,onSelectMessage:i}=Zo(),c=l.useRef(null);return nr({containerRef:c,itemSelector:Hn}),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(Lf,{message:o,onBack:()=>i(void 0)}):e.length===0?r.jsx("div",{className:"flex h-full bg-surface",children:r.jsx(zs,{message:Of(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(Yo,{}),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(Pf,{message:u,isSelected:a===u.outboxMessageId,onSelect:()=>i(u.outboxMessageId)},u.outboxMessageId))})]})}const Fn=Object.assign(Uj,{List:Kj,Reading:qj,Phone:Hj}),Wj=({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:qe("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(Nt,{className:"size-5"})})]}),r.jsx("div",{className:"grid gap-x-8 gap-y-6 sm:grid-cols-2",children:Wc.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 Vj(e){const t=mt({queries:e.map(s=>({...it({path:{accountId:s.accountId}}),staleTime:1/0}))});return l.useMemo(()=>SS(t.map(s=>s.data?.items??[])),[t])}const Qj=e=>e.map(t=>t.data?.items??[]);function Gj(e){const t=mt({queries:e.map(s=>({...it({path:{accountId:s.accountId}}),staleTime:1/0})),combine:Qj});return l.useMemo(()=>ah(e.map((s,n)=>({folderAppointments:s.folderAppointments,mailboxes:t[n]??[]}))),[e,t])}var $n={exports:{}},Gl;function Yj(){if(Gl)return $n.exports;Gl=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 y=()=>{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(x=>s(x,p)).then(x=>{c[p]=x,f--,y()},x=>{m=!0,o(x)})};for(let g=0;g<i&&(y(),!d);g++);});return $n.exports=e,$n.exports.default=e,$n.exports}var Xj=Yj();const Jj=oh(Xj),Zj=900*1e3,eN=300,tN=(e,t)=>{if(!e)return t;const s=Number.parseInt(e,10);return Number.isFinite(s)&&s>0?s:t},sN=60*1e3,nN=e=>Math.max(tN(e,eN)*1e3,sN),qn=nN(ih().mailboxPollIntervalSeconds),rN=5,Oa=new Set,aN=(e,t,s=Zj)=>e.filter(n=>{const a=n.lastSyncAt;return a==null?!0:t-a>s}).map(n=>n.accountId),oN=(e,t,s=qn)=>e-t>=s,iN=(e,t)=>e.filter(s=>!t.has(s)),Yl=(e,t)=>{if(Oa.delete(e),cc(t,{softError:!0})){Ka(t);return}console.warn("[remit] background mailbox sync failed",{accountId:e,error:t})},Xl=(e,t)=>lc({path:{accountId:e},throwOnError:!0}).then(()=>{t.invalidateQueries({queryKey:Ft({path:{accountId:e}})})}),lN=e=>{const t=Ee(),s=l.useRef(e);s.current=e;const n=e.map(a=>a.accountId).join(",");l.useEffect(()=>{const a=Date.now(),i=aN(s.current,a).filter(c=>!Oa.has(c));if(i.length!==0)for(const c of i)Oa.add(c),Xl(c,t).catch(u=>{Yl(c,u)})},[n,t]),l.useEffect(()=>{let a=Date.now(),o;const i=new Set,c=()=>{a=Date.now();const d=iN(s.current.map(f=>f.accountId),i);for(const f of d)i.add(f);Jj(d,f=>Xl(f,t).catch(h=>{Yl(f,h)}).finally(()=>{i.delete(f)}),{concurrency:rN})},u=()=>{if(document.visibilityState==="visible"){c(),o=setTimeout(u,qn);return}},m=()=>{document.visibilityState==="visible"&&oN(Date.now(),a)&&(o!==void 0&&clearTimeout(o),c(),o=setTimeout(u,qn))};return o=setTimeout(u,qn),document.addEventListener("visibilitychange",m),()=>{o!==void 0&&clearTimeout(o),document.removeEventListener("visibilitychange",m)}},[n,t])};function cN(e,t,s){if(e!==t)return s}function uN(e,t){return e===""?"":t}function dN(e,t,s){return t!==e?!1:t!==s}function fN(){const{q:e=""}=As({from:"/mail"}),t=Ve(),s=Mr(),n=Qd(s),[a,o]=l.useState(!1),[i,c]=l.useState(!1),[u,m]=l.useState(!1),d=l.useCallback(_=>{m(_),Hl(_)},[]),[f,h]=l.useState(e),y=mr(f,200),g=uN(f,y),p=l.useRef(e);p.current=e;const x=Ot({select:_=>yy(_.matches)}),[b,S]=l.useState(x);if(b!==x){const _=cN(b,x,e);S(x),_!==void 0&&h(_)}l.useEffect(()=>{dN(f,g,p.current)&&t({to:".",search:_=>{const ue=_.q===g;return{..._,q:g||void 0,...g&&!ue?{selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0}:{}}},replace:!0})},[f,g,t]);const{data:w,isLoading:v,isError:k,error:R,refetch:A}=ve({...$t(),staleTime:1/0}),C=!!(w&&(w.accounts?.length??0)===0);l.useEffect(()=>{C&&t({to:"/onboarding",replace:!0})},[C,t]),Ro({enabled:!a,bindings:[{key:"?",handler:()=>o(!0),noModifiers:!1,preventDefault:!0}]});const M=l.useCallback(_=>{h(_)},[]),L=l.useCallback(()=>{h("")},[]),E=l.useCallback(()=>{h("")},[]),F=l.useCallback(()=>{m(_=>{const ue=!_;return Hl(ue),ue})},[]),O=w?.accounts??[],j=l.useMemo(()=>O.map(_=>_.accountId),[O]),T=Vj(O),P=Gj(O),I=l.useMemo(()=>wS(O),[O]),D=Ot({select:_=>_.matches.find(pe=>"mailboxId"in pe.params)?.params.mailboxId}),{selectedMessageId:N}=As({strict:!1}),G=Ot({select:_=>No(_.matches)}),W=Ot({select:_=>xn(_.matches)}),ne=Ot({select:_=>Cr(_.matches)});lN(O);const re=l.useCallback(()=>{c(!1)},[]),he={accounts:O,mailboxNameIndex:T,accountNameIndex:I,resultFolderIndex:P,searchQuery:g,searchInput:f,searchViewKey:x,onSearchChange:M,onSearchClear:L,onSearchClearQuery:E,intelligenceOpen:u,onToggleIntelligence:F,onSetIntelligenceOpen:d},te=r.jsx(Fj,{accounts:O,onMailboxSelect:re}),ce=n?r.jsx(ay,{accounts:O}):void 0,ie=n?void 0:r.jsx(Ny,{accounts:O}),U={navOpen:i,onOpenNav:()=>c(!0),onCloseNav:()=>c(!1)};return r.jsx(lh.Provider,{value:he,children:r.jsxs(my,{accountIds:j,children:[k?r.jsx("div",{className:"flex h-full items-center justify-center bg-canvas p-4",children:r.jsx(ts,{title:"Couldn't load your account",error:R,onRetry:()=>{A()}})}):G?r.jsx(Zs,{selectedMessageId:N,children:n?r.jsx(Bt,{nav:te,list:r.jsx(Zs.Phone,{}),intelligenceOpen:u,overlay:ce,skeleton:r.jsx(At,{}),isLoading:v||C,...U}):r.jsx(Bt,{nav:te,topBar:ie,list:r.jsx(Zs.List,{}),reading:r.jsx(Zs.Reading,{}),intelligence:r.jsx(Zs.Intelligence,{}),intelligenceOpen:u,hasThread:!!N,overlay:ce,skeleton:r.jsx(At,{}),isLoading:v||C,...U})}):W?r.jsx(en,{selectedMessageId:N,children:n?r.jsx(Bt,{nav:te,list:r.jsx(en.Phone,{}),intelligenceOpen:u,overlay:ce,skeleton:r.jsx(At,{}),isLoading:v||C,...U}):r.jsx(Bt,{nav:te,topBar:ie,list:r.jsx(en.List,{}),reading:r.jsx(en.Reading,{}),intelligence:r.jsx(en.Intelligence,{}),intelligenceOpen:u,hasThread:!!N,overlay:ce,skeleton:r.jsx(At,{}),isLoading:v||C,...U})}):D?r.jsx(sn,{mailboxId:D,selectedMessageId:N,children:n?r.jsx(Bt,{nav:te,list:r.jsx(sn.Phone,{}),intelligenceOpen:u,overlay:ce,skeleton:r.jsx(At,{}),isLoading:v||C,...U}):r.jsx(Bt,{nav:te,topBar:ie,list:r.jsx(sn.List,{}),reading:r.jsx(sn.Reading,{}),intelligence:r.jsx(sn.Intelligence,{}),intelligenceOpen:u,hasThread:!!N,overlay:ce,skeleton:r.jsx(At,{}),isLoading:v||C,...U})}):ne?r.jsx(Fn,{children:n?r.jsx(Bt,{nav:te,list:r.jsx(Fn.Phone,{}),intelligenceOpen:!1,overlay:ce,skeleton:r.jsx(At,{}),isLoading:v||C,...U}):r.jsx(Bt,{nav:te,topBar:ie,list:r.jsx(Fn.List,{}),reading:r.jsx(Fn.Reading,{}),intelligenceOpen:!1,overlay:ce,skeleton:r.jsx(At,{}),isLoading:v||C,...U})}):r.jsx(At,{}),r.jsx(Wj,{isOpen:a,onClose:()=>o(!1)}),r.jsx(ch,{})]})})}const MN=Object.freeze(Object.defineProperty({__proto__:null,component:fN,useMailContext:De},Symbol.toStringTag,{value:"Module"}));export{vp as U,MN as m,TN as s};
|