@remit/web-client-dist 0.0.44 → 0.0.46
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-ByyX2-iG.js → ComposeBody-Bc6JAYVe.js} +1 -1
- package/assets/{ErrorState-BaDfyuf_.js → ErrorState-CXmTpadx.js} +1 -1
- package/assets/{OnboardingWizard-D_dyPcK8.js → OnboardingWizard-CWJA1SOY.js} +1 -1
- package/assets/{account-form-helpers-h-cr5HUp.js → account-form-helpers-CFwieItK.js} +1 -1
- package/assets/{accounts-C5iQ5yGC.js → accounts-Byf4m66S.js} +1 -1
- package/assets/{advanced-DZEiKlOp.js → advanced-k1XUo3QY.js} +1 -1
- package/assets/{appearance-DMfof84n.js → appearance-CgWbmJNL.js} +1 -1
- package/assets/{avatar-DEojoTYb.js → avatar-Bka6ToFz.js} +1 -1
- package/assets/{browser-ponyfill-Bvxu0dic.js → browser-ponyfill-CzdkSWXS.js} +1 -1
- package/assets/{filter-status-g_ItY2BY.js → filter-status-CKpIu7_D.js} +1 -1
- package/assets/{filters-DHFo0JM2.js → filters-8zzmPox8.js} +1 -1
- package/assets/{flagged-Lbi7gDRN.js → flagged-CktArMNh.js} +1 -1
- package/assets/{folder-role-Xb44YpPb.js → folder-role-3iNrG1Or.js} +1 -1
- package/assets/{folders-D7ikz9Na.js → folders-BgxQp-QZ.js} +1 -1
- package/assets/{index-eWx4BglZ.js → index-667BTMN2.js} +1 -1
- package/assets/index-BcouPEHR.js +1 -0
- package/assets/{index-CzrTPifm.js → index-xy2Bk49C.js} +4 -4
- package/assets/{kbd-CZYCgnXf.js → kbd-CQJpBdzn.js} +1 -1
- package/assets/{mail-CTP-NI56.js → mail-B0USOkXK.js} +3 -3
- package/assets/{onboarding-Dcmuk5-F.js → onboarding-BT33O_rl.js} +1 -1
- package/assets/{select-ByKtppny.js → select-C6XBuFrO.js} +1 -1
- package/assets/{senders-BjLD175U.js → senders-DR73Xpw3.js} +1 -1
- package/assets/settings-BRnaba4m.js +1 -0
- package/assets/{settings-screen-CR6tRiuq.js → settings-screen-BD9X_mr_.js} +1 -1
- package/assets/{star-CLsQD1JN.js → star-DJ4mMik6.js} +1 -1
- package/assets/{suggested-vips-Dg4AyT-l.js → suggested-vips-D3Yoxho4.js} +1 -1
- package/assets/{trash-2-DidEGdqy.js → trash-2-CLLYEKQU.js} +1 -1
- package/assets/{useDebouncedValue-M0w63M0E.js → useDebouncedValue-Ce9nqlbE.js} +1 -1
- package/assets/{useMutation-Dxhol3zw.js → useMutation-BQP3G0ud.js} +1 -1
- package/assets/{useSignature-lyiy8Q1F.js → useSignature-DwXuEi5J.js} +1 -1
- package/index.html +1 -1
- package/package.json +1 -1
- package/assets/index-C7hS9hA9.js +0 -1
- package/assets/settings-Dt0kLYES.js +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ComposeBody-
|
|
2
|
-
import{c as ie,r as c,j as s,C as Et,X as Ke,a as K,B as G,b as Ge,d as _t,e as Ic,f as Ls,g as Ao,I as Oo,p as Po,h as Rr,i as Rc,D as Lo,O as Mc,S as Tc,k as Dc,F as Mr,l as zo,T as Tr,P as Ac,m as Oc,R as Dr,n as Ar,_ as St,o as Fo,q as Pc,Q as Or,s as Lc,t as zc,u as Fc,v as fr,w as _c,x as Bc,y as je,z as $c,A as Kc,E as qc,G as Uc,H as Qc,J as Hc,K as ha,L as Wc,M as Vc,N as Yc,U as _o,V as Bo,W as $o,Y as It,Z as Me,$ as rt,a0 as de,a1 as Pr,a2 as Lr,a3 as zr,a4 as Fr,a5 as yn,a6 as Se,a7 as zs,a8 as ue,a9 as Ko,aa as Gc,ab as qo,ac as Xc,ad as wn,ae as Uo,af as ht,ag as qe,ah as Jc,ai as st,aj as Qo,ak as zt,al as jn,am as Zc,an as at,ao as gt,ap as Bt,aq as Sn,ar as $t,as as Ho,at as eu,au as tu,av as su,aw as Wo,ax as B,ay as as,az as nu,aA as _r,aB as ru,aC as au,aD as Vo,aE as ds,aF as mr,aG as hr,aH as ou,aI as Yo,aJ as mt,aK as iu,aL as Br,aM as Go,aN as lu,aO as cu,aP as uu,aQ as du,aR as fu,aS as mu,aT as hu,aU as gu,aV as pu,aW as xu,aX as bu,aY as vu,aZ as yu,a_ as wt,a$ as dt,b0 as wu}from"./index-CzrTPifm.js";import{b as fs,l as os,R as gr,g as hn,s as ju}from"./folder-roles-XnseeyyD.js";import{S as Fs,u as Xo}from"./useDebouncedValue-M0w63M0E.js";import{A as Xe,M as $r,C as Su}from"./avatar-DEojoTYb.js";import{K as ns}from"./kbd-CZYCgnXf.js";import{S as Rt}from"./star-CLsQD1JN.js";import{T as ot}from"./trash-2-DidEGdqy.js";import{L as Kt,M as Jo,a as ku}from"./account-form-helpers-h-cr5HUp.js";import{S as _s,F as Nu,M as Cu,A as Eu,a as Zo,p as Iu}from"./folder-role-Xb44YpPb.js";import{u as pe}from"./useMutation-Dxhol3zw.js";import{R as Ru,u as Mu}from"./useSignature-lyiy8Q1F.js";import{E as Mt,f as ei}from"./ErrorState-BaDfyuf_.js";import{f as ti,a as Tt,b as gn,c as ft,d as Tu,t as Du}from"./format-QyUYNmWo.js";import{C as Bs,S as Au}from"./select-ByKtppny.js";import{b as si,h as Ou,p as Pu,u as Lu}from"./filter-status-g_ItY2BY.js";const ni=ie("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);const zu=ie("ArrowRight",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]);const kn=ie("BadgeCheck",[["path",{d:"M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z",key:"3c2336"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const Fu=ie("Ban",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m4.9 4.9 14.2 14.2",key:"1m5liu"}]]);const ri=ie("BellOff",[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M17 17H4a1 1 0 0 1-.74-1.673C4.59 13.956 6 12.499 6 8a6 6 0 0 1 .258-1.742",key:"178tsu"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M8.668 3.01A6 6 0 0 1 18 8c0 2.687.77 4.653 1.707 6.05",key:"1hqiys"}]]);const _u=ie("BookmarkPlus",[["path",{d:"m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z",key:"1fy3hk"}],["line",{x1:"12",x2:"12",y1:"7",y2:"13",key:"1cppfj"}],["line",{x1:"15",x2:"9",y1:"10",y2:"10",key:"1gty7f"}]]);const ga=ie("Bug",[["path",{d:"m8 2 1.88 1.88",key:"fmnt4t"}],["path",{d:"M14.12 3.88 16 2",key:"qol33r"}],["path",{d:"M9 7.13v-1a3.003 3.003 0 1 1 6 0v1",key:"d7y7pr"}],["path",{d:"M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6",key:"xs1cw7"}],["path",{d:"M12 20v-9",key:"1qisl0"}],["path",{d:"M6.53 9C4.6 8.8 3 7.1 3 5",key:"32zzws"}],["path",{d:"M6 13H2",key:"82j7cp"}],["path",{d:"M3 21c0-2.1 1.7-3.9 3.8-4",key:"4p0ekp"}],["path",{d:"M20.97 5c0 2.1-1.6 3.8-3.5 4",key:"18gb23"}],["path",{d:"M22 13h-4",key:"1jl80f"}],["path",{d:"M17.2 17c2.1.1 3.8 1.9 3.8 4",key:"k3fwyw"}]]);const is=ie("ChevronRight",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]);const ai=ie("CircleCheckBig",[["path",{d:"M21.801 10A10 10 0 1 1 17 3.335",key:"yps3ct"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]]);const Kr=ie("CircleCheck",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const qr=ie("Clock",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]]);const oi=ie("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]);const ii=ie("EllipsisVertical",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]]);const Bu=ie("Flag",[["path",{d:"M4 15s1-1 4-1 5 2 8 2 4-1 4-1V3s-1 1-4 1-5-2-8-2-4 1-4 1z",key:"i9b6wo"}],["line",{x1:"4",x2:"4",y1:"22",y2:"15",key:"1cm3nv"}]]);const li=ie("FolderInput",[["path",{d:"M2 9V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-1",key:"fm4g5t"}],["path",{d:"M2 13h10",key:"pgb2dq"}],["path",{d:"m9 16 3-3-3-3",key:"6m91ic"}]]);const ci=ie("Forward",[["polyline",{points:"15 17 20 12 15 7",key:"1w3sku"}],["path",{d:"M4 18v-2a4 4 0 0 1 4-4h12",key:"jmiej9"}]]);const ui=ie("LogOut",[["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}],["polyline",{points:"16 17 21 12 16 7",key:"1gabdz"}],["line",{x1:"21",x2:"9",y1:"12",y2:"12",key:"1uyos4"}]]);const $u=ie("MailCheck",[["path",{d:"M22 13V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v12c0 1.1.9 2 2 2h8",key:"12jkf8"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}],["path",{d:"m16 19 2 2 4-4",key:"1b14m6"}]]);const $s=ie("MailOpen",[["path",{d:"M21.2 8.4c.5.38.8.97.8 1.6v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V10a2 2 0 0 1 .8-1.6l8-6a2 2 0 0 1 2.4 0l8 6Z",key:"1jhwl8"}],["path",{d:"m22 10-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 10",key:"1qfld7"}]]);const Ku=ie("MailX",[["path",{d:"M22 13V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v12c0 1.1.9 2 2 2h9",key:"1j9vog"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}],["path",{d:"m17 17 4 4",key:"1b3523"}],["path",{d:"m21 17-4 4",key:"uinynz"}]]);const qu=ie("Minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);const Nn=ie("Paperclip",[["path",{d:"M13.234 20.252 21 12.3",key:"1cbrk9"}],["path",{d:"m16 6-8.414 8.586a2 2 0 0 0 0 2.828 2 2 0 0 0 2.828 0l8.414-8.586a4 4 0 0 0 0-5.656 4 4 0 0 0-5.656 0l-8.415 8.585a6 6 0 1 0 8.486 8.486",key:"1pkts6"}]]);const Uu=ie("Pencil",[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]]);const di=ie("RefreshCw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]);const fi=ie("ReplyAll",[["polyline",{points:"7 17 2 12 7 7",key:"t83bqg"}],["polyline",{points:"12 17 7 12 12 7",key:"1g4ajm"}],["path",{d:"M22 18v-2a4 4 0 0 0-4-4H7",key:"1fcyog"}]]);const mi=ie("Reply",[["polyline",{points:"9 17 4 12 9 7",key:"hvgpf2"}],["path",{d:"M20 18v-2a4 4 0 0 0-4-4H4",key:"5vmcpk"}]]);const Qu=ie("RotateCcw",[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]]);const hi=ie("Settings",[["path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z",key:"1qme2f"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);const Ks=ie("ShieldAlert",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M12 16h.01",key:"1drbdi"}]]);const qs=ie("ShieldCheck",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const Hu=ie("ShieldQuestion",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M9.1 9a3 3 0 0 1 5.82 1c0 2-3 3-3 3",key:"mhlwft"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);const Wu=ie("ShieldX",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m14.5 9.5-5 5",key:"17q4r4"}],["path",{d:"m9.5 9.5 5 5",key:"18nt4w"}]]);const nt=ie("Sparkles",[["path",{d:"M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z",key:"4pj2yx"}],["path",{d:"M20 3v4",key:"1olli1"}],["path",{d:"M22 5h-4",key:"1gvqau"}],["path",{d:"M4 17v2",key:"vumght"}],["path",{d:"M5 18H3",key:"zchphs"}]]);const Vu=ie("SquarePen",[["path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7",key:"1m0v6g"}],["path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z",key:"ohrbg2"}]]);const Yu=ie("Undo2",[["path",{d:"M9 14 4 9l5-5",key:"102s5s"}],["path",{d:"M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11",key:"f3b9sd"}]]),Gu=({address:e,showTrustedBadge:t=!1})=>{const n=t?s.jsx(kn,{className:"inline-block size-4 ml-1 -mt-0.5 text-positive","aria-label":"Trusted sender","data-testid":"trusted-sender-badge"}):null;return e.displayName?s.jsxs("span",{children:[s.jsx("span",{className:"text-fg",children:e.displayName}),s.jsxs("span",{className:"text-fg-muted",children:[" ","<",e.normalizedEmail,">"]}),n]}):s.jsxs("span",{className:"text-fg",children:[e.normalizedEmail,n]})},Xu=({label:e,addresses:t,showTrustedBadge:n=!1})=>{const[r,a]=c.useState(!1);if(t.length===0)return null;const o=t.length>3,i=l=>{const u=n&&l.flags?.trusted?.value===!0;return s.jsx(Gu,{address:l,showTrustedBadge:u})};return s.jsxs("div",{className:"flex gap-2 text-sm",children:[s.jsxs("span",{className:"text-fg-muted shrink-0 w-12",children:[e,":"]}),s.jsx("div",{className:"flex-1 min-w-0",children:r?s.jsx("div",{className:"flex flex-wrap gap-1",children:t.map((l,u)=>s.jsxs("span",{children:[i(l),u<t.length-1&&", "]},u))}):s.jsx("div",{className:"truncate",children:t.map((l,u)=>s.jsxs("span",{children:[i(l),u<t.length-1&&", "]},u))})}),o&&s.jsx("button",{type:"button",onClick:l=>{l.stopPropagation(),a(!r)},className:"shrink-0 text-fg-muted hover:text-fg transition-colors","aria-label":r?"Collapse":"Expand",children:r?s.jsx(Et,{className:"h-4 w-4"}):s.jsx(is,{className:"h-4 w-4"})})]})},Ju=({email:e,displayName:t,onRemove:n,className:r})=>s.jsxs("span",{className:K("inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-accent-2-soft text-sm max-w-[200px]",r),children:[s.jsx("span",{className:"truncate",children:t||e}),s.jsx("button",{type:"button",onClick:n,className:"shrink-0 p-0.5 rounded-full hover:bg-fg-muted/20 transition-colors","aria-label":`Remove ${e}`,children:s.jsx(Ke,{className:"size-3"})})]}),Zu={unknown:{label:"Unknown sender",tone:"neutral"},wellknown:{label:"Known sender",tone:"positive"},vip:{label:"VIP",tone:"accent"}};function Vt({label:e,children:t,className:n}){return s.jsxs("section",{className:K("border-b border-line px-row-inset py-3",n),children:[s.jsx("h3",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e}),s.jsx("div",{className:"mt-2",children:t})]})}function ed({sender:e}){const t=Zu[e.trust],n=e.inboundCount==null?null:(e.replyCount??0)>0?`${e.inboundCount} received · you replied ${e.replyCount}×`:`${e.inboundCount} received · you've never replied`;return s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx(Xe,{name:e.name,email:e.email,size:"md"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"truncate text-sm font-semibold text-fg",children:e.name}),s.jsx("div",{className:"truncate text-2xs text-fg-subtle",children:e.email})]})]}),s.jsx("div",{className:"mt-2 flex items-center gap-2",children:e.addressUnverified?s.jsx(Ge,{tone:"danger",dot:!0,children:"Address couldn't be verified"}):s.jsx(Ge,{tone:t.tone,dot:!0,children:t.label})}),s.jsxs("p",{className:"mt-2 text-xs text-fg-muted",children:["First seen ",e.firstSeenLabel,n?` · ${n}`:""]})]})}function td({auth:e,onShowSimilar:t}){if(e.verdict==="aligned")return s.jsxs("div",{className:"flex items-start gap-2 text-xs text-fg-muted",children:[s.jsx(qs,{className:"mt-0.5 size-3.5 shrink-0 text-positive"}),s.jsx("span",{children:e.summary})]});if(e.verdict==="caution")return s.jsxs("div",{className:"flex items-start gap-2 rounded-md bg-warning/10 p-3 text-warning",children:[s.jsx(Hu,{className:"mt-0.5 size-4 shrink-0"}),s.jsx("p",{className:"text-xs leading-relaxed",children:e.summary})]});const n=e.addressUnreadable?"This sender can't be verified":"This message may be impersonating someone";return s.jsxs("div",{className:"rounded-md bg-danger-soft p-3",children:[s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(Ks,{className:"mt-0.5 size-4 shrink-0 text-danger"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"text-sm font-semibold text-danger",children:n}),s.jsx("p",{className:"mt-1 text-xs leading-relaxed text-fg",children:e.summary}),!e.addressUnreadable&&e.dkimDomain&&s.jsxs("p",{className:"mt-1 text-2xs text-fg-muted",children:["Sent from"," ",s.jsx("code",{className:"rounded bg-surface px-1 py-0.5",children:e.dkimDomain}),", claims to be"," ",s.jsx("code",{className:"rounded bg-surface px-1 py-0.5",children:e.fromDomain})]})]})]}),e.similarCount!=null&&e.similarCount>0&&s.jsxs(G,{variant:"secondary",size:"sm",className:"mt-2 w-full border-danger/30 text-danger hover:bg-danger-soft",onClick:t,children:[e.similarCount," similar messages"]})]})}function Yt({icon:e,label:t,active:n,danger:r,onClick:a}){const o=a===void 0;return s.jsxs("button",{type:"button",onClick:a,disabled:o,className:K("flex items-center gap-2 rounded-md border px-2 py-1 text-xs transition-colors",n?"border-accent-2 bg-accent-2-soft text-accent-2":"border-line text-fg-muted hover:border-line-strong hover:text-fg",r&&!n&&"text-danger hover:bg-danger-soft",o&&"cursor-not-allowed opacity-50 hover:border-line"),children:[e,t]})}const sd={sender:"matched: sender",recipient:"matched: recipient",subject:"matched: subject",attachment:"matched: attachment",body:"matched: body",entities:"matched: entities"};function gi({data:e,onClose:t,onShowSimilar:n,actions:r,similarState:a="ready",similarLinkComponent:o,className:i,hideCloseButton:l=!1}){const{sender:u,authenticity:d,category:m,flags:f={},similar:h}=e,x=d.verdict==="mismatch";return s.jsxs("aside",{className:K("flex w-76 shrink-0 flex-col overflow-y-auto border-l border-line bg-surface",i),children:[s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center justify-between border-b border-line px-row-inset",children:[s.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"}),!l&&s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(Ke,{className:"size-3.5"}),onClick:t,"aria-label":"Collapse intelligence sidebar"})]}),s.jsx(Vt,{label:"Sender",children:s.jsx(ed,{sender:u})}),s.jsx(Vt,{label:"Authenticity",children:s.jsx(td,{auth:d,onShowSimilar:n})}),s.jsx(Vt,{label:"Category",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Ge,{tone:x?"danger":"neutral",children:m.value}),m.overridden&&s.jsx("span",{className:"text-2xs text-fg-subtle",children:"your override"}),s.jsx("button",{type:"button",className:K("ml-auto text-2xs text-accent hover:underline",!r?.onReclassify&&"cursor-not-allowed opacity-50 hover:no-underline"),disabled:!r?.onReclassify,onClick:r?.onReclassify,children:"reclassify"})]})}),s.jsx(Vt,{label:"Quick actions",children:s.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[s.jsx(Yt,{icon:s.jsx(Rt,{className:"size-3.5"}),label:"VIP",active:f.vip,onClick:r?.onToggleVip}),s.jsx(Yt,{icon:s.jsx(ri,{className:"size-3.5"}),label:"Mute",active:f.muted,onClick:r?.onToggleMute}),s.jsx(Yt,{icon:s.jsx(Fu,{className:"size-3.5"}),label:"Block",active:f.blocked,danger:!0,onClick:r?.onToggleBlock}),s.jsx(Yt,{icon:s.jsx(Ku,{className:"size-3.5"}),label:"Unsubscribe",active:f.unsubscribed,onClick:r?.onToggleUnsubscribe}),r?.onNotSpam&&s.jsx(Yt,{icon:s.jsx($u,{className:"size-3.5"}),label:"Not spam",onClick:r.onNotSpam}),r?.onMarkSpam&&s.jsx(Yt,{icon:s.jsx(Wu,{className:"size-3.5"}),label:"Mark spam",danger:!0,onClick:r.onMarkSpam})]})}),(a!=="ready"||h.length>0)&&s.jsx(Vt,{label:"Similar messages",children:a==="loading"?s.jsx("div",{className:"animate-pulse space-y-2",children:Array.from({length:3}).map((b,p)=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"h-3 w-3/4 rounded bg-surface-sunken"}),s.jsx("div",{className:"h-2.5 w-1/2 rounded bg-surface-sunken"})]},p))}):a==="error"?s.jsx("p",{className:"text-xs text-fg-subtle",children:"Similarity search unavailable"}):s.jsx("ul",{className:"-mx-1 space-y-1",children:h.map(b=>{const p="block w-full rounded-md px-1 py-1 text-left hover:bg-surface-sunken",v=`Open message from ${b.fromName||"unknown sender"}: ${b.subject}`,g=s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[s.jsx("span",{className:"truncate text-xs font-medium text-fg",children:b.fromName}),s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:b.timeLabel})]}),s.jsx("div",{className:"truncate text-xs text-fg-muted",children:b.subject}),s.jsx("span",{className:"mt-1 inline-block rounded-full bg-surface-sunken px-1.5 py-px text-2xs text-fg-subtle",children:sd[b.matched]})]});return s.jsx("li",{children:o?o({mailboxId:b.mailboxId,messageId:b.id,className:p,ariaLabel:v,children:g}):s.jsx("div",{className:p,children:g})},b.id)})})}),s.jsx(Vt,{label:"Coming soon",className:"border-b-0 opacity-70",children:s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed border-line p-2",children:[s.jsx(nt,{className:"mt-0.5 size-3.5 shrink-0 text-fg-subtle"}),s.jsxs("div",{children:[s.jsx("div",{className:"text-xs font-medium text-fg-muted",children:"Suggested actions"}),s.jsx("div",{className:"text-2xs text-fg-subtle",children:'"Create a filter for messages like this" — on-device model'})]})]}),s.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed border-line p-2",children:[s.jsx(nt,{className:"mt-0.5 size-3.5 shrink-0 text-fg-subtle"}),s.jsxs("div",{children:[s.jsx("div",{className:"text-xs font-medium text-fg-muted",children:"Thread summary"}),s.jsx("div",{className:"text-2xs text-fg-subtle",children:"One-paragraph digest — Bedrock"})]})]})]})})]})}const nd=[{keys:["j","k"],label:"navigate"},{keys:["m"],label:"mute"},{keys:["?"],label:"all shortcuts"}];function pi({hints:e=nd,className:t}){return s.jsx("footer",{className:K("flex items-center gap-2 border-t border-line px-row-inset py-1 text-2xs text-fg-subtle",t),children:e.map(n=>s.jsx(rd,{hint:n},n.label))})}function rd({hint:e}){return s.jsxs("span",{className:"flex items-center gap-1",children:[e.keys.map(t=>s.jsx(ns,{children:t},t)),s.jsx("span",{children:e.label})]})}function ad(){return s.jsx("div",{className:"space-y-0",role:"status","aria-busy":"true","aria-label":"Loading messages",children:Array.from({length:8}).map((e,t)=>s.jsxs("div",{className:"animate-pulse border-b border-line px-3 py-2",children:[s.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[s.jsx("div",{className:"h-4 w-32 rounded bg-surface-sunken"}),s.jsx("div",{className:"h-3 w-16 rounded bg-surface-sunken"})]}),s.jsx("div",{className:"mb-2 h-4 w-48 rounded bg-surface-sunken"}),s.jsx("div",{className:"h-3 w-full rounded bg-surface-sunken"})]},t))})}function od({searchQuery:e}){const t=!!e?.trim();return s.jsx("div",{className:"flex h-full flex-1 items-center justify-center",children:s.jsx("div",{className:"flex flex-col items-center justify-center p-8 text-center",children:s.jsx("p",{className:"text-fg-muted",children:t?"No messages match your search":"No messages in this mailbox"})})})}function id({message:e="Something went wrong loading this mailbox.",onRetry:t,onReport:n}){return s.jsx("div",{className:"flex h-full flex-1 items-center justify-center p-4",children:s.jsxs("div",{role:"alert",className:"flex max-w-sm flex-col items-center justify-center gap-3 text-center",children:[s.jsx(_t,{className:"size-8 text-danger","aria-hidden":"true"}),s.jsxs("div",{children:[s.jsx("p",{className:"font-medium text-danger",children:"Couldn't load messages"}),s.jsx("p",{className:"mt-1 break-words text-sm text-fg-muted",children:e})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[t&&s.jsx(G,{variant:"secondary",size:"sm",onClick:t,children:"Retry"}),n&&s.jsx(G,{variant:"ghost",size:"sm",onClick:n,children:"Report a problem"})]})]})})}const xi=({active:e,focused:t})=>K("relative flex h-8 w-full items-center gap-2 px-row-inset text-left",e?"bg-accent-2-soft":t?"bg-surface-sunken":"hover:bg-surface-sunken",t&&!e&&"before:absolute before:inset-y-0 before:left-0 before:w-0.5 before:bg-accent-2"),ms=({active:e,focused:t})=>K("relative flex w-full items-start gap-3 py-2 pl-5 pr-row-inset text-left transition-colors",e?"bg-accent-2-soft":t?"bg-surface-sunken":"hover:bg-surface-sunken",t&&!e&&"before:absolute before:inset-y-0 before:left-0 before:w-0.5 before:bg-accent-2");function bi({thread:e}){const t=!e.isRead;return s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"flex w-4 shrink-0 items-center justify-center",children:e.suspicious?s.jsx(Ks,{className:"size-3.5 text-danger"}):e.starred?s.jsx(Rt,{className:"size-3 fill-warning text-warning"}):t?s.jsx("span",{className:"size-1.5 rounded-full bg-accent"}):null}),s.jsx("span",{className:K("w-36 shrink-0 truncate text-xs",t?"font-semibold text-fg":"text-fg-muted"),children:e.fromName}),s.jsxs("span",{className:"min-w-0 flex-1 truncate text-xs",children:[s.jsx("span",{className:K(t?"font-medium text-fg":"text-fg-muted"),children:e.subject}),s.jsxs("span",{className:"text-fg-subtle",children:[" — ",e.snippet]})]}),e.hasAttachment&&s.jsx(Nn,{className:"size-3 shrink-0 text-fg-subtle"}),s.jsx("span",{className:"w-11 shrink-0 text-right text-2xs text-fg-subtle tabular-nums",children:e.timeLabel})]})}function Ft({thread:e,badge:t}){const n=!e.isRead;return s.jsxs("span",{className:"min-w-0 flex-1",children:[s.jsxs("span",{className:"flex items-baseline justify-between gap-2",children:[s.jsxs("span",{className:K("flex min-w-0 items-center gap-1.5 truncate text-sm",n?"font-semibold text-fg":"font-medium text-fg-muted"),children:[e.trust==="vip"&&s.jsx("span",{className:"size-1.5 shrink-0 rounded-full bg-accent-2"}),s.jsx("span",{className:"truncate",children:e.fromName}),e.messageCount!=null&&e.messageCount>1&&s.jsx("span",{className:"shrink-0 text-2xs font-normal text-fg-subtle",children:e.messageCount})]}),s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.timeLabel})]}),s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:K("truncate text-sm",n?"text-fg":"text-fg-muted"),children:e.subject}),e.suspicious&&s.jsx(Ks,{className:"size-3.5 shrink-0 text-danger"}),e.starred&&s.jsx(Rt,{className:"size-3 shrink-0 fill-warning text-warning"}),e.hasAttachment&&s.jsx(Nn,{className:"size-3 shrink-0 text-fg-subtle"})]}),s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"line-clamp-1 min-w-0 flex-1 text-xs text-fg-subtle",children:e.snippet}),e.category&&e.category!=="personal"&&s.jsx(Ge,{tone:Ic[e.category],className:"shrink-0",children:e.category}),t]})]})}function ld({thread:e}){const t=!e.isRead;return s.jsxs(s.Fragment,{children:[t&&s.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),s.jsx(Xe,{name:e.fromName,email:e.fromEmail,size:"sm"}),s.jsx(Ft,{thread:e})]})}function cd({thread:e,active:t,onClick:n}){return s.jsx("button",{type:"button",onClick:n,className:xi({active:t}),children:s.jsx(bi,{thread:e})})}function vi({thread:e,active:t,onClick:n}){return s.jsx("button",{type:"button",onClick:n,className:ms({active:t}),children:s.jsx(ld,{thread:e})})}const ud="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",pa="pointer-events-none absolute inset-0 m-auto size-3.5 text-accent-fg";function Ur({label:e,description:t,indeterminate:n=!1,checked:r,onChange:a,className:o,...i}){const l=c.useRef(null);c.useEffect(()=>{l.current&&(l.current.indeterminate=n)},[n]);const u=s.jsxs("span",{className:"relative inline-flex",children:[s.jsx("input",{ref:l,type:"checkbox",checked:r,onChange:a,className:ud,...i}),s.jsx(Bs,{className:K(pa,"hidden peer-checked:block"),"aria-hidden":!0}),s.jsx(qu,{className:K(pa,"hidden peer-indeterminate:block"),"aria-hidden":!0})]});return e===void 0&&t===void 0?s.jsx("span",{className:o,children:u}):s.jsxs("label",{className:K("flex min-h-11 cursor-pointer items-center gap-3 text-left",o),children:[u,s.jsxs("span",{className:"flex min-w-0 flex-col",children:[e!==void 0&&s.jsx("span",{className:"text-sm text-fg",children:e}),t!==void 0&&s.jsx("span",{className:"text-xs text-fg-subtle",children:t})]})]})}const dd={info:"bg-accent-2",success:"bg-positive",warning:"bg-warning",danger:"bg-danger"};function fd({value:e,max:t,tone:n="info",indeterminate:r=!1,className:a}){const o=r?100:t<=0?0:Math.min(100,Math.max(0,e/t*100));return s.jsx("div",{role:"progressbar","aria-valuenow":r?void 0:e,"aria-valuemin":r?void 0:0,"aria-valuemax":r?void 0:t,className:K("h-1.5 w-full overflow-hidden rounded-full bg-surface-sunken",a),children:s.jsx("div",{className:K("h-full rounded-full transition-[width] duration-300 ease-out",dd[n],r&&"w-1/3 animate-pulse"),style:r?void 0:{width:`${o}%`}})})}const xa=e=>e.toLocaleString();function yi({count:e,onCancel:t,onMarkRead:n,onDelete:r,moveSlot:a,isBusy:o=!1,isCounting:i=!1,selectAll:l,statusLabel:u,progress:d,notice:m}){const f=l?.checked?`All ${xa(e)} loaded selected`:`${xa(e)} ${e===1?"message":"messages"} selected`;return s.jsxs("header",{className:"flex shrink-0 flex-col border-b border-line bg-surface-sunken",children:[s.jsxs("div",{className:"flex h-pane-header items-center gap-2 px-row-inset",children:[s.jsx(G,{variant:"ghost",size:"touch",icon:s.jsx(Ke,{className:"size-4"}),onClick:t,"aria-label":"Cancel selection",className:"-ml-2 shrink-0"}),l&&s.jsx("label",{className:"-ml-1.5 flex size-11 shrink-0 cursor-pointer items-center justify-center",children:s.jsx(Ur,{"aria-label":"Select all",checked:l.checked,indeterminate:l.indeterminate,onChange:l.onChange})}),s.jsx("span",{className:"min-w-0 flex-1 truncate text-sm font-medium text-fg",role:"status","aria-live":"polite",children:u??f}),n&&!o&&s.jsx(G,{variant:"ghost",size:"touch",icon:s.jsx($s,{className:"size-4"}),onClick:n,"aria-label":"Mark as read",className:"shrink-0"}),a,!i&&s.jsx(G,{variant:"ghost",size:"touch",icon:o?s.jsx(Kt,{className:"size-4 animate-spin"}):s.jsx(ot,{className:"size-4 text-danger"}),onClick:o?void 0:r,"aria-label":"Move selected messages to Trash","aria-busy":o||void 0,className:"ml-4 shrink-0"})]}),d&&s.jsx("div",{className:"px-row-inset pb-2",children:s.jsx(fd,{value:d.value,max:d.max,tone:d.tone})}),m&&s.jsx(Ls,{tone:m.tone,variant:"soft",role:"status","aria-live":"polite",className:"mx-row-inset mb-2",children:s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[m.text&&s.jsx("span",{children:m.text}),m.action&&s.jsx(G,{variant:"ghost",size:"md",onClick:m.action.onClick,className:"-my-1 min-h-11 shrink-0",children:m.action.label})]})})]})}const ls=72,ba=10;function va(e){return e==="leading"?ls:e==="trailing"?-ls:0}function md(e){return e>=ls/2?"leading":e<=-ls/2?"trailing":"none"}function wi({thread:e,selectionMode:t,checked:n,active:r,peek:a,onPeek:o,onToggleCheck:i,onLongPress:l,onOpen:u,onAct:d,linkComponent:m}){const f=c.useRef(void 0),h=c.useRef(null),[x,b]=c.useState(null),p=()=>clearTimeout(f.current),v=E=>{h.current={startX:E.clientX,startY:E.clientY,axis:"none",moved:!1},!t&&(f.current=setTimeout(()=>{h.current=null,b(null),l()},500))},g=E=>{if(t)return;const M=h.current;if(!M)return;const R=E.clientX-M.startX,A=E.clientY-M.startY;if(M.axis==="none"){if(Math.abs(A)>ba&&Math.abs(A)>Math.abs(R)){M.axis="vertical",p(),h.current=null;return}Math.abs(R)>ba&&(M.axis="horizontal",M.moved=!0,p(),E.currentTarget.setPointerCapture(E.pointerId))}if(M.axis!=="horizontal")return;const D=va(a),F=Math.max(-ls,Math.min(ls,D+R));b(F)},y=()=>{p();const E=h.current;h.current=null;const M=x;if(b(null),!!E){if(E.axis==="horizontal"&&M!==null){o(md(M));return}if(t){i();return}if(a!=="none"){o("none");return}m||u()}},j=E=>{a!=="none"&&E.preventDefault()},w=x??va(a),C=w>0?"leading":w<0?"trailing":"none",k=K("relative touch-pan-y bg-surface",ms({active:n||r})),S={transform:w!==0?`translateX(${w}px)`:void 0,transition:x===null?"transform 150ms ease":"none",minHeight:44},N=!e.isRead,I=E=>E.stopPropagation(),T=t?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:K("inline-flex size-7 shrink-0 items-center justify-center rounded-full border",n?"border-accent bg-accent text-accent-fg":"border-line-strong bg-canvas"),children:n&&s.jsx(Bs,{className:"size-3.5"})}),s.jsx(Ft,{thread:e})]}):s.jsxs(s.Fragment,{children:[N&&s.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),s.jsx("button",{type:"button",role:"checkbox","aria-checked":n,"aria-label":`Select message from ${e.fromName}`,onPointerDown:I,onPointerMove:I,onPointerUp:I,onClick:E=>{E.preventDefault(),E.stopPropagation(),l()},className:"inline-flex size-7 shrink-0 items-center justify-center rounded-full",children:s.jsx(Xe,{name:e.fromName,email:e.fromEmail,size:"sm"})}),s.jsx(Ft,{thread:e})]});return s.jsxs("div",{className:"relative overflow-hidden",children:[C==="leading"&&s.jsx("button",{type:"button",onClick:()=>d("leading"),"aria-label":e.isRead?"Mark as unread":"Mark as read",className:"absolute inset-y-0 left-0 flex items-center justify-start bg-accent-2 px-6 text-accent-fg",children:e.isRead?s.jsx(Jo,{className:"size-6"}):s.jsx($s,{className:"size-6"})}),C==="trailing"&&s.jsx("button",{type:"button",onClick:()=>d("trailing"),"aria-label":"Delete message",className:"absolute inset-y-0 right-0 flex items-center justify-end bg-danger px-6 text-canvas",children:s.jsx(ot,{className:"size-6"})}),m&&!t?m({className:k,style:S,onPointerDown:v,onPointerMove:g,onPointerUp:y,onPointerCancel:y,onOpenClick:j,children:T}):s.jsx("button",{type:"button",role:t?"checkbox":void 0,"aria-checked":t?n:void 0,onPointerDown:v,onPointerMove:g,onPointerUp:y,onPointerCancel:y,className:k,style:S,children:T})]})}function hd({sections:e,selectedThreadId:t,selectionMode:n,checkedIds:r,initialPeek:a,onToggleCheck:o,onEnterSelection:i,onOpenThread:l,onRefresh:u,refreshing:d,busy:m=!1}){const[f,h]=c.useState(()=>e.flatMap(v=>v.threads)),[x,b]=c.useState(a&&a!=="none"&&f[1]?{id:f[1].id,side:a}:null),p=(v,g)=>{h(g==="trailing"?y=>y.filter(j=>j.id!==v):y=>y.map(j=>j.id===v?{...j,isRead:!j.isRead}:j)),b(null)};return s.jsxs("div",{className:"flex-1 overflow-y-auto",children:[d&&s.jsxs("div",{className:"flex items-center justify-center gap-2 border-b border-line py-3 text-fg-muted",children:[s.jsx(di,{className:"size-4 animate-spin"}),s.jsx("span",{className:"text-xs",children:"Checking for new mail…"})]}),s.jsx("div",{className:"divide-y divide-line",children:f.map(v=>s.jsx("div",{className:m?"pointer-events-none opacity-50":void 0,children:s.jsx(wi,{thread:v,selectionMode:n,checked:r.has(v.id),active:v.id===t,peek:x?.id===v.id?x.side:"none",onPeek:g=>b(g==="none"?null:{id:v.id,side:g}),onToggleCheck:()=>o(v.id),onLongPress:()=>i(v.id),onOpen:()=>l(v.id),onAct:g=>p(v.id,g)})},v.id))}),!n&&!d&&!m&&s.jsx("button",{type:"button",onClick:u,className:"w-full border-t border-line py-2 text-center text-2xs text-fg-subtle transition-colors hover:bg-surface-sunken",children:"Pull to refresh"})]})}function ji({listTitle:e,listMeta:t,sections:n,briefFilters:r,flatList:a,listState:o="ready",searchQuery:i,errorMessage:l,onRetry:u,onReportError:d,briefCategory:m,selectedThreadId:f,density:h="comfortable",onSelectThread:x,onSelectBriefCategory:b,onOpenNav:p,isDesktop:v,initialTouchState:g,selectionBar:y,listBody:j,hideHeader:w=!1}){const C=h==="compact"?cd:vi,k=!v&&!r&&o==="ready",S=n.flatMap(Q=>Q.threads),[N,I]=c.useState(g==="selection"),[T,E]=c.useState(()=>g==="selection"?new Set(S.slice(0,2).map(Q=>Q.id)):new Set),[M,R]=c.useState(!1),A=g==="peek-trailing"?"trailing":g==="peek-leading"?"leading":void 0,D=Q=>{E(X=>{const ee=new Set(X);return ee.has(Q)?ee.delete(Q):ee.add(Q),ee.size===0&&I(!1),ee})},F=Q=>{I(!0),E(new Set([Q]))},$=()=>{I(!1),E(new Set)},te=()=>{R(!0),setTimeout(()=>R(!1),1400)},q=!y&&k&&N&&T.size>0;return s.jsxs("section",{className:"flex h-full w-full flex-col bg-surface",children:[y??(q?s.jsx(yi,{count:T.size,onCancel:$,onMarkRead:$,onDelete:$}):w?null:s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[p&&s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx($r,{className:"size-4"}),onClick:p,"aria-label":"Open folders",className:"-ml-1 shrink-0"}),s.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e}),t&&s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle",children:t})]})),o==="loading"?s.jsx("div",{className:"flex-1 overflow-y-auto",children:s.jsx(ad,{})}):o==="empty"?s.jsx(od,{searchQuery:i}):o==="error"?s.jsx(id,{message:l,onRetry:u,onReport:d}):r?s.jsx(Ao,{sections:n,briefCategory:m,selectedThreadId:f,Row:C,onSelectThread:x,onSelectBriefCategory:b}):j??(k?s.jsx(hd,{sections:n,selectedThreadId:f,selectionMode:N,checkedIds:T,initialPeek:A,onToggleCheck:D,onEnterSelection:F,onOpenThread:Q=>x?.(Q),onRefresh:te,refreshing:M}):s.jsx("div",{className:"flex-1 overflow-y-auto",children:n.map(Q=>s.jsxs("div",{children:[!a&&Q.label&&s.jsxs("div",{className:"sticky top-0 flex h-section-row items-center justify-between border-b border-line bg-surface-sunken px-row-inset",children:[s.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:Q.label}),s.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:Q.threads.length})]}),s.jsx("div",{className:"divide-y divide-line",children:Q.threads.map(X=>s.jsx(C,{thread:X,active:X.id===f,onClick:()=>x?.(X.id)},X.id))})]},Q.id))})),v&&s.jsx(pi,{})]})}function gd({triggerLabel:e,triggerIcon:t,items:n,align:r="end",touch:a=!0,className:o}){const[i,l]=c.useState(!1),u=c.useRef(null);return c.useEffect(()=>{if(!i)return;const d=f=>{u.current&&!u.current.contains(f.target)&&l(!1)},m=f=>{f.key==="Escape"&&l(!1)};return document.addEventListener("mousedown",d),document.addEventListener("keydown",m),()=>{document.removeEventListener("mousedown",d),document.removeEventListener("keydown",m)}},[i]),n.length===0?null:s.jsxs("div",{ref:u,className:K("relative",o),children:[s.jsx(G,{variant:"ghost",size:"sm",icon:t??s.jsx(ii,{className:"size-5"}),onClick:()=>l(d=>!d),"aria-label":e,"aria-haspopup":"menu","aria-expanded":i,className:K(a&&"min-h-11 min-w-11 px-0")}),i&&s.jsx("div",{role:"menu",className:K("absolute top-full z-50 mt-1 flex min-w-44 flex-col rounded-md border border-line bg-surface py-1 shadow-lg",r==="end"?"right-0":"left-0"),children:n.map(d=>s.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{l(!1),d.onSelect()},className:"flex min-h-11 items-center gap-3 px-4 py-2.5 text-left text-sm text-fg transition-colors hover:bg-surface-sunken",children:[d.icon&&s.jsx("span",{className:"shrink-0 text-fg-subtle",children:d.icon}),d.label]},d.key))})]})}const Ss="min-h-11 min-w-11 px-0";function Si({hasThread:e,onReply:t,onReplyAll:n,onForward:r,isStarred:a,onToggleStar:o,onDelete:i,isRead:l,onToggleRead:u,moveSlot:d,overflowItems:m=[],onUnavailable:f,unavailableHint:h,className:x}){const b=(v,g)=>()=>{if(!e){f?.(v);return}g?.()},p=u?[{key:"toggle-read",label:l?"Mark as unread":"Mark as read",icon:l?s.jsx(Jo,{className:"size-4"}):s.jsx($s,{className:"size-4"}),onSelect:b("toggleRead",u)}]:[];return s.jsxs("div",{className:K("relative",x),children:[s.jsxs("div",{className:"flex h-12 shrink-0 items-center gap-0.5 border-y border-line bg-canvas px-1",children:[s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(mi,{className:"size-5"}),onClick:b("reply",t),"aria-label":"Reply",title:"Reply",className:Ss}),s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(fi,{className:"size-5"}),onClick:b("replyAll",n),"aria-label":"Reply all",title:"Reply all",className:Ss}),s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(ci,{className:"size-5"}),onClick:b("forward",r),"aria-label":"Forward",title:"Forward",className:Ss}),s.jsx("div",{className:"flex-1"}),s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(Rt,{className:K("size-5",a&&"fill-warning text-warning")}),onClick:b("star",o),"aria-label":a?"Unstar":"Star","aria-pressed":a,title:a?"Unstar":"Star",className:Ss}),d,s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(ot,{className:"size-5"}),onClick:b("delete",i),"aria-label":"Move to Trash",title:"Move to Trash",className:Ss}),s.jsx(gd,{triggerLabel:"More actions",items:[...p,...m]})]}),!e&&h&&s.jsx("p",{role:"status",className:"border-b border-line bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:h})]})}function pd({open:e=!1,enabled:t=!0,onToggle:n,className:r}){return s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(Oo,{className:"size-4"}),title:"Intelligence","aria-label":e?"Hide intelligence sidebar":"Show intelligence sidebar","aria-pressed":e,disabled:!t,onClick:n,className:K(e&&"bg-accent-2-soft text-accent-2",r)})}function xd({hasThread:e,onUnavailable:t,unavailableHint:n,isStarred:r,showTriage:a=!0,onReply:o,onReplyAll:i,onForward:l,onDelete:u,onToggleStar:d,moveSlot:m,onMove:f,replyTitle:h="Reply (r)",replyAllTitle:x="Reply all (a)",forwardTitle:b="Forward (f)",deleteTitle:p="Move to Trash (#)",flagTitle:v="Star (s)",children:g,className:y}){const j=(w,C)=>()=>{if(!e){t?.(w);return}C?.()};return s.jsxs("div",{className:"relative",children:[s.jsxs("header",{className:K("flex h-pane-header shrink-0 items-center gap-1 border-b border-line bg-surface px-3",y),children:[s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(mi,{className:"size-4"}),title:h,"aria-label":"Reply",onClick:j("reply",o)}),s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(fi,{className:"size-4"}),title:x,"aria-label":"Reply all",onClick:j("replyAll",i)}),s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(ci,{className:"size-4"}),title:b,"aria-label":"Forward",onClick:j("forward",l)}),a&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"mx-1 h-4 w-px bg-line","aria-hidden":!0}),s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(ot,{className:"size-4"}),title:p,"aria-label":"Move to Trash",onClick:j("delete",u)}),m??s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(li,{className:"size-4"}),title:"Move to mailbox","aria-label":"Move to mailbox",onClick:j("move",f)}),s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(Rt,{className:K("size-4",r&&"fill-warning text-warning")}),title:v,"aria-label":"Star",onClick:j("flag",d)})]}),s.jsx("div",{className:"flex-1"}),g]}),!e&&n&&s.jsx("p",{role:"status",className:"border-b border-line bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:n})]})}const bd=(e,t)=>{const r=e==="newsletter"||e==="marketing"||t;return{framed:r,isPlain:!r}},vd=()=>`
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ComposeBody-Bc6JAYVe.js","assets/index-xy2Bk49C.js","assets/index-aToiseR7.css","assets/folder-roles-XnseeyyD.js","assets/useDebouncedValue-Ce9nqlbE.js","assets/avatar-Bka6ToFz.js","assets/kbd-CQJpBdzn.js","assets/star-DJ4mMik6.js","assets/trash-2-CLLYEKQU.js","assets/account-form-helpers-CFwieItK.js","assets/folder-role-3iNrG1Or.js","assets/useMutation-BQP3G0ud.js","assets/useSignature-DwXuEi5J.js","assets/ErrorState-CXmTpadx.js","assets/format-QyUYNmWo.js","assets/select-C6XBuFrO.js","assets/filter-status-CKpIu7_D.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{c as ie,r as c,j as s,C as Et,X as Ke,a as K,B as G,b as Ge,d as _t,e as Ic,f as Ls,g as Ao,I as Oo,p as Po,h as Rr,i as Rc,D as Lo,O as Mc,S as Tc,k as Dc,F as Mr,l as zo,T as Tr,P as Ac,m as Oc,R as Dr,n as Ar,_ as St,o as Fo,q as Pc,Q as Or,s as Lc,t as zc,u as Fc,v as fr,w as _c,x as Bc,y as je,z as $c,A as Kc,E as qc,G as Uc,H as Qc,J as Hc,K as ha,L as Wc,M as Vc,N as Yc,U as _o,V as Bo,W as $o,Y as It,Z as Me,$ as rt,a0 as de,a1 as Pr,a2 as Lr,a3 as zr,a4 as Fr,a5 as yn,a6 as Se,a7 as zs,a8 as ue,a9 as Ko,aa as Gc,ab as qo,ac as Xc,ad as wn,ae as Uo,af as ht,ag as qe,ah as Jc,ai as st,aj as Qo,ak as zt,al as jn,am as Zc,an as at,ao as gt,ap as Bt,aq as Sn,ar as $t,as as Ho,at as eu,au as tu,av as su,aw as Wo,ax as B,ay as as,az as nu,aA as _r,aB as ru,aC as au,aD as Vo,aE as ds,aF as mr,aG as hr,aH as ou,aI as Yo,aJ as mt,aK as iu,aL as Br,aM as Go,aN as lu,aO as cu,aP as uu,aQ as du,aR as fu,aS as mu,aT as hu,aU as gu,aV as pu,aW as xu,aX as bu,aY as vu,aZ as yu,a_ as wt,a$ as dt,b0 as wu}from"./index-xy2Bk49C.js";import{b as fs,l as os,R as gr,g as hn,s as ju}from"./folder-roles-XnseeyyD.js";import{S as Fs,u as Xo}from"./useDebouncedValue-Ce9nqlbE.js";import{A as Xe,M as $r,C as Su}from"./avatar-Bka6ToFz.js";import{K as ns}from"./kbd-CQJpBdzn.js";import{S as Rt}from"./star-DJ4mMik6.js";import{T as ot}from"./trash-2-CLLYEKQU.js";import{L as Kt,M as Jo,a as ku}from"./account-form-helpers-CFwieItK.js";import{S as _s,F as Nu,M as Cu,A as Eu,a as Zo,p as Iu}from"./folder-role-3iNrG1Or.js";import{u as pe}from"./useMutation-BQP3G0ud.js";import{R as Ru,u as Mu}from"./useSignature-DwXuEi5J.js";import{E as Mt,f as ei}from"./ErrorState-CXmTpadx.js";import{f as ti,a as Tt,b as gn,c as ft,d as Tu,t as Du}from"./format-QyUYNmWo.js";import{C as Bs,S as Au}from"./select-C6XBuFrO.js";import{b as si,h as Ou,p as Pu,u as Lu}from"./filter-status-CKpIu7_D.js";const ni=ie("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);const zu=ie("ArrowRight",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]);const kn=ie("BadgeCheck",[["path",{d:"M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z",key:"3c2336"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const Fu=ie("Ban",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m4.9 4.9 14.2 14.2",key:"1m5liu"}]]);const ri=ie("BellOff",[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M17 17H4a1 1 0 0 1-.74-1.673C4.59 13.956 6 12.499 6 8a6 6 0 0 1 .258-1.742",key:"178tsu"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M8.668 3.01A6 6 0 0 1 18 8c0 2.687.77 4.653 1.707 6.05",key:"1hqiys"}]]);const _u=ie("BookmarkPlus",[["path",{d:"m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z",key:"1fy3hk"}],["line",{x1:"12",x2:"12",y1:"7",y2:"13",key:"1cppfj"}],["line",{x1:"15",x2:"9",y1:"10",y2:"10",key:"1gty7f"}]]);const ga=ie("Bug",[["path",{d:"m8 2 1.88 1.88",key:"fmnt4t"}],["path",{d:"M14.12 3.88 16 2",key:"qol33r"}],["path",{d:"M9 7.13v-1a3.003 3.003 0 1 1 6 0v1",key:"d7y7pr"}],["path",{d:"M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6",key:"xs1cw7"}],["path",{d:"M12 20v-9",key:"1qisl0"}],["path",{d:"M6.53 9C4.6 8.8 3 7.1 3 5",key:"32zzws"}],["path",{d:"M6 13H2",key:"82j7cp"}],["path",{d:"M3 21c0-2.1 1.7-3.9 3.8-4",key:"4p0ekp"}],["path",{d:"M20.97 5c0 2.1-1.6 3.8-3.5 4",key:"18gb23"}],["path",{d:"M22 13h-4",key:"1jl80f"}],["path",{d:"M17.2 17c2.1.1 3.8 1.9 3.8 4",key:"k3fwyw"}]]);const is=ie("ChevronRight",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]);const ai=ie("CircleCheckBig",[["path",{d:"M21.801 10A10 10 0 1 1 17 3.335",key:"yps3ct"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]]);const Kr=ie("CircleCheck",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const qr=ie("Clock",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]]);const oi=ie("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]);const ii=ie("EllipsisVertical",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]]);const Bu=ie("Flag",[["path",{d:"M4 15s1-1 4-1 5 2 8 2 4-1 4-1V3s-1 1-4 1-5-2-8-2-4 1-4 1z",key:"i9b6wo"}],["line",{x1:"4",x2:"4",y1:"22",y2:"15",key:"1cm3nv"}]]);const li=ie("FolderInput",[["path",{d:"M2 9V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-1",key:"fm4g5t"}],["path",{d:"M2 13h10",key:"pgb2dq"}],["path",{d:"m9 16 3-3-3-3",key:"6m91ic"}]]);const ci=ie("Forward",[["polyline",{points:"15 17 20 12 15 7",key:"1w3sku"}],["path",{d:"M4 18v-2a4 4 0 0 1 4-4h12",key:"jmiej9"}]]);const ui=ie("LogOut",[["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}],["polyline",{points:"16 17 21 12 16 7",key:"1gabdz"}],["line",{x1:"21",x2:"9",y1:"12",y2:"12",key:"1uyos4"}]]);const $u=ie("MailCheck",[["path",{d:"M22 13V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v12c0 1.1.9 2 2 2h8",key:"12jkf8"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}],["path",{d:"m16 19 2 2 4-4",key:"1b14m6"}]]);const $s=ie("MailOpen",[["path",{d:"M21.2 8.4c.5.38.8.97.8 1.6v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V10a2 2 0 0 1 .8-1.6l8-6a2 2 0 0 1 2.4 0l8 6Z",key:"1jhwl8"}],["path",{d:"m22 10-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 10",key:"1qfld7"}]]);const Ku=ie("MailX",[["path",{d:"M22 13V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v12c0 1.1.9 2 2 2h9",key:"1j9vog"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}],["path",{d:"m17 17 4 4",key:"1b3523"}],["path",{d:"m21 17-4 4",key:"uinynz"}]]);const qu=ie("Minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);const Nn=ie("Paperclip",[["path",{d:"M13.234 20.252 21 12.3",key:"1cbrk9"}],["path",{d:"m16 6-8.414 8.586a2 2 0 0 0 0 2.828 2 2 0 0 0 2.828 0l8.414-8.586a4 4 0 0 0 0-5.656 4 4 0 0 0-5.656 0l-8.415 8.585a6 6 0 1 0 8.486 8.486",key:"1pkts6"}]]);const Uu=ie("Pencil",[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]]);const di=ie("RefreshCw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]);const fi=ie("ReplyAll",[["polyline",{points:"7 17 2 12 7 7",key:"t83bqg"}],["polyline",{points:"12 17 7 12 12 7",key:"1g4ajm"}],["path",{d:"M22 18v-2a4 4 0 0 0-4-4H7",key:"1fcyog"}]]);const mi=ie("Reply",[["polyline",{points:"9 17 4 12 9 7",key:"hvgpf2"}],["path",{d:"M20 18v-2a4 4 0 0 0-4-4H4",key:"5vmcpk"}]]);const Qu=ie("RotateCcw",[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]]);const hi=ie("Settings",[["path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z",key:"1qme2f"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);const Ks=ie("ShieldAlert",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M12 16h.01",key:"1drbdi"}]]);const qs=ie("ShieldCheck",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const Hu=ie("ShieldQuestion",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M9.1 9a3 3 0 0 1 5.82 1c0 2-3 3-3 3",key:"mhlwft"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);const Wu=ie("ShieldX",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m14.5 9.5-5 5",key:"17q4r4"}],["path",{d:"m9.5 9.5 5 5",key:"18nt4w"}]]);const nt=ie("Sparkles",[["path",{d:"M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z",key:"4pj2yx"}],["path",{d:"M20 3v4",key:"1olli1"}],["path",{d:"M22 5h-4",key:"1gvqau"}],["path",{d:"M4 17v2",key:"vumght"}],["path",{d:"M5 18H3",key:"zchphs"}]]);const Vu=ie("SquarePen",[["path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7",key:"1m0v6g"}],["path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z",key:"ohrbg2"}]]);const Yu=ie("Undo2",[["path",{d:"M9 14 4 9l5-5",key:"102s5s"}],["path",{d:"M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11",key:"f3b9sd"}]]),Gu=({address:e,showTrustedBadge:t=!1})=>{const n=t?s.jsx(kn,{className:"inline-block size-4 ml-1 -mt-0.5 text-positive","aria-label":"Trusted sender","data-testid":"trusted-sender-badge"}):null;return e.displayName?s.jsxs("span",{children:[s.jsx("span",{className:"text-fg",children:e.displayName}),s.jsxs("span",{className:"text-fg-muted",children:[" ","<",e.normalizedEmail,">"]}),n]}):s.jsxs("span",{className:"text-fg",children:[e.normalizedEmail,n]})},Xu=({label:e,addresses:t,showTrustedBadge:n=!1})=>{const[r,a]=c.useState(!1);if(t.length===0)return null;const o=t.length>3,i=l=>{const u=n&&l.flags?.trusted?.value===!0;return s.jsx(Gu,{address:l,showTrustedBadge:u})};return s.jsxs("div",{className:"flex gap-2 text-sm",children:[s.jsxs("span",{className:"text-fg-muted shrink-0 w-12",children:[e,":"]}),s.jsx("div",{className:"flex-1 min-w-0",children:r?s.jsx("div",{className:"flex flex-wrap gap-1",children:t.map((l,u)=>s.jsxs("span",{children:[i(l),u<t.length-1&&", "]},u))}):s.jsx("div",{className:"truncate",children:t.map((l,u)=>s.jsxs("span",{children:[i(l),u<t.length-1&&", "]},u))})}),o&&s.jsx("button",{type:"button",onClick:l=>{l.stopPropagation(),a(!r)},className:"shrink-0 text-fg-muted hover:text-fg transition-colors","aria-label":r?"Collapse":"Expand",children:r?s.jsx(Et,{className:"h-4 w-4"}):s.jsx(is,{className:"h-4 w-4"})})]})},Ju=({email:e,displayName:t,onRemove:n,className:r})=>s.jsxs("span",{className:K("inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-accent-2-soft text-sm max-w-[200px]",r),children:[s.jsx("span",{className:"truncate",children:t||e}),s.jsx("button",{type:"button",onClick:n,className:"shrink-0 p-0.5 rounded-full hover:bg-fg-muted/20 transition-colors","aria-label":`Remove ${e}`,children:s.jsx(Ke,{className:"size-3"})})]}),Zu={unknown:{label:"Unknown sender",tone:"neutral"},wellknown:{label:"Known sender",tone:"positive"},vip:{label:"VIP",tone:"accent"}};function Vt({label:e,children:t,className:n}){return s.jsxs("section",{className:K("border-b border-line px-row-inset py-3",n),children:[s.jsx("h3",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e}),s.jsx("div",{className:"mt-2",children:t})]})}function ed({sender:e}){const t=Zu[e.trust],n=e.inboundCount==null?null:(e.replyCount??0)>0?`${e.inboundCount} received · you replied ${e.replyCount}×`:`${e.inboundCount} received · you've never replied`;return s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx(Xe,{name:e.name,email:e.email,size:"md"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"truncate text-sm font-semibold text-fg",children:e.name}),s.jsx("div",{className:"truncate text-2xs text-fg-subtle",children:e.email})]})]}),s.jsx("div",{className:"mt-2 flex items-center gap-2",children:e.addressUnverified?s.jsx(Ge,{tone:"danger",dot:!0,children:"Address couldn't be verified"}):s.jsx(Ge,{tone:t.tone,dot:!0,children:t.label})}),s.jsxs("p",{className:"mt-2 text-xs text-fg-muted",children:["First seen ",e.firstSeenLabel,n?` · ${n}`:""]})]})}function td({auth:e,onShowSimilar:t}){if(e.verdict==="aligned")return s.jsxs("div",{className:"flex items-start gap-2 text-xs text-fg-muted",children:[s.jsx(qs,{className:"mt-0.5 size-3.5 shrink-0 text-positive"}),s.jsx("span",{children:e.summary})]});if(e.verdict==="caution")return s.jsxs("div",{className:"flex items-start gap-2 rounded-md bg-warning/10 p-3 text-warning",children:[s.jsx(Hu,{className:"mt-0.5 size-4 shrink-0"}),s.jsx("p",{className:"text-xs leading-relaxed",children:e.summary})]});const n=e.addressUnreadable?"This sender can't be verified":"This message may be impersonating someone";return s.jsxs("div",{className:"rounded-md bg-danger-soft p-3",children:[s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(Ks,{className:"mt-0.5 size-4 shrink-0 text-danger"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"text-sm font-semibold text-danger",children:n}),s.jsx("p",{className:"mt-1 text-xs leading-relaxed text-fg",children:e.summary}),!e.addressUnreadable&&e.dkimDomain&&s.jsxs("p",{className:"mt-1 text-2xs text-fg-muted",children:["Sent from"," ",s.jsx("code",{className:"rounded bg-surface px-1 py-0.5",children:e.dkimDomain}),", claims to be"," ",s.jsx("code",{className:"rounded bg-surface px-1 py-0.5",children:e.fromDomain})]})]})]}),e.similarCount!=null&&e.similarCount>0&&s.jsxs(G,{variant:"secondary",size:"sm",className:"mt-2 w-full border-danger/30 text-danger hover:bg-danger-soft",onClick:t,children:[e.similarCount," similar messages"]})]})}function Yt({icon:e,label:t,active:n,danger:r,onClick:a}){const o=a===void 0;return s.jsxs("button",{type:"button",onClick:a,disabled:o,className:K("flex items-center gap-2 rounded-md border px-2 py-1 text-xs transition-colors",n?"border-accent-2 bg-accent-2-soft text-accent-2":"border-line text-fg-muted hover:border-line-strong hover:text-fg",r&&!n&&"text-danger hover:bg-danger-soft",o&&"cursor-not-allowed opacity-50 hover:border-line"),children:[e,t]})}const sd={sender:"matched: sender",recipient:"matched: recipient",subject:"matched: subject",attachment:"matched: attachment",body:"matched: body",entities:"matched: entities"};function gi({data:e,onClose:t,onShowSimilar:n,actions:r,similarState:a="ready",similarLinkComponent:o,className:i,hideCloseButton:l=!1}){const{sender:u,authenticity:d,category:m,flags:f={},similar:h}=e,x=d.verdict==="mismatch";return s.jsxs("aside",{className:K("flex w-76 shrink-0 flex-col overflow-y-auto border-l border-line bg-surface",i),children:[s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center justify-between border-b border-line px-row-inset",children:[s.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"}),!l&&s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(Ke,{className:"size-3.5"}),onClick:t,"aria-label":"Collapse intelligence sidebar"})]}),s.jsx(Vt,{label:"Sender",children:s.jsx(ed,{sender:u})}),s.jsx(Vt,{label:"Authenticity",children:s.jsx(td,{auth:d,onShowSimilar:n})}),s.jsx(Vt,{label:"Category",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Ge,{tone:x?"danger":"neutral",children:m.value}),m.overridden&&s.jsx("span",{className:"text-2xs text-fg-subtle",children:"your override"}),s.jsx("button",{type:"button",className:K("ml-auto text-2xs text-accent hover:underline",!r?.onReclassify&&"cursor-not-allowed opacity-50 hover:no-underline"),disabled:!r?.onReclassify,onClick:r?.onReclassify,children:"reclassify"})]})}),s.jsx(Vt,{label:"Quick actions",children:s.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[s.jsx(Yt,{icon:s.jsx(Rt,{className:"size-3.5"}),label:"VIP",active:f.vip,onClick:r?.onToggleVip}),s.jsx(Yt,{icon:s.jsx(ri,{className:"size-3.5"}),label:"Mute",active:f.muted,onClick:r?.onToggleMute}),s.jsx(Yt,{icon:s.jsx(Fu,{className:"size-3.5"}),label:"Block",active:f.blocked,danger:!0,onClick:r?.onToggleBlock}),s.jsx(Yt,{icon:s.jsx(Ku,{className:"size-3.5"}),label:"Unsubscribe",active:f.unsubscribed,onClick:r?.onToggleUnsubscribe}),r?.onNotSpam&&s.jsx(Yt,{icon:s.jsx($u,{className:"size-3.5"}),label:"Not spam",onClick:r.onNotSpam}),r?.onMarkSpam&&s.jsx(Yt,{icon:s.jsx(Wu,{className:"size-3.5"}),label:"Mark spam",danger:!0,onClick:r.onMarkSpam})]})}),(a!=="ready"||h.length>0)&&s.jsx(Vt,{label:"Similar messages",children:a==="loading"?s.jsx("div",{className:"animate-pulse space-y-2",children:Array.from({length:3}).map((b,p)=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"h-3 w-3/4 rounded bg-surface-sunken"}),s.jsx("div",{className:"h-2.5 w-1/2 rounded bg-surface-sunken"})]},p))}):a==="error"?s.jsx("p",{className:"text-xs text-fg-subtle",children:"Similarity search unavailable"}):s.jsx("ul",{className:"-mx-1 space-y-1",children:h.map(b=>{const p="block w-full rounded-md px-1 py-1 text-left hover:bg-surface-sunken",v=`Open message from ${b.fromName||"unknown sender"}: ${b.subject}`,g=s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[s.jsx("span",{className:"truncate text-xs font-medium text-fg",children:b.fromName}),s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:b.timeLabel})]}),s.jsx("div",{className:"truncate text-xs text-fg-muted",children:b.subject}),s.jsx("span",{className:"mt-1 inline-block rounded-full bg-surface-sunken px-1.5 py-px text-2xs text-fg-subtle",children:sd[b.matched]})]});return s.jsx("li",{children:o?o({mailboxId:b.mailboxId,messageId:b.id,className:p,ariaLabel:v,children:g}):s.jsx("div",{className:p,children:g})},b.id)})})}),s.jsx(Vt,{label:"Coming soon",className:"border-b-0 opacity-70",children:s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed border-line p-2",children:[s.jsx(nt,{className:"mt-0.5 size-3.5 shrink-0 text-fg-subtle"}),s.jsxs("div",{children:[s.jsx("div",{className:"text-xs font-medium text-fg-muted",children:"Suggested actions"}),s.jsx("div",{className:"text-2xs text-fg-subtle",children:'"Create a filter for messages like this" — on-device model'})]})]}),s.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed border-line p-2",children:[s.jsx(nt,{className:"mt-0.5 size-3.5 shrink-0 text-fg-subtle"}),s.jsxs("div",{children:[s.jsx("div",{className:"text-xs font-medium text-fg-muted",children:"Thread summary"}),s.jsx("div",{className:"text-2xs text-fg-subtle",children:"One-paragraph digest — Bedrock"})]})]})]})})]})}const nd=[{keys:["j","k"],label:"navigate"},{keys:["m"],label:"mute"},{keys:["?"],label:"all shortcuts"}];function pi({hints:e=nd,className:t}){return s.jsx("footer",{className:K("flex items-center gap-2 border-t border-line px-row-inset py-1 text-2xs text-fg-subtle",t),children:e.map(n=>s.jsx(rd,{hint:n},n.label))})}function rd({hint:e}){return s.jsxs("span",{className:"flex items-center gap-1",children:[e.keys.map(t=>s.jsx(ns,{children:t},t)),s.jsx("span",{children:e.label})]})}function ad(){return s.jsx("div",{className:"space-y-0",role:"status","aria-busy":"true","aria-label":"Loading messages",children:Array.from({length:8}).map((e,t)=>s.jsxs("div",{className:"animate-pulse border-b border-line px-3 py-2",children:[s.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[s.jsx("div",{className:"h-4 w-32 rounded bg-surface-sunken"}),s.jsx("div",{className:"h-3 w-16 rounded bg-surface-sunken"})]}),s.jsx("div",{className:"mb-2 h-4 w-48 rounded bg-surface-sunken"}),s.jsx("div",{className:"h-3 w-full rounded bg-surface-sunken"})]},t))})}function od({searchQuery:e}){const t=!!e?.trim();return s.jsx("div",{className:"flex h-full flex-1 items-center justify-center",children:s.jsx("div",{className:"flex flex-col items-center justify-center p-8 text-center",children:s.jsx("p",{className:"text-fg-muted",children:t?"No messages match your search":"No messages in this mailbox"})})})}function id({message:e="Something went wrong loading this mailbox.",onRetry:t,onReport:n}){return s.jsx("div",{className:"flex h-full flex-1 items-center justify-center p-4",children:s.jsxs("div",{role:"alert",className:"flex max-w-sm flex-col items-center justify-center gap-3 text-center",children:[s.jsx(_t,{className:"size-8 text-danger","aria-hidden":"true"}),s.jsxs("div",{children:[s.jsx("p",{className:"font-medium text-danger",children:"Couldn't load messages"}),s.jsx("p",{className:"mt-1 break-words text-sm text-fg-muted",children:e})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[t&&s.jsx(G,{variant:"secondary",size:"sm",onClick:t,children:"Retry"}),n&&s.jsx(G,{variant:"ghost",size:"sm",onClick:n,children:"Report a problem"})]})]})})}const xi=({active:e,focused:t})=>K("relative flex h-8 w-full items-center gap-2 px-row-inset text-left",e?"bg-accent-2-soft":t?"bg-surface-sunken":"hover:bg-surface-sunken",t&&!e&&"before:absolute before:inset-y-0 before:left-0 before:w-0.5 before:bg-accent-2"),ms=({active:e,focused:t})=>K("relative flex w-full items-start gap-3 py-2 pl-5 pr-row-inset text-left transition-colors",e?"bg-accent-2-soft":t?"bg-surface-sunken":"hover:bg-surface-sunken",t&&!e&&"before:absolute before:inset-y-0 before:left-0 before:w-0.5 before:bg-accent-2");function bi({thread:e}){const t=!e.isRead;return s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"flex w-4 shrink-0 items-center justify-center",children:e.suspicious?s.jsx(Ks,{className:"size-3.5 text-danger"}):e.starred?s.jsx(Rt,{className:"size-3 fill-warning text-warning"}):t?s.jsx("span",{className:"size-1.5 rounded-full bg-accent"}):null}),s.jsx("span",{className:K("w-36 shrink-0 truncate text-xs",t?"font-semibold text-fg":"text-fg-muted"),children:e.fromName}),s.jsxs("span",{className:"min-w-0 flex-1 truncate text-xs",children:[s.jsx("span",{className:K(t?"font-medium text-fg":"text-fg-muted"),children:e.subject}),s.jsxs("span",{className:"text-fg-subtle",children:[" — ",e.snippet]})]}),e.hasAttachment&&s.jsx(Nn,{className:"size-3 shrink-0 text-fg-subtle"}),s.jsx("span",{className:"w-11 shrink-0 text-right text-2xs text-fg-subtle tabular-nums",children:e.timeLabel})]})}function Ft({thread:e,badge:t}){const n=!e.isRead;return s.jsxs("span",{className:"min-w-0 flex-1",children:[s.jsxs("span",{className:"flex items-baseline justify-between gap-2",children:[s.jsxs("span",{className:K("flex min-w-0 items-center gap-1.5 truncate text-sm",n?"font-semibold text-fg":"font-medium text-fg-muted"),children:[e.trust==="vip"&&s.jsx("span",{className:"size-1.5 shrink-0 rounded-full bg-accent-2"}),s.jsx("span",{className:"truncate",children:e.fromName}),e.messageCount!=null&&e.messageCount>1&&s.jsx("span",{className:"shrink-0 text-2xs font-normal text-fg-subtle",children:e.messageCount})]}),s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.timeLabel})]}),s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:K("truncate text-sm",n?"text-fg":"text-fg-muted"),children:e.subject}),e.suspicious&&s.jsx(Ks,{className:"size-3.5 shrink-0 text-danger"}),e.starred&&s.jsx(Rt,{className:"size-3 shrink-0 fill-warning text-warning"}),e.hasAttachment&&s.jsx(Nn,{className:"size-3 shrink-0 text-fg-subtle"})]}),s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"line-clamp-1 min-w-0 flex-1 text-xs text-fg-subtle",children:e.snippet}),e.category&&e.category!=="personal"&&s.jsx(Ge,{tone:Ic[e.category],className:"shrink-0",children:e.category}),t]})]})}function ld({thread:e}){const t=!e.isRead;return s.jsxs(s.Fragment,{children:[t&&s.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),s.jsx(Xe,{name:e.fromName,email:e.fromEmail,size:"sm"}),s.jsx(Ft,{thread:e})]})}function cd({thread:e,active:t,onClick:n}){return s.jsx("button",{type:"button",onClick:n,className:xi({active:t}),children:s.jsx(bi,{thread:e})})}function vi({thread:e,active:t,onClick:n}){return s.jsx("button",{type:"button",onClick:n,className:ms({active:t}),children:s.jsx(ld,{thread:e})})}const ud="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",pa="pointer-events-none absolute inset-0 m-auto size-3.5 text-accent-fg";function Ur({label:e,description:t,indeterminate:n=!1,checked:r,onChange:a,className:o,...i}){const l=c.useRef(null);c.useEffect(()=>{l.current&&(l.current.indeterminate=n)},[n]);const u=s.jsxs("span",{className:"relative inline-flex",children:[s.jsx("input",{ref:l,type:"checkbox",checked:r,onChange:a,className:ud,...i}),s.jsx(Bs,{className:K(pa,"hidden peer-checked:block"),"aria-hidden":!0}),s.jsx(qu,{className:K(pa,"hidden peer-indeterminate:block"),"aria-hidden":!0})]});return e===void 0&&t===void 0?s.jsx("span",{className:o,children:u}):s.jsxs("label",{className:K("flex min-h-11 cursor-pointer items-center gap-3 text-left",o),children:[u,s.jsxs("span",{className:"flex min-w-0 flex-col",children:[e!==void 0&&s.jsx("span",{className:"text-sm text-fg",children:e}),t!==void 0&&s.jsx("span",{className:"text-xs text-fg-subtle",children:t})]})]})}const dd={info:"bg-accent-2",success:"bg-positive",warning:"bg-warning",danger:"bg-danger"};function fd({value:e,max:t,tone:n="info",indeterminate:r=!1,className:a}){const o=r?100:t<=0?0:Math.min(100,Math.max(0,e/t*100));return s.jsx("div",{role:"progressbar","aria-valuenow":r?void 0:e,"aria-valuemin":r?void 0:0,"aria-valuemax":r?void 0:t,className:K("h-1.5 w-full overflow-hidden rounded-full bg-surface-sunken",a),children:s.jsx("div",{className:K("h-full rounded-full transition-[width] duration-300 ease-out",dd[n],r&&"w-1/3 animate-pulse"),style:r?void 0:{width:`${o}%`}})})}const xa=e=>e.toLocaleString();function yi({count:e,onCancel:t,onMarkRead:n,onDelete:r,moveSlot:a,isBusy:o=!1,isCounting:i=!1,selectAll:l,statusLabel:u,progress:d,notice:m}){const f=l?.checked?`All ${xa(e)} loaded selected`:`${xa(e)} ${e===1?"message":"messages"} selected`;return s.jsxs("header",{className:"flex shrink-0 flex-col border-b border-line bg-surface-sunken",children:[s.jsxs("div",{className:"flex h-pane-header items-center gap-2 px-row-inset",children:[s.jsx(G,{variant:"ghost",size:"touch",icon:s.jsx(Ke,{className:"size-4"}),onClick:t,"aria-label":"Cancel selection",className:"-ml-2 shrink-0"}),l&&s.jsx("label",{className:"-ml-1.5 flex size-11 shrink-0 cursor-pointer items-center justify-center",children:s.jsx(Ur,{"aria-label":"Select all",checked:l.checked,indeterminate:l.indeterminate,onChange:l.onChange})}),s.jsx("span",{className:"min-w-0 flex-1 truncate text-sm font-medium text-fg",role:"status","aria-live":"polite",children:u??f}),n&&!o&&s.jsx(G,{variant:"ghost",size:"touch",icon:s.jsx($s,{className:"size-4"}),onClick:n,"aria-label":"Mark as read",className:"shrink-0"}),a,!i&&s.jsx(G,{variant:"ghost",size:"touch",icon:o?s.jsx(Kt,{className:"size-4 animate-spin"}):s.jsx(ot,{className:"size-4 text-danger"}),onClick:o?void 0:r,"aria-label":"Move selected messages to Trash","aria-busy":o||void 0,className:"ml-4 shrink-0"})]}),d&&s.jsx("div",{className:"px-row-inset pb-2",children:s.jsx(fd,{value:d.value,max:d.max,tone:d.tone})}),m&&s.jsx(Ls,{tone:m.tone,variant:"soft",role:"status","aria-live":"polite",className:"mx-row-inset mb-2",children:s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[m.text&&s.jsx("span",{children:m.text}),m.action&&s.jsx(G,{variant:"ghost",size:"md",onClick:m.action.onClick,className:"-my-1 min-h-11 shrink-0",children:m.action.label})]})})]})}const ls=72,ba=10;function va(e){return e==="leading"?ls:e==="trailing"?-ls:0}function md(e){return e>=ls/2?"leading":e<=-ls/2?"trailing":"none"}function wi({thread:e,selectionMode:t,checked:n,active:r,peek:a,onPeek:o,onToggleCheck:i,onLongPress:l,onOpen:u,onAct:d,linkComponent:m}){const f=c.useRef(void 0),h=c.useRef(null),[x,b]=c.useState(null),p=()=>clearTimeout(f.current),v=E=>{h.current={startX:E.clientX,startY:E.clientY,axis:"none",moved:!1},!t&&(f.current=setTimeout(()=>{h.current=null,b(null),l()},500))},g=E=>{if(t)return;const M=h.current;if(!M)return;const R=E.clientX-M.startX,A=E.clientY-M.startY;if(M.axis==="none"){if(Math.abs(A)>ba&&Math.abs(A)>Math.abs(R)){M.axis="vertical",p(),h.current=null;return}Math.abs(R)>ba&&(M.axis="horizontal",M.moved=!0,p(),E.currentTarget.setPointerCapture(E.pointerId))}if(M.axis!=="horizontal")return;const D=va(a),F=Math.max(-ls,Math.min(ls,D+R));b(F)},y=()=>{p();const E=h.current;h.current=null;const M=x;if(b(null),!!E){if(E.axis==="horizontal"&&M!==null){o(md(M));return}if(t){i();return}if(a!=="none"){o("none");return}m||u()}},j=E=>{a!=="none"&&E.preventDefault()},w=x??va(a),C=w>0?"leading":w<0?"trailing":"none",k=K("relative touch-pan-y bg-surface",ms({active:n||r})),S={transform:w!==0?`translateX(${w}px)`:void 0,transition:x===null?"transform 150ms ease":"none",minHeight:44},N=!e.isRead,I=E=>E.stopPropagation(),T=t?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:K("inline-flex size-7 shrink-0 items-center justify-center rounded-full border",n?"border-accent bg-accent text-accent-fg":"border-line-strong bg-canvas"),children:n&&s.jsx(Bs,{className:"size-3.5"})}),s.jsx(Ft,{thread:e})]}):s.jsxs(s.Fragment,{children:[N&&s.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),s.jsx("button",{type:"button",role:"checkbox","aria-checked":n,"aria-label":`Select message from ${e.fromName}`,onPointerDown:I,onPointerMove:I,onPointerUp:I,onClick:E=>{E.preventDefault(),E.stopPropagation(),l()},className:"inline-flex size-7 shrink-0 items-center justify-center rounded-full",children:s.jsx(Xe,{name:e.fromName,email:e.fromEmail,size:"sm"})}),s.jsx(Ft,{thread:e})]});return s.jsxs("div",{className:"relative overflow-hidden",children:[C==="leading"&&s.jsx("button",{type:"button",onClick:()=>d("leading"),"aria-label":e.isRead?"Mark as unread":"Mark as read",className:"absolute inset-y-0 left-0 flex items-center justify-start bg-accent-2 px-6 text-accent-fg",children:e.isRead?s.jsx(Jo,{className:"size-6"}):s.jsx($s,{className:"size-6"})}),C==="trailing"&&s.jsx("button",{type:"button",onClick:()=>d("trailing"),"aria-label":"Delete message",className:"absolute inset-y-0 right-0 flex items-center justify-end bg-danger px-6 text-canvas",children:s.jsx(ot,{className:"size-6"})}),m&&!t?m({className:k,style:S,onPointerDown:v,onPointerMove:g,onPointerUp:y,onPointerCancel:y,onOpenClick:j,children:T}):s.jsx("button",{type:"button",role:t?"checkbox":void 0,"aria-checked":t?n:void 0,onPointerDown:v,onPointerMove:g,onPointerUp:y,onPointerCancel:y,className:k,style:S,children:T})]})}function hd({sections:e,selectedThreadId:t,selectionMode:n,checkedIds:r,initialPeek:a,onToggleCheck:o,onEnterSelection:i,onOpenThread:l,onRefresh:u,refreshing:d,busy:m=!1}){const[f,h]=c.useState(()=>e.flatMap(v=>v.threads)),[x,b]=c.useState(a&&a!=="none"&&f[1]?{id:f[1].id,side:a}:null),p=(v,g)=>{h(g==="trailing"?y=>y.filter(j=>j.id!==v):y=>y.map(j=>j.id===v?{...j,isRead:!j.isRead}:j)),b(null)};return s.jsxs("div",{className:"flex-1 overflow-y-auto",children:[d&&s.jsxs("div",{className:"flex items-center justify-center gap-2 border-b border-line py-3 text-fg-muted",children:[s.jsx(di,{className:"size-4 animate-spin"}),s.jsx("span",{className:"text-xs",children:"Checking for new mail…"})]}),s.jsx("div",{className:"divide-y divide-line",children:f.map(v=>s.jsx("div",{className:m?"pointer-events-none opacity-50":void 0,children:s.jsx(wi,{thread:v,selectionMode:n,checked:r.has(v.id),active:v.id===t,peek:x?.id===v.id?x.side:"none",onPeek:g=>b(g==="none"?null:{id:v.id,side:g}),onToggleCheck:()=>o(v.id),onLongPress:()=>i(v.id),onOpen:()=>l(v.id),onAct:g=>p(v.id,g)})},v.id))}),!n&&!d&&!m&&s.jsx("button",{type:"button",onClick:u,className:"w-full border-t border-line py-2 text-center text-2xs text-fg-subtle transition-colors hover:bg-surface-sunken",children:"Pull to refresh"})]})}function ji({listTitle:e,listMeta:t,sections:n,briefFilters:r,flatList:a,listState:o="ready",searchQuery:i,errorMessage:l,onRetry:u,onReportError:d,briefCategory:m,selectedThreadId:f,density:h="comfortable",onSelectThread:x,onSelectBriefCategory:b,onOpenNav:p,isDesktop:v,initialTouchState:g,selectionBar:y,listBody:j,hideHeader:w=!1}){const C=h==="compact"?cd:vi,k=!v&&!r&&o==="ready",S=n.flatMap(Q=>Q.threads),[N,I]=c.useState(g==="selection"),[T,E]=c.useState(()=>g==="selection"?new Set(S.slice(0,2).map(Q=>Q.id)):new Set),[M,R]=c.useState(!1),A=g==="peek-trailing"?"trailing":g==="peek-leading"?"leading":void 0,D=Q=>{E(X=>{const ee=new Set(X);return ee.has(Q)?ee.delete(Q):ee.add(Q),ee.size===0&&I(!1),ee})},F=Q=>{I(!0),E(new Set([Q]))},$=()=>{I(!1),E(new Set)},te=()=>{R(!0),setTimeout(()=>R(!1),1400)},q=!y&&k&&N&&T.size>0;return s.jsxs("section",{className:"flex h-full w-full flex-col bg-surface",children:[y??(q?s.jsx(yi,{count:T.size,onCancel:$,onMarkRead:$,onDelete:$}):w?null:s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[p&&s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx($r,{className:"size-4"}),onClick:p,"aria-label":"Open folders",className:"-ml-1 shrink-0"}),s.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e}),t&&s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle",children:t})]})),o==="loading"?s.jsx("div",{className:"flex-1 overflow-y-auto",children:s.jsx(ad,{})}):o==="empty"?s.jsx(od,{searchQuery:i}):o==="error"?s.jsx(id,{message:l,onRetry:u,onReport:d}):r?s.jsx(Ao,{sections:n,briefCategory:m,selectedThreadId:f,Row:C,onSelectThread:x,onSelectBriefCategory:b}):j??(k?s.jsx(hd,{sections:n,selectedThreadId:f,selectionMode:N,checkedIds:T,initialPeek:A,onToggleCheck:D,onEnterSelection:F,onOpenThread:Q=>x?.(Q),onRefresh:te,refreshing:M}):s.jsx("div",{className:"flex-1 overflow-y-auto",children:n.map(Q=>s.jsxs("div",{children:[!a&&Q.label&&s.jsxs("div",{className:"sticky top-0 flex h-section-row items-center justify-between border-b border-line bg-surface-sunken px-row-inset",children:[s.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:Q.label}),s.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:Q.threads.length})]}),s.jsx("div",{className:"divide-y divide-line",children:Q.threads.map(X=>s.jsx(C,{thread:X,active:X.id===f,onClick:()=>x?.(X.id)},X.id))})]},Q.id))})),v&&s.jsx(pi,{})]})}function gd({triggerLabel:e,triggerIcon:t,items:n,align:r="end",touch:a=!0,className:o}){const[i,l]=c.useState(!1),u=c.useRef(null);return c.useEffect(()=>{if(!i)return;const d=f=>{u.current&&!u.current.contains(f.target)&&l(!1)},m=f=>{f.key==="Escape"&&l(!1)};return document.addEventListener("mousedown",d),document.addEventListener("keydown",m),()=>{document.removeEventListener("mousedown",d),document.removeEventListener("keydown",m)}},[i]),n.length===0?null:s.jsxs("div",{ref:u,className:K("relative",o),children:[s.jsx(G,{variant:"ghost",size:"sm",icon:t??s.jsx(ii,{className:"size-5"}),onClick:()=>l(d=>!d),"aria-label":e,"aria-haspopup":"menu","aria-expanded":i,className:K(a&&"min-h-11 min-w-11 px-0")}),i&&s.jsx("div",{role:"menu",className:K("absolute top-full z-50 mt-1 flex min-w-44 flex-col rounded-md border border-line bg-surface py-1 shadow-lg",r==="end"?"right-0":"left-0"),children:n.map(d=>s.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{l(!1),d.onSelect()},className:"flex min-h-11 items-center gap-3 px-4 py-2.5 text-left text-sm text-fg transition-colors hover:bg-surface-sunken",children:[d.icon&&s.jsx("span",{className:"shrink-0 text-fg-subtle",children:d.icon}),d.label]},d.key))})]})}const Ss="min-h-11 min-w-11 px-0";function Si({hasThread:e,onReply:t,onReplyAll:n,onForward:r,isStarred:a,onToggleStar:o,onDelete:i,isRead:l,onToggleRead:u,moveSlot:d,overflowItems:m=[],onUnavailable:f,unavailableHint:h,className:x}){const b=(v,g)=>()=>{if(!e){f?.(v);return}g?.()},p=u?[{key:"toggle-read",label:l?"Mark as unread":"Mark as read",icon:l?s.jsx(Jo,{className:"size-4"}):s.jsx($s,{className:"size-4"}),onSelect:b("toggleRead",u)}]:[];return s.jsxs("div",{className:K("relative",x),children:[s.jsxs("div",{className:"flex h-12 shrink-0 items-center gap-0.5 border-y border-line bg-canvas px-1",children:[s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(mi,{className:"size-5"}),onClick:b("reply",t),"aria-label":"Reply",title:"Reply",className:Ss}),s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(fi,{className:"size-5"}),onClick:b("replyAll",n),"aria-label":"Reply all",title:"Reply all",className:Ss}),s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(ci,{className:"size-5"}),onClick:b("forward",r),"aria-label":"Forward",title:"Forward",className:Ss}),s.jsx("div",{className:"flex-1"}),s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(Rt,{className:K("size-5",a&&"fill-warning text-warning")}),onClick:b("star",o),"aria-label":a?"Unstar":"Star","aria-pressed":a,title:a?"Unstar":"Star",className:Ss}),d,s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(ot,{className:"size-5"}),onClick:b("delete",i),"aria-label":"Move to Trash",title:"Move to Trash",className:Ss}),s.jsx(gd,{triggerLabel:"More actions",items:[...p,...m]})]}),!e&&h&&s.jsx("p",{role:"status",className:"border-b border-line bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:h})]})}function pd({open:e=!1,enabled:t=!0,onToggle:n,className:r}){return s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(Oo,{className:"size-4"}),title:"Intelligence","aria-label":e?"Hide intelligence sidebar":"Show intelligence sidebar","aria-pressed":e,disabled:!t,onClick:n,className:K(e&&"bg-accent-2-soft text-accent-2",r)})}function xd({hasThread:e,onUnavailable:t,unavailableHint:n,isStarred:r,showTriage:a=!0,onReply:o,onReplyAll:i,onForward:l,onDelete:u,onToggleStar:d,moveSlot:m,onMove:f,replyTitle:h="Reply (r)",replyAllTitle:x="Reply all (a)",forwardTitle:b="Forward (f)",deleteTitle:p="Move to Trash (#)",flagTitle:v="Star (s)",children:g,className:y}){const j=(w,C)=>()=>{if(!e){t?.(w);return}C?.()};return s.jsxs("div",{className:"relative",children:[s.jsxs("header",{className:K("flex h-pane-header shrink-0 items-center gap-1 border-b border-line bg-surface px-3",y),children:[s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(mi,{className:"size-4"}),title:h,"aria-label":"Reply",onClick:j("reply",o)}),s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(fi,{className:"size-4"}),title:x,"aria-label":"Reply all",onClick:j("replyAll",i)}),s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(ci,{className:"size-4"}),title:b,"aria-label":"Forward",onClick:j("forward",l)}),a&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"mx-1 h-4 w-px bg-line","aria-hidden":!0}),s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(ot,{className:"size-4"}),title:p,"aria-label":"Move to Trash",onClick:j("delete",u)}),m??s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(li,{className:"size-4"}),title:"Move to mailbox","aria-label":"Move to mailbox",onClick:j("move",f)}),s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(Rt,{className:K("size-4",r&&"fill-warning text-warning")}),title:v,"aria-label":"Star",onClick:j("flag",d)})]}),s.jsx("div",{className:"flex-1"}),g]}),!e&&n&&s.jsx("p",{role:"status",className:"border-b border-line bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:n})]})}const bd=(e,t)=>{const r=e==="newsletter"||e==="marketing"||t;return{framed:r,isPlain:!r}},vd=()=>`
|
|
3
3
|
/* Zero the UA default body margin and clamp the document to the iframe width so
|
|
4
4
|
wide author markup can't push the body (and the page) past the viewport. */
|
|
5
5
|
html, body {
|
|
@@ -107,6 +107,6 @@ a, a:visited {
|
|
|
107
107
|
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
108
108
|
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
109
109
|
`)},Sh=0,Zt=[];function kh(e){var t=c.useRef([]),n=c.useRef([0,0]),r=c.useRef(),a=c.useState(Sh++)[0],o=c.useState(Bi)[0],i=c.useRef(e);c.useEffect(function(){i.current=e},[e]),c.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(a));var p=Pc([e.lockRef.current],(e.shards||[]).map(Ja),!0).filter(Boolean);return p.forEach(function(v){return v.classList.add("allow-interactivity-".concat(a))}),function(){document.body.classList.remove("block-interactivity-".concat(a)),p.forEach(function(v){return v.classList.remove("allow-interactivity-".concat(a))})}}},[e.inert,e.lockRef.current,e.shards]);var l=c.useCallback(function(p,v){if("touches"in p&&p.touches.length===2||p.type==="wheel"&&p.ctrlKey)return!i.current.allowPinchZoom;var g=rn(p),y=n.current,j="deltaX"in p?p.deltaX:y[0]-g[0],w="deltaY"in p?p.deltaY:y[1]-g[1],C,k=p.target,S=Math.abs(j)>Math.abs(w)?"h":"v";if("touches"in p&&S==="h"&&k.type==="range")return!1;var N=window.getSelection(),I=N&&N.anchorNode,T=I?I===k||I.contains(k):!1;if(T)return!1;var E=Ga(S,k);if(!E)return!0;if(E?C=S:(C=S==="v"?"h":"v",E=Ga(S,k)),!E)return!1;if(!r.current&&"changedTouches"in p&&(j||w)&&(r.current=C),!C)return!0;var M=r.current||C;return yh(M,v,p,M==="h"?j:w)},[]),u=c.useCallback(function(p){var v=p;if(!(!Zt.length||Zt[Zt.length-1]!==o)){var g="deltaY"in v?Xa(v):rn(v),y=t.current.filter(function(C){return C.name===v.type&&(C.target===v.target||v.target===C.shadowParent)&&wh(C.delta,g)})[0];if(y&&y.should){v.cancelable&&v.preventDefault();return}if(!y){var j=(i.current.shards||[]).map(Ja).filter(Boolean).filter(function(C){return C.contains(v.target)}),w=j.length>0?l(v,j[0]):!i.current.noIsolation;w&&v.cancelable&&v.preventDefault()}}},[]),d=c.useCallback(function(p,v,g,y){var j={name:p,delta:v,target:g,should:y,shadowParent:Nh(g)};t.current.push(j),setTimeout(function(){t.current=t.current.filter(function(w){return w!==j})},1)},[]),m=c.useCallback(function(p){n.current=rn(p),r.current=void 0},[]),f=c.useCallback(function(p){d(p.type,Xa(p),p.target,l(p,e.lockRef.current))},[]),h=c.useCallback(function(p){d(p.type,rn(p),p.target,l(p,e.lockRef.current))},[]);c.useEffect(function(){return Zt.push(o),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:h}),document.addEventListener("wheel",u,Jt),document.addEventListener("touchmove",u,Jt),document.addEventListener("touchstart",m,Jt),function(){Zt=Zt.filter(function(p){return p!==o}),document.removeEventListener("wheel",u,Jt),document.removeEventListener("touchmove",u,Jt),document.removeEventListener("touchstart",m,Jt)}},[]);var x=e.removeScrollBar,b=e.inert;return c.createElement(c.Fragment,null,b?c.createElement(o,{styles:jh(a)}):null,x?c.createElement(mh,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Nh(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const Ch=eh(_i,kh);var Ui=c.forwardRef(function(e,t){return c.createElement(En,St({},e,{ref:t,sideCar:Ch}))});Ui.classNames=En.classNames;var Eh=class extends Or{constructor(e,t){super(e,t)}bindMethods(){super.bindMethods(),this.fetchNextPage=this.fetchNextPage.bind(this),this.fetchPreviousPage=this.fetchPreviousPage.bind(this)}setOptions(e){e._type="infinite",super.setOptions(e)}getOptimisticResult(e){return e._type="infinite",super.getOptimisticResult(e)}fetchNextPage(e){return this.fetch({...e,meta:{fetchMore:{direction:"forward"}}})}fetchPreviousPage(e){return this.fetch({...e,meta:{fetchMore:{direction:"backward"}}})}createResult(e,t){const{state:n}=e,r=super.createResult(e,t),{isFetching:a,isRefetching:o,isError:i,isRefetchError:l}=r,u=n.fetchMeta?.fetchMore?.direction,d=i&&u==="forward",m=a&&u==="forward",f=i&&u==="backward",h=a&&u==="backward";return{...r,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:zc(t,n.data),hasPreviousPage:Lc(t,n.data),isFetchNextPageError:d,isFetchingNextPage:m,isFetchPreviousPageError:f,isFetchingPreviousPage:h,isRefetchError:l&&!d&&!f,isRefetching:o&&!m&&!h}}};function Za(e,t){const n=new Set(t);return e.filter(r=>!n.has(r))}function Ih(e,t,n){const r=e.slice(0);return r[t]=n,r}var Rh=class extends Fc{#r;#e;#a;#n;#t;#s;#o;#i;#l;#c=[];constructor(e,t,n){super(),this.#r=e,this.#n=n,this.#a=[],this.#t=[],this.#e=[],this.setQueries(t)}onSubscribe(){this.listeners.size===1&&this.#t.forEach(e=>{e.subscribe(t=>{this.#m(e,t)})})}onUnsubscribe(){this.listeners.size||this.destroy()}destroy(){this.listeners=new Set,this.#t.forEach(e=>{e.destroy()})}setQueries(e,t){this.#a=e,this.#n=t,fr.batch(()=>{const n=this.#t,r=this.#f(this.#a);r.forEach(m=>m.observer.setOptions(m.defaultedQueryOptions));const a=r.map(m=>m.observer),o=a.map(m=>m.getCurrentResult()),i=n.length!==a.length,l=a.some((m,f)=>m!==n[f]),u=i||l,d=u?!0:o.some((m,f)=>{const h=this.#e[f];return!h||!_c(m,h)});!u&&!d||(u&&(this.#c=r,this.#t=a),this.#e=o,this.hasListeners()&&(u&&(Za(n,a).forEach(m=>{m.destroy()}),Za(a,n).forEach(m=>{m.subscribe(f=>{this.#m(m,f)})})),this.#h()))})}getCurrentResult(){return this.#e}getQueries(){return this.#t.map(e=>e.getCurrentQuery())}getObservers(){return this.#t}getOptimisticResult(e,t){const n=this.#f(e),r=n.map(o=>o.observer.getOptimisticResult(o.defaultedQueryOptions)),a=n.map(o=>o.defaultedQueryOptions.queryHash);return[r,o=>this.#d(o??r,t,a),()=>this.#u(r,n)]}#u(e,t){return t.map((n,r)=>{const a=e[r];return n.defaultedQueryOptions.notifyOnChangeProps?a:n.observer.trackResult(a,o=>{t.forEach(i=>{i.observer.trackProp(o)})})})}#d(e,t,n){if(t){const r=this.#l,a=n!==void 0&&r!==void 0&&(r.length!==n.length||n.some((o,i)=>o!==r[i]));return(!this.#s||this.#e!==this.#i||a||t!==this.#o)&&(this.#o=t,this.#i=this.#e,n!==void 0&&(this.#l=n),this.#s=Bc(this.#s,t(e))),this.#s}return e}#g(){return this.#n?.combine!==void 0&&this.#t.some((e,t)=>e.options.suspense&&this.#e[t]?.data===void 0)}#f(e){const t=new Map;this.#t.forEach(r=>{const a=r.options.queryHash;if(!a)return;const o=t.get(a);o?o.push(r):t.set(a,[r])});const n=[];return e.forEach(r=>{const a=this.#r.defaultQueryOptions(r),i=t.get(a.queryHash)?.shift()??new Or(this.#r,a);n.push({defaultedQueryOptions:a,observer:i})}),n}#m(e,t){const n=this.#t.indexOf(e);n!==-1&&(this.#e=Ih(this.#e,n,t),this.#h())}#h(){if(this.hasListeners()){const e=this.#u(this.#e,this.#c),t=this.#g(),n=this.#s,r=t?n:this.#d(e,this.#n?.combine);(t||n!==r)&&fr.batch(()=>{this.listeners.forEach(a=>{a(this.#e)})})}}};function Ut({queries:e,...t},n){const r=je(),a=$c(),o=Kc(),i=c.useMemo(()=>e.map(p=>{const v=r.defaultQueryOptions(p);return v._optimisticResults=a?"isRestoring":"optimistic",v}),[e,r,a]);i.forEach(p=>{qc(p);const v=r.getQueryCache().get(p.queryHash);Uc(p,o,v)}),Qc(o);const[l]=c.useState(()=>new Rh(r,i,t)),[u,d,m]=l.getOptimisticResult(i,t.combine),f=!a&&t.subscribed!==!1;c.useSyncExternalStore(c.useCallback(p=>f?l.subscribe(fr.batchCalls(p)):Hc,[l,f]),()=>l.getCurrentResult(),()=>l.getCurrentResult()),c.useEffect(()=>{l.setQueries(i,t)},[i,t,l]);const x=u.some((p,v)=>ha(i[v],p))?u.flatMap((p,v)=>{const g=i[v];if(g&&ha(g,p)){const y=new Or(r,g);return Wc(g,y,o)}return[]}):[];if(x.length>0)throw Promise.all(x);const b=u.find((p,v)=>{const g=i[v];return g&&Vc({result:p,errorResetBoundary:o,throwOnError:g.throwOnError,query:r.getQueryCache().get(g.queryHash),suspense:g.suspense})});if(b?.error)throw b.error;return d(m())}function Qi(e,t){return Yc(e,Eh)}function kt(e){const t=_o({warn:e?.router===void 0}),n=e?.router||t;return Bo(n.stores.__store,$o(e,n))}function In(e){const t=_o();return Bo(t.stores.location,$o(e,t))}const Mh=new Set(["outbox","flagged"]),Th=e=>{const[,t,n]=e.split(/[?#]/)[0].split("/");return t!=="mail"||!n?!1:!Mh.has(n)};function Dh(e){const t=Ut({queries:e.map(n=>({...rt({path:{accountId:n.accountId}}),staleTime:1/0}))});for(const[n,r]of e.entries()){const a=t[n];if(!a||a.isPending)return;const o=a.data?.items??[];if(o.length===0)continue;const i=fs(r.folderAppointments);return(o.find(u=>i.get(u.mailboxId)==="inbox")??o[0])?.mailboxId}}function Hi(e){const{openCompose:t}=It(),n=Me(),r=In(),a=Dh(e);return c.useCallback(()=>{if(Th(r.pathname)){c.startTransition(()=>{t({mode:"new"})});return}a&&(c.startTransition(()=>{t({mode:"new"})}),n({to:"/mail/$mailboxId",params:{mailboxId:a}}))},[t,n,r.pathname,a])}const Ah=e=>e.startsWith("/mail")||e.startsWith("/settings"),Oh=({accounts:e})=>{const{state:t}=It(),n=In(),r=Hi(e),a=n.search,o=typeof a?.selectedMessageId=="string"&&a.selectedMessageId.length>0;return!Ah(n.pathname)||t.isOpen||o?null:s.jsx("button",{type:"button",onClick:r,"aria-label":"Compose new message",className:"lg:hidden fixed right-4 z-30 h-14 w-14 rounded-full bg-accent text-accent-fg shadow-lg flex items-center justify-center hover:opacity-90 active:scale-95 transition-all",style:{bottom:"calc(env(safe-area-inset-bottom, 0) + 1rem)"},children:s.jsx(Uu,{className:"size-6"})})},Wi=({trigger:e,children:t,align:n="right"})=>{const[r,a]=c.useState(!1),o=c.useRef(null),i=c.useCallback(u=>{o.current&&!o.current.contains(u.target)&&a(!1)},[]),l=c.useCallback(u=>{u.key==="Escape"&&a(!1)},[]);return c.useEffect(()=>(r&&(document.addEventListener("mousedown",i),document.addEventListener("keydown",l)),()=>{document.removeEventListener("mousedown",i),document.removeEventListener("keydown",l)}),[r,i,l]),s.jsxs("div",{ref:o,className:"relative",children:[s.jsx("button",{type:"button",onClick:u=>{u.stopPropagation(),a(!r)},className:de("p-1.5 min-h-11 min-w-11 inline-flex items-center justify-center rounded-md transition-colors","hover:bg-surface-raised text-fg-muted hover:text-fg"),children:e}),r&&s.jsx("div",{className:de("absolute z-50 mt-1 min-w-[180px] py-1","bg-surface border border-line rounded-md shadow-lg",n==="right"?"right-0":"left-0"),children:t})]})},ss=({onClick:e,disabled:t,destructive:n,children:r})=>s.jsx("button",{type:"button",onClick:a=>{a.stopPropagation(),t||e()},disabled:t,className:de("w-full px-3 py-2 text-left text-sm transition-colors","flex items-center gap-2",t&&"opacity-50 cursor-not-allowed",!t&&"hover:bg-surface-raised",n&&"text-danger hover:text-danger"),children:r}),vr=()=>s.jsx("div",{className:"my-1 h-px bg-line"}),Vi=({children:e})=>{const{Account:t}=Pr();return s.jsx(t,{children:e})},Ph=({email:e,onSignOut:t})=>{const n=Me(),r=e??"Account";return s.jsxs(Wi,{trigger:s.jsx(Xe,{name:r,email:e??void 0,size:"sm"}),align:"right",children:[e&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-3 py-2 text-xs text-fg-muted truncate",title:e,"data-testid":"account-menu-email",children:e}),s.jsx(vr,{})]}),s.jsxs(ss,{onClick:()=>n({to:"/settings/accounts"}),children:[s.jsx(hi,{className:"size-4"}),"Settings"]}),s.jsx(vr,{}),s.jsxs(ss,{onClick:t,children:[s.jsx(ui,{className:"size-4"}),"Sign out"]})]})},Lh=()=>s.jsx(Vi,{children:({email:e,signOut:t})=>s.jsx(Ph,{email:e,onSignOut:t})}),eo=()=>{const e=Lr(),t=zr(e);window.open(t,"_blank","noopener,noreferrer")};function Yi({variant:e="icon"}){return e==="drawer"?s.jsxs("button",{type:"button",onClick:eo,className:"flex w-full items-center gap-2 rounded-md px-2 py-1 text-sm text-fg-muted transition-colors hover:bg-surface hover:text-fg",children:[s.jsx(ga,{className:"size-4 shrink-0"}),s.jsx("span",{className:"flex-1 truncate text-left",children:"Report a bug"})]}):s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(ga,{className:"size-4"}),title:"Report a bug","aria-label":"Report a bug",onClick:eo})}const Gi="/mail/",Gr="/mail/$mailboxId",Xi="/mail/outbox",Ji="/mail/flagged";function Xr(e){return e.some(t=>t.routeId===Gi)}function Rn(e){return e.some(t=>t.routeId===Ji)}function Mn(e){return e.some(t=>t.routeId===Xi)}function Zi(e){return e.some(t=>t.routeId===Gr)}function zh(e){const t=e.find(n=>n.params?.mailboxId)?.params?.mailboxId;return t?`${Gr}:${t}`:Rn(e)?Ji:Mn(e)?Xi:Xr(e)?Gi:""}const fn="search-scope";function Fh(e){const t=e.trim().replace(/\s+/g," ").toLowerCase();return/\s/.test(t)?`in:"${t}"`:`in:${t}`}function el(e){return Rn(e)||Mn(e)||Zi(e)}function _h(e){return e.find(t=>t.routeId===Gr)?.params?.mailboxId}function Bh(e){const t=_h(e.matches);return t||(el(e.matches)?e.callerMailboxId:e.callerMailboxId??e.inTokenMailboxId)}function $h(e,t){return Xr(e)?{kind:"global"}:Rn(e)?{kind:"scoped",chip:{id:fn,label:"is:starred"}}:Mn(e)?{kind:"scoped",chip:{id:fn,label:"in:outbox"}}:Zi(e)?t?{kind:"scoped",chip:{id:fn,label:Fh(t)}}:{kind:"pending"}:{kind:"global"}}const tl=({accounts:e})=>{const t=Fr({strict:!1}),n=In(),r=t.mailboxId,{t:a}=yn("mail",{useSuspense:!1}),o=c.useCallback((l,u)=>a(l,{defaultValue:u}),[a]),i=Ut({queries:e.map(l=>({...rt({path:{accountId:l.accountId}}),staleTime:1/0}))});if(n.pathname.startsWith("/mail/outbox"))return"Outbox";if(!r)return null;for(let l=0;l<e.length;l++){const u=i[l]?.data?.items;if(!u)continue;const d=u.find(f=>f.mailboxId===r);if(!d)continue;const m=fs(e[l].folderAppointments);return os(d,m.get(r),o)}return null},Kh=({accounts:e})=>{const n=Fr({strict:!1}).mailboxId,r=Ut({queries:e.map(a=>({...rt({path:{accountId:a.accountId}}),staleTime:1/0}))});if(!n)return null;for(const a of r){const o=a.data?.items;if(!o)continue;const i=o.find(l=>l.mailboxId===n);if(i)return i.unseenCount}return null};function qh(e){const t=Me(),{searchInput:n}=Se(),r=tl({accounts:e}),a=kt({select:l=>l.matches}),o=$h(a,r),i=c.useCallback(l=>{l===fn&&t({to:"/mail",search:{q:n||void 0,selectedMessageId:void 0}})},[t,n]);return{scope:o,clearScope:i}}const sl=[{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 Uh(e){for(const t of sl){const n=t.hints.find(r=>r.action===e);if(n)return n.keys}}function ts(e){const t=Uh(e);return!t||t.length===0?"":t.length===1?`(${t[0]})`:t[0]==="g"?`(${t.join(" then ")})`:`(${t.join("")})`}const Qh={global:"Search all mail",pending:"Search mail",scoped:"Search this folder"};function Hh({accounts:e}){const{searchInput:t,onSearchChange:n,onSearchClear:r,onSearchClearQuery:a}=Se(),o=Hi(e),{scope:i,clearScope:l}=qh(e),u=i.kind==="scoped"?[{id:i.chip.id,label:i.chip.label,tone:"scope"}]:void 0,d=Qh[i.kind];return s.jsx(Zd,{leading:s.jsx("span",{className:"px-1 text-sm font-semibold tracking-tight text-fg",children:"remit"}),search:s.jsx(Qr,{value:t,onChange:n,onClear:r,onClearQuery:a,chips:u,onRemoveChip:l,placeholder:d,size:"lg"}),actions:s.jsxs(s.Fragment,{children:[s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(Vu,{className:"size-4"}),title:`Compose ${ts("compose")}`,"aria-label":"Compose",onClick:o}),s.jsx(Yi,{}),s.jsx(Lh,{})]})})}const Jr=({isOpen:e,onClose:t,children:n,ariaLabel:r="Navigation",side:a="left",widthClassName:o="w-[80vw] max-w-[320px]"})=>{const i=c.useRef(null),l=c.useRef(null);if(c.useEffect(()=>{if(!e)return;l.current=document.activeElement;const d=h=>{h.key==="Escape"&&(h.preventDefault(),t())};document.addEventListener("keydown",d),i.current?.querySelector("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])")?.focus();const f=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",d),document.body.style.overflow=f,l.current?.focus()}},[e,t]),!e)return null;const u=a==="left"?"left-0 border-r animate-in slide-in-from-left duration-150":"right-0 border-l animate-in slide-in-from-right duration-150";return s.jsxs("div",{className:"fixed inset-0 z-50 lg:hidden",role:"dialog","aria-modal":"true","aria-label":r,children:[s.jsx("button",{type:"button","aria-label":"Close menu",onClick:t,className:"absolute inset-0 bg-black/40 animate-in fade-in duration-150 cursor-default"}),s.jsxs("div",{ref:i,className:de("absolute top-0 bottom-0 bg-canvas border-line shadow-xl flex flex-col",o,u),children:[s.jsx("div",{className:"flex items-center justify-end h-12 px-2 border-b border-line shrink-0",children:s.jsx("button",{type:"button",onClick:t,className:"p-2 rounded-md hover:bg-surface-raised transition-colors min-h-11 min-w-11 inline-flex items-center justify-center","aria-label":"Close menu",children:s.jsx(Ke,{className:"size-5"})})}),s.jsx("div",{className:"flex-1 overflow-y-auto",children:n})]})]})},Wh=e=>{const t=e.filter(a=>!a.isMultipart&&a.disposition!=="attachment"&&a.mediaType==="TEXT"&&a.contentUrl.length>0),n=t.find(a=>a.mediaSubtype.toUpperCase()==="HTML");if(n)return{kind:"html",contentUrl:n.contentUrl};const r=t.find(a=>a.mediaSubtype.toUpperCase()==="PLAIN");return r?{kind:"text",contentUrl:r.contentUrl}:null},yr={all:["messages"],detail:e=>[...yr.all,"detail",e],body:e=>[...yr.detail(e),"body"]};class Lt extends Error{reason;status;retryAfterSeconds;constructor(t,n,r,a){super(n),this.name="BodyFetchError",this.reason=t,this.status=r,this.retryAfterSeconds=a}}const Vh=e=>{const t=Number.parseInt(e??"",10);return!Number.isFinite(t)||t<=0?1:Math.min(t,30)},Yh=8,Gh="x-remit-403-reason",Xh=(e,t)=>{const n=t?.trim()??"";return e===401?"auth":e===403?n.length>0?"auth":"body-missing":e===404?"body-missing":"generic"},Jh=(e,t)=>(t??"").toLowerCase().startsWith("text/html")?/<div\s+id=["']root["']/i.test(e):!1,Zh=(e,t)=>{const n=(t??"").toLowerCase();return!!(e==="text"&&n.startsWith("text/html"))},eg=async(e,t,n=async()=>null)=>{const r={},a=await n();a&&(r.Authorization=`Bearer ${a}`);const o=await Gc(e,{headers:r});if(o.status===202)throw new Lt("not-ready","Message body is still syncing",202,Vh(o.headers.get("Retry-After")));if(!o.ok){const u=o.headers.get(Gh),d=Xh(o.status,u);throw new Lt(d,`Failed to load message body (${o.status} ${o.statusText})`,o.status)}const i=o.headers.get("content-type");if(Zh(t,i))throw new Lt("content-type-mismatch",`Refusing to render message body — expected ${t}, got Content-Type ${i}`);const l=await o.text();if(Jh(l,i))throw new Lt("spa-shell-leak","Refusing to render message body — response looks like the SPA shell (CloudFront 403/404 fallback leaked through to /content/*)");return l},tg=async(e,t)=>(t.isRetryAfterNotReady&&await e.refetchDescribeMessage(),e.fetchContent(t.contentUrl,t.kind)),nl=({messageId:e,bodyParts:t,enabled:n=!0})=>{const r=t?Wh(t):null,a=zs(),{getToken:o}=Pr(),i=c.useRef(null),l=je(),u=c.useRef(!1),d=c.useRef(null),m=e&&r?`${e}:${r.contentUrl}`:null;d.current!==m&&(d.current=m,u.current=!1);const f=ue({queryKey:e?[...yr.body(e),r?.contentUrl??null]:["messages","body","noop"],queryFn:()=>{if(!r)throw new Error("No renderable body part");if(!e)throw new Error("No messageId");const b=u.current;return u.current=!1,tg({fetchContent:(p,v)=>eg(p,v,o),refetchDescribeMessage:()=>l.refetchQueries({queryKey:Ko({path:{messageId:e}})})},{contentUrl:r.contentUrl,kind:r.kind,isRetryAfterNotReady:b})},enabled:n&&!!e&&!!r,staleTime:300*1e3,gcTime:1800*1e3,retry:(b,p)=>p instanceof Lt&&p.reason==="not-ready"?b<Yh:b<1,retryDelay:(b,p)=>p instanceof Lt&&p.reason==="not-ready"?(u.current=!0,(p.retryAfterSeconds??1)*1e3):1e3,meta:{softError:!0}}),h=f.isLoading&&!!r;c.useEffect(()=>{h&&(i.current=performance.now())},[h]),c.useEffect(()=>{f.isSuccess&&i.current!==null&&(a.recordTiming("message.body.load",Math.round(performance.now()-i.current)),i.current=null)},[f.isSuccess,a]);const x=f.data&&r?{kind:r.kind,body:f.data}:void 0;return{picked:r,data:x,isLoading:h,isError:f.isError,error:f.error,refetch:f.refetch}},sg=({outboxMessageId:e,onDraftCreated:t})=>{const[n,r]=c.useState("idle"),[a,o]=c.useState(null),i=c.useRef(void 0),l=je(),u=pe(qo()),d=pe(Xc()),m=c.useCallback(async b=>{if(r("saving"),o(null),e){const v=await d.mutateAsync({path:{outboxMessageId:e},body:{toAddresses:b.toAddresses,ccAddresses:b.ccAddresses,bccAddresses:b.bccAddresses,subject:b.subject,textBody:b.textBody,htmlBody:b.htmlBody,inReplyTo:b.inReplyTo,references:b.references}});return r("saved"),v}const p=await u.mutateAsync({body:{...b,sendImmediately:!1}});return t(p.outboxMessageId),r("saved"),l.invalidateQueries({queryKey:wn().queryKey}),p},[e,u,d,t,l]),f=c.useCallback(b=>{i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{m(b).catch(p=>{o(p),r("error")})},2e3)},[m]),h=c.useCallback(b=>(i.current&&clearTimeout(i.current),m(b)),[m]),x=c.useCallback(()=>{i.current&&clearTimeout(i.current)},[]);return{saveStatus:n,saveError:a,saveDraft:f,saveImmediately:h,cancelAutoSave:x}},rl=e=>"text"in e&&!("children"in e),al=e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),ng=e=>{let t=al(e.text);return e.bold&&(t=`<strong>${t}</strong>`),e.italic&&(t=`<em>${t}</em>`),t},ol=e=>{const t=e.children.map(n=>rl(n)?ng(n):ol(n)).join("");switch(e.type){case"blockquote":return`<blockquote>${t}</blockquote>`;case"a":{const n=e.url??"";return`<a href="${al(n)}">${t}</a>`}default:return`<p>${t}</p>`}},to=e=>e.map(ol).join(""),il=e=>rl(e)?e.text:e.children.map(il).join(""),wr=e=>e.map(il).join(`
|
|
110
|
-
`),rg=e=>e.displayName?`${e.displayName} <${e.normalizedEmail}>`:e.normalizedEmail,so=e=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.trim()),ag=e=>{const t=e.trim();if(!t)return;const n=t.match(/^(.+?)\s*<([^>]+)>$/);if(n){const r=n[1].trim(),a=n[2].trim();if(so(a))return{email:a,displayName:r}}if(so(t))return{email:t}},rr=({label:e,addresses:t,onChange:n,placeholder:r})=>{const[a,o]=c.useState(""),[i,l]=c.useState(-1),[u,d]=c.useState(!1),m=c.useRef(null),f=c.useRef(null),h=Xo(a,200),{data:x}=ue({...Uo({query:{q:h,limit:8}}),enabled:h.length>=2}),b=x?.items??[],p=new Set(t.map(S=>S.email.toLowerCase())),v=b.filter(S=>!p.has(S.normalizedEmail.toLowerCase()));c.useEffect(()=>{l(-1),d(v.length>0&&a.length>=2)},[v.length,a.length]);const g=c.useCallback(S=>{p.has(S.email.toLowerCase())||(n([...t,S]),o(""),d(!1))},[t,p,n]),y=c.useCallback(S=>{n(t.filter((N,I)=>I!==S))},[t,n]),j=c.useCallback(S=>{g({email:S.normalizedEmail,displayName:S.displayName}),m.current?.focus()},[g]),w=c.useCallback(()=>{const S=ag(a);S&&g(S)},[a,g]),C=c.useCallback(S=>{if(S.key==="Backspace"&&a===""&&t.length>0){y(t.length-1);return}if(S.key==="Enter"||S.key==="Tab"||S.key===","){if(i>=0&&v[i]){S.preventDefault(),j(v[i]);return}a.trim()&&(S.preventDefault(),w());return}if(S.key==="ArrowDown"&&u){S.preventDefault(),l(N=>N<v.length-1?N+1:0);return}if(S.key==="ArrowUp"&&u){S.preventDefault(),l(N=>N>0?N-1:v.length-1);return}S.key==="Escape"&&(d(!1),l(-1))},[a,t.length,i,v,u,y,j,w]),k=c.useCallback(()=>{setTimeout(()=>{w(),d(!1)},150)},[w]);return s.jsxs("div",{className:"relative",children:[s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("label",{htmlFor:`address-field-${e}`,className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:[e,":"]}),s.jsxs("div",{className:"flex-1 flex flex-wrap items-center gap-1 min-h-[36px] px-2 py-1 border rounded-md bg-canvas cursor-text",onClick:()=>m.current?.focus(),onKeyDown:S=>{(S.key==="Enter"||S.key===" ")&&m.current?.focus()},children:[t.map((S,N)=>s.jsx(Ju,{email:S.email,displayName:S.displayName,onRemove:()=>y(N)},S.email)),s.jsx("input",{ref:m,id:`address-field-${e}`,type:"text",value:a,onChange:S=>o(S.target.value),onKeyDown:C,onBlur:k,placeholder:t.length===0?r:"",className:"flex-1 min-w-[120px] bg-transparent outline-none text-sm py-0.5"})]})]}),u&&v.length>0&&s.jsx("ul",{ref:f,className:"absolute left-12 right-0 mt-1 bg-surface border border-line rounded-md shadow-lg z-50 max-h-[200px] overflow-auto",children:v.map((S,N)=>s.jsx("li",{className:de("px-3 py-2 text-sm cursor-pointer transition-colors",N===i&&"bg-accent-2-soft"),onMouseDown:I=>{I.preventDefault(),j(S)},onMouseEnter:()=>l(N),children:rg(S)},S.addressId))})]})},og=({accountId:e})=>{const t=Me();return s.jsxs("div",{role:"alert","data-testid":"compose-smtp-missing-banner",className:"flex items-start gap-3 border-b border-warning/50 bg-warning/10 px-3 py-2",children:[s.jsx(Tr,{className:"size-5 shrink-0 mt-0.5 text-warning","aria-hidden":"true"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"text-sm font-medium text-warning",children:"This account can't send mail until SMTP is configured."}),s.jsxs("button",{type:"button",onClick:()=>{t({to:"/settings/accounts",search:{editAccountId:e,focusSmtp:!0}})},className:"mt-1 inline-flex items-center gap-1 text-xs font-medium text-warning hover:underline",children:["Configure SMTP",s.jsx(zu,{className:"size-3","aria-hidden":"true"})]})]})]})},jr=e=>{const[t,n]=c.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return c.useEffect(()=>{if(typeof window>"u"||!window.matchMedia)return;const r=window.matchMedia(e),a=o=>n(o.matches);return n(r.matches),r.addEventListener("change",a),()=>r.removeEventListener("change",a)},[e]),t},Qt=()=>jr("(min-width: 1024px)"),no=150,ig=()=>{const[e,t]=c.useState(()=>{if(typeof window>"u"||!window.visualViewport)return{viewportHeight:0,isKeyboardOpen:!1};const n=window.visualViewport.height;return{viewportHeight:n,isKeyboardOpen:window.innerHeight-n>no}});return c.useEffect(()=>{if(typeof window>"u"||!window.visualViewport)return;const n=window.visualViewport,r=()=>{const a=n.height;t({viewportHeight:a,isKeyboardOpen:window.innerHeight-a>no})};return r(),n.addEventListener("resize",r),()=>n.removeEventListener("resize",r)},[]),e},lg=({selectedAccountId:e,onSelect:t})=>{const{data:n}=ue({...ht(),staleTime:1/0}),r=n?.accounts??[];if(c.useEffect(()=>{!e&&r.length===1&&r[0]&&t(r[0])},[e,r,t]),r.length<=1){const a=r[0];return a?s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx("label",{className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:"From:"}),s.jsx("div",{className:"text-sm py-1.5",children:a.email})]}):null}return s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx("label",{htmlFor:"from-account-selector",className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:"From:"}),s.jsx("select",{id:"from-account-selector",value:e??"",onChange:a=>{const o=r.find(i=>i.accountId===a.target.value);o&&t(o)},className:"flex-1 px-2 py-1.5 border rounded-md bg-canvas text-sm",children:r.map(a=>s.jsx("option",{value:a.accountId,children:a.email},a.accountId))})]})},cg=({value:e,onChange:t})=>s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx("label",{className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:"Subj:"}),s.jsx("input",{type:"text",value:e,onChange:n=>t(n.target.value),className:"flex-1 px-2 py-1.5 border rounded-md bg-canvas text-sm",placeholder:"Subject","data-subject-field":!0})]}),ug=["p","br","strong","b","em","i","a","blockquote","ul","ol","li"],dg=["href"],fg=e=>Po.sanitize(e,{ALLOWED_TAGS:ug,ALLOWED_ATTR:dg}),mg=c.lazy(()=>Zc(()=>import("./ComposeBody-ByyX2-iG.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16])).then(e=>({default:e.ComposeBody}))),hg=()=>s.jsxs("div",{className:"min-h-[120px] px-3 py-2",children:[s.jsx("div",{className:"h-8 mb-2 rounded bg-surface-sunken animate-pulse"}),s.jsx("div",{className:"min-h-[80px] rounded bg-surface-sunken/50 animate-pulse"})]}),ll=[{type:"p",children:[{text:""}]}],gg=[{type:"p",children:[{text:""}]},{type:"p",children:[{text:"-- "}]}],pg=e=>e?[...gg,{type:"p",children:[{text:e}]}]:ll,xg=e=>e?/^re:\s/i.test(e)?e:`Re: ${e}`:"Re: ",bg=e=>e?/^fwd?:\s/i.test(e)?e:`Fwd: ${e}`:"Fwd: ",vg=(e,t,n)=>{const{envelope:r}=e,o=(r.replyTo.length>0?r.replyTo:r.from).map(d=>({email:d.normalizedEmail,displayName:d.displayName}));if(t!=="reply_all")return{to:o,cc:[]};const i=n?.toLowerCase(),l=new Set(o.map(d=>d.email.toLowerCase())),u=[...r.to,...r.cc].filter(d=>d.normalizedEmail.toLowerCase()!==i&&!l.has(d.normalizedEmail.toLowerCase())).map(d=>({email:d.normalizedEmail,displayName:d.displayName}));return{to:o,cc:u}},yg=e=>{const t=e.envelope.messageIdValue,r=[...e.references.filter(a=>a.referenceType==="references").sort((a,o)=>a.referenceOrder-o.referenceOrder).map(a=>a.messageIdValue)];return t&&!r.includes(t)&&r.push(t),{inReplyTo:t,references:r}},wg=(e,t,n,r,a)=>e.length===0&&t.length===0&&n.length===0&&r.trim()===""&&wr(a).trim()==="",jg=({selectedAccountId:e,onAccountChange:t,toAddresses:n,setToAddresses:r,ccAddresses:a,setCcAddresses:o,bccAddresses:i,setBccAddresses:l,showCc:u,setShowCc:d,showBcc:m,setShowBcc:f,subject:h,setSubject:x})=>{const b=Qt(),{isKeyboardOpen:p}=ig();if(!b&&p){const g=[];return n.length>0&&g.push(`To: ${n.map(y=>y.displayName??y.email).join(", ")}`),a.length>0&&g.push(`Cc: ${a.length}`),i.length>0&&g.push(`Bcc: ${i.length}`),h&&g.push(h),s.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-line overflow-hidden","data-testid":"compose-header-collapsed",children:[s.jsx("span",{className:"truncate text-xs text-fg-muted",children:g.length>0?g.join(" · "):"…"}),s.jsx("span",{className:"shrink-0 inline-flex items-center justify-center rounded bg-surface-sunken px-1.5 py-0.5 text-2xs text-fg-muted",children:"…"})]})}return s.jsxs("div",{className:"space-y-1 px-3 py-2 border-b border-line",children:[s.jsx(lg,{selectedAccountId:e,onSelect:t}),s.jsx(rr,{label:"To",addresses:n,onChange:r,placeholder:"Recipients"}),u?s.jsx(rr,{label:"Cc",addresses:a,onChange:o}):s.jsxs("div",{className:"flex gap-2 pl-14",children:[s.jsx("button",{type:"button",onClick:()=>d(!0),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:"Cc"}),s.jsx("button",{type:"button",onClick:()=>f(!0),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:"Bcc"})]}),u&&!m&&s.jsx("div",{className:"pl-14",children:s.jsx("button",{type:"button",onClick:()=>f(!0),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:"Bcc"})}),m&&s.jsx(rr,{label:"Bcc",addresses:i,onChange:l}),s.jsx(cg,{value:h,onChange:x})]})},Zr=({mode:e,account:t,sourceMessage:n,onClose:r,onAccountChange:a})=>{const{state:o,setOutboxMessageId:i,startSendPolling:l}=It(),{pushError:u}=qe(),{outboxMessageId:d}=o,[m,f]=c.useState([]),[h,x]=c.useState([]),[b,p]=c.useState([]),[v,g]=c.useState(""),[y,j]=c.useState(!1),[w,C]=c.useState(!1),[k,S]=c.useState(t?.accountId),[N,I]=c.useState(!1),T=c.useRef(d);c.useEffect(()=>{T.current!==d&&(T.current=d,d&&(f([]),x([]),p([]),g(""),j(!1),C(!1),R(ll),I(!1)))},[d]);const{signature:E}=Mu(k),[M,R]=c.useState(()=>pg(E.plainText)),{data:A}=ue({...Jc({path:{outboxMessageId:d??""}}),enabled:!!d&&!N});c.useEffect(()=>{!A||N||(f(A.toAddresses.map(U=>({email:U,displayName:void 0}))),A.ccAddresses&&A.ccAddresses.length>0&&(x(A.ccAddresses.map(U=>({email:U,displayName:void 0}))),j(!0)),A.bccAddresses&&A.bccAddresses.length>0&&(p(A.bccAddresses.map(U=>({email:U,displayName:void 0}))),C(!0)),A.subject&&g(A.subject),A.textBody&&R([{type:"p",children:[{text:A.textBody}]}]),S(A.accountId),I(!0))},[A,N]),c.useEffect(()=>{if(n){if(e==="reply"||e==="reply_all"){const{to:U,cc:z}=vg(n,e,t?.email);f(U),x(z),z.length>0&&j(!0),g(xg(n.envelope.subject))}e==="forward"&&g(bg(n.envelope.subject))}},[e,n,t?.email]);const D=e==="reply"||e==="reply_all"||e==="forward",{data:F}=nl({messageId:n?.message.messageId,bodyParts:n?.bodyParts,enabled:D&&!!n}),$=F?.kind==="text"?F.body:"",te=F?.kind==="html"?fg(F.body):void 0,q=n?.envelope.from[0]?.displayName??n?.envelope.from[0]?.normalizedEmail,{saveStatus:Q,saveError:X,saveDraft:ee,cancelAutoSave:se}=sg({outboxMessageId:d,onDraftCreated:i});c.useEffect(()=>{X&&u({title:"Couldn't save draft",detail:st(X)??"Saving the draft failed.",error:X})},[X,u]);const P=pe(qo()),_=pe(Qo()),H=pe({...jn(),onError:U=>{u(zt("Couldn't discard draft","The draft wasn't discarded.",U))}}),{data:W}=ue({...ht(),staleTime:1/0}),le=W?.accounts.find(U=>U.accountId===k),me=le?ku(le):!1,J=P.isPending||_.isPending,Ie=m.length>0&&!!k&&!me;c.useEffect(()=>{if(!k||d&&!N||wg(m,h,b,v,M))return;const U=wr(M),z=to(M);ee({accountId:k,toAddresses:m.map(ne=>ne.email),ccAddresses:h.length>0?h.map(ne=>ne.email):void 0,bccAddresses:b.length>0?b.map(ne=>ne.email):void 0,subject:v||void 0,textBody:U||void 0,htmlBody:z||void 0})},[k,d,N,m,h,b,v,M,ee]);const he=c.useCallback(async()=>{if(!k||m.length===0)return;se();const U=n&&(e==="reply"||e==="reply_all")?yg(n):{};let z=d,ne=!1;if(!z){const Qe=wr(M),Pe=to(M),Te=await P.mutateAsync({body:{accountId:k,toAddresses:m.map(xe=>xe.email),ccAddresses:h.length>0?h.map(xe=>xe.email):void 0,bccAddresses:b.length>0?b.map(xe=>xe.email):void 0,subject:v||void 0,textBody:Qe||void 0,htmlBody:Pe||void 0,sendImmediately:!0,...U}}).catch(xe=>(u({title:"Couldn't send message",detail:st(xe)??"Saving the draft failed.",error:xe}),null));if(Te===null)return;z=Te.outboxMessageId,ne=!0,i(z)}await _.mutateAsync({path:{outboxMessageId:z}}).catch(Qe=>(u({title:"Couldn't send message",detail:st(Qe)??(ne?"The draft was saved but the send request failed. Try again from the Outbox.":"The send request failed. Try again."),error:Qe}),null))!==null&&(l(z),r())},[k,m,h,b,v,M,e,n,d,P,_,se,l,i,u,r]),ke=c.useCallback(()=>{se(),d&&H.mutate({path:{outboxMessageId:d}}),r()},[se,d,H,r]),Y=c.useCallback(U=>{S(U.accountId),a?.(U)},[a]);return s.jsx(df,{banner:le&&me?s.jsx(og,{accountId:le.accountId}):void 0,header:s.jsx(jg,{selectedAccountId:k,onAccountChange:Y,toAddresses:m,setToAddresses:f,ccAddresses:h,setCcAddresses:x,bccAddresses:b,setBccAddresses:p,showCc:y,setShowCc:j,showBcc:w,setShowBcc:C,subject:v,setSubject:g}),quoted:$||te?s.jsx(Lf,{text:$,html:te,senderName:q}):void 0,actionBar:s.jsx(uf,{onSend:he,onDiscard:ke,sending:J,canSend:Ie,saveStatus:Q,unavailableReason:me?"SMTP not configured":void 0,onUnavailable:U=>u({title:"Can't send yet",detail:U})}),children:s.jsx(c.Suspense,{fallback:s.jsx(hg,{}),children:s.jsx(mg,{value:M,onChange:R,onSubmit:he,autoFocus:e==="new"})})})},ro=({mode:e,account:t,sourceMessage:n,onClose:r})=>s.jsx("div",{className:"border-t border-line bg-canvas max-h-[400px] flex flex-col",children:s.jsx(Zr,{mode:e,account:t,sourceMessage:n,onClose:r})}),cl=({message:e,icon:t})=>s.jsxs("div",{className:"flex flex-col items-center justify-center p-8 text-center",children:[t&&s.jsx("div",{className:"mb-4 text-fg-muted",children:t}),s.jsx("p",{className:"text-fg-muted",children:e})]}),ea=({enabled:e=!0,bindings:t,capture:n=!1})=>{const r=c.useCallback(a=>{const o=a.target;if(!(o.tagName==="INPUT"||o.tagName==="TEXTAREA"||o.isContentEditable))for(const i of t){if(!(a.key.toLowerCase()===i.key.toLowerCase())||i.requireShift!==void 0&&i.requireShift!==a.shiftKey)continue;const u=a.ctrlKey||a.metaKey;if(i.requireMeta!==void 0){if(i.requireMeta!==u)continue}else{const d=i.noModifiers??!0,m=u||a.altKey||i.requireShift===void 0&&a.shiftKey;if(d&&m)continue}i.preventDefault&&a.preventDefault(),i.stopPropagation&&(a.stopPropagation(),a.stopImmediatePropagation()),i.handler(a);return}},[t]);c.useEffect(()=>{if(e)return window.addEventListener("keydown",r,n),()=>window.removeEventListener("keydown",r,n)},[e,r,n])},ul=e=>{const{data:t,isLoading:n}=ue({...ht(),staleTime:1/0}),r=c.useMemo(()=>(t?.accounts??[]).map(l=>l.accountId),[t?.accounts]),a=Ut({queries:r.map(l=>({...rt({path:{accountId:l}}),staleTime:1/0,enabled:!!e}))}),o=n||a.some(l=>l.isLoading);return{accountId:c.useMemo(()=>{if(e){for(let l=0;l<r.length;l++)if((a[l].data?.items??[]).some(m=>m.mailboxId===e))return r[l]}},[e,r,a]),isLoading:o}},Sg=e=>typeof e=="object"&&e!==null&&Array.isArray(e.pages),kg=e=>typeof e=="object"&&e!==null&&Array.isArray(e.items),cs=(e,t)=>e===void 0?e:Sg(e)?{...e,pages:e.pages.map(n=>({...n,items:t(n.items)}))}:kg(e)?{...e,items:t(e.items)}:e,Ng=(e,t,n)=>{const r=new Map(t.map(o=>[o.messageId,o.mailboxId])),a=new Set;for(const o of e)a.add(r.get(o)??n);return[...a]},ao=(e,t,n)=>e.map(r=>t.has(r.messageId)?{...r,isRead:n}:r),Cg=(e,t,n,r)=>e.filter(a=>!a.isRead&&t.has(a.threadMessageId)&&!n.has(a.messageId)&&!r.has(a.messageId)).map(a=>a.messageId),Eg=({messages:e,expandedIds:t,threadId:n,mailboxId:r,accountId:a})=>{const o=je(),{pushError:i}=qe(),l=c.useRef(new Set),u=c.useRef(new Set),{mutate:d}=pe({...Sn(),onMutate:async h=>{const x=new Set(h.body.messageIds??[]),b=h.body.isRead??!0,p=$t({path:{threadId:n}}),v=Ng(x,e,r),g=v.map(k=>at({path:{mailboxId:k}})),y=v.map(k=>gt({path:{mailboxId:k}}));await Promise.all([o.cancelQueries({queryKey:p}),...g.map(k=>o.cancelQueries({queryKey:k})),...y.map(k=>o.cancelQueries({queryKey:k}))]);const j=o.getQueriesData({queryKey:p}).filter(k=>k[1]!==void 0).map(([k,S])=>({queryKey:k,data:S})),w=[...g,...y].flatMap(k=>o.getQueriesData({queryKey:k})).filter(k=>k[1]!==void 0).map(([k,S])=>({queryKey:k,data:S}));o.setQueriesData({queryKey:p},k=>k&&{...k,items:ao(k.items,x,b)});const C=k=>cs(k,S=>ao(S,x,b));for(const k of[...g,...y])o.setQueriesData({queryKey:k},C);return{threadMessagesPrefix:p,threadsListPrefixes:g,threadsSearchPrefixes:y,previousThreadMessages:j,previousThreadsList:w}},onSuccess:(h,x)=>{const b=x.body.messageIds??[];for(const p of b)l.current.add(p),u.current.delete(p)},onError:(h,x,b)=>{const p=x.body.messageIds??[];for(const g of p)u.current.delete(g);if(b){for(const g of b.previousThreadMessages)o.setQueryData(g.queryKey,g.data);for(const g of b.previousThreadsList)o.setQueryData(g.queryKey,g.data)}const v=x.body.isRead??!0;i({title:v?"Couldn't mark as read":"Couldn't mark as unread",detail:st(h),error:h})},onSettled:(h,x,b,p)=>{if(p){o.invalidateQueries({queryKey:p.threadMessagesPrefix});for(const v of[...p.threadsListPrefixes,...p.threadsSearchPrefixes])o.invalidateQueries({queryKey:v});a&&o.invalidateQueries({queryKey:Bt({path:{accountId:a}})})}}}),m=c.useCallback(h=>{const x=h.filter(b=>!l.current.has(b)&&!u.current.has(b));if(x.length!==0){for(const b of x)u.current.add(b);d({body:{messageIds:x,isRead:!0}})}},[d]),f=c.useMemo(()=>Cg(e,t,l.current,u.current),[e,t]);c.useEffect(()=>{f.length!==0&&m(f)},[f,m]),c.useEffect(()=>{l.current.clear(),u.current.clear()},[n])},dl=e=>{const{mailboxId:t,accountId:n}=e,r=je(),{pushError:a}=qe(),{mutate:o,isPending:i}=pe({...Sn(),onError:(u,d)=>{const m=d.body.isRead??!0;a({title:m?"Couldn't mark as read":"Couldn't mark as unread",detail:st(u),error:u})},onSettled:()=>{r.invalidateQueries({queryKey:at({path:{mailboxId:t}})}),r.invalidateQueries({queryKey:gt({path:{mailboxId:t}})}),n&&r.invalidateQueries({queryKey:Bt({path:{accountId:n}})})}});return{toggleReadFor:c.useCallback((u,d)=>{u.length!==0&&o({body:{messageIds:u,isRead:d}})},[o]),isPending:i}},Ig=60,Rg=1.5,Mg=(e,t,n)=>{const r=Math.abs(e),a=Math.abs(t);return r<n?{direction:null}:r<a*Rg?{direction:null}:{direction:e<0?"left":"right"}},Tg=({onSwipeLeft:e,onSwipeRight:t,thresholdPx:n=Ig})=>{const r=c.useRef(null),a=c.useCallback(u=>{if(u.pointerType==="mouse"){r.current=null;return}r.current={x:u.clientX,y:u.clientY}},[]),o=c.useCallback(()=>{},[]),i=c.useCallback(u=>{const d=r.current;if(r.current=null,!d)return;const{direction:m}=Mg(u.clientX-d.x,u.clientY-d.y,n);m==="left"&&e?.(),m==="right"&&t?.()},[e,t,n]),l=c.useCallback(()=>{r.current=null},[]);return{handlers:{onPointerDown:a,onPointerMove:o,onPointerUp:i,onPointerCancel:l}}},Dg=(e,t,n)=>t?.find(r=>r.messageId===e)?.mailboxId??n,oo=(e,t,n)=>e.map(r=>r.messageId===t?{...r,hasStars:n}:r),Sr=({threadId:e,mailboxId:t,messages:n})=>{const r=je(),{pushError:a}=qe(),{mutate:o,isPending:i,variables:l}=pe({...eu(),onMutate:async d=>{const m=d.path.messageId,f=d.body.isStarred??!1,h=$t({path:{threadId:e}}),x=Dg(m,n,t),b=at({path:{mailboxId:x}}),p=gt({path:{mailboxId:x}}),v=Ho();await Promise.all([r.cancelQueries({queryKey:h}),r.cancelQueries({queryKey:b}),r.cancelQueries({queryKey:p}),r.cancelQueries({queryKey:v})]);const g=r.getQueriesData({queryKey:h}).filter(k=>k[1]!==void 0).map(([k,S])=>({queryKey:k,data:S})),y=r.getQueriesData({queryKey:b}).concat(r.getQueriesData({queryKey:p})).filter(k=>k[1]!==void 0).map(([k,S])=>({queryKey:k,data:S})),j=r.getQueriesData({queryKey:v}).filter(k=>k[1]!==void 0).map(([k,S])=>({queryKey:k,data:S})),w=k=>cs(k,S=>oo(S,m,f));r.setQueriesData({queryKey:h},w),r.setQueriesData({queryKey:v},w);const C=k=>cs(k,S=>oo(S,m,f));return r.setQueriesData({queryKey:b},C),r.setQueriesData({queryKey:p},C),{threadMessagesPrefix:h,threadsListPrefix:b,threadsSearchPrefix:p,unifiedThreadsPrefix:v,previousThreadMessages:g,previousThreadsList:y,previousUnifiedThreads:j}},onError:(d,m,f)=>{if(f){for(const x of f.previousThreadMessages)r.setQueryData(x.queryKey,x.data);for(const x of f.previousThreadsList)r.setQueryData(x.queryKey,x.data);for(const x of f.previousUnifiedThreads)r.setQueryData(x.queryKey,x.data)}const h=m.body.isStarred??!1;a({title:h?"Couldn't star message":"Couldn't unstar message",detail:st(d),error:d})},onSettled:(d,m,f,h)=>{h&&(r.invalidateQueries({queryKey:h.threadMessagesPrefix}),r.invalidateQueries({queryKey:h.threadsListPrefix}),r.invalidateQueries({queryKey:h.threadsSearchPrefix}),r.invalidateQueries({queryKey:h.unifiedThreadsPrefix}))}});return{toggleStar:(d,m)=>{o({path:{messageId:d},body:{isStarred:!m}})},isPending:i,pendingMessageId:i?l?.path.messageId:void 0}};function Tn(e){return e===void 0?"uncategorized":e}const tt={uncategorized:"uncategorized",personal:"personal",newsletter:"newsletter",marketing:"marketing",automated:"automated",transactional:"transactional",social:"social"},io={MoveToInbox:"MoveToInbox",MoveToJunk:"MoveToJunk"},Ag={inbox:"Inbox",junk:"Junk"},Og=e=>`Moved from ${Ag[e]??"another folder"} by Remit`,Pg=(e,t)=>{if(e===io.MoveToInbox)return t.inboxMailboxId;if(e===io.MoveToJunk)return t.junkMailboxId},Lg=(e,t,n)=>{if(!e||!t)return!1;const r=Pg(e.action,n);return r!==void 0&&r===t},zg=(e,t)=>{if(e==="inbox")return t.inboxMailboxId;if(e==="junk")return t.junkMailboxId},Dn=(e,t)=>{const{data:n,isLoading:r}=ue({...ht(),staleTime:1/0,enabled:!!e});return{mailboxId:c.useMemo(()=>e?n?.accounts.find(i=>i.accountId===e)?.folderAppointments.find(i=>i.role===t)?.mailboxId:void 0,[n,e,t]),isLoading:r}},Fg=e=>{const{mailboxId:t,isLoading:n}=Dn(e,"Archive");return{archiveMailboxId:t,isLoading:n}},_g=e=>{const{mailboxId:t,isLoading:n}=Dn(e,"Drafts");return{draftsMailboxId:t,isLoading:n}},ta=e=>{const{mailboxId:t,isLoading:n}=Dn(e,"Inbox");return{inboxMailboxId:t,isLoading:n}},sa=e=>{const{mailboxId:t,isLoading:n}=Dn(e,"Junk");return{junkMailboxId:t,isLoading:n}},fl=e=>{const{data:t}=ue({...ht(),staleTime:1/0,enabled:!!e});return c.useMemo(()=>t?.accounts.find(n=>n.accountId===e)?.folderAppointments??[],[t,e])},lo=(e,t)=>e.filter(n=>!t.has(n.messageId)),Ct=({mailboxId:e,threadId:t,accountId:n,onAfterOptimisticRemove:r})=>{const a=je(),{pushError:o}=qe(),{mutate:i,isPending:l}=pe({...tu(),onMutate:async d=>{const m=new Set(d.body.messageIds??[]),f=t?$t({path:{threadId:t}}):[],h=at({path:{mailboxId:e}}),x=gt({path:{mailboxId:e}});await Promise.all([...t?[a.cancelQueries({queryKey:f})]:[],a.cancelQueries({queryKey:h}),a.cancelQueries({queryKey:x})]);const b=t?a.getQueriesData({queryKey:f}).filter(g=>g[1]!==void 0).map(([g,y])=>({queryKey:g,data:y})):[],p=a.getQueriesData({queryKey:h}).concat(a.getQueriesData({queryKey:x})).filter(g=>g[1]!==void 0).map(([g,y])=>({queryKey:g,data:y}));t&&a.setQueriesData({queryKey:f},g=>g&&{...g,items:lo(g.items,m)});const v=g=>cs(g,y=>lo(y,m));return a.setQueriesData({queryKey:h},v),a.setQueriesData({queryKey:x},v),r?.(Array.from(m)),{threadMessagesPrefix:f,threadsListPrefix:h,threadsSearchPrefix:x,previousThreadMessages:b,previousThreadsList:p}},onError:(d,m,f)=>{if(f){for(const x of f.previousThreadMessages)a.setQueryData(x.queryKey,x.data);for(const x of f.previousThreadsList)a.setQueryData(x.queryKey,x.data)}const h=m.body.messageIds?.length??0;o({title:h>1?`Couldn't move ${h} messages`:"Couldn't move this message",detail:st(d),error:d})},onSettled:(d,m,f,h)=>{h&&(t&&a.invalidateQueries({queryKey:h.threadMessagesPrefix}),a.invalidateQueries({queryKey:h.threadsListPrefix}),a.invalidateQueries({queryKey:h.threadsSearchPrefix}),n&&a.invalidateQueries({queryKey:Bt({path:{accountId:n}})}))}});return{moveMessages:c.useCallback((d,m)=>{d.length!==0&&i({body:{messageIds:d,destinationMailboxId:m}})},[i]),isPending:l}},Bg=({accountId:e,messageId:t,threadId:n,mailboxId:r,autoMoved:a})=>{const{inboxMailboxId:o}=ta(e),{junkMailboxId:i}=sa(e),{moveMessages:l,isPending:u}=Ct({mailboxId:r,threadId:n,accountId:e}),d={inboxMailboxId:o,junkMailboxId:i},m=Lg(a,r,d),f=a?zg(a.fromPlacement,d):void 0,h=c.useCallback(()=>{f&&l([t],f)},[l,t,f]);return!m||!a?{show:!1,label:"",isUndoing:!1}:{show:!0,label:Og(a.fromPlacement),onUndo:f?h:void 0,isUndoing:u}};function ml({accountId:e,messageId:t,threadId:n,mailboxId:r,autoMoved:a,size:o="sm"}){const i=Bg({accountId:e,messageId:t,threadId:n,mailboxId:r,autoMoved:a});return i.show?s.jsx(ef,{label:i.label,size:o,onUndo:i.onUndo,undoLabel:i.isUndoing?"Undoing…":"Undo"}):null}const co=(e,t)=>e.filter(n=>!t.has(n.messageId)),$g=e=>e.filter(t=>t.isDeleted!==!0),As=({mailboxId:e,threadId:t,accountId:n,onAfterOptimisticRemove:r})=>{const a=je(),{pushError:o}=qe(),{mutate:i,isPending:l}=pe({...su(),onMutate:async d=>{const m=new Set(d.body.messageIds??[]),f=t?$t({path:{threadId:t}}):[],h=at({path:{mailboxId:e}}),x=gt({path:{mailboxId:e}});await Promise.all([a.cancelQueries({queryKey:f}),a.cancelQueries({queryKey:h}),a.cancelQueries({queryKey:x})]);const b=t?a.getQueriesData({queryKey:f}).filter(g=>g[1]!==void 0).map(([g,y])=>({queryKey:g,data:y})):[],p=a.getQueriesData({queryKey:h}).concat(a.getQueriesData({queryKey:x})).filter(g=>g[1]!==void 0).map(([g,y])=>({queryKey:g,data:y}));t&&a.setQueriesData({queryKey:f},g=>g&&{...g,items:co(g.items,m)});const v=g=>cs(g,y=>co(y,m));return a.setQueriesData({queryKey:h},v),a.setQueriesData({queryKey:x},v),r?.(Array.from(m)),{threadMessagesPrefix:f,threadsListPrefix:h,threadsSearchPrefix:x,previousThreadMessages:b,previousThreadsList:p}},onError:(d,m,f)=>{if(f){for(const x of f.previousThreadMessages)a.setQueryData(x.queryKey,x.data);for(const x of f.previousThreadsList)a.setQueryData(x.queryKey,x.data)}const h=m.body.messageIds?.length??0;o({title:h>1?`Couldn't delete ${h} messages`:"Couldn't delete this message",detail:st(d),error:d})},onSettled:(d,m,f,h)=>{h&&(t&&a.invalidateQueries({queryKey:h.threadMessagesPrefix}),a.invalidateQueries({queryKey:h.threadsListPrefix}),a.invalidateQueries({queryKey:h.threadsSearchPrefix}),n&&a.invalidateQueries({queryKey:Bt({path:{accountId:n}})}))}});return{deleteMessages:c.useCallback(d=>{d.length!==0&&i({body:{messageIds:d}})},[i]),isPending:l}},hl=(e,t=Date.now())=>({value:e,setAt:t}),Kg=(e,t,n,r)=>{if(e.addressId!==t)return e;const a={...e.flags??{}};return n?a.trusted=hl(!0,r):delete a.trusted,{...e,flags:a}},qg=(e,t,n,r)=>{const a=o=>o.map(i=>Kg(i,t,n,r));return{...e,envelope:{...e.envelope,from:a(e.envelope.from),to:a(e.envelope.to),cc:a(e.envelope.cc),bcc:a(e.envelope.bcc),replyTo:a(e.envelope.replyTo)}}},na=({messageId:e})=>{const t=je(),{pushError:n}=qe(),{mutate:r,isPending:a,error:o,reset:i}=pe({...Wo(),onMutate:async u=>{const d=u.path.addressId,f=u.body.flags?.trusted?.value===!0,h=Ko({path:{messageId:e}});await t.cancelQueries({queryKey:h});const x=t.getQueriesData({queryKey:h}).filter(b=>b[1]!==void 0).map(([b,p])=>({queryKey:b,data:p}));return t.setQueriesData({queryKey:h},b=>b&&qg(b,d,f)),{describePrefix:h,previous:x}},onError:(u,d,m)=>{if(m)for(const f of m.previous)t.setQueryData(f.queryKey,f.data);n(zt("Couldn't trust sender","The change wasn't saved.",u))},onSettled:(u,d,m,f)=>{f&&t.invalidateQueries({queryKey:f.describePrefix})}});return{toggleTrusted:(u,d)=>{r({path:{addressId:u},body:{flags:{trusted:hl(!d)}}})},isPending:a,error:o,reset:i}};var An="Dialog",[gl]=tm(An),[Ug,Je]=gl(An),pl=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:a,onOpenChange:o,modal:i=!0}=e,l=c.useRef(null),u=c.useRef(null),[d,m]=rm({prop:r,defaultProp:a??!1,onChange:o,caller:An});return s.jsx(Ug,{scope:t,triggerRef:l,contentRef:u,contentId:Zn(),titleId:Zn(),descriptionId:Zn(),open:d,onOpenChange:m,onOpenToggle:c.useCallback(()=>m(f=>!f),[m]),modal:i,children:n})};pl.displayName=An;var xl="DialogTrigger",Qg=c.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,a=Je(xl,n),o=qt(t,a.triggerRef);return s.jsx(pt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":aa(a.open),...r,ref:o,onClick:Nt(e.onClick,a.onOpenToggle)})});Qg.displayName=xl;var ra="DialogPortal",[Hg,bl]=gl(ra,{forceMount:void 0}),vl=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:a}=e,o=Je(ra,t);return s.jsx(Hg,{scope:t,forceMount:n,children:c.Children.map(r,i=>s.jsx(Cn,{present:n||o.open,children:s.jsx(Li,{asChild:!0,container:a,children:i})}))})};vl.displayName=ra;var pn="DialogOverlay",yl=c.forwardRef((e,t)=>{const n=bl(pn,e.__scopeDialog),{forceMount:r=n.forceMount,...a}=e,o=Je(pn,e.__scopeDialog);return o.modal?s.jsx(Cn,{present:r||o.open,children:s.jsx(Vg,{...a,ref:t})}):null});yl.displayName=pn;var Wg=Vr("DialogOverlay.RemoveScroll"),Vg=c.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,a=Je(pn,n),o=Sm(),i=qt(t,o);return s.jsx(Ui,{as:Wg,allowPinchZoom:!0,shards:[a.contentRef],children:s.jsx(pt.div,{"data-state":aa(a.open),...r,ref:i,style:{pointerEvents:"auto",...r.style}})})}),us="DialogContent",wl=c.forwardRef((e,t)=>{const n=bl(us,e.__scopeDialog),{forceMount:r=n.forceMount,...a}=e,o=Je(us,e.__scopeDialog);return s.jsx(Cn,{present:r||o.open,children:o.modal?s.jsx(Yg,{...a,ref:t}):s.jsx(Gg,{...a,ref:t})})});wl.displayName=us;var Yg=c.forwardRef((e,t)=>{const n=Je(us,e.__scopeDialog),r=c.useRef(null),a=qt(t,n.contentRef,r);return c.useEffect(()=>{const o=r.current;if(o)return Qm(o)},[]),s.jsx(jl,{...e,ref:a,trapFocus:n.open,disableOutsidePointerEvents:n.open,onCloseAutoFocus:Nt(e.onCloseAutoFocus,o=>{o.preventDefault(),n.triggerRef.current?.focus()}),onPointerDownOutside:Nt(e.onPointerDownOutside,o=>{const i=o.detail.originalEvent,l=i.button===0&&i.ctrlKey===!0;(i.button===2||l)&&o.preventDefault()}),onFocusOutside:Nt(e.onFocusOutside,o=>o.preventDefault())})}),Gg=c.forwardRef((e,t)=>{const n=Je(us,e.__scopeDialog),r=c.useRef(!1),a=c.useRef(!1);return s.jsx(jl,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{e.onCloseAutoFocus?.(o),o.defaultPrevented||(r.current||n.triggerRef.current?.focus(),o.preventDefault()),r.current=!1,a.current=!1},onInteractOutside:o=>{e.onInteractOutside?.(o),o.defaultPrevented||(r.current=!0,o.detail.originalEvent.type==="pointerdown"&&(a.current=!0));const i=o.target;n.triggerRef.current?.contains(i)&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&a.current&&o.preventDefault()}})}),jl=c.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:a,onCloseAutoFocus:o,...i}=e,l=Je(us,n);return Em(),s.jsx(s.Fragment,{children:s.jsx(Oi,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:a,onUnmountAutoFocus:o,children:s.jsx(Di,{role:"dialog",id:l.contentId,"aria-describedby":l.descriptionId,"aria-labelledby":l.titleId,"data-state":aa(l.open),...i,ref:t,deferPointerDownOutside:!0,onDismiss:()=>l.onOpenChange(!1)})})})}),Sl="DialogTitle",kl=c.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,a=Je(Sl,n);return s.jsx(pt.h2,{id:a.titleId,...r,ref:t})});kl.displayName=Sl;var Nl="DialogDescription",Xg=c.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,a=Je(Nl,n);return s.jsx(pt.p,{id:a.descriptionId,...r,ref:t})});Xg.displayName=Nl;var Cl="DialogClose",Jg=c.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,a=Je(Cl,n);return s.jsx(pt.button,{type:"button",...r,ref:t,onClick:Nt(e.onClick,()=>a.onOpenChange(!1))})});Jg.displayName=Cl;function aa(e){return e?"open":"closed"}function Zg(e){if(typeof document>"u")return;let t=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.type="text/css",t.appendChild(n),n.styleSheet?n.styleSheet.cssText=e:n.appendChild(document.createTextNode(e))}const El=B.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}),Us=()=>{const e=B.useContext(El);if(!e)throw new Error("useDrawerContext must be used within a Drawer.Root");return e};Zg(`[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(
|
|
110
|
+
`),rg=e=>e.displayName?`${e.displayName} <${e.normalizedEmail}>`:e.normalizedEmail,so=e=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.trim()),ag=e=>{const t=e.trim();if(!t)return;const n=t.match(/^(.+?)\s*<([^>]+)>$/);if(n){const r=n[1].trim(),a=n[2].trim();if(so(a))return{email:a,displayName:r}}if(so(t))return{email:t}},rr=({label:e,addresses:t,onChange:n,placeholder:r})=>{const[a,o]=c.useState(""),[i,l]=c.useState(-1),[u,d]=c.useState(!1),m=c.useRef(null),f=c.useRef(null),h=Xo(a,200),{data:x}=ue({...Uo({query:{q:h,limit:8}}),enabled:h.length>=2}),b=x?.items??[],p=new Set(t.map(S=>S.email.toLowerCase())),v=b.filter(S=>!p.has(S.normalizedEmail.toLowerCase()));c.useEffect(()=>{l(-1),d(v.length>0&&a.length>=2)},[v.length,a.length]);const g=c.useCallback(S=>{p.has(S.email.toLowerCase())||(n([...t,S]),o(""),d(!1))},[t,p,n]),y=c.useCallback(S=>{n(t.filter((N,I)=>I!==S))},[t,n]),j=c.useCallback(S=>{g({email:S.normalizedEmail,displayName:S.displayName}),m.current?.focus()},[g]),w=c.useCallback(()=>{const S=ag(a);S&&g(S)},[a,g]),C=c.useCallback(S=>{if(S.key==="Backspace"&&a===""&&t.length>0){y(t.length-1);return}if(S.key==="Enter"||S.key==="Tab"||S.key===","){if(i>=0&&v[i]){S.preventDefault(),j(v[i]);return}a.trim()&&(S.preventDefault(),w());return}if(S.key==="ArrowDown"&&u){S.preventDefault(),l(N=>N<v.length-1?N+1:0);return}if(S.key==="ArrowUp"&&u){S.preventDefault(),l(N=>N>0?N-1:v.length-1);return}S.key==="Escape"&&(d(!1),l(-1))},[a,t.length,i,v,u,y,j,w]),k=c.useCallback(()=>{setTimeout(()=>{w(),d(!1)},150)},[w]);return s.jsxs("div",{className:"relative",children:[s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("label",{htmlFor:`address-field-${e}`,className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:[e,":"]}),s.jsxs("div",{className:"flex-1 flex flex-wrap items-center gap-1 min-h-[36px] px-2 py-1 border rounded-md bg-canvas cursor-text",onClick:()=>m.current?.focus(),onKeyDown:S=>{(S.key==="Enter"||S.key===" ")&&m.current?.focus()},children:[t.map((S,N)=>s.jsx(Ju,{email:S.email,displayName:S.displayName,onRemove:()=>y(N)},S.email)),s.jsx("input",{ref:m,id:`address-field-${e}`,type:"text",value:a,onChange:S=>o(S.target.value),onKeyDown:C,onBlur:k,placeholder:t.length===0?r:"",className:"flex-1 min-w-[120px] bg-transparent outline-none text-sm py-0.5"})]})]}),u&&v.length>0&&s.jsx("ul",{ref:f,className:"absolute left-12 right-0 mt-1 bg-surface border border-line rounded-md shadow-lg z-50 max-h-[200px] overflow-auto",children:v.map((S,N)=>s.jsx("li",{className:de("px-3 py-2 text-sm cursor-pointer transition-colors",N===i&&"bg-accent-2-soft"),onMouseDown:I=>{I.preventDefault(),j(S)},onMouseEnter:()=>l(N),children:rg(S)},S.addressId))})]})},og=({accountId:e})=>{const t=Me();return s.jsxs("div",{role:"alert","data-testid":"compose-smtp-missing-banner",className:"flex items-start gap-3 border-b border-warning/50 bg-warning/10 px-3 py-2",children:[s.jsx(Tr,{className:"size-5 shrink-0 mt-0.5 text-warning","aria-hidden":"true"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"text-sm font-medium text-warning",children:"This account can't send mail until SMTP is configured."}),s.jsxs("button",{type:"button",onClick:()=>{t({to:"/settings/accounts",search:{editAccountId:e,focusSmtp:!0}})},className:"mt-1 inline-flex items-center gap-1 text-xs font-medium text-warning hover:underline",children:["Configure SMTP",s.jsx(zu,{className:"size-3","aria-hidden":"true"})]})]})]})},jr=e=>{const[t,n]=c.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return c.useEffect(()=>{if(typeof window>"u"||!window.matchMedia)return;const r=window.matchMedia(e),a=o=>n(o.matches);return n(r.matches),r.addEventListener("change",a),()=>r.removeEventListener("change",a)},[e]),t},Qt=()=>jr("(min-width: 1024px)"),no=150,ig=()=>{const[e,t]=c.useState(()=>{if(typeof window>"u"||!window.visualViewport)return{viewportHeight:0,isKeyboardOpen:!1};const n=window.visualViewport.height;return{viewportHeight:n,isKeyboardOpen:window.innerHeight-n>no}});return c.useEffect(()=>{if(typeof window>"u"||!window.visualViewport)return;const n=window.visualViewport,r=()=>{const a=n.height;t({viewportHeight:a,isKeyboardOpen:window.innerHeight-a>no})};return r(),n.addEventListener("resize",r),()=>n.removeEventListener("resize",r)},[]),e},lg=({selectedAccountId:e,onSelect:t})=>{const{data:n}=ue({...ht(),staleTime:1/0}),r=n?.accounts??[];if(c.useEffect(()=>{!e&&r.length===1&&r[0]&&t(r[0])},[e,r,t]),r.length<=1){const a=r[0];return a?s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx("label",{className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:"From:"}),s.jsx("div",{className:"text-sm py-1.5",children:a.email})]}):null}return s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx("label",{htmlFor:"from-account-selector",className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:"From:"}),s.jsx("select",{id:"from-account-selector",value:e??"",onChange:a=>{const o=r.find(i=>i.accountId===a.target.value);o&&t(o)},className:"flex-1 px-2 py-1.5 border rounded-md bg-canvas text-sm",children:r.map(a=>s.jsx("option",{value:a.accountId,children:a.email},a.accountId))})]})},cg=({value:e,onChange:t})=>s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx("label",{className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:"Subj:"}),s.jsx("input",{type:"text",value:e,onChange:n=>t(n.target.value),className:"flex-1 px-2 py-1.5 border rounded-md bg-canvas text-sm",placeholder:"Subject","data-subject-field":!0})]}),ug=["p","br","strong","b","em","i","a","blockquote","ul","ol","li"],dg=["href"],fg=e=>Po.sanitize(e,{ALLOWED_TAGS:ug,ALLOWED_ATTR:dg}),mg=c.lazy(()=>Zc(()=>import("./ComposeBody-Bc6JAYVe.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16])).then(e=>({default:e.ComposeBody}))),hg=()=>s.jsxs("div",{className:"min-h-[120px] px-3 py-2",children:[s.jsx("div",{className:"h-8 mb-2 rounded bg-surface-sunken animate-pulse"}),s.jsx("div",{className:"min-h-[80px] rounded bg-surface-sunken/50 animate-pulse"})]}),ll=[{type:"p",children:[{text:""}]}],gg=[{type:"p",children:[{text:""}]},{type:"p",children:[{text:"-- "}]}],pg=e=>e?[...gg,{type:"p",children:[{text:e}]}]:ll,xg=e=>e?/^re:\s/i.test(e)?e:`Re: ${e}`:"Re: ",bg=e=>e?/^fwd?:\s/i.test(e)?e:`Fwd: ${e}`:"Fwd: ",vg=(e,t,n)=>{const{envelope:r}=e,o=(r.replyTo.length>0?r.replyTo:r.from).map(d=>({email:d.normalizedEmail,displayName:d.displayName}));if(t!=="reply_all")return{to:o,cc:[]};const i=n?.toLowerCase(),l=new Set(o.map(d=>d.email.toLowerCase())),u=[...r.to,...r.cc].filter(d=>d.normalizedEmail.toLowerCase()!==i&&!l.has(d.normalizedEmail.toLowerCase())).map(d=>({email:d.normalizedEmail,displayName:d.displayName}));return{to:o,cc:u}},yg=e=>{const t=e.envelope.messageIdValue,r=[...e.references.filter(a=>a.referenceType==="references").sort((a,o)=>a.referenceOrder-o.referenceOrder).map(a=>a.messageIdValue)];return t&&!r.includes(t)&&r.push(t),{inReplyTo:t,references:r}},wg=(e,t,n,r,a)=>e.length===0&&t.length===0&&n.length===0&&r.trim()===""&&wr(a).trim()==="",jg=({selectedAccountId:e,onAccountChange:t,toAddresses:n,setToAddresses:r,ccAddresses:a,setCcAddresses:o,bccAddresses:i,setBccAddresses:l,showCc:u,setShowCc:d,showBcc:m,setShowBcc:f,subject:h,setSubject:x})=>{const b=Qt(),{isKeyboardOpen:p}=ig();if(!b&&p){const g=[];return n.length>0&&g.push(`To: ${n.map(y=>y.displayName??y.email).join(", ")}`),a.length>0&&g.push(`Cc: ${a.length}`),i.length>0&&g.push(`Bcc: ${i.length}`),h&&g.push(h),s.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-line overflow-hidden","data-testid":"compose-header-collapsed",children:[s.jsx("span",{className:"truncate text-xs text-fg-muted",children:g.length>0?g.join(" · "):"…"}),s.jsx("span",{className:"shrink-0 inline-flex items-center justify-center rounded bg-surface-sunken px-1.5 py-0.5 text-2xs text-fg-muted",children:"…"})]})}return s.jsxs("div",{className:"space-y-1 px-3 py-2 border-b border-line",children:[s.jsx(lg,{selectedAccountId:e,onSelect:t}),s.jsx(rr,{label:"To",addresses:n,onChange:r,placeholder:"Recipients"}),u?s.jsx(rr,{label:"Cc",addresses:a,onChange:o}):s.jsxs("div",{className:"flex gap-2 pl-14",children:[s.jsx("button",{type:"button",onClick:()=>d(!0),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:"Cc"}),s.jsx("button",{type:"button",onClick:()=>f(!0),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:"Bcc"})]}),u&&!m&&s.jsx("div",{className:"pl-14",children:s.jsx("button",{type:"button",onClick:()=>f(!0),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:"Bcc"})}),m&&s.jsx(rr,{label:"Bcc",addresses:i,onChange:l}),s.jsx(cg,{value:h,onChange:x})]})},Zr=({mode:e,account:t,sourceMessage:n,onClose:r,onAccountChange:a})=>{const{state:o,setOutboxMessageId:i,startSendPolling:l}=It(),{pushError:u}=qe(),{outboxMessageId:d}=o,[m,f]=c.useState([]),[h,x]=c.useState([]),[b,p]=c.useState([]),[v,g]=c.useState(""),[y,j]=c.useState(!1),[w,C]=c.useState(!1),[k,S]=c.useState(t?.accountId),[N,I]=c.useState(!1),T=c.useRef(d);c.useEffect(()=>{T.current!==d&&(T.current=d,d&&(f([]),x([]),p([]),g(""),j(!1),C(!1),R(ll),I(!1)))},[d]);const{signature:E}=Mu(k),[M,R]=c.useState(()=>pg(E.plainText)),{data:A}=ue({...Jc({path:{outboxMessageId:d??""}}),enabled:!!d&&!N});c.useEffect(()=>{!A||N||(f(A.toAddresses.map(U=>({email:U,displayName:void 0}))),A.ccAddresses&&A.ccAddresses.length>0&&(x(A.ccAddresses.map(U=>({email:U,displayName:void 0}))),j(!0)),A.bccAddresses&&A.bccAddresses.length>0&&(p(A.bccAddresses.map(U=>({email:U,displayName:void 0}))),C(!0)),A.subject&&g(A.subject),A.textBody&&R([{type:"p",children:[{text:A.textBody}]}]),S(A.accountId),I(!0))},[A,N]),c.useEffect(()=>{if(n){if(e==="reply"||e==="reply_all"){const{to:U,cc:z}=vg(n,e,t?.email);f(U),x(z),z.length>0&&j(!0),g(xg(n.envelope.subject))}e==="forward"&&g(bg(n.envelope.subject))}},[e,n,t?.email]);const D=e==="reply"||e==="reply_all"||e==="forward",{data:F}=nl({messageId:n?.message.messageId,bodyParts:n?.bodyParts,enabled:D&&!!n}),$=F?.kind==="text"?F.body:"",te=F?.kind==="html"?fg(F.body):void 0,q=n?.envelope.from[0]?.displayName??n?.envelope.from[0]?.normalizedEmail,{saveStatus:Q,saveError:X,saveDraft:ee,cancelAutoSave:se}=sg({outboxMessageId:d,onDraftCreated:i});c.useEffect(()=>{X&&u({title:"Couldn't save draft",detail:st(X)??"Saving the draft failed.",error:X})},[X,u]);const P=pe(qo()),_=pe(Qo()),H=pe({...jn(),onError:U=>{u(zt("Couldn't discard draft","The draft wasn't discarded.",U))}}),{data:W}=ue({...ht(),staleTime:1/0}),le=W?.accounts.find(U=>U.accountId===k),me=le?ku(le):!1,J=P.isPending||_.isPending,Ie=m.length>0&&!!k&&!me;c.useEffect(()=>{if(!k||d&&!N||wg(m,h,b,v,M))return;const U=wr(M),z=to(M);ee({accountId:k,toAddresses:m.map(ne=>ne.email),ccAddresses:h.length>0?h.map(ne=>ne.email):void 0,bccAddresses:b.length>0?b.map(ne=>ne.email):void 0,subject:v||void 0,textBody:U||void 0,htmlBody:z||void 0})},[k,d,N,m,h,b,v,M,ee]);const he=c.useCallback(async()=>{if(!k||m.length===0)return;se();const U=n&&(e==="reply"||e==="reply_all")?yg(n):{};let z=d,ne=!1;if(!z){const Qe=wr(M),Pe=to(M),Te=await P.mutateAsync({body:{accountId:k,toAddresses:m.map(xe=>xe.email),ccAddresses:h.length>0?h.map(xe=>xe.email):void 0,bccAddresses:b.length>0?b.map(xe=>xe.email):void 0,subject:v||void 0,textBody:Qe||void 0,htmlBody:Pe||void 0,sendImmediately:!0,...U}}).catch(xe=>(u({title:"Couldn't send message",detail:st(xe)??"Saving the draft failed.",error:xe}),null));if(Te===null)return;z=Te.outboxMessageId,ne=!0,i(z)}await _.mutateAsync({path:{outboxMessageId:z}}).catch(Qe=>(u({title:"Couldn't send message",detail:st(Qe)??(ne?"The draft was saved but the send request failed. Try again from the Outbox.":"The send request failed. Try again."),error:Qe}),null))!==null&&(l(z),r())},[k,m,h,b,v,M,e,n,d,P,_,se,l,i,u,r]),ke=c.useCallback(()=>{se(),d&&H.mutate({path:{outboxMessageId:d}}),r()},[se,d,H,r]),Y=c.useCallback(U=>{S(U.accountId),a?.(U)},[a]);return s.jsx(df,{banner:le&&me?s.jsx(og,{accountId:le.accountId}):void 0,header:s.jsx(jg,{selectedAccountId:k,onAccountChange:Y,toAddresses:m,setToAddresses:f,ccAddresses:h,setCcAddresses:x,bccAddresses:b,setBccAddresses:p,showCc:y,setShowCc:j,showBcc:w,setShowBcc:C,subject:v,setSubject:g}),quoted:$||te?s.jsx(Lf,{text:$,html:te,senderName:q}):void 0,actionBar:s.jsx(uf,{onSend:he,onDiscard:ke,sending:J,canSend:Ie,saveStatus:Q,unavailableReason:me?"SMTP not configured":void 0,onUnavailable:U=>u({title:"Can't send yet",detail:U})}),children:s.jsx(c.Suspense,{fallback:s.jsx(hg,{}),children:s.jsx(mg,{value:M,onChange:R,onSubmit:he,autoFocus:e==="new"})})})},ro=({mode:e,account:t,sourceMessage:n,onClose:r})=>s.jsx("div",{className:"border-t border-line bg-canvas max-h-[400px] flex flex-col",children:s.jsx(Zr,{mode:e,account:t,sourceMessage:n,onClose:r})}),cl=({message:e,icon:t})=>s.jsxs("div",{className:"flex flex-col items-center justify-center p-8 text-center",children:[t&&s.jsx("div",{className:"mb-4 text-fg-muted",children:t}),s.jsx("p",{className:"text-fg-muted",children:e})]}),ea=({enabled:e=!0,bindings:t,capture:n=!1})=>{const r=c.useCallback(a=>{const o=a.target;if(!(o.tagName==="INPUT"||o.tagName==="TEXTAREA"||o.isContentEditable))for(const i of t){if(!(a.key.toLowerCase()===i.key.toLowerCase())||i.requireShift!==void 0&&i.requireShift!==a.shiftKey)continue;const u=a.ctrlKey||a.metaKey;if(i.requireMeta!==void 0){if(i.requireMeta!==u)continue}else{const d=i.noModifiers??!0,m=u||a.altKey||i.requireShift===void 0&&a.shiftKey;if(d&&m)continue}i.preventDefault&&a.preventDefault(),i.stopPropagation&&(a.stopPropagation(),a.stopImmediatePropagation()),i.handler(a);return}},[t]);c.useEffect(()=>{if(e)return window.addEventListener("keydown",r,n),()=>window.removeEventListener("keydown",r,n)},[e,r,n])},ul=e=>{const{data:t,isLoading:n}=ue({...ht(),staleTime:1/0}),r=c.useMemo(()=>(t?.accounts??[]).map(l=>l.accountId),[t?.accounts]),a=Ut({queries:r.map(l=>({...rt({path:{accountId:l}}),staleTime:1/0,enabled:!!e}))}),o=n||a.some(l=>l.isLoading);return{accountId:c.useMemo(()=>{if(e){for(let l=0;l<r.length;l++)if((a[l].data?.items??[]).some(m=>m.mailboxId===e))return r[l]}},[e,r,a]),isLoading:o}},Sg=e=>typeof e=="object"&&e!==null&&Array.isArray(e.pages),kg=e=>typeof e=="object"&&e!==null&&Array.isArray(e.items),cs=(e,t)=>e===void 0?e:Sg(e)?{...e,pages:e.pages.map(n=>({...n,items:t(n.items)}))}:kg(e)?{...e,items:t(e.items)}:e,Ng=(e,t,n)=>{const r=new Map(t.map(o=>[o.messageId,o.mailboxId])),a=new Set;for(const o of e)a.add(r.get(o)??n);return[...a]},ao=(e,t,n)=>e.map(r=>t.has(r.messageId)?{...r,isRead:n}:r),Cg=(e,t,n,r)=>e.filter(a=>!a.isRead&&t.has(a.threadMessageId)&&!n.has(a.messageId)&&!r.has(a.messageId)).map(a=>a.messageId),Eg=({messages:e,expandedIds:t,threadId:n,mailboxId:r,accountId:a})=>{const o=je(),{pushError:i}=qe(),l=c.useRef(new Set),u=c.useRef(new Set),{mutate:d}=pe({...Sn(),onMutate:async h=>{const x=new Set(h.body.messageIds??[]),b=h.body.isRead??!0,p=$t({path:{threadId:n}}),v=Ng(x,e,r),g=v.map(k=>at({path:{mailboxId:k}})),y=v.map(k=>gt({path:{mailboxId:k}}));await Promise.all([o.cancelQueries({queryKey:p}),...g.map(k=>o.cancelQueries({queryKey:k})),...y.map(k=>o.cancelQueries({queryKey:k}))]);const j=o.getQueriesData({queryKey:p}).filter(k=>k[1]!==void 0).map(([k,S])=>({queryKey:k,data:S})),w=[...g,...y].flatMap(k=>o.getQueriesData({queryKey:k})).filter(k=>k[1]!==void 0).map(([k,S])=>({queryKey:k,data:S}));o.setQueriesData({queryKey:p},k=>k&&{...k,items:ao(k.items,x,b)});const C=k=>cs(k,S=>ao(S,x,b));for(const k of[...g,...y])o.setQueriesData({queryKey:k},C);return{threadMessagesPrefix:p,threadsListPrefixes:g,threadsSearchPrefixes:y,previousThreadMessages:j,previousThreadsList:w}},onSuccess:(h,x)=>{const b=x.body.messageIds??[];for(const p of b)l.current.add(p),u.current.delete(p)},onError:(h,x,b)=>{const p=x.body.messageIds??[];for(const g of p)u.current.delete(g);if(b){for(const g of b.previousThreadMessages)o.setQueryData(g.queryKey,g.data);for(const g of b.previousThreadsList)o.setQueryData(g.queryKey,g.data)}const v=x.body.isRead??!0;i({title:v?"Couldn't mark as read":"Couldn't mark as unread",detail:st(h),error:h})},onSettled:(h,x,b,p)=>{if(p){o.invalidateQueries({queryKey:p.threadMessagesPrefix});for(const v of[...p.threadsListPrefixes,...p.threadsSearchPrefixes])o.invalidateQueries({queryKey:v});a&&o.invalidateQueries({queryKey:Bt({path:{accountId:a}})})}}}),m=c.useCallback(h=>{const x=h.filter(b=>!l.current.has(b)&&!u.current.has(b));if(x.length!==0){for(const b of x)u.current.add(b);d({body:{messageIds:x,isRead:!0}})}},[d]),f=c.useMemo(()=>Cg(e,t,l.current,u.current),[e,t]);c.useEffect(()=>{f.length!==0&&m(f)},[f,m]),c.useEffect(()=>{l.current.clear(),u.current.clear()},[n])},dl=e=>{const{mailboxId:t,accountId:n}=e,r=je(),{pushError:a}=qe(),{mutate:o,isPending:i}=pe({...Sn(),onError:(u,d)=>{const m=d.body.isRead??!0;a({title:m?"Couldn't mark as read":"Couldn't mark as unread",detail:st(u),error:u})},onSettled:()=>{r.invalidateQueries({queryKey:at({path:{mailboxId:t}})}),r.invalidateQueries({queryKey:gt({path:{mailboxId:t}})}),n&&r.invalidateQueries({queryKey:Bt({path:{accountId:n}})})}});return{toggleReadFor:c.useCallback((u,d)=>{u.length!==0&&o({body:{messageIds:u,isRead:d}})},[o]),isPending:i}},Ig=60,Rg=1.5,Mg=(e,t,n)=>{const r=Math.abs(e),a=Math.abs(t);return r<n?{direction:null}:r<a*Rg?{direction:null}:{direction:e<0?"left":"right"}},Tg=({onSwipeLeft:e,onSwipeRight:t,thresholdPx:n=Ig})=>{const r=c.useRef(null),a=c.useCallback(u=>{if(u.pointerType==="mouse"){r.current=null;return}r.current={x:u.clientX,y:u.clientY}},[]),o=c.useCallback(()=>{},[]),i=c.useCallback(u=>{const d=r.current;if(r.current=null,!d)return;const{direction:m}=Mg(u.clientX-d.x,u.clientY-d.y,n);m==="left"&&e?.(),m==="right"&&t?.()},[e,t,n]),l=c.useCallback(()=>{r.current=null},[]);return{handlers:{onPointerDown:a,onPointerMove:o,onPointerUp:i,onPointerCancel:l}}},Dg=(e,t,n)=>t?.find(r=>r.messageId===e)?.mailboxId??n,oo=(e,t,n)=>e.map(r=>r.messageId===t?{...r,hasStars:n}:r),Sr=({threadId:e,mailboxId:t,messages:n})=>{const r=je(),{pushError:a}=qe(),{mutate:o,isPending:i,variables:l}=pe({...eu(),onMutate:async d=>{const m=d.path.messageId,f=d.body.isStarred??!1,h=$t({path:{threadId:e}}),x=Dg(m,n,t),b=at({path:{mailboxId:x}}),p=gt({path:{mailboxId:x}}),v=Ho();await Promise.all([r.cancelQueries({queryKey:h}),r.cancelQueries({queryKey:b}),r.cancelQueries({queryKey:p}),r.cancelQueries({queryKey:v})]);const g=r.getQueriesData({queryKey:h}).filter(k=>k[1]!==void 0).map(([k,S])=>({queryKey:k,data:S})),y=r.getQueriesData({queryKey:b}).concat(r.getQueriesData({queryKey:p})).filter(k=>k[1]!==void 0).map(([k,S])=>({queryKey:k,data:S})),j=r.getQueriesData({queryKey:v}).filter(k=>k[1]!==void 0).map(([k,S])=>({queryKey:k,data:S})),w=k=>cs(k,S=>oo(S,m,f));r.setQueriesData({queryKey:h},w),r.setQueriesData({queryKey:v},w);const C=k=>cs(k,S=>oo(S,m,f));return r.setQueriesData({queryKey:b},C),r.setQueriesData({queryKey:p},C),{threadMessagesPrefix:h,threadsListPrefix:b,threadsSearchPrefix:p,unifiedThreadsPrefix:v,previousThreadMessages:g,previousThreadsList:y,previousUnifiedThreads:j}},onError:(d,m,f)=>{if(f){for(const x of f.previousThreadMessages)r.setQueryData(x.queryKey,x.data);for(const x of f.previousThreadsList)r.setQueryData(x.queryKey,x.data);for(const x of f.previousUnifiedThreads)r.setQueryData(x.queryKey,x.data)}const h=m.body.isStarred??!1;a({title:h?"Couldn't star message":"Couldn't unstar message",detail:st(d),error:d})},onSettled:(d,m,f,h)=>{h&&(r.invalidateQueries({queryKey:h.threadMessagesPrefix}),r.invalidateQueries({queryKey:h.threadsListPrefix}),r.invalidateQueries({queryKey:h.threadsSearchPrefix}),r.invalidateQueries({queryKey:h.unifiedThreadsPrefix}))}});return{toggleStar:(d,m)=>{o({path:{messageId:d},body:{isStarred:!m}})},isPending:i,pendingMessageId:i?l?.path.messageId:void 0}};function Tn(e){return e===void 0?"uncategorized":e}const tt={uncategorized:"uncategorized",personal:"personal",newsletter:"newsletter",marketing:"marketing",automated:"automated",transactional:"transactional",social:"social"},io={MoveToInbox:"MoveToInbox",MoveToJunk:"MoveToJunk"},Ag={inbox:"Inbox",junk:"Junk"},Og=e=>`Moved from ${Ag[e]??"another folder"} by Remit`,Pg=(e,t)=>{if(e===io.MoveToInbox)return t.inboxMailboxId;if(e===io.MoveToJunk)return t.junkMailboxId},Lg=(e,t,n)=>{if(!e||!t)return!1;const r=Pg(e.action,n);return r!==void 0&&r===t},zg=(e,t)=>{if(e==="inbox")return t.inboxMailboxId;if(e==="junk")return t.junkMailboxId},Dn=(e,t)=>{const{data:n,isLoading:r}=ue({...ht(),staleTime:1/0,enabled:!!e});return{mailboxId:c.useMemo(()=>e?n?.accounts.find(i=>i.accountId===e)?.folderAppointments.find(i=>i.role===t)?.mailboxId:void 0,[n,e,t]),isLoading:r}},Fg=e=>{const{mailboxId:t,isLoading:n}=Dn(e,"Archive");return{archiveMailboxId:t,isLoading:n}},_g=e=>{const{mailboxId:t,isLoading:n}=Dn(e,"Drafts");return{draftsMailboxId:t,isLoading:n}},ta=e=>{const{mailboxId:t,isLoading:n}=Dn(e,"Inbox");return{inboxMailboxId:t,isLoading:n}},sa=e=>{const{mailboxId:t,isLoading:n}=Dn(e,"Junk");return{junkMailboxId:t,isLoading:n}},fl=e=>{const{data:t}=ue({...ht(),staleTime:1/0,enabled:!!e});return c.useMemo(()=>t?.accounts.find(n=>n.accountId===e)?.folderAppointments??[],[t,e])},lo=(e,t)=>e.filter(n=>!t.has(n.messageId)),Ct=({mailboxId:e,threadId:t,accountId:n,onAfterOptimisticRemove:r})=>{const a=je(),{pushError:o}=qe(),{mutate:i,isPending:l}=pe({...tu(),onMutate:async d=>{const m=new Set(d.body.messageIds??[]),f=t?$t({path:{threadId:t}}):[],h=at({path:{mailboxId:e}}),x=gt({path:{mailboxId:e}});await Promise.all([...t?[a.cancelQueries({queryKey:f})]:[],a.cancelQueries({queryKey:h}),a.cancelQueries({queryKey:x})]);const b=t?a.getQueriesData({queryKey:f}).filter(g=>g[1]!==void 0).map(([g,y])=>({queryKey:g,data:y})):[],p=a.getQueriesData({queryKey:h}).concat(a.getQueriesData({queryKey:x})).filter(g=>g[1]!==void 0).map(([g,y])=>({queryKey:g,data:y}));t&&a.setQueriesData({queryKey:f},g=>g&&{...g,items:lo(g.items,m)});const v=g=>cs(g,y=>lo(y,m));return a.setQueriesData({queryKey:h},v),a.setQueriesData({queryKey:x},v),r?.(Array.from(m)),{threadMessagesPrefix:f,threadsListPrefix:h,threadsSearchPrefix:x,previousThreadMessages:b,previousThreadsList:p}},onError:(d,m,f)=>{if(f){for(const x of f.previousThreadMessages)a.setQueryData(x.queryKey,x.data);for(const x of f.previousThreadsList)a.setQueryData(x.queryKey,x.data)}const h=m.body.messageIds?.length??0;o({title:h>1?`Couldn't move ${h} messages`:"Couldn't move this message",detail:st(d),error:d})},onSettled:(d,m,f,h)=>{h&&(t&&a.invalidateQueries({queryKey:h.threadMessagesPrefix}),a.invalidateQueries({queryKey:h.threadsListPrefix}),a.invalidateQueries({queryKey:h.threadsSearchPrefix}),n&&a.invalidateQueries({queryKey:Bt({path:{accountId:n}})}))}});return{moveMessages:c.useCallback((d,m)=>{d.length!==0&&i({body:{messageIds:d,destinationMailboxId:m}})},[i]),isPending:l}},Bg=({accountId:e,messageId:t,threadId:n,mailboxId:r,autoMoved:a})=>{const{inboxMailboxId:o}=ta(e),{junkMailboxId:i}=sa(e),{moveMessages:l,isPending:u}=Ct({mailboxId:r,threadId:n,accountId:e}),d={inboxMailboxId:o,junkMailboxId:i},m=Lg(a,r,d),f=a?zg(a.fromPlacement,d):void 0,h=c.useCallback(()=>{f&&l([t],f)},[l,t,f]);return!m||!a?{show:!1,label:"",isUndoing:!1}:{show:!0,label:Og(a.fromPlacement),onUndo:f?h:void 0,isUndoing:u}};function ml({accountId:e,messageId:t,threadId:n,mailboxId:r,autoMoved:a,size:o="sm"}){const i=Bg({accountId:e,messageId:t,threadId:n,mailboxId:r,autoMoved:a});return i.show?s.jsx(ef,{label:i.label,size:o,onUndo:i.onUndo,undoLabel:i.isUndoing?"Undoing…":"Undo"}):null}const co=(e,t)=>e.filter(n=>!t.has(n.messageId)),$g=e=>e.filter(t=>t.isDeleted!==!0),As=({mailboxId:e,threadId:t,accountId:n,onAfterOptimisticRemove:r})=>{const a=je(),{pushError:o}=qe(),{mutate:i,isPending:l}=pe({...su(),onMutate:async d=>{const m=new Set(d.body.messageIds??[]),f=t?$t({path:{threadId:t}}):[],h=at({path:{mailboxId:e}}),x=gt({path:{mailboxId:e}});await Promise.all([a.cancelQueries({queryKey:f}),a.cancelQueries({queryKey:h}),a.cancelQueries({queryKey:x})]);const b=t?a.getQueriesData({queryKey:f}).filter(g=>g[1]!==void 0).map(([g,y])=>({queryKey:g,data:y})):[],p=a.getQueriesData({queryKey:h}).concat(a.getQueriesData({queryKey:x})).filter(g=>g[1]!==void 0).map(([g,y])=>({queryKey:g,data:y}));t&&a.setQueriesData({queryKey:f},g=>g&&{...g,items:co(g.items,m)});const v=g=>cs(g,y=>co(y,m));return a.setQueriesData({queryKey:h},v),a.setQueriesData({queryKey:x},v),r?.(Array.from(m)),{threadMessagesPrefix:f,threadsListPrefix:h,threadsSearchPrefix:x,previousThreadMessages:b,previousThreadsList:p}},onError:(d,m,f)=>{if(f){for(const x of f.previousThreadMessages)a.setQueryData(x.queryKey,x.data);for(const x of f.previousThreadsList)a.setQueryData(x.queryKey,x.data)}const h=m.body.messageIds?.length??0;o({title:h>1?`Couldn't delete ${h} messages`:"Couldn't delete this message",detail:st(d),error:d})},onSettled:(d,m,f,h)=>{h&&(t&&a.invalidateQueries({queryKey:h.threadMessagesPrefix}),a.invalidateQueries({queryKey:h.threadsListPrefix}),a.invalidateQueries({queryKey:h.threadsSearchPrefix}),n&&a.invalidateQueries({queryKey:Bt({path:{accountId:n}})}))}});return{deleteMessages:c.useCallback(d=>{d.length!==0&&i({body:{messageIds:d}})},[i]),isPending:l}},hl=(e,t=Date.now())=>({value:e,setAt:t}),Kg=(e,t,n,r)=>{if(e.addressId!==t)return e;const a={...e.flags??{}};return n?a.trusted=hl(!0,r):delete a.trusted,{...e,flags:a}},qg=(e,t,n,r)=>{const a=o=>o.map(i=>Kg(i,t,n,r));return{...e,envelope:{...e.envelope,from:a(e.envelope.from),to:a(e.envelope.to),cc:a(e.envelope.cc),bcc:a(e.envelope.bcc),replyTo:a(e.envelope.replyTo)}}},na=({messageId:e})=>{const t=je(),{pushError:n}=qe(),{mutate:r,isPending:a,error:o,reset:i}=pe({...Wo(),onMutate:async u=>{const d=u.path.addressId,f=u.body.flags?.trusted?.value===!0,h=Ko({path:{messageId:e}});await t.cancelQueries({queryKey:h});const x=t.getQueriesData({queryKey:h}).filter(b=>b[1]!==void 0).map(([b,p])=>({queryKey:b,data:p}));return t.setQueriesData({queryKey:h},b=>b&&qg(b,d,f)),{describePrefix:h,previous:x}},onError:(u,d,m)=>{if(m)for(const f of m.previous)t.setQueryData(f.queryKey,f.data);n(zt("Couldn't trust sender","The change wasn't saved.",u))},onSettled:(u,d,m,f)=>{f&&t.invalidateQueries({queryKey:f.describePrefix})}});return{toggleTrusted:(u,d)=>{r({path:{addressId:u},body:{flags:{trusted:hl(!d)}}})},isPending:a,error:o,reset:i}};var An="Dialog",[gl]=tm(An),[Ug,Je]=gl(An),pl=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:a,onOpenChange:o,modal:i=!0}=e,l=c.useRef(null),u=c.useRef(null),[d,m]=rm({prop:r,defaultProp:a??!1,onChange:o,caller:An});return s.jsx(Ug,{scope:t,triggerRef:l,contentRef:u,contentId:Zn(),titleId:Zn(),descriptionId:Zn(),open:d,onOpenChange:m,onOpenToggle:c.useCallback(()=>m(f=>!f),[m]),modal:i,children:n})};pl.displayName=An;var xl="DialogTrigger",Qg=c.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,a=Je(xl,n),o=qt(t,a.triggerRef);return s.jsx(pt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":aa(a.open),...r,ref:o,onClick:Nt(e.onClick,a.onOpenToggle)})});Qg.displayName=xl;var ra="DialogPortal",[Hg,bl]=gl(ra,{forceMount:void 0}),vl=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:a}=e,o=Je(ra,t);return s.jsx(Hg,{scope:t,forceMount:n,children:c.Children.map(r,i=>s.jsx(Cn,{present:n||o.open,children:s.jsx(Li,{asChild:!0,container:a,children:i})}))})};vl.displayName=ra;var pn="DialogOverlay",yl=c.forwardRef((e,t)=>{const n=bl(pn,e.__scopeDialog),{forceMount:r=n.forceMount,...a}=e,o=Je(pn,e.__scopeDialog);return o.modal?s.jsx(Cn,{present:r||o.open,children:s.jsx(Vg,{...a,ref:t})}):null});yl.displayName=pn;var Wg=Vr("DialogOverlay.RemoveScroll"),Vg=c.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,a=Je(pn,n),o=Sm(),i=qt(t,o);return s.jsx(Ui,{as:Wg,allowPinchZoom:!0,shards:[a.contentRef],children:s.jsx(pt.div,{"data-state":aa(a.open),...r,ref:i,style:{pointerEvents:"auto",...r.style}})})}),us="DialogContent",wl=c.forwardRef((e,t)=>{const n=bl(us,e.__scopeDialog),{forceMount:r=n.forceMount,...a}=e,o=Je(us,e.__scopeDialog);return s.jsx(Cn,{present:r||o.open,children:o.modal?s.jsx(Yg,{...a,ref:t}):s.jsx(Gg,{...a,ref:t})})});wl.displayName=us;var Yg=c.forwardRef((e,t)=>{const n=Je(us,e.__scopeDialog),r=c.useRef(null),a=qt(t,n.contentRef,r);return c.useEffect(()=>{const o=r.current;if(o)return Qm(o)},[]),s.jsx(jl,{...e,ref:a,trapFocus:n.open,disableOutsidePointerEvents:n.open,onCloseAutoFocus:Nt(e.onCloseAutoFocus,o=>{o.preventDefault(),n.triggerRef.current?.focus()}),onPointerDownOutside:Nt(e.onPointerDownOutside,o=>{const i=o.detail.originalEvent,l=i.button===0&&i.ctrlKey===!0;(i.button===2||l)&&o.preventDefault()}),onFocusOutside:Nt(e.onFocusOutside,o=>o.preventDefault())})}),Gg=c.forwardRef((e,t)=>{const n=Je(us,e.__scopeDialog),r=c.useRef(!1),a=c.useRef(!1);return s.jsx(jl,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{e.onCloseAutoFocus?.(o),o.defaultPrevented||(r.current||n.triggerRef.current?.focus(),o.preventDefault()),r.current=!1,a.current=!1},onInteractOutside:o=>{e.onInteractOutside?.(o),o.defaultPrevented||(r.current=!0,o.detail.originalEvent.type==="pointerdown"&&(a.current=!0));const i=o.target;n.triggerRef.current?.contains(i)&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&a.current&&o.preventDefault()}})}),jl=c.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:a,onCloseAutoFocus:o,...i}=e,l=Je(us,n);return Em(),s.jsx(s.Fragment,{children:s.jsx(Oi,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:a,onUnmountAutoFocus:o,children:s.jsx(Di,{role:"dialog",id:l.contentId,"aria-describedby":l.descriptionId,"aria-labelledby":l.titleId,"data-state":aa(l.open),...i,ref:t,deferPointerDownOutside:!0,onDismiss:()=>l.onOpenChange(!1)})})})}),Sl="DialogTitle",kl=c.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,a=Je(Sl,n);return s.jsx(pt.h2,{id:a.titleId,...r,ref:t})});kl.displayName=Sl;var Nl="DialogDescription",Xg=c.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,a=Je(Nl,n);return s.jsx(pt.p,{id:a.descriptionId,...r,ref:t})});Xg.displayName=Nl;var Cl="DialogClose",Jg=c.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,a=Je(Cl,n);return s.jsx(pt.button,{type:"button",...r,ref:t,onClick:Nt(e.onClick,()=>a.onOpenChange(!1))})});Jg.displayName=Cl;function aa(e){return e?"open":"closed"}function Zg(e){if(typeof document>"u")return;let t=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.type="text/css",t.appendChild(n),n.styleSheet?n.styleSheet.cssText=e:n.appendChild(document.createTextNode(e))}const El=B.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}),Us=()=>{const e=B.useContext(El);if(!e)throw new Error("useDrawerContext must be used within a Drawer.Root");return e};Zg(`[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(
|
|
111
111
|
[data-state=closed]
|
|
112
112
|
){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 ep(){const e=navigator.userAgent;return typeof window<"u"&&(/Firefox/.test(e)&&/Mobile/.test(e)||/FxiOS/.test(e))}function tp(){return oa(/^Mac/)}function sp(){return oa(/^iPhone/)}function uo(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function np(){return oa(/^iPad/)||tp()&&navigator.maxTouchPoints>1}function Il(){return sp()||np()}function oa(e){return typeof window<"u"&&window.navigator!=null?e.test(window.navigator.platform):void 0}const rp=24,ap=typeof window<"u"?c.useLayoutEffect:c.useEffect;function fo(...e){return(...t)=>{for(let n of e)typeof n=="function"&&n(...t)}}const ar=typeof document<"u"&&window.visualViewport;function mo(e){let t=window.getComputedStyle(e);return/(auto|scroll)/.test(t.overflow+t.overflowX+t.overflowY)}function Rl(e){for(mo(e)&&(e=e.parentElement);e&&!mo(e);)e=e.parentElement;return e||document.scrollingElement||document.documentElement}const op=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);let an=0,or;function ip(e={}){let{isDisabled:t}=e;ap(()=>{if(!t)return an++,an===1&&Il()&&(or=lp()),()=>{an--,an===0&&or?.()}},[t])}function lp(){let e,t=0,n=f=>{e=Rl(f.target),!(e===document.documentElement&&e===document.body)&&(t=f.changedTouches[0].pageY)},r=f=>{if(!e||e===document.documentElement||e===document.body){f.preventDefault();return}let h=f.changedTouches[0].pageY,x=e.scrollTop,b=e.scrollHeight-e.clientHeight;b!==0&&((x<=0&&h>t||x>=b&&h<t)&&f.preventDefault(),t=h)},a=f=>{let h=f.target;kr(h)&&h!==document.activeElement&&(f.preventDefault(),h.style.transform="translateY(-2000px)",h.focus(),requestAnimationFrame(()=>{h.style.transform=""}))},o=f=>{let h=f.target;kr(h)&&(h.style.transform="translateY(-2000px)",requestAnimationFrame(()=>{h.style.transform="",ar&&(ar.height<window.innerHeight?requestAnimationFrame(()=>{ho(h)}):ar.addEventListener("resize",()=>ho(h),{once:!0}))}))},i=()=>{window.scrollTo(0,0)},l=window.pageXOffset,u=window.pageYOffset,d=fo(cp(document.documentElement,"paddingRight",`${window.innerWidth-document.documentElement.clientWidth}px`));window.scrollTo(0,0);let m=fo(Ns(document,"touchstart",n,{passive:!1,capture:!0}),Ns(document,"touchmove",r,{passive:!1,capture:!0}),Ns(document,"touchend",a,{passive:!1,capture:!0}),Ns(document,"focus",o,!0),Ns(window,"scroll",i));return()=>{d(),m(),window.scrollTo(l,u)}}function cp(e,t,n){let r=e.style[t];return e.style[t]=n,()=>{e.style[t]=r}}function Ns(e,t,n,r){return e.addEventListener(t,n,r),()=>{e.removeEventListener(t,n,r)}}function ho(e){let t=document.scrollingElement||document.documentElement;for(;e&&e!==t;){let n=Rl(e);if(n!==document.documentElement&&n!==document.body&&n!==e){let r=n.getBoundingClientRect().top,a=e.getBoundingClientRect().top,o=e.getBoundingClientRect().bottom;const i=n.getBoundingClientRect().bottom+rp;o>i&&(n.scrollTop+=a-r)}e=n.parentElement}}function kr(e){return e instanceof HTMLInputElement&&!op.has(e.type)||e instanceof HTMLTextAreaElement||e instanceof HTMLElement&&e.isContentEditable}function up(e,t){typeof e=="function"?e(t):e!=null&&(e.current=t)}function dp(...e){return t=>e.forEach(n=>up(n,t))}function Ml(...e){return c.useCallback(dp(...e),e)}const Tl=new WeakMap;function Ce(e,t,n=!1){if(!e||!(e instanceof HTMLElement))return;let r={};Object.entries(t).forEach(([a,o])=>{if(a.startsWith("--")){e.style.setProperty(a,o);return}r[a]=e.style[a],e.style[a]=o}),!n&&Tl.set(e,r)}function fp(e,t){if(!e||!(e instanceof HTMLElement))return;let n=Tl.get(e);n&&(e.style[t]=n[t])}const we=e=>{switch(e){case"top":case"bottom":return!0;case"left":case"right":return!1;default:return e}};function on(e,t){if(!e)return null;const n=window.getComputedStyle(e),r=n.transform||n.webkitTransform||n.mozTransform;let a=r.match(/^matrix3d\((.+)\)$/);return a?parseFloat(a[1].split(", ")[we(t)?13:12]):(a=r.match(/^matrix\((.+)\)$/),a?parseFloat(a[1].split(", ")[we(t)?5:4]):null)}function mp(e){return 8*(Math.log(e+1)-2)}function ir(e,t){if(!e)return()=>{};const n=e.style.cssText;return Object.assign(e.style,t),()=>{e.style.cssText=n}}function hp(...e){return(...t)=>{for(const n of e)typeof n=="function"&&n(...t)}}const ge={DURATION:.5,EASE:[.32,.72,0,1]},Dl=.4,gp=.25,pp=100,Al=8,Pt=16,Nr=26,lr="vaul-dragging";function Ol(e){const t=B.useRef(e);return B.useEffect(()=>{t.current=e}),B.useMemo(()=>(...n)=>t.current==null?void 0:t.current.call(t,...n),[])}function xp({defaultProp:e,onChange:t}){const n=B.useState(e),[r]=n,a=B.useRef(r),o=Ol(t);return B.useEffect(()=>{a.current!==r&&(o(r),a.current=r)},[r,a,o]),n}function Pl({prop:e,defaultProp:t,onChange:n=()=>{}}){const[r,a]=xp({defaultProp:t,onChange:n}),o=e!==void 0,i=o?e:r,l=Ol(n),u=B.useCallback(d=>{if(o){const f=typeof d=="function"?d(e):d;f!==e&&l(f)}else a(d)},[o,e,a,l]);return[i,u]}function bp({activeSnapPointProp:e,setActiveSnapPointProp:t,snapPoints:n,drawerRef:r,overlayRef:a,fadeFromIndex:o,onSnapPointChange:i,direction:l="bottom",container:u,snapToSequentialPoint:d}){const[m,f]=Pl({prop:e,defaultProp:n?.[0],onChange:t}),[h,x]=B.useState(typeof window<"u"?{innerWidth:window.innerWidth,innerHeight:window.innerHeight}:void 0);B.useEffect(()=>{function S(){x({innerWidth:window.innerWidth,innerHeight:window.innerHeight})}return window.addEventListener("resize",S),()=>window.removeEventListener("resize",S)},[]);const b=B.useMemo(()=>m===n?.[n.length-1]||null,[n,m]),p=B.useMemo(()=>{var S;return(S=n?.findIndex(N=>N===m))!=null?S:null},[n,m]),v=n&&n.length>0&&(o||o===0)&&!Number.isNaN(o)&&n[o]===m||!n,g=B.useMemo(()=>{const S=u?{width:u.getBoundingClientRect().width,height:u.getBoundingClientRect().height}:typeof window<"u"?{width:window.innerWidth,height:window.innerHeight}:{width:0,height:0};var N;return(N=n?.map(I=>{const T=typeof I=="string";let E=0;if(T&&(E=parseInt(I,10)),we(l)){const R=T?E:h?I*S.height:0;return h?l==="bottom"?S.height-R:-S.height+R:R}const M=T?E:h?I*S.width:0;return h?l==="right"?S.width-M:-S.width+M:M}))!=null?N:[]},[n,h,u]),y=B.useMemo(()=>p!==null?g?.[p]:null,[g,p]),j=B.useCallback(S=>{var N;const I=(N=g?.findIndex(T=>T===S))!=null?N:null;i(I),Ce(r.current,{transition:`transform ${ge.DURATION}s cubic-bezier(${ge.EASE.join(",")})`,transform:we(l)?`translate3d(0, ${S}px, 0)`:`translate3d(${S}px, 0, 0)`}),g&&I!==g.length-1&&o!==void 0&&I!==o&&I<o?Ce(a.current,{transition:`opacity ${ge.DURATION}s cubic-bezier(${ge.EASE.join(",")})`,opacity:"0"}):Ce(a.current,{transition:`opacity ${ge.DURATION}s cubic-bezier(${ge.EASE.join(",")})`,opacity:"1"}),f(n?.[Math.max(I,0)])},[r.current,n,g,o,a,f]);B.useEffect(()=>{if(m||e){var S;const N=(S=n?.findIndex(I=>I===e||I===m))!=null?S:-1;g&&N!==-1&&typeof g[N]=="number"&&j(g[N])}},[m,e,n,g,j]);function w({draggedDistance:S,closeDrawer:N,velocity:I,dismissible:T}){if(o===void 0)return;const E=l==="bottom"||l==="right"?(y??0)-S:(y??0)+S,M=p===o-1,R=p===0,A=S>0;if(M&&Ce(a.current,{transition:`opacity ${ge.DURATION}s cubic-bezier(${ge.EASE.join(",")})`}),!d&&I>2&&!A){T?N():j(g[0]);return}if(!d&&I>2&&A&&g&&n){j(g[n.length-1]);return}const D=g?.reduce(($,te)=>typeof $!="number"||typeof te!="number"?$:Math.abs(te-E)<Math.abs($-E)?te:$),F=we(l)?window.innerHeight:window.innerWidth;if(I>Dl&&Math.abs(S)<F*.4){const $=A?1:-1;if($>0&&b&&n){j(g[n.length-1]);return}if(R&&$<0&&T&&N(),p===null)return;j(g[p+$]);return}j(D)}function C({draggedDistance:S}){if(y===null)return;const N=l==="bottom"||l==="right"?y-S:y+S;(l==="bottom"||l==="right")&&N<g[g.length-1]||(l==="top"||l==="left")&&N>g[g.length-1]||Ce(r.current,{transform:we(l)?`translate3d(0, ${N}px, 0)`:`translate3d(${N}px, 0, 0)`})}function k(S,N){if(!n||typeof p!="number"||!g||o===void 0)return null;const I=p===o-1;if(p>=o&&N)return 0;if(I&&!N)return 1;if(!v&&!I)return null;const E=I?p+1:p-1,M=I?g[E]-g[E-1]:g[E+1]-g[E],R=S/Math.abs(M);return I?1-R:R}return{isLastSnapPoint:b,activeSnapPoint:m,shouldFade:v,getPercentageDragged:k,setActiveSnapPoint:f,activeSnapPointIndex:p,onRelease:w,onDrag:C,snapPointsOffset:g}}const vp=()=>()=>{};function yp(){const{direction:e,isOpen:t,shouldScaleBackground:n,setBackgroundColorOnScale:r,noBodyStyles:a}=Us(),o=B.useRef(null),i=c.useMemo(()=>document.body.style.backgroundColor,[]);function l(){return(window.innerWidth-Nr)/window.innerWidth}B.useEffect(()=>{if(t&&n){o.current&&clearTimeout(o.current);const u=document.querySelector("[data-vaul-drawer-wrapper]")||document.querySelector("[vaul-drawer-wrapper]");if(!u)return;hp(r&&!a?ir(document.body,{background:"black"}):vp,ir(u,{transformOrigin:we(e)?"top":"left",transitionProperty:"transform, border-radius",transitionDuration:`${ge.DURATION}s`,transitionTimingFunction:`cubic-bezier(${ge.EASE.join(",")})`}));const d=ir(u,{borderRadius:`${Al}px`,overflow:"hidden",...we(e)?{transform:`scale(${l()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`}:{transform:`scale(${l()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)`}});return()=>{d(),o.current=window.setTimeout(()=>{i?document.body.style.background=i:document.body.style.removeProperty("background")},ge.DURATION*1e3)}}},[t,n,i])}let Cs=null;function wp({isOpen:e,modal:t,nested:n,hasBeenOpened:r,preventScrollRestoration:a,noBodyStyles:o}){const[i,l]=B.useState(()=>typeof window<"u"?window.location.href:""),u=B.useRef(0),d=B.useCallback(()=>{if(uo()&&Cs===null&&e&&!o){Cs={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 x=h-window.innerHeight;x&&u.current>=h&&(document.body.style.top=`${-(u.current+x)}px`)}),300)}},[e]),m=B.useCallback(()=>{if(uo()&&Cs!==null&&!o){const f=-parseInt(document.body.style.top,10),h=-parseInt(document.body.style.left,10);Object.assign(document.body.style,Cs),window.requestAnimationFrame(()=>{if(a&&i!==window.location.href){l(window.location.href);return}window.scrollTo(h,f)}),Cs=null}},[i]);return B.useEffect(()=>{function f(){u.current=window.scrollY}return f(),window.addEventListener("scroll",f),()=>{window.removeEventListener("scroll",f)}},[]),B.useEffect(()=>{if(t)return()=>{typeof document>"u"||document.querySelector("[data-vaul-drawer]")||m()}},[t,m]),B.useEffect(()=>{n||!r||(e?(!window.matchMedia("(display-mode: standalone)").matches&&d(),t||window.setTimeout(()=>{m()},500)):m())},[e,r,i,t,n,d,m]),{restorePositionSetting:m}}function jp({open:e,onOpenChange:t,children:n,onDrag:r,onRelease:a,snapPoints:o,shouldScaleBackground:i=!1,setBackgroundColorOnScale:l=!0,closeThreshold:u=gp,scrollLockTimeout:d=pp,dismissible:m=!0,handleOnly:f=!1,fadeFromIndex:h=o&&o.length-1,activeSnapPoint:x,setActiveSnapPoint:b,fixed:p,modal:v=!0,onClose:g,nested:y,noBodyStyles:j=!1,direction:w="bottom",defaultOpen:C=!1,disablePreventScroll:k=!0,snapToSequentialPoint:S=!1,preventScrollRestoration:N=!1,repositionInputs:I=!0,onAnimationEnd:T,container:E,autoFocus:M=!1}){var R,A;const[D=!1,F]=Pl({defaultProp:C,prop:e,onChange:V=>{t?.(V),!V&&!y&<(),setTimeout(()=>{T?.(V)},ge.DURATION*1e3),V&&!v&&typeof window<"u"&&window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"}),V||(document.body.style.pointerEvents="auto")}}),[$,te]=B.useState(!1),[q,Q]=B.useState(!1),[X,ee]=B.useState(!1),se=B.useRef(null),P=B.useRef(null),_=B.useRef(null),H=B.useRef(null),W=B.useRef(null),le=B.useRef(!1),me=B.useRef(null),J=B.useRef(0),Ie=B.useRef(!1),he=B.useRef(!C),ke=B.useRef(0),Y=B.useRef(null),U=B.useRef(((R=Y.current)==null?void 0:R.getBoundingClientRect().height)||0),z=B.useRef(((A=Y.current)==null?void 0:A.getBoundingClientRect().width)||0),ne=B.useRef(0),Ue=B.useCallback(V=>{o&&V===ce.length-1&&(P.current=new Date)},[]),{activeSnapPoint:Qe,activeSnapPointIndex:Pe,setActiveSnapPoint:Te,onRelease:xe,snapPointsOffset:ce,onDrag:it,shouldFade:xt,getPercentageDragged:vs}=bp({snapPoints:o,activeSnapPointProp:x,setActiveSnapPointProp:b,drawerRef:Y,fadeFromIndex:h,overlayRef:se,onSnapPointChange:Ue,direction:w,container:E,snapToSequentialPoint:S});ip({isDisabled:!D||q||!v||X||!$||!I||!k});const{restorePositionSetting:lt}=wp({isOpen:D,modal:v,nested:y??!1,hasBeenOpened:$,preventScrollRestoration:N,noBodyStyles:j});function Fe(){return(window.innerWidth-Nr)/window.innerWidth}function Le(V){var oe,re;!m&&!o||Y.current&&!Y.current.contains(V.target)||(U.current=((oe=Y.current)==null?void 0:oe.getBoundingClientRect().height)||0,z.current=((re=Y.current)==null?void 0:re.getBoundingClientRect().width)||0,Q(!0),_.current=new Date,Il()&&window.addEventListener("touchend",()=>le.current=!1,{once:!0}),V.target.setPointerCapture(V.pointerId),J.current=we(w)?V.pageY:V.pageX)}function De(V,oe){var re;let ae=V;const fe=(re=window.getSelection())==null?void 0:re.toString(),Ne=Y.current?on(Y.current,w):null,be=new Date;if(ae.tagName==="SELECT"||ae.hasAttribute("data-vaul-no-drag")||ae.closest("[data-vaul-no-drag]"))return!1;if(w==="right"||w==="left")return!0;if(P.current&&be.getTime()-P.current.getTime()<500)return!1;if(Ne!==null&&(w==="bottom"?Ne>0:Ne<0))return!0;if(fe&&fe.length>0)return!1;if(W.current&&be.getTime()-W.current.getTime()<d&&Ne===0||oe)return W.current=be,!1;for(;ae;){if(ae.scrollHeight>ae.clientHeight){if(ae.scrollTop!==0)return W.current=new Date,!1;if(ae.getAttribute("role")==="dialog")return!0}ae=ae.parentNode}return!0}function Dt(V){if(Y.current&&q){const oe=w==="bottom"||w==="right"?1:-1,re=(J.current-(we(w)?V.pageY:V.pageX))*oe,ae=re>0,fe=o&&!m&&!ae;if(fe&&Pe===0)return;const Ne=Math.abs(re),be=document.querySelector("[data-vaul-drawer-wrapper]"),ve=w==="bottom"||w==="top"?U.current:z.current;let ye=Ne/ve;const Ae=vs(Ne,ae);if(Ae!==null&&(ye=Ae),fe&&ye>=1||!le.current&&!De(V.target,ae))return;if(Y.current.classList.add(lr),le.current=!0,Ce(Y.current,{transition:"none"}),Ce(se.current,{transition:"none"}),o&&it({draggedDistance:re}),ae&&!o){const Re=mp(re),ut=Math.min(Re*-1,0)*oe;Ce(Y.current,{transform:we(w)?`translate3d(0, ${ut}px, 0)`:`translate3d(${ut}px, 0, 0)`});return}const _e=1-ye;if((xt||h&&Pe===h-1)&&(r?.(V,ye),Ce(se.current,{opacity:`${_e}`,transition:"none"},!0)),be&&se.current&&i){const Re=Math.min(Fe()+ye*(1-Fe()),1),ut=8-ye*8,Ve=Math.max(0,14-ye*14);Ce(be,{borderRadius:`${ut}px`,transform:we(w)?`scale(${Re}) translate3d(0, ${Ve}px, 0)`:`scale(${Re}) translate3d(${Ve}px, 0, 0)`,transition:"none"},!0)}if(!o){const Re=Ne*oe;Ce(Y.current,{transform:we(w)?`translate3d(0, ${Re}px, 0)`:`translate3d(${Re}px, 0, 0)`})}}}B.useEffect(()=>{window.requestAnimationFrame(()=>{he.current=!0})},[]),B.useEffect(()=>{var V;function oe(){if(!Y.current||!I)return;const re=document.activeElement;if(kr(re)||Ie.current){var ae;const fe=((ae=window.visualViewport)==null?void 0:ae.height)||0,Ne=window.innerHeight;let be=Ne-fe;const ve=Y.current.getBoundingClientRect().height||0,ye=ve>Ne*.8;ne.current||(ne.current=ve);const Ae=Y.current.getBoundingClientRect().top;if(Math.abs(ke.current-be)>60&&(Ie.current=!Ie.current),o&&o.length>0&&ce&&Pe){const _e=ce[Pe]||0;be+=_e}if(ke.current=be,ve>fe||Ie.current){const _e=Y.current.getBoundingClientRect().height;let Re=_e;_e>fe&&(Re=fe-(ye?Ae:Nr)),p?Y.current.style.height=`${_e-Math.max(be,0)}px`:Y.current.style.height=`${Math.max(Re,fe-Ae)}px`}else ep()||(Y.current.style.height=`${ne.current}px`);o&&o.length>0&&!Ie.current?Y.current.style.bottom="0px":Y.current.style.bottom=`${Math.max(be,0)}px`}}return(V=window.visualViewport)==null||V.addEventListener("resize",oe),()=>{var re;return(re=window.visualViewport)==null?void 0:re.removeEventListener("resize",oe)}},[Pe,o,ce]);function He(V){Ht(),g?.(),V||F(!1),setTimeout(()=>{o&&Te(o[0])},ge.DURATION*1e3)}function ct(){if(!Y.current)return;const V=document.querySelector("[data-vaul-drawer-wrapper]"),oe=on(Y.current,w);Ce(Y.current,{transform:"translate3d(0, 0, 0)",transition:`transform ${ge.DURATION}s cubic-bezier(${ge.EASE.join(",")})`}),Ce(se.current,{transition:`opacity ${ge.DURATION}s cubic-bezier(${ge.EASE.join(",")})`,opacity:"1"}),i&&oe&&oe>0&&D&&Ce(V,{borderRadius:`${Al}px`,overflow:"hidden",...we(w)?{transform:`scale(${Fe()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`,transformOrigin:"top"}:{transform:`scale(${Fe()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)`,transformOrigin:"left"},transitionProperty:"transform, border-radius",transitionDuration:`${ge.DURATION}s`,transitionTimingFunction:`cubic-bezier(${ge.EASE.join(",")})`},!0)}function Ht(){!q||!Y.current||(Y.current.classList.remove(lr),le.current=!1,Q(!1),H.current=new Date)}function We(V){if(!q||!Y.current)return;Y.current.classList.remove(lr),le.current=!1,Q(!1),H.current=new Date;const oe=on(Y.current,w);if(!V||!De(V.target,!1)||!oe||Number.isNaN(oe)||_.current===null)return;const re=H.current.getTime()-_.current.getTime(),ae=J.current-(we(w)?V.pageY:V.pageX),fe=Math.abs(ae)/re;if(fe>.05&&(ee(!0),setTimeout(()=>{ee(!1)},200)),o){xe({draggedDistance:ae*(w==="bottom"||w==="right"?1:-1),closeDrawer:He,velocity:fe,dismissible:m}),a?.(V,!0);return}if(w==="bottom"||w==="right"?ae>0:ae<0){ct(),a?.(V,!0);return}if(fe>Dl){He(),a?.(V,!1);return}var Ne;const be=Math.min((Ne=Y.current.getBoundingClientRect().height)!=null?Ne:0,window.innerHeight);var ve;const ye=Math.min((ve=Y.current.getBoundingClientRect().width)!=null?ve:0,window.innerWidth),Ae=w==="left"||w==="right";if(Math.abs(oe)>=(Ae?ye:be)*u){He(),a?.(V,!1);return}a?.(V,!0),ct()}B.useEffect(()=>(D&&(Ce(document.documentElement,{scrollBehavior:"auto"}),P.current=new Date),()=>{fp(document.documentElement,"scrollBehavior")}),[D]);function Ee(V){const oe=V?(window.innerWidth-Pt)/window.innerWidth:1,re=V?-Pt:0;me.current&&window.clearTimeout(me.current),Ce(Y.current,{transition:`transform ${ge.DURATION}s cubic-bezier(${ge.EASE.join(",")})`,transform:we(w)?`scale(${oe}) translate3d(0, ${re}px, 0)`:`scale(${oe}) translate3d(${re}px, 0, 0)`}),!V&&Y.current&&(me.current=setTimeout(()=>{const ae=on(Y.current,w);Ce(Y.current,{transition:"none",transform:we(w)?`translate3d(0, ${ae}px, 0)`:`translate3d(${ae}px, 0, 0)`})},500))}function ys(V,oe){if(oe<0)return;const re=(window.innerWidth-Pt)/window.innerWidth,ae=re+oe*(1-re),fe=-Pt+oe*Pt;Ce(Y.current,{transform:we(w)?`scale(${ae}) translate3d(0, ${fe}px, 0)`:`scale(${ae}) translate3d(${fe}px, 0, 0)`,transition:"none"})}function Ze(V,oe){const re=we(w)?window.innerHeight:window.innerWidth,ae=oe?(re-Pt)/re:1,fe=oe?-Pt:0;oe&&Ce(Y.current,{transition:`transform ${ge.DURATION}s cubic-bezier(${ge.EASE.join(",")})`,transform:we(w)?`scale(${ae}) translate3d(0, ${fe}px, 0)`:`scale(${ae}) translate3d(${fe}px, 0, 0)`})}return B.useEffect(()=>{v||window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"})},[v]),B.createElement(pl,{defaultOpen:C,onOpenChange:V=>{!m&&!V||(V?te(!0):He(!0),F(V))},open:D},B.createElement(El.Provider,{value:{activeSnapPoint:Qe,snapPoints:o,setActiveSnapPoint:Te,drawerRef:Y,overlayRef:se,onOpenChange:t,onPress:Le,onRelease:We,onDrag:Dt,dismissible:m,shouldAnimate:he,handleOnly:f,isOpen:D,isDragging:q,shouldFade:xt,closeDrawer:He,onNestedDrag:ys,onNestedOpenChange:Ee,onNestedRelease:Ze,keyboardIsOpen:Ie,modal:v,snapPointsOffset:ce,activeSnapPointIndex:Pe,direction:w,shouldScaleBackground:i,setBackgroundColorOnScale:l,noBodyStyles:j,container:E,autoFocus:M}},n))}const Ll=B.forwardRef(function({...e},t){const{overlayRef:n,snapPoints:r,onRelease:a,shouldFade:o,isOpen:i,modal:l,shouldAnimate:u}=Us(),d=Ml(t,n),m=r&&r.length>0;if(!l)return null;const f=B.useCallback(h=>a(h),[a]);return B.createElement(yl,{onMouseUp:f,ref:d,"data-vaul-overlay":"","data-vaul-snap-points":i&&m?"true":"false","data-vaul-snap-points-overlay":i&&o?"true":"false","data-vaul-animate":u?.current?"true":"false",...e})});Ll.displayName="Drawer.Overlay";const zl=B.forwardRef(function({onPointerDownOutside:e,style:t,onOpenAutoFocus:n,...r},a){const{drawerRef:o,onPress:i,onRelease:l,onDrag:u,keyboardIsOpen:d,snapPointsOffset:m,activeSnapPointIndex:f,modal:h,isOpen:x,direction:b,snapPoints:p,container:v,handleOnly:g,shouldAnimate:y,autoFocus:j}=Us(),[w,C]=B.useState(!1),k=Ml(a,o),S=B.useRef(null),N=B.useRef(null),I=B.useRef(!1),T=p&&p.length>0;yp();const E=(R,A,D=0)=>{if(I.current)return!0;const F=Math.abs(R.y),$=Math.abs(R.x),te=$>F,q=["bottom","right"].includes(A)?1:-1;if(A==="left"||A==="right"){if(!(R.x*q<0)&&$>=0&&$<=D)return te}else if(!(R.y*q<0)&&F>=0&&F<=D)return!te;return I.current=!0,!0};B.useEffect(()=>{T&&window.requestAnimationFrame(()=>{C(!0)})},[]);function M(R){S.current=null,I.current=!1,l(R)}return B.createElement(wl,{"data-vaul-drawer-direction":b,"data-vaul-drawer":"","data-vaul-delayed-snap-points":w?"true":"false","data-vaul-snap-points":x&&T?"true":"false","data-vaul-custom-container":v?"true":"false","data-vaul-animate":y?.current?"true":"false",...r,ref:k,style:m&&m.length>0?{"--snap-point-height":`${m[f??0]}px`,...t}:t,onPointerDown:R=>{g||(r.onPointerDown==null||r.onPointerDown.call(r,R),S.current={x:R.pageX,y:R.pageY},i(R))},onOpenAutoFocus:R=>{n?.(R),j||R.preventDefault()},onPointerDownOutside:R=>{if(e?.(R),!h||R.defaultPrevented){R.preventDefault();return}d.current&&(d.current=!1)},onFocusOutside:R=>{if(!h){R.preventDefault();return}},onPointerMove:R=>{if(N.current=R,g||(r.onPointerMove==null||r.onPointerMove.call(r,R),!S.current))return;const A=R.pageY-S.current.y,D=R.pageX-S.current.x,F=R.pointerType==="touch"?10:2;E({x:D,y:A},b,F)?u(R):(Math.abs(D)>F||Math.abs(A)>F)&&(S.current=null)},onPointerUp:R=>{r.onPointerUp==null||r.onPointerUp.call(r,R),S.current=null,I.current=!1,l(R)},onPointerOut:R=>{r.onPointerOut==null||r.onPointerOut.call(r,R),M(N.current)},onContextMenu:R=>{r.onContextMenu==null||r.onContextMenu.call(r,R),N.current&&M(N.current)}})});zl.displayName="Drawer.Content";const Sp=250,kp=120,Fl=B.forwardRef(function({preventCycle:e=!1,children:t,...n},r){const{closeDrawer:a,isDragging:o,snapPoints:i,activeSnapPoint:l,setActiveSnapPoint:u,dismissible:d,handleOnly:m,isOpen:f,onPress:h,onDrag:x}=Us(),b=B.useRef(null),p=B.useRef(!1);function v(){if(p.current){j();return}window.setTimeout(()=>{g()},kp)}function g(){if(o||e||p.current){j();return}if(j(),!i||i.length===0){d||a();return}if(l===i[i.length-1]&&d){a();return}const C=i.findIndex(S=>S===l);if(C===-1)return;const k=i[C+1];u(k)}function y(){b.current=window.setTimeout(()=>{p.current=!0},Sp)}function j(){b.current&&window.clearTimeout(b.current),p.current=!1}return B.createElement("div",{onClick:v,onPointerCancel:j,onPointerDown:w=>{m&&h(w),y()},onPointerMove:w=>{m&&x(w)},ref:r,"data-vaul-drawer-visible":f?"true":"false","data-vaul-handle":"","aria-hidden":"true",...n},B.createElement("span",{"data-vaul-handle-hitarea":"","aria-hidden":"true"},t))});Fl.displayName="Drawer.Handle";function Np(e){const t=Us(),{container:n=t.container,...r}=e;return B.createElement(vl,{container:n,...r})}const $e={Root:jp,Content:zl,Overlay:Ll,Portal:Np,Handle:Fl,Title:kl},Cp=new Set(["outbox","postvak uit","boîte d'envoi","postausgang","buzón de salida","posta in uscita","送信トレイ","送件匣","发件箱","skrzynka nadawcza"]),Ep=e=>{const t=hn(e.fullPath).trim().toLowerCase();return Cp.has(t)},go=gr.length,ia=(e,t=[])=>{const n=fs(t);return[...e.filter(a=>{const o=n.get(a.mailboxId);return o==="drafts"||o==="sent"?!1:!Ep(a)})].sort((a,o)=>{const i=n.has(a.mailboxId)?gr.indexOf(n.get(a.mailboxId)??"inbox"):go,l=n.has(o.mailboxId)?gr.indexOf(n.get(o.mailboxId)??"inbox"):go;return i!==l?i-l:hn(a.fullPath).localeCompare(hn(o.fullPath),void 0,{sensitivity:"base",numeric:!0})})},_l="inline-flex items-center justify-center transition-colors",Ip=de(_l,"min-h-11 min-w-11 rounded hover:bg-surface-raised"),Rp=de(_l,"min-h-11 gap-1.5 px-3 rounded text-sm font-medium hover:bg-surface-raised"),Qs=({accountId:e,currentMailboxId:t,onMove:n,disabled:r=!1,disabledHint:a,variant:o="icon-only",label:i})=>{const[l,u]=c.useState(!1),d=Qt(),m=c.useRef(null),f=i??"Move to folder",h=c.useId(),{t:x}=yn("mail",{useSuspense:!1}),b=c.useCallback((T,E)=>x(T,{defaultValue:E}),[x]),{data:p,isLoading:v,isError:g,error:y,refetch:j}=ue({...rt({path:{accountId:e}}),staleTime:1/0,enabled:l}),w=fl(e),C=c.useMemo(()=>{const T=ia(p?.items??[],w),E=fs(w);return T.map(M=>({id:M.mailboxId,label:os(M,E.get(M.mailboxId),b),searchValue:M.fullPath,isCurrent:M.mailboxId===t}))},[p?.items,w,t,b]),k=c.useCallback(T=>{u(!1),n(T)},[n]);c.useEffect(()=>{if(!l||!d)return;const T=M=>{m.current&&!m.current.contains(M.target)&&u(!1)},E=M=>{M.key==="Escape"&&u(!1)};return document.addEventListener("mousedown",T),document.addEventListener("keydown",E),()=>{document.removeEventListener("mousedown",T),document.removeEventListener("keydown",E)}},[l,d]);const S=r||!!a,N=s.jsxs("button",{type:"button",onClick:T=>{T.stopPropagation(),!S&&u(E=>!E)},"aria-label":f,"aria-haspopup":d?"listbox":"dialog","aria-expanded":l,"aria-controls":l?h:void 0,title:a,className:o==="icon-only"?Ip:Rp,children:[s.jsx(li,{className:"size-4"}),o==="compact"&&s.jsx("span",{className:"hidden sm:inline",children:"Move"})]}),I=v?s.jsx("div",{className:"px-3 py-5 text-sm text-fg-muted",children:"Loading folders…"}):g?s.jsx("div",{className:"p-3",children:s.jsx(Mt,{variant:"inline",title:"Couldn't load folders",error:y,onRetry:()=>j()})}):s.jsx(Ri,{mailboxes:C,onSelect:k,onCancel:()=>u(!1),autoFocus:!d,labels:{searchPlaceholder:x("move_picker_placeholder",{defaultValue:"Move to…"}),searchAriaLabel:x("move_picker_filter_label",{defaultValue:"Filter folders"}),optionLabel:T=>`Move to ${T}`,currentSuffix:"(current folder)",currentTag:"current",emptyMessage:T=>`No folders match "${T}"`}});return d?s.jsxs("div",{ref:m,className:"relative inline-block",children:[N,l&&s.jsx("div",{id:h,className:de("absolute right-0 mt-1 z-50 w-72 max-h-96 flex flex-col","bg-surface border border-line rounded-md shadow-lg"),children:I})]}):s.jsxs(s.Fragment,{children:[N,s.jsx($e.Root,{open:l,onOpenChange:u,children:s.jsxs($e.Portal,{children:[s.jsx($e.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),s.jsxs($e.Content,{className:"fixed inset-x-0 bottom-0 z-50 flex flex-col bg-canvas rounded-t-lg",style:{maxHeight:"85dvh"},id:h,children:[s.jsx($e.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-subtle/30"}),s.jsx($e.Title,{className:"px-4 py-2 text-base font-semibold border-b border-line",children:"Move to folder"}),s.jsx("div",{className:"flex-1 overflow-hidden",children:I})]})]})})]})},Mp=({messageId:e,threadId:t,mailboxId:n,isRead:r,accountId:a,fromAddressId:o,isTrusted:i=!1,showRaw:l=!1,onToggleRaw:u})=>{const d=je(),m=Me(),{pushError:f}=qe(),{selectedMessageId:h}=as({strict:!1}),{mutate:x,isPending:b}=pe({...Sn(),onMutate:async D=>{const F=D.body.isRead??!0,$=new Set(D.body.messageIds??[]),te=$t({path:{threadId:t}}),q=at({path:{mailboxId:n}}),Q=gt({path:{mailboxId:n}});await Promise.all([d.cancelQueries({queryKey:te}),d.cancelQueries({queryKey:q}),d.cancelQueries({queryKey:Q})]);const X=d.getQueriesData({queryKey:te}).filter(P=>P[1]!==void 0).map(([P,_])=>({queryKey:P,data:_})),ee=d.getQueriesData({queryKey:q}).concat(d.getQueriesData({queryKey:Q})).filter(P=>P[1]!==void 0).map(([P,_])=>({queryKey:P,data:_}));d.setQueriesData({queryKey:te},P=>P&&{...P,items:P.items.map(_=>$.has(_.messageId)?{..._,isRead:F}:_)});const se=P=>cs(P,_=>_.map(H=>$.has(H.messageId)?{...H,isRead:F}:H));return d.setQueriesData({queryKey:q},se),d.setQueriesData({queryKey:Q},se),{threadMessagesPrefix:te,threadsListPrefix:q,threadsSearchPrefix:Q,previousThreadMessages:X,previousThreadsList:ee}},onError:(D,F,$)=>{if($){for(const q of $.previousThreadMessages)d.setQueryData(q.queryKey,q.data);for(const q of $.previousThreadsList)d.setQueryData(q.queryKey,q.data)}const te=F.body.isRead??!0;f({title:te?"Couldn't mark as read":"Couldn't mark as unread",detail:st(D),error:D})},onSettled:(D,F,$,te)=>{te&&(d.invalidateQueries({queryKey:te.threadMessagesPrefix}),d.invalidateQueries({queryKey:te.threadsListPrefix}),d.invalidateQueries({queryKey:te.threadsSearchPrefix}))}}),p=c.useCallback(D=>{h&&D.includes(h)&&m({to:"/mail/$mailboxId",params:{mailboxId:n},search:F=>({...F,selectedMessageId:void 0})})},[h,n,m]),{deleteMessages:v,isPending:g}=As({mailboxId:n,threadId:t,onAfterOptimisticRemove:p}),{moveMessages:y,isPending:j}=Ct({mailboxId:n,threadId:t,accountId:a,onAfterOptimisticRemove:p}),{toggleTrusted:w,isPending:C,error:k,reset:S}=na({messageId:e}),N=()=>{x({body:{messageIds:[e],isRead:!1}})},I=()=>{v([e])},T=()=>{o&&w(o,i)},E=b||g||j||C,M=E||!o,R=c.useCallback(D=>{y([e],D)},[y,e]),A=o?void 0:"Sender has no parseable address";return s.jsxs("div",{className:"flex flex-col items-end gap-1",children:[s.jsxs("div",{className:"flex items-center gap-1",children:[a&&s.jsx(Qs,{accountId:a,currentMailboxId:n,onMove:R,disabled:E,label:"Move this message"}),s.jsxs(Wi,{trigger:s.jsx(ii,{className:"size-4"}),children:[s.jsxs(ss,{onClick:T,disabled:M,children:[i?s.jsx(kn,{className:"size-4 text-positive"}):s.jsx(Bs,{className:"size-4 opacity-0"}),s.jsx("span",{title:A,children:"Trusted sender"})]}),r&&s.jsxs(ss,{onClick:N,disabled:E,children:[s.jsx($s,{className:"size-4"}),"Mark as unread"]}),u&&s.jsxs(ss,{onClick:u,children:[s.jsx(oi,{className:"size-4"}),l?"Show formatted":"Show raw email"]}),s.jsx(vr,{}),s.jsxs(ss,{onClick:I,disabled:E,destructive:!0,children:[s.jsx(ot,{className:"size-4"}),"Delete"]})]})]}),k&&s.jsx("div",{className:"w-64",children:s.jsx(Mt,{variant:"inline",title:"Couldn't update trust",error:k,onRetry:()=>{S(),T()}})})]})},Tp=()=>{const[e,t]=c.useState(()=>typeof document<"u"&&document.documentElement.classList.contains("dark"));return c.useEffect(()=>{const n=document.documentElement,r=new MutationObserver(()=>{t(n.classList.contains("dark"))});return r.observe(n,{attributes:!0,attributeFilter:["class"]}),()=>r.disconnect()},[]),e},Dp=({blockedImageCount:e,canAlwaysTrust:t,isTrustPending:n,onLoadOnce:r,onAlwaysTrust:a})=>s.jsxs("div",{className:"mb-3 flex items-center justify-between rounded-md bg-surface-sunken/50 px-3 py-2 text-sm",children:[s.jsxs("span",{className:"text-fg-muted",children:[e," image",e>1?"s":""," blocked for privacy"]}),s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("button",{type:"button",onClick:r,className:"text-accent hover:underline",children:"Load once"}),t&&s.jsx("button",{type:"button",onClick:a,"aria-busy":n,className:"text-accent hover:underline aria-busy:opacity-50",children:n?"Trusting…":"Always trust"})]})]}),Ap=(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}}},Op=e=>e instanceof Lt?e.reason:"generic",Pp=e=>e instanceof Error?e.message:typeof e=="string"?e:"An unexpected error occurred while loading the message body.",Lp=({error:e,onRetry:t})=>{const n=Op(e),r=Pp(e),{title:a,detail:o}=Ap(n,r),[i,l]=c.useState(!1),{Account:u}=Pr();return i?null:s.jsxs("div",{role:"alert","data-testid":"message-body-error-banner","data-reason":n,className:"flex items-start gap-2 rounded-md border border-danger/40 bg-danger-soft px-3 py-2 text-sm",children:[s.jsx(_t,{className:"size-4 shrink-0 text-danger mt-0.5","aria-hidden":"true"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"font-medium text-danger",children:a}),s.jsx("p",{className:"text-fg-muted mt-1 break-words",children:o})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-3",children:[n==="auth"&&s.jsx(u,{children:({signOut:d})=>s.jsx("button",{type:"button",onClick:()=>d(),className:"text-sm font-medium text-accent hover:underline",children:"Sign in again"})}),t&&s.jsx("button",{type:"button",onClick:t,className:"text-sm font-medium text-accent hover:underline",children:"Retry"}),s.jsx("button",{type:"button",onClick:()=>l(!0),"aria-label":"Dismiss message body error",className:"rounded-md p-1 text-fg-muted hover:bg-surface-raised hover:text-fg transition-colors",children:s.jsx(Ke,{className:"size-4","aria-hidden":"true"})})]})]})},zp=()=>s.jsxs("div",{className:"animate-pulse space-y-2",role:"status","aria-label":"Loading message body",children:[s.jsx("div",{className:"h-4 bg-surface-sunken rounded w-full"}),s.jsx("div",{className:"h-4 bg-surface-sunken rounded w-11/12"}),s.jsx("div",{className:"h-4 bg-surface-sunken rounded w-3/4"}),s.jsx("div",{className:"h-4 bg-surface-sunken rounded w-5/6"})]}),po=()=>s.jsx("p",{className:"text-fg-muted text-sm italic",children:"This message has no body content."}),Bl=({bodyParts:e,html:t,text:n,isTrusted:r=!1,messageId:a,fromAddressId:o,category:i,className:l})=>{const[u,d]=c.useState(!1),m=r||u,f=Tp(),{toggleTrusted:h,isPending:x}=na({messageId:a??""}),b=!!e&&e.length>0,{picked:p,data:v,isLoading:g,isError:y,error:j,refetch:w}=nl({messageId:a,bodyParts:e,enabled:b}),C=c.useMemo(()=>yd(e??[]),[e]),k=b&&v?.kind==="html"?v.body:t,S=b&&v?.kind==="text"?v.body:n;if(b){if(g)return s.jsx("div",{className:de("message-body",l),children:s.jsx(zp,{})});if(y)return s.jsx("div",{className:de("message-body",l),children:s.jsx(Lp,{error:j,onRetry:()=>w()})});if(!p)return s.jsx("div",{className:de("message-body",l),children:s.jsx(po,{})})}else if(!t&&!n)return s.jsx("div",{className:de("message-body",l),children:s.jsx(po,{})});const N=!!(o&&a),I=()=>{!o||x||(d(!0),h(o,!1))};return s.jsx(ki,{className:l,html:k,text:S,isDark:f,category:i,allowImages:m,resolveCid:C,renderBlockedNotice:T=>s.jsx(Dp,{blockedImageCount:T,canAlwaysTrust:N,isTrustPending:x,onLoadOnce:()=>d(!0),onAlwaysTrust:I})})},Fp=({messageId:e,threadId:t,mailboxId:n,accountId:r,isRead:a,isStarred:o,onToggleStar:i,fromAddressId:l,isTrusted:u,showRaw:d,onToggleRaw:m,onReply:f,onReplyAll:h,onForward:x})=>{const b=je(),{deleteMessages:p}=As({mailboxId:n,threadId:t}),{moveMessages:v}=Ct({mailboxId:n,threadId:t,accountId:r}),{toggleTrusted:g}=na({messageId:e}),{mutate:y}=pe({...Sn(),onSettled:()=>{b.invalidateQueries({queryKey:$t({path:{threadId:t}})}),b.invalidateQueries({queryKey:at({path:{mailboxId:n}})}),b.invalidateQueries({queryKey:gt({path:{mailboxId:n}})})}}),j=c.useCallback(S=>{v([e],S)},[v,e]),w=c.useCallback(()=>{p([e])},[p,e]),C=c.useCallback(()=>{y({body:{messageIds:[e],isRead:!a}})},[y,e,a]),k=[];return l&&k.push({key:"trusted",label:u?"Trusted sender":"Mark sender trusted",icon:u?s.jsx(kn,{className:"size-4 text-positive"}):s.jsx(Bs,{className:"size-4"}),onSelect:()=>g(l,u)}),m&&k.push({key:"raw",label:d?"Show formatted":"Show raw email",icon:s.jsx(oi,{className:"size-4"}),onSelect:m}),s.jsx(Si,{hasThread:!0,onReply:f,onReplyAll:h,onForward:x,isStarred:o,onToggleStar:i,onDelete:w,isRead:a,onToggleRead:C,overflowItems:k,moveSlot:r?s.jsx(Qs,{accountId:r,currentMailboxId:n,onMove:j,label:"Move this message"}):void 0})},_p=()=>s.jsxs("div",{className:"animate-pulse space-y-2",role:"status","aria-label":"Loading raw email",children:[s.jsx("div",{className:"h-4 bg-surface-sunken rounded w-full"}),s.jsx("div",{className:"h-4 bg-surface-sunken rounded w-11/12"}),s.jsx("div",{className:"h-4 bg-surface-sunken rounded w-5/6"}),s.jsx("div",{className:"h-4 bg-surface-sunken rounded w-3/4"})]}),Bp=({messageId:e,enabled:t=!0})=>{const{data:n,isLoading:r,isError:a,error:o,refetch:i}=ue({...nu({path:{messageId:e}}),enabled:t});if(r)return s.jsx("div",{className:"message-body",children:s.jsx(_p,{})});if(a)return s.jsx("div",{className:"message-body",children:s.jsx(Mt,{variant:"inline",title:"Couldn't load the raw email",error:o,onRetry:()=>i()})});const l=n?.raw??"";return l===""?s.jsx("div",{className:"message-body",children:s.jsx("p",{className:"text-fg-muted text-sm italic",children:"No raw source available for this message."})}):s.jsx("div",{className:"message-body",children:s.jsx("pre",{className:"email-text whitespace-pre-wrap break-words text-sm leading-relaxed bg-surface-sunken rounded-md p-3 max-h-[32rem] overflow-auto",children:l})})},$p=()=>s.jsx(kn,{className:"inline-block size-4 ml-1 -mt-0.5 text-positive align-middle","aria-label":"Trusted sender","data-testid":"trusted-sender-badge"}),$l=(e,t)=>({id:e.messageId,fromName:e.fromName??e.fromEmail??"?",fromEmail:e.fromEmail??"",toLabel:"",dateLabel:t,snippet:e.snippet||"",bodyHtml:""}),Kl=({isStarred:e,onToggleStar:t,isStarPending:n,hoverReveal:r})=>s.jsx("button",{type:"button",onClick:a=>{a.stopPropagation(),t()},disabled:n,"aria-label":e?"Remove star":"Add star",className:de("shrink-0 p-0.5 rounded transition-colors",e?"text-warning":de("text-fg-subtle hover:text-warning",r&&"opacity-0 group-hover:opacity-100 focus:opacity-100"),n&&"opacity-50"),children:s.jsx(Rt,{className:de("size-3.5",e&&"fill-current")})}),Kp=({threadMessage:e,isFocused:t,onToggle:n,onToggleStar:r,isStarPending:a})=>{const o=ti(e.sentDate,"datetime"),i=$l(e,o);return s.jsx(Ni,{message:i,onClick:n,isFocused:t,isUnread:!e.isRead,trailing:s.jsxs(s.Fragment,{children:[e.hasAttachment&&s.jsx(Nn,{className:"size-3 shrink-0 text-fg-subtle"}),s.jsx(Kl,{isStarred:e.hasStars,onToggleStar:r,isStarPending:a,hoverReveal:!0}),s.jsx("span",{"data-testid":"message-date",className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:o})]})})},qp=({threadMessage:e,messageData:t,isLoading:n,isError:r,error:a,onRetry:o,isFocused:i,onToggle:l,onToggleStar:u,isStarPending:d,accountId:m,showRaw:f,onToggleRaw:h,mobile:x,onReply:b,onReplyAll:p,onForward:v})=>{const g=ti(e.sentDate,"long"),y=!e.isRead,j=t?.envelope.from[0]?.flags?.trusted?.value===!0,w=t?.envelope.from[0]?.addressId,C=$l(e,g),k=e.autoMoved?s.jsx(ml,{accountId:m,messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,autoMoved:e.autoMoved,size:"md"}):null;return s.jsx(Ci,{message:C,isFocused:i,onHeaderClick:l,senderBadge:j?s.jsx($p,{}):void 0,trailing:s.jsx("span",{"data-testid":"message-date",className:"text-2xs text-fg-subtle",children:g}),to:t?s.jsx(Xu,{label:"To",addresses:t.envelope.to}):null,indicators:k||!x?s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mt-0.5",children:[k,!x&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex items-center justify-end gap-1",children:[s.jsx(Kl,{isStarred:e.hasStars,onToggleStar:u,isStarPending:d}),e.hasAttachment&&s.jsx("span",{className:"text-fg-subtle p-0.5",children:s.jsx(Nn,{className:"size-3.5"})})]}),y&&s.jsx("span",{className:"size-1.5 rounded-full bg-accent","aria-label":"Unread"})]})]}):void 0,actionMenu:x?void 0:s.jsx(Mp,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,isRead:e.isRead,accountId:m,fromAddressId:w,isTrusted:j,showRaw:f,onToggleRaw:h}),actionBar:x?s.jsx(Fp,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,accountId:m,isRead:e.isRead,isStarred:e.hasStars,onToggleStar:u,fromAddressId:w,isTrusted:j,showRaw:f,onToggleRaw:h,onReply:b,onReplyAll:p,onForward:v}):void 0,body:n?s.jsxs("div",{className:"mt-3 animate-pulse space-y-2",children:[s.jsx("div",{className:"h-4 bg-surface-sunken rounded w-full"}),s.jsx("div",{className:"h-4 bg-surface-sunken rounded w-3/4"}),s.jsx("div",{className:"h-4 bg-surface-sunken rounded w-1/2"})]}):r&&ru(a)?s.jsx("div",{className:"mt-3",children:s.jsx(cl,{message:"This message has been deleted"})}):r?s.jsx("div",{className:"mt-3",children:s.jsx(Mt,{variant:"inline",title:"Couldn't load this message",error:a,onRetry:o})}):f?s.jsx("div",{className:"mt-3",children:s.jsx(Bp,{messageId:e.messageId})}):s.jsx("div",{className:"mt-3",children:s.jsx(Bl,{bodyParts:t?.bodyParts,messageId:e.messageId,fromAddressId:t?.envelope.from[0]?.addressId,isTrusted:j,category:Tn(e.category)})})})},Up=({threadMessage:e,isExpanded:t,isFocused:n,onToggle:r,onToggleStar:a,isStarPending:o,accountId:i,mobile:l,onReply:u,onReplyAll:d,onForward:m})=>{const[f,h]=c.useState(!1),{data:x,isLoading:b,isError:p,error:v,refetch:g}=ue({..._r({path:{messageId:e.messageId}}),enabled:t,meta:{softError:!0}});return t?s.jsx(qp,{threadMessage:e,messageData:x,isLoading:b,isError:p,error:v,onRetry:()=>g(),isFocused:n,onToggle:r,onToggleStar:a,isStarPending:o,accountId:i,showRaw:f,onToggleRaw:()=>h(y=>!y),mobile:l,onReply:u,onReplyAll:d,onForward:m}):s.jsx(Kp,{threadMessage:e,isFocused:n,onToggle:r,onToggleStar:a,isStarPending:o})},Qp=()=>s.jsxs("div",{className:"animate-pulse p-4",children:[s.jsx("div",{className:"h-6 bg-surface-sunken rounded w-3/4 mb-5"}),s.jsx("div",{className:"space-y-4",children:Array.from({length:2}).map((e,t)=>s.jsxs("div",{className:"flex gap-3 py-3",children:[s.jsx("div",{className:"size-10 bg-surface-sunken rounded-full shrink-0"}),s.jsxs("div",{className:"flex-1",children:[s.jsx("div",{className:"h-4 bg-surface-sunken rounded w-32 mb-2"}),s.jsx("div",{className:"h-3 bg-surface-sunken rounded w-48"})]})]},t))})]});function xo({authenticity:e,onOpenIntelligence:t}){return e.dkimMismatch?s.jsxs("div",{className:"flex items-start gap-2 rounded-none border-b border-danger/20 bg-danger-soft px-5 py-2.5 text-sm",children:[s.jsx(Ks,{className:"mt-0.5 size-4 shrink-0 text-danger"}),s.jsxs("p",{className:"flex-1 leading-snug text-fg",children:["This message claims to be from"," ",s.jsx("span",{className:"font-semibold",children:e.fromDomain})," but was sent",e.dkimDomain?` via ${e.dkimDomain}`:" from a different domain","."]}),t&&s.jsx("button",{type:"button",onClick:t,className:"shrink-0 text-2xs font-medium text-danger hover:underline",children:"Why?"})]}):null}const gs=({threadId:e,mailboxId:t,subject:n,selectedMessageId:r,authenticity:a,onOpenIntelligence:o,onBack:i,composeRequest:l,onComposeClose:u,onSwipeNext:d,onSwipePrevious:m,mobileIntelligenceOpen:f})=>{const h=Qt(),{handlers:x}=Tg({onSwipeLeft:d,onSwipeRight:m}),{accountId:b}=ul(t),{data:p,isLoading:v,isError:g,error:y,refetch:j}=ue({...au({path:{threadId:e}})}),w=c.useMemo(()=>p?.items??[],[p?.items]),C=w[w.length-1],k=c.useRef(new Map),[S,N]=c.useState(new Set),[I,T]=c.useState(null),[E,M]=c.useState(0);c.useEffect(()=>{if(w.length>0&&e!==I){T(e);const U=new Set([w[w.length-1].threadMessageId]);if(r){const z=w.find(ne=>ne.messageId===r);z&&U.add(z.threadMessageId)}N(U),M(w.length-1)}},[e,w,I,r]);const R=c.useCallback(U=>{N(z=>{const ne=new Set(z);return ne.has(U)?ne.delete(U):ne.add(U),ne})},[]),A=c.useCallback(U=>{const z=w[U];if(!z)return;k.current.get(z.threadMessageId)?.scrollIntoView({behavior:"smooth",block:"nearest"})},[w]),D=c.useCallback(()=>{if(w.length===0)return;const U=Math.min(E+1,w.length-1);M(U),A(U)},[w.length,E,A]),F=c.useCallback(()=>{if(w.length===0)return;const U=Math.max(E-1,0);M(U),A(U)},[w.length,E,A]),$=c.useCallback(()=>{const U=w[E];U&&R(U.threadMessageId)},[w,E,R]),{data:te}=ue({...ht(),staleTime:1/0}),q=te?.accounts?.[0],Q=!!q?.smtpHost;Eg({messages:w,expandedIds:S,threadId:e,mailboxId:t,accountId:q?.accountId});const{toggleStar:X,isPending:ee,pendingMessageId:se}=Sr({threadId:e,mailboxId:t,messages:w}),[P,_]=c.useState(null);c.useEffect(()=>{l&&l!=="new"&&(_(l),u?.())},[l,u]);const{data:H}=ue({..._r({path:{messageId:C?.messageId??""}}),enabled:!!C&&P!==null}),W=c.useCallback(()=>{_("reply")},[]),le=c.useCallback(()=>{_("reply_all")},[]),me=c.useCallback(()=>{_("forward")},[]),J=c.useCallback(()=>{_(null),u?.()},[u]);if(ea({enabled:!v&&w.length>0&&P===null,bindings:[{key:"j",handler:D,preventDefault:!0},{key:"ArrowDown",handler:D,preventDefault:!0},{key:"k",handler:F,preventDefault:!0},{key:"ArrowUp",handler:F,preventDefault:!0},{key:"Enter",handler:$,preventDefault:!0},{key:"o",handler:$,preventDefault:!0},...Q?[{key:"r",handler:W,preventDefault:!0},{key:"R",handler:le,noModifiers:!1,preventDefault:!0},{key:"f",handler:me,preventDefault:!0}]:[]]}),v)return s.jsx(Qp,{});if(g)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsx(Mt,{title:"Couldn't load this conversation",error:y,onRetry:()=>j()})});if(w.length===0)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsx(cl,{message:"No messages in this thread"})});const Ie=n||w[0]?.subject||"(No subject)",he=w.length,ke=U=>s.jsx("div",{children:w.map((z,ne)=>s.jsx("div",{ref:Ue=>{Ue&&k.current.set(z.threadMessageId,Ue)},children:s.jsx(Up,{threadMessage:z,isExpanded:S.has(z.threadMessageId),isFocused:ne===E,onToggle:()=>R(z.threadMessageId),onToggleStar:()=>X(z.messageId,z.hasStars),isStarPending:ee&&se===z.messageId,accountId:b,mobile:U,onReply:U&&Q?W:void 0,onReplyAll:U&&Q?le:void 0,onForward:U&&Q?me:void 0})},z.threadMessageId))}),Y=s.jsxs("header",{className:"border-b border-line px-5 pt-5 pb-3",children:[s.jsx("h1",{className:"max-w-2xl text-lg font-semibold leading-snug text-fg",children:Ie}),s.jsxs("p",{className:"mt-1 text-2xs text-fg-subtle",children:[he," ",he===1?"message":"messages"]})]});return h?s.jsxs("article",{className:"h-full flex flex-col",children:[Y,a?.dkimMismatch&&s.jsx(xo,{authenticity:a,onOpenIntelligence:o}),s.jsx("div",{className:"flex-1 overflow-auto",children:ke(!1)}),P!==null&&s.jsx(ro,{mode:P,account:q,sourceMessage:H,onClose:J})]}):s.jsxs(Qd,{thread:{subject:Ie,messages:[]},onBack:i??(()=>{}),intelligenceOpen:f,onToggleIntelligence:o,touchHandlers:x,children:[a?.dkimMismatch&&s.jsx(xo,{authenticity:a,onOpenIntelligence:o}),ke(!0),P!==null&&s.jsx(ro,{mode:P,account:q,sourceMessage:H,onClose:J})]})};function ps(){const{mailboxNameIndex:e,accountNameIndex:t}=Se();return{...kt({select:r=>el(r.matches)})?{}:{mailboxesByName:e},accountsByName:t}}const la=e=>e.trim().toLocaleLowerCase(),Hp=/^\d{4}-\d{2}-\d{2}$/;function bo(e,t,n){if(!Hp.test(n))return;const r=Date.parse(`${n}T00:00:00Z`);if(!Number.isNaN(r))return{type:e,raw:t,value:n,epochSeconds:Math.floor(r/1e3)}}function Wp(e,t){const n=e.toLowerCase();if(n.startsWith("from:")&&e.length>5)return{type:"from",raw:e,value:e.slice(5)};if(n==="has:attachment")return{type:"hasAttachment",raw:e};if(n==="is:unread")return{type:"isUnread",raw:e};if(n.startsWith("before:")&&e.length>7)return bo("before",e,e.slice(7));if(n.startsWith("after:")&&e.length>6)return bo("after",e,e.slice(6));if(n.startsWith("in:")&&e.length>3){const r=e.slice(3),a=t.mailboxesByName?.get(r.toLowerCase());return a?{type:"in",raw:e,value:r,mailboxId:a}:void 0}if(n.startsWith("account:")&&e.length>8){const r=e.slice(8),a=t.accountsByName?.get(r.toLowerCase());return a?{type:"account",raw:e,value:r,accountId:a}:void 0}}function xs(e,t={}){const n=e.split(/\s+/).filter(o=>o.length>0),r=[],a=[];for(const o of n){const i=Wp(o,t);i?r.push(i):a.push(o)}return{freeText:a.join(" "),tokens:r}}function Vp(e,t){return e.split(/\s+/).filter(n=>n.length>0&&n!==t.raw).join(" ")}function Yp(e){switch(e.type){case"from":return`From: ${e.value}`;case"hasAttachment":return"Has attachment";case"isUnread":return"Unread";case"before":return`Before ${e.value}`;case"after":return`After ${e.value}`;case"in":return`In: ${e.value}`;case"account":return`Account: ${e.value}`}}const Gp=20,Xp=new Set(Object.values(tt)),Jp=e=>e!==void 0&&Xp.has(e)?e:void 0;function ql({mailboxId:e,filterCategory:t}={}){const{searchQuery:n}=Se(),r=ps(),a=kt({select:y=>y.matches}),o=la(n),{freeText:i,tokens:l}=xs(o,r),u=i.length>0,d=Jp(t),m=l.some(y=>y.type==="hasAttachment")?!0:void 0,f=l.some(y=>y.type==="isUnread")?!1:void 0,h=l.find(y=>y.type==="after"),x=l.find(y=>y.type==="before"),b=l.find(y=>y.type==="in"),p=Bh({matches:a,callerMailboxId:e,inTokenMailboxId:b?.mailboxId}),{data:v,isLoading:g}=ue({...Vo({query:{query:i,mailboxId:p,limit:Gp,...d!==void 0?{category:d}:{},...m!==void 0?{hasAttachment:m}:{},...f!==void 0?{isRead:f}:{},...h?{sentDateFrom:h.epochSeconds}:{},...x?{sentDateTo:x.epochSeconds}:{}}}),enabled:u,staleTime:6e4});return{hits:v?.items??[],isLoading:u&&g}}const Zp=(e,t)=>e.createdAt!==t.createdAt?e.createdAt-t.createdAt:e.accountId.localeCompare(t.accountId),ex=e=>[...e].sort(Zp);function Cr(e){const t=e.authenticity?.dkimMismatch===!0;return{id:e.messageId,accountId:e.accountId??e.accountConfigId,mailboxId:e.mailboxId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:Tt(e.sentDate),sentDate:e.sentDate,isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Tn(e.category),suspicious:t}}function tx(e,t){const n=new Set,r=[];for(const a of[...e,...t])n.has(a.id)||(n.add(a.id),r.push(a));return r.sort((a,o)=>(o.sentDate??0)-(a.sentDate??0))}const vo=[{id:"personal",label:"Personal",category:tt.personal},{id:"transactional",label:"Transactional",category:tt.transactional},{id:"newsletter",label:"Newsletter",category:tt.newsletter},{id:"marketing",label:"Marketing",category:tt.marketing},{id:"social",label:"Social",category:tt.social},{id:"automated",label:"Automated",category:tt.automated},{id:"uncategorized",label:"Unclassified",category:tt.uncategorized}];function sx(e){const t=new Map(vo.map(r=>[r.category,[]]));for(const r of e){const a=r.category??tt.uncategorized;(t.get(a)??t.get(tt.uncategorized))?.push(r)}const n=[];for(const r of vo){const a=t.get(r.category);a&&a.length>0&&n.push({id:r.id,label:r.label,threads:a})}return n}function Ul(e,t){return e.fromName.toLowerCase().includes(t)||e.fromEmail.toLowerCase().includes(t)||e.subject.toLowerCase().includes(t)||e.snippet.toLowerCase().includes(t)}function Ql(e,t){return t.every(n=>{switch(n.type){case"from":{const r=n.value.toLowerCase();return e.fromEmail.toLowerCase().includes(r)||e.fromName.toLowerCase().includes(r)}case"hasAttachment":return e.hasAttachment===!0;case"isUnread":return!e.isRead;case"after":return e.sentDate!=null&&e.sentDate>=n.epochSeconds*1e3;case"before":return e.sentDate!=null&&e.sentDate<n.epochSeconds*1e3;case"in":return e.mailboxId===n.mailboxId;case"account":return e.accountId===n.accountId;default:return!1}})}const nx={sender:"sender",recipient:"recipient",subject:"subject",attachment:"attachment",body:"body",entities:"entities"};function rx(e){return nx[e]??e}function ax(e){return{id:e.messageId,sender:e.fromName??e.fromEmail??"Unknown",subject:e.subject??"(No subject)",snippet:e.snippet??"",date:Tt(e.sentDate),unread:!e.isRead,flagged:e.hasStars===!0,threadId:e.threadId,mailboxId:e.mailboxId}}function Hl(e){return{id:e.id,sender:e.fromName,subject:e.subject,snippet:e.snippet,date:e.timeLabel,unread:!e.isRead,flagged:e.starred===!0}}function ox(e){return{id:e.messageId,sender:e.fromName??"Unknown",subject:e.subject??"(No subject)",snippet:"",date:e.sentDate!=null?Tt(e.sentDate*1e3):"",threadId:e.threadId,matchedChunkLabel:rx(e.matchedChunkType),score:e.score,...e.mailboxIds[0]!=null?{mailboxId:e.mailboxIds[0]}:{}}}function Wl(e,t){const n=new Set(t),r=[];for(const a of[...e].sort((o,i)=>i.score-o.score))n.has(a.threadId)||(n.add(a.threadId),r.push(ox(a)));return r}const ix=768,lx=1024,Vl=e=>e!=="desktop",On=()=>{const e=jr(`(min-width: ${ix}px)`);return jr(`(min-width: ${lx}px)`)?"desktop":e?"tablet":"phone"},Yl="remit.recentSearches",cx=5;function Er(){try{const e=localStorage.getItem(Yl);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(n=>typeof n=="string"):[]}catch{return[]}}function yo(e){const t=e.trim();if(!t)return Er();const n=[t,...Er().filter(r=>r!==t)].slice(0,cx);try{localStorage.setItem(Yl,JSON.stringify(n))}catch{return n}return n}function Gl({title:e,unreadCount:t,children:n,footer:r,searchFilter:a,searchResults:o,searchLoading:i,relatedResults:l,relatedLoading:u,onSelectSearchResult:d,searchResultsLabel:m="Top matches",relatedResultsLabel:f="Related"}){const{searchInput:h,onSearchChange:x,onSearchClear:b,searchViewKey:p}=Se(),v=ps(),g=ds(),y=On(),[j,w]=c.useState(!1),[C,k]=c.useState(Er),S=c.useRef(p);c.useEffect(()=>{S.current!==p&&(S.current=p,w(!1))},[p]);const N=h.trim().length>0,I=xs(h,v).tokens.map(q=>({label:Yp(q),onRemove:()=>x(Vp(h,q))})),T=o??[],E=l??[],M=N?[{id:"top",label:m,results:T},{id:"related",label:f,results:E}]:[],A=!(T.length+E.length>0)&&(i===!0||u===!0);if(y==="phone"&&j){const q=Q=>{k(yo(h)),w(!1),d?.(Q)};return s.jsx(Ef,{value:h,onChange:x,onClear:b,onCancel:()=>{w(!1),b()},filter:a,recentSearches:C,onPickRecent:x,sections:M,loading:A,onSelectResult:q,tokens:I})}const D=y!=="phone"&&N,F=q=>{k(yo(h)),d?.(q)},$=s.jsx(Ii,{value:h,sections:M,loading:A,onSelectResult:F,tokens:I}),te=D?a?s.jsx(Mr,{...a,children:$}):s.jsx("div",{className:"h-full overflow-y-auto",children:$}):n;return s.jsxs("section",{className:"flex h-full w-full flex-col bg-surface",children:[s.jsx(xf,{title:e,unreadCount:t,isDesktop:!1,showSearch:Vl(y),onMenuClick:()=>g?.openNav(),searchValue:h,onSearchChange:x,onSearchClear:b,searchOpen:j,onSearchOpenChange:w}),s.jsx("div",{className:"min-h-0 flex-1",children:te}),r]})}const ux=200,dx={unread:e=>!e.isRead,attachment:e=>e.hasAttachment===!0,contacts:e=>e.trust==="vip"||e.trust==="wellknown",today:e=>e.sentDate!=null&&new Date(e.sentDate).toDateString()===new Date().toDateString()},wo=()=>s.jsx("div",{className:"animate-pulse",children:Array.from({length:3}).map((e,t)=>s.jsxs("div",{className:"flex items-start gap-3 py-2 pl-5 pr-4 border-b border-line",children:[s.jsx("div",{className:"size-7 rounded-full bg-surface-sunken shrink-0 mt-0.5"}),s.jsxs("div",{className:"flex-1 space-y-1.5",children:[s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("div",{className:"h-3.5 bg-surface-sunken rounded w-28"}),s.jsx("div",{className:"h-3 bg-surface-sunken rounded w-12"})]}),s.jsx("div",{className:"h-3.5 bg-surface-sunken rounded w-48"}),s.jsx("div",{className:"h-3 bg-surface-sunken rounded w-full"})]})]},t))}),fx=({accountEmail:e})=>{const t=Me();return s.jsxs("div",{className:"flex items-center gap-2 px-row-inset py-2 border-b border-line bg-danger-soft/40 text-xs text-danger",children:[s.jsx(_t,{className:"size-3.5 shrink-0"}),s.jsxs("span",{className:"flex-1 truncate",children:[e," can't connect"]}),s.jsx("button",{type:"button",onClick:()=>t({to:"/settings/accounts"}),className:"shrink-0 underline text-danger hover:opacity-80",children:"Reconnect"})]})},mx=({thread:e,active:t,onClick:n})=>{const r=!e.isRead;return s.jsxs("button",{type:"button",onClick:n,className:K("group w-full",ms({active:t})),children:[r&&s.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),s.jsx(Xe,{name:e.fromName,email:e.fromEmail,size:"sm"}),s.jsx(Ft,{thread:e})]})};function Xl({accounts:e,selectedMessageId:t,onSelectMessage:n,onSelectSearchResult:r}){const{searchQuery:a}=Se(),o=ps(),i=Qt(),l=c.useMemo(()=>ex(e.filter(P=>!P.muted?.value)),[e]),[u,d]=c.useState("all"),[m,f]=c.useState("all"),[h,x]=c.useState(new Set),[b,p]=c.useState(!1),v=c.useCallback(P=>{x(_=>{const H=new Set(_);return H.has(P)?H.delete(P):H.add(P),H})},[]),{data:g,isLoading:y,isError:j,refetch:w}=ue({...mr(),staleTime:6e4}),C=Ut({queries:l.map(P=>({...rt({path:{accountId:P.accountId}}),staleTime:1/0,meta:{softError:!0}}))}),k=c.useMemo(()=>{const P=new Map;for(let _=0;_<l.length;_++){const H=l[_].accountId,le=(C[_]?.data?.items??[]).reduce((me,J)=>me+(J.unseenCount??0),0);P.set(H,le)}return P},[l,C]),S=c.useMemo(()=>l.filter((P,_)=>{const H=C[_];return H?.isError?!hr(H.error):!1}),[l,C]),{freeText:N,tokens:I}=xs(a.trim().toLowerCase(),o),{data:T,isFetching:E}=ue({...mr({query:{query:N,limit:ux}}),enabled:N.length>0,staleTime:3e4}),M=c.useMemo(()=>{const P=(g?.items??[]).map(Cr);return(N?tx(P.filter(H=>Ul(H,N)),(T?.items??[]).map(Cr)):P).filter(H=>(u==="all"||H.accountId===u)&&Ql(H,I))},[g,T,u,N,I]),R=c.useMemo(()=>sx(M),[M]),A=c.useMemo(()=>l.length<=1?[]:[{id:"all",label:"All",active:u==="all"},...l.map(P=>({id:P.accountId,label:P.email.split("@")[0]??P.email,count:k.get(P.accountId),active:u===P.accountId}))],[l,k,u]),D=c.useMemo(()=>e.filter(P=>P.muted?.value).length,[e]),F=c.useMemo(()=>Array.from(k.values()).reduce((P,_)=>P+_,0),[k]),$=c.useMemo(()=>{const P=Array.from(h).map(_=>dx[_]).filter(_=>_!=null);return M.filter(_=>(m==="all"||_.category===m)&&P.every(H=>H(_))).map(Hl)},[M,m,h]),{hits:te,isLoading:q}=ql(),Q=c.useMemo(()=>{const P=new Map;for(const H of g?.items??[])P.set(H.messageId,H.threadId);const _=$.map(H=>P.get(H.id)).filter(H=>H!=null);return Wl(te,_)},[te,$,g]),X=c.useMemo(()=>{const P=Xf(A.map(_=>({id:_.id,label:_.label,count:_.count,active:_.active})));return{categories:P.categories,filters:P.filters,sources:P.sources,sourcesNote:D>0?`+${D} muted`:void 0,selectedCategory:m,activeFilters:h,expanded:b,onExpandedChange:p,onSelectCategory:_=>f(_),onSelectSource:d,onToggleFilter:v,onClear:()=>{f("all"),d("all"),x(new Set)}}},[A,D,m,h,b,v]),ee=R.length===0&&u==="all"&&N.length===0,se=y?s.jsxs("div",{className:"h-full overflow-y-auto",children:[s.jsx(wo,{}),s.jsx(wo,{})]}):j?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 py-12 text-sm text-fg-muted",children:[s.jsx(_t,{className:"size-8 text-danger"}),s.jsx("p",{children:"Couldn't load your messages"}),s.jsxs("button",{type:"button",onClick:()=>w(),className:"flex items-center gap-1 text-accent underline text-xs",children:[s.jsx(di,{className:"size-3.5"}),"Try again"]})]}):ee?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 py-12 text-center px-4",children:[s.jsx(nt,{className:"size-8 text-fg-subtle"}),s.jsx("p",{className:"text-sm font-medium text-fg",children:"You're caught up"}),s.jsx("p",{className:"text-xs text-fg-subtle",children:"Nothing needs attention."})]}):s.jsx(Ao,{sections:R,Row:mx,briefCategory:m,onSelectBriefCategory:f,sources:A,sourcesNote:D>0?`+${D} muted`:void 0,onSelectSource:d,selectedThreadId:t,onSelectThread:n});return s.jsx(Gl,{title:"Daily brief",unreadCount:F,footer:i?s.jsx(pi,{}):void 0,searchFilter:X,searchResults:$,searchLoading:y||E,relatedResults:Q,relatedLoading:q,onSelectSearchResult:r,children:s.jsxs("div",{className:"flex h-full flex-col",children:[S.map(P=>s.jsx(fx,{accountEmail:P.email,accountId:P.accountId},P.accountId)),s.jsx("div",{className:"min-h-0 flex-1",children:se})]})})}const Jl=({isOpen:e,title:t,description:n,confirmLabel:r,cancelLabel:a="Cancel",destructive:o=!1,isBusy:i=!1,onConfirm:l,onCancel:u})=>{const d=c.useRef(null),m=c.useCallback(f=>{f.key==="Escape"&&(f.preventDefault(),f.stopPropagation(),f.stopImmediatePropagation(),u())},[u]);return c.useEffect(()=>{if(e)return window.addEventListener("keydown",m,!0),()=>window.removeEventListener("keydown",m,!0)},[e,m]),c.useEffect(()=>{e&&d.current?.focus()},[e]),e?s.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[s.jsx("div",{className:"absolute inset-0 bg-canvas/80 backdrop-blur-sm","aria-hidden":"true",onClick:u}),s.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":t,className:de("relative z-10 w-full max-w-sm","bg-surface border border-line rounded-sm shadow-lg","p-6"),onClick:f=>f.stopPropagation(),onKeyDown:f=>f.stopPropagation(),children:[s.jsx("h2",{className:"text-lg font-semibold",children:t}),n&&s.jsx("p",{className:"mt-2 text-sm text-fg-muted",children:n}),s.jsxs("div",{className:"mt-6 flex items-center justify-end gap-2",children:[s.jsx("button",{ref:d,type:"button",onClick:u,className:de("min-h-11 inline-flex items-center justify-center px-4 rounded text-sm font-medium transition-colors","border border-line hover:bg-surface-raised"),children:a}),s.jsx("button",{type:"button",onClick:l,disabled:i,className:de("min-h-11 inline-flex items-center justify-center px-4 rounded text-sm font-medium transition-colors",o?"bg-danger text-canvas hover:bg-danger/90":"bg-accent text-accent-fg hover:bg-accent-hover","disabled:opacity-50 disabled:cursor-not-allowed"),children:r})]})]})]}):null},hx=10,Zl=e=>({q:e?.toLowerCase()??"",limit:hx}),gx=(e,t)=>{if(!t)return;const n=t.toLowerCase();return e?.find(r=>r.normalizedEmail===n)};function px(e){const t=new Date(e),n=new Date;return t.toDateString()===n.toDateString()?"today":gn(t,{month:"short",year:"numeric"})}function ec(e){if(!e)return!0;const[,t]=e.split("@");return t?!t.includes("."):!0}const xx="We can't verify the sender of this email, which could mean it's from an insecure source.",bx="We couldn't read this sender's address, so we can't confirm who really sent this message.";function vx(e,t){return{name:e.fromName??e.fromEmail??"Unknown",email:e.fromEmail??"",trust:e.senderTrust,firstSeenLabel:t?px(t.createdAt):"unknown",inboundCount:t?.inboundCount,replyCount:t?.replyCount,addressUnverified:ec(e.fromEmail)}}function yx(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 wx(e,t){const n=t>0?t:void 0;if(ec(e.fromEmail))return{verdict:"mismatch",fromDomain:"",addressUnreadable:!0,summary:bx,similarCount:n};const r=e.authenticity;if(!r)return{verdict:"caution",fromDomain:e.fromEmail?.split("@")[1]??"",summary:xx};if(!r.dkimMismatch)return{verdict:"aligned",fromDomain:r.fromDomain,dkimDomain:r.dkimDomain,summary:r.dkimDomain?`We verified this message was really sent by ${r.fromDomain}.`:"Nothing looks unusual about this sender."};const a=r.fromDomain,o=r.dkimDomain,i=e.fromName&&e.fromName!==e.fromEmail?e.fromName:void 0,l=i?`The display name claims "${i}", but this message was actually sent from ${o??"another sender"} — not ${a}. Real senders use their own address.`:`This message claims to be from ${a}, but it was actually sent from ${o??"a different sender"}.`;return{verdict:"mismatch",fromDomain:a,dkimDomain:o,claimedBrand:i,summary:l,similarCount:n}}function tc(e,t){const n=e?.fromEmail??null,r=e?.subject??"",{data:a,error:o}=ue({...Uo({query:Zl(n??void 0)}),enabled:!!n,staleTime:3e4}),i=gx(a?.items,n??void 0),l=[r,n].filter(Boolean).join(" "),{data:u,isLoading:d,error:m}=ue({...Vo({query:{query:l,limit:5}}),enabled:!!(e&&l.length>3),staleTime:6e4,retry:1});return{data:c.useMemo(()=>{if(!e)return null;const h=(u?.items??[]).filter(g=>g.messageId!==e.messageId).map(g=>({id:g.messageId,mailboxId:t!=null&&g.mailboxIds.includes(t)?t:g.mailboxIds[0]??"",fromName:g.fromName??"",subject:g.subject??"(No subject)",timeLabel:g.sentDate!=null?Tt(g.sentDate*1e3):"",matched:g.matchedChunkType})),x=vx(e,i),b=wx(e,h.length),p={value:e.category??"personal",overridden:i?.flags?.category?.value!=null&&i.flags.category.value!==e.category},v=yx(i);return{sender:x,authenticity:b,category:p,flags:v,similar:h}},[e,i,u,t]),isSimilarLoading:d,similarError:m,similarErrorIsFatal:hr(m),addressErrorIsFatal:hr(o),addressId:i?.addressId,address:i}}function jx(e,t){const n={...e??{}};for(const[r,a]of Object.entries(t))a==null?delete n[r]:n[r]={...a,setAt:a.setAt??Date.now()};return n}function sc({addressId:e,senderEmail:t}){const n=je(),{pushError:r}=qe(),a=ou({query:Zl(t)}),{mutate:o,isPending:i}=pe({...Wo(),onMutate:async u=>{const d=u.body.flags??{};await n.cancelQueries({queryKey:a});const m=n.getQueryData(a);return n.setQueryData(a,f=>f&&{...f,items:f.items.map(h=>h.addressId===u.path.addressId?{...h,flags:jx(h.flags,d)}:h)}),{previous:m}},onError:(u,d,m)=>{m?.previous!==void 0&&n.setQueryData(a,m.previous),r({title:"Couldn't update sender preference",detail:st(u),error:u})},onSettled:()=>{n.invalidateQueries({queryKey:a})}});return{updateFlags:c.useCallback(u=>{if(!e){Yo(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 Sx=e=>e==="vip"?"A sender you know":e==="wellknown"?"You've emailed them before":"Passed authentication",nc=e=>e.senderTrust!=="vip"&&e.senderTrust!=="wellknown"?!1:e.authenticity?.dkimMismatch!==!0;function kx(e,t){e.recordEvent("rescue.candidates_surfaced",{count:String(t)})}function Nx(e,t){e.recordEvent("rescue.flow_opened",{count:String(t)})}function Cx(e,t){e.recordEvent("rescue.committed",{selected:String(t.selected),total:String(t.total),destination:t.toInbox?"inbox":"other"})}function rc(e,t){e.recordEvent("rescue.sent_to_junk",{count:String(t.count),senderTrust:t.senderTrust,wasRescuable:String(t.wasRescuable)})}const Ex=["personal","newsletter","marketing","automated","transactional","social"],Ix=e=>{const{mailboxId:t,junkMailboxId:n,inboxMailboxId:r}=e;return t?n&&t===n?r?"notSpam":null:n?"markSpam":null:null},Rx=e=>{const{similarError:t,similarErrorIsFatal:n,isSimilarLoading:r}=e;return t&&!n?"error":r?"loading":"ready"};function Mx(){return s.jsxs("aside",{className:"flex h-full w-full flex-col bg-surface-sunken",children:[s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-1.5 border-b border-line px-row-inset",children:[s.jsx(nt,{className:"size-3.5 text-fg-subtle"}),s.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"})]}),s.jsxs("div",{className:"flex-1 animate-pulse space-y-4 p-4",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"h-2.5 rounded bg-surface w-1/4"}),s.jsxs("div",{className:"flex gap-3",children:[s.jsx("div",{className:"size-10 rounded-full bg-surface shrink-0"}),s.jsxs("div",{className:"flex-1 space-y-1.5",children:[s.jsx("div",{className:"h-3 rounded bg-surface w-3/4"}),s.jsx("div",{className:"h-2.5 rounded bg-surface w-1/2"})]})]})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"h-2.5 rounded bg-surface w-1/4"}),s.jsx("div",{className:"h-8 rounded bg-surface"})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"h-2.5 rounded bg-surface w-1/4"}),s.jsx("div",{className:"flex gap-1.5 flex-wrap",children:Array.from({length:5}).map((e,t)=>s.jsx("div",{className:"h-6 w-16 rounded bg-surface"},t))})]})]})]})}function Tx({isOpen:e,current:t,onSelect:n,onCancel:r}){return e?s.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center","aria-hidden":"true",onClick:r,children:[s.jsx("div",{className:"absolute inset-0 bg-canvas/80 backdrop-blur-sm"}),s.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":"Reclassify sender",className:"relative z-10 w-full max-w-sm rounded-sm border border-line bg-surface p-6 shadow-lg",onClick:a=>a.stopPropagation(),onKeyDown:a=>a.stopPropagation(),children:[s.jsx("h2",{className:"text-lg font-semibold",children:"Reclassify this sender"}),s.jsx("p",{className:"mt-2 text-sm text-fg-muted",children:"Set a category override for future messages from this sender."}),s.jsx("div",{className:"mt-4 flex flex-col gap-1",children:Ex.map(a=>s.jsxs("button",{type:"button",onClick:()=>n(a),className:`flex min-h-11 items-center justify-between rounded px-3 text-left text-sm capitalize transition-colors hover:bg-surface-raised ${a===t?"font-semibold text-accent":"text-fg"}`,children:[a,a===t&&s.jsx("span",{className:"text-2xs text-fg-subtle",children:"current"})]},a))}),s.jsx("div",{className:"mt-6 flex justify-end",children:s.jsx("button",{type:"button",onClick:r,className:"inline-flex min-h-11 items-center justify-center rounded border border-line px-4 text-sm font-medium transition-colors hover:bg-surface-raised",children:"Cancel"})})]})]}):null}function Dx({thread:e,onClose:t,mailboxId:n,accountId:r,hideCloseButton:a}){const{data:o,addressId:i,isSimilarLoading:l,similarError:u,similarErrorIsFatal:d}=tc(e,n),[m,f]=c.useState(!1),[h,x]=c.useState(!1),b=e.fromEmail??void 0,{updateFlags:p,isPending:v}=sc({addressId:i,senderEmail:b}),{junkMailboxId:g}=sa(r),{inboxMailboxId:y}=ta(r),{moveMessages:j}=Ct({mailboxId:n??"",threadId:e.threadId,accountId:r}),w=zs(),C=Ix({mailboxId:n,junkMailboxId:g,inboxMailboxId:y}),k=c.useCallback(()=>{y&&j([e.messageId],y)},[y,j,e.messageId]),S=c.useCallback(()=>{g&&(rc(w,{count:1,senderTrust:e.senderTrust,wasRescuable:nc(e)}),j([e.messageId],g))},[g,j,e,w]),N=c.useCallback(()=>{},[]),I=c.useCallback(()=>{const q=o?.flags?.vip!==!0;p({vip:{value:q}})},[o?.flags?.vip,p]),T=c.useCallback(()=>{const q=o?.flags?.muted!==!0;p({muted:{value:q}})},[o?.flags?.muted,p]),E=c.useCallback(()=>{o?.flags?.blocked===!0?p({blocked:{value:!1}}):f(!0)},[o?.flags?.blocked,p]),M=c.useCallback(()=>{f(!1),p({blocked:{value:!0}})},[p]),R=c.useCallback(()=>{const q=o?.flags?.unsubscribed!==!0;p({unsubscribed:{value:q}})},[o?.flags?.unsubscribed,p]),A=c.useCallback(q=>{x(!1),p({category:{value:q}})},[p]),D=i!==void 0,F={onToggleVip:D?I:void 0,onToggleMute:D?T:void 0,onToggleBlock:D?E:void 0,onToggleUnsubscribe:D?R:void 0,onReclassify:D?()=>x(!0):void 0,onNotSpam:C==="notSpam"?k:void 0,onMarkSpam:C==="markSpam"?S:void 0},$=({mailboxId:q,messageId:Q,className:X,ariaLabel:ee,children:se})=>s.jsx(mt,{to:"/mail/$mailboxId",params:{mailboxId:q},search:P=>({...P,selectedMessageId:Q}),className:X,"aria-label":ee,children:se});if(!o)return s.jsx(Mx,{});const te=Rx({similarError:u,similarErrorIsFatal:d,isSimilarLoading:l});return s.jsxs(s.Fragment,{children:[s.jsx(gi,{data:o,onClose:t,hideCloseButton:a,onShowSimilar:N,actions:F,similarState:te,similarLinkComponent:$,className:"border-l-0 h-full w-full"}),s.jsx(Jl,{isOpen:m,title:"Block this sender?",description:`Messages from ${b??"this sender"} will never load images and will be flagged. You can undo this in Settings → Senders.`,confirmLabel:"Block sender",destructive:!0,isBusy:v,onConfirm:M,onCancel:()=>f(!1)}),s.jsx(Tx,{isOpen:h,current:o.category.value,onSelect:A,onCancel:()=>x(!1)})]})}const bs=({onClose:e,thread:t,mailboxId:n,accountId:r,hideCloseButton:a})=>t?s.jsx(Dx,{thread:t,onClose:e,mailboxId:n,accountId:r,hideCloseButton:a}):s.jsxs("aside",{className:"flex h-full w-full flex-col bg-surface-sunken",children:[s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-1.5 border-b border-line px-row-inset",children:[s.jsx(nt,{className:"size-3.5 text-fg-subtle"}),s.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"})]}),s.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center px-row-inset text-center",children:[s.jsx(nt,{className:"size-8 text-fg-subtle"}),s.jsx("p",{className:"mt-3 text-sm text-fg-muted",children:"Intelligence"}),s.jsx("p",{className:"mt-1 text-2xs text-fg-subtle",children:"Sender trust, authenticity and similar messages will appear here."})]})]}),cr="Open a message first",ca=({hasThread:e,intelligenceOpen:t,canToggleIntelligence:n,onToggleIntelligence:r,onReply:a,onReplyAll:o,onForward:i,onDelete:l,canDelete:u,onToggleStar:d,isStarred:m,moveContext:f})=>{const[h,x]=c.useState(null),b=u??e,p=v=>()=>x(v);return s.jsx(xd,{hasThread:e,isStarred:m,onUnavailable:v=>x(cr),unavailableHint:h,replyTitle:`Reply ${ts("reply")}`,replyAllTitle:`Reply all ${ts("replyAll")}`,forwardTitle:`Forward ${ts("forward")}`,deleteTitle:`Move to Trash ${ts("delete")}`,flagTitle:`Star ${ts("toggleStar")}`,onReply:a,onReplyAll:o,onForward:i,onDelete:b?l:p(cr),onToggleStar:d,onMove:p(cr),moveSlot:f?s.jsx(Qs,{accountId:f.accountId,currentMailboxId:f.currentMailboxId,onMove:f.onMove,label:"Move to mailbox"}):void 0,children:s.jsx(pd,{open:t,enabled:n,onToggle:r})})};function Ax(e){return{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,messageId:e.messageId,authenticity:e.authenticity}}function ac(e,t){if(e)return Ax(e);if(t.messageId&&t.threadId&&t.mailboxId)return{threadId:t.threadId,mailboxId:t.mailboxId,messageId:t.messageId}}const oc=c.createContext(null);function Pn(){const e=c.useContext(oc);if(!e)throw new Error("BriefPane.* must be used inside <BriefPane>");return e}function Ox({selectedMessageId:e,children:t}){const n=Me(),{searchInput:r}=Se(),{selectedThreadId:a,selectedMailboxId:o}=as({strict:!1}),{data:i}=ue({...mr(),staleTime:6e4}),l=c.useMemo(()=>{if(e)return i?.items.find(x=>x.messageId===e)},[i,e]),u=c.useMemo(()=>ac(l,{messageId:e,threadId:a,mailboxId:o}),[l,e,a,o]),d=c.useCallback(x=>{n({to:"/mail",search:b=>({...b,selectedMessageId:x,selectedThreadId:void 0,selectedMailboxId:void 0})})},[n]),m=c.useCallback(x=>{n({to:"/mail",search:b=>({...b,q:r||void 0,selectedMessageId:x.id,selectedThreadId:x.threadId,selectedMailboxId:x.mailboxId})})},[n,r]),f=c.useCallback(()=>{n({to:"/mail",search:x=>({...x,selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0})})},[n]),h={selectedMessageId:e,selectedThread:l,conversation:u,onSelectMessage:d,onSelectSearchResult:m,onCloseThread:f};return s.jsx(oc.Provider,{value:h,children:t})}function Px(){const{selectedMessageId:e,onSelectMessage:t,onSelectSearchResult:n}=Pn(),{accounts:r}=Se();return s.jsx(Xl,{accounts:r,selectedMessageId:e,onSelectMessage:t,onSelectSearchResult:n})}function Lx(){const{conversation:e}=Pn(),{intelligenceOpen:t,onToggleIntelligence:n}=Se(),r=ds()?.showIntelligencePane??!1,a=!!e,o=r&&a;return s.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[s.jsx(ca,{hasThread:a,intelligenceOpen:o&&t,canToggleIntelligence:o,onToggleIntelligence:n}),s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?s.jsx(gs,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,selectedMessageId:e.messageId,authenticity:e.authenticity}):s.jsx(hs,{})})]})}function zx(){const{selectedThread:e}=Pn(),{onToggleIntelligence:t}=Se();return s.jsx(bs,{onClose:t,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId})}function Fx(){const{selectedThread:e,conversation:t,selectedMessageId:n,onSelectMessage:r,onSelectSearchResult:a,onCloseThread:o}=Pn(),{accounts:i,intelligenceOpen:l,onToggleIntelligence:u}=Se();return t?s.jsxs(s.Fragment,{children:[s.jsx(gs,{threadId:t.threadId,mailboxId:t.mailboxId,subject:t.subject,selectedMessageId:t.messageId,authenticity:t.authenticity,onBack:o,onOpenIntelligence:u}),s.jsx(Jr,{isOpen:l,onClose:u,ariaLabel:"Message details",side:"right",children:s.jsx(bs,{onClose:u,thread:e,hideCloseButton:!0})})]}):s.jsx("div",{className:"h-full",children:s.jsx(Xl,{accounts:i,selectedMessageId:n,onSelectMessage:r,onSelectSearchResult:a})})}const Es=Object.assign(Ox,{List:Px,Reading:Lx,Intelligence:zx,Phone:Fx}),_x=()=>Ho({query:{starred:!0,order:"desc"}});function ic(){const{data:e,isLoading:t,isError:n,error:r,refetch:a,fetchNextPage:o,hasNextPage:i,isFetchingNextPage:l}=Qi({queryKey:_x(),queryFn:async({pageParam:d})=>{const{data:m}=await iu({query:{starred:!0,order:"desc",continuationToken:d},throwOnError:!0});return m},initialPageParam:void 0,getNextPageParam:d=>d.continuationToken,staleTime:6e4});return{threads:c.useMemo(()=>(e?.pages??[]).flatMap(d=>d.items??[]),[e]),isLoading:t,isError:n,error:r,refetch:a,fetchNextPage:o,hasNextPage:i,isFetchingNextPage:l}}const Bx=e=>{const t=new Set;return e.filter(n=>t.has(n.threadId)?!1:(t.add(n.threadId),!0))};function lc({title:e,unreadCount:t,preset:n,selectedCategory:r,activeFilters:a,onSelectCategory:o,onToggleFilter:i,onSelectSource:l,onClearFilters:u,children:d,footer:m,searchResults:f,searchLoading:h,relatedResults:x,relatedLoading:b,onSelectSearchResult:p,searchResultsLabel:v,relatedResultsLabel:g}){const[y,j]=c.useState(!1),w={categories:n.categories,filters:n.filters,sources:n.sources,selectedCategory:r,activeFilters:a,expanded:y,onExpandedChange:j,onSelectCategory:o,onSelectSource:l,onToggleFilter:i,onClear:u};return s.jsx(Gl,{title:e,unreadCount:t,footer:m,searchFilter:w,searchResults:f,searchLoading:h,relatedResults:x,relatedLoading:b,onSelectSearchResult:p,searchResultsLabel:v,relatedResultsLabel:g,children:s.jsx(Mr,{...w,children:d})})}const $x={unread:e=>!e.isRead,attachment:e=>e.hasAttachment===!0};function Kx({selectedMessageId:e,onSelectMessage:t}){const{searchQuery:n}=Se(),r=ps(),a=Qt(),[o,i]=c.useState("all"),[l,u]=c.useState(new Set),d=c.useCallback(M=>{u(R=>{const A=new Set(R);return A.has(M)?A.delete(M):A.add(M),A})},[]),m=c.useCallback(()=>{i("all"),u(new Set)},[]),{threads:f,isLoading:h,isError:x,error:b,refetch:p,fetchNextPage:v,hasNextPage:g,isFetchingNextPage:y}=ic(),{freeText:j,tokens:w}=xs(n.trim().toLowerCase(),r),C=c.useMemo(()=>{const M=Array.from(l).map(R=>$x[R]).filter(R=>R!=null);return Bx(f).map(Cr).filter(R=>(o==="all"||R.category===o)&&M.every(A=>A(R))&&(!j||Ul(R,j))&&Ql(R,w))},[f,o,l,j,w]),k=c.useMemo(()=>Zf(),[]),S=c.useMemo(()=>C.map(Hl),[C]),N=c.useMemo(()=>C.filter(M=>!M.isRead).length,[C]),I=h?"loading":x?"error":C.length===0?"empty":"ready",T=c.useCallback(()=>{const M=zr(Lr());window.open(M,"_blank","noopener,noreferrer")},[]),E=s.jsxs("div",{className:"flex-1 overflow-y-auto",children:[s.jsx("div",{className:"divide-y divide-line",children:C.map(M=>s.jsx(vi,{thread:M,active:M.id===e,onClick:()=>t?.(M.id)},M.id))}),g?s.jsx("button",{type:"button",className:"w-full py-3 text-sm text-muted hover:text-fg disabled:opacity-50",onClick:()=>v(),disabled:y,children:y?"Loading…":"Load more"}):null]});return s.jsx(lc,{title:"Starred",unreadCount:N,preset:k,selectedCategory:o,activeFilters:l,onSelectCategory:i,onToggleFilter:d,onClearFilters:m,searchResults:S,searchLoading:h,onSelectSearchResult:M=>t?.(M.id),children:s.jsx(ji,{listTitle:"Starred",sections:[{id:"flagged",threads:C}],flatList:!0,hideHeader:!0,listState:I,searchQuery:j?n:void 0,errorMessage:x?ei(b):void 0,onRetry:()=>p(),onReportError:T,selectedThreadId:e,onSelectThread:t,onSelectBriefCategory:()=>{},isDesktop:a,listBody:I==="ready"?E:void 0})})}const cc=c.createContext(null);function Ln(){const e=c.useContext(cc);if(!e)throw new Error("FlaggedPane.* must be used inside <FlaggedPane>");return e}function qx({selectedMessageId:e,children:t}){const n=Me(),{threads:r}=ic(),a=c.useMemo(()=>{if(e)return r.find(u=>u.messageId===e)},[r,e]),o=c.useCallback(u=>{n({to:"/mail/flagged",search:d=>({...d,selectedMessageId:u})})},[n]),i=c.useCallback(()=>{n({to:"/mail/flagged",search:u=>({...u,selectedMessageId:void 0})})},[n]),l={selectedMessageId:e,selectedThread:a,onSelectMessage:o,onCloseThread:i};return s.jsx(cc.Provider,{value:l,children:t})}function uc(){const{selectedMessageId:e,onSelectMessage:t}=Ln();return s.jsx(Kx,{selectedMessageId:e,onSelectMessage:t})}function Ux(){const{selectedThread:e}=Ln(),{intelligenceOpen:t,onToggleIntelligence:n}=Se(),r=ds()?.showIntelligencePane??!1,a=!!e,o=r&&a;return s.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[s.jsx(ca,{hasThread:a,intelligenceOpen:o&&t,canToggleIntelligence:o,onToggleIntelligence:n}),s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?s.jsx(gs,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,authenticity:e.authenticity}):s.jsx(hs,{})})]})}function Qx(){const{selectedThread:e}=Ln(),{onToggleIntelligence:t}=Se();return s.jsx(bs,{onClose:t,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId})}function Hx(){const{selectedThread:e,onCloseThread:t}=Ln(),{intelligenceOpen:n,onToggleIntelligence:r}=Se();return e?s.jsxs(s.Fragment,{children:[s.jsx(gs,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,authenticity:e.authenticity,onBack:t,onOpenIntelligence:r}),s.jsx(Jr,{isOpen:n,onClose:r,ariaLabel:"Message details",side:"right",children:s.jsx(bs,{onClose:r,thread:e,hideCloseButton:!0})})]}):s.jsx("div",{className:"h-full",children:s.jsx(uc,{})})}const Is=Object.assign(qx,{List:uc,Reading:Ux,Intelligence:Qx,Phone:Hx}),Wx={reply:"Reply",reply_all:"Reply All",forward:"Forward",new:"New Message"},Vx=()=>{const e=c.useRef(!1);return c.useCallback(()=>{const n=document.querySelector("[data-subject-field]")?.value??"",o=(document.querySelector("[data-slate-editor]")?.textContent??"").replace(/--\s*/g,"").trim();return e.current=n.trim().length>0||o.length>0,e.current},[])},Yx=()=>{const{state:e,closeCompose:t}=It(),n=Vx(),[r,a]=c.useState(!1),{isError:o,error:i,refetch:l}=ue({...ht(),staleTime:1/0}),u=c.useCallback(h=>{h||(n()?a(!0):t())},[t,n]),d=c.useCallback(()=>{a(!1),t()},[t]),m=c.useCallback(()=>{a(!1)},[]);if(!e.isOpen)return null;const f=Wx[e.mode]??"New Message";return s.jsxs($e.Root,{open:e.isOpen,onOpenChange:u,children:[s.jsxs($e.Portal,{children:[s.jsx($e.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),s.jsxs($e.Content,{className:"fixed inset-x-0 bottom-0 z-50 flex flex-col bg-canvas rounded-t-lg",style:{height:"95dvh"},children:[s.jsx($e.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-muted/30"}),s.jsx($e.Title,{className:"px-4 py-2 text-base font-semibold border-b border-line",children:f}),o?s.jsx("div",{className:"flex-1 flex items-center justify-center p-4",children:s.jsx(Mt,{title:"Couldn't load compose",error:i,onRetry:()=>{l()}})}):s.jsx("div",{className:"flex-1 overflow-hidden",children:s.jsx(Zr,{mode:e.mode,account:e.account,sourceMessage:e.sourceMessage,onClose:t})})]})]}),r&&s.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center bg-black/50",children:s.jsxs("div",{className:"mx-4 w-full max-w-sm rounded-xl bg-canvas p-6 shadow-xl",children:[s.jsx("h3",{className:"text-lg font-semibold",children:"Discard draft?"}),s.jsx("p",{className:"mt-2 text-sm text-fg-muted",children:"Your message has unsaved content. Are you sure you want to discard it?"}),s.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[s.jsx("button",{type:"button",onClick:m,className:"rounded-md px-4 py-2 text-sm font-medium hover:bg-surface-raised transition-colors",children:"Keep editing"}),s.jsx("button",{type:"button",onClick:d,className:"rounded-md bg-danger px-4 py-2 text-sm font-medium text-canvas hover:bg-danger/90 transition-colors",children:"Discard"})]})]})})]})},Gx={reply:"Reply",reply_all:"Reply All",forward:"Forward",new:"New Message"},dc=()=>{const{state:e,closeCompose:t}=It(),n=Qt(),{isError:r,error:a,refetch:o}=ue({...ht(),staleTime:1/0});if(!n)return s.jsx(Yx,{});if(!e.isOpen)return null;const i=Gx[e.mode]??"New Message",l=s.jsxs("header",{className:"flex items-center justify-between gap-2 px-4 py-3 border-b border-line shrink-0",children:[s.jsx("div",{className:"flex items-center gap-2 min-w-0",children:s.jsx("h2",{className:"text-lg font-semibold truncate",children:i})}),s.jsx("button",{type:"button",onClick:t,className:"p-2 rounded-md hover:bg-surface-raised transition-colors min-h-11 min-w-11 inline-flex items-center justify-center","aria-label":"Close",children:s.jsx(Ke,{className:"size-5"})})]});return r?s.jsxs("div",{className:"h-full flex flex-col bg-canvas",children:[l,s.jsx("div",{className:"flex-1 flex items-center justify-center p-4",children:s.jsx(Mt,{title:"Couldn't load compose",error:a,onRetry:()=>{o()}})})]}):s.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-canvas",children:[l,s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:s.jsx(Zr,{mode:e.mode,account:e.account,sourceMessage:e.sourceMessage,onClose:t},e.outboxMessageId??"new")})]})};function Xx(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:Tt(e.updatedAt),isRead:!0}}function Jx(e){return{id:e.messageId,accountId:e.accountConfigId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:Tt(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0}}function Zx({outboxMessages:e,accountId:t,imapThreads:n}){const r=e.filter(i=>i.status==="draft"&&i.accountId===t).map(Xx),a=n.map(Jx),o=[];return r.length>0&&o.push({id:"remit-drafts",label:"Not yet sent (Remit)",threads:r}),a.length>0&&o.push({id:"imap-drafts",label:"On the server",threads:a}),o}function ua(){const e=ds();return!e||e.showNavPane?null:s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx($r,{className:"size-4"}),onClick:e.openNav,"aria-label":"Open folders",className:"-ml-1 shrink-0"})}const eb=({label:e,count:t})=>s.jsxs("div",{className:"sticky top-0 z-10 flex items-baseline justify-between border-b border-line bg-surface-sunken px-row-inset py-1",children:[s.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e}),s.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:t})]}),tb=({row:e,isSelected:t,onOpen:n,onDelete:r,isDeleting:a})=>s.jsxs("button",{type:"button",onClick:()=>n(e.id),className:K("group",ms({active:t})),children:[s.jsx(Zo,{className:"size-7 shrink-0 text-fg-muted mt-0.5"}),s.jsx(Ft,{thread:e}),s.jsx("div",{className:"flex items-center gap-1 shrink-0",children:s.jsx("button",{type:"button",onClick:o=>{o.stopPropagation(),r(e.id)},disabled:a,className:"p-1.5 rounded-md text-fg-muted hover:text-danger hover:bg-surface-raised transition-colors opacity-0 group-hover:opacity-100 focus:opacity-100",title:"Delete draft",children:s.jsx(ot,{className:"size-3.5"})})})]}),sb=({row:e,isSelected:t,onOpen:n})=>{const r=!e.isRead;return s.jsxs("button",{type:"button",onClick:()=>n(e.id),className:K("group",ms({active:t})),children:[r&&s.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),s.jsx(Xe,{name:e.fromName,email:e.fromEmail,size:"sm"}),s.jsx(Ft,{thread:e})]})};function nb({mailboxId:e,accountId:t,selectedMessageId:n,imapThreads:r,title:a,unreadCount:o}){const{openCompose:i,state:l}=It(),u=Me(),d=je(),{data:m}=ue(wn()),f=c.useMemo(()=>Zx({outboxMessages:m?.items??[],accountId:t,imapThreads:r}),[m?.items,t,r]),h=pe({...jn(),onSuccess:()=>{d.invalidateQueries({queryKey:Br()})}}),x=g=>{h.mutate({path:{outboxMessageId:g}})},b=g=>{n&&u({to:"/mail/$mailboxId",params:{mailboxId:e},search:{selectedMessageId:void 0}}),i({mode:"new",outboxMessageId:g})},p=g=>{u({to:"/mail/$mailboxId",params:{mailboxId:e},search:{selectedMessageId:g}})},v=f.length===0;return s.jsxs("section",{className:"flex h-full w-full flex-col bg-surface",children:[s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[s.jsx(ua,{}),s.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:a}),(o??0)>0&&s.jsxs("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:[o," unread"]})]}),s.jsx("div",{className:"flex-1 overflow-y-auto",children:v?s.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-2 text-center px-4",children:[s.jsx(Rr,{className:"size-8 text-fg-subtle"}),s.jsx("p",{className:"text-sm font-medium text-fg",children:"No drafts"}),s.jsx("p",{className:"text-xs text-fg-subtle",children:"Messages you start composing will appear here."})]}):f.map(g=>s.jsxs("div",{children:[g.label&&s.jsx(eb,{label:g.label,count:g.threads.length}),s.jsx("div",{className:"divide-y divide-line",children:g.threads.map(y=>g.id==="remit-drafts"?s.jsx(tb,{row:y,isSelected:l.isOpen&&y.id===l.outboxMessageId,onOpen:b,onDelete:x,isDeleting:h.isPending},y.id):s.jsx(sb,{row:y,isSelected:y.id===n,onOpen:p},y.id))})]},g.id))})]})}function rb(e,t,n){const r=new Array(e);return new Proxy(r,{get(a,o,i){if(typeof o=="string"){const l=o.charCodeAt(0);if(l>=48&&l<=57){const u=+o;if(Number.isInteger(u)&&u>=0&&u<e){let d=a[u];if(!d){const m=t[u*2];d=a[u]={index:u,key:n(u),start:m,size:t[u*2+1],end:m+t[u*2+1],lane:0}}return d}}if(o==="length")return e}return Reflect.get(a,o,i)}})}function es(e,t,n){let r=n.initialDeps??[],a,o=!0;function i(){const l=e();return(l.length!==r.length||l.some((d,m)=>r[m]!==d))&&(r=l,a=t(...l),n?.onChange&&!(o&&n.skipInitialOnChange)&&n.onChange(a),o=!1),a}return i.updateDeps=l=>{r=l},i}function jo(e,t){if(e===void 0)throw new Error("Unexpected undefined");return e}const ab=(e,t)=>Math.abs(e-t)<1.01,ob=(e,t,n)=>{let r;return function(...a){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,a),n)}};let Rs;const ur=()=>{if(Rs!==void 0)return Rs;if(typeof navigator>"u")return Rs=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return Rs=!0;const e=navigator.maxTouchPoints;return Rs=navigator.platform==="MacIntel"&&e!==void 0&&e>0},So=e=>{const{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},ib=e=>e,lb=e=>{const t=Math.max(e.startIndex-e.overscan,0),r=Math.min(e.endIndex+e.overscan,e.count-1)-t+1,a=new Array(r);for(let o=0;o<r;o++)a[o]=t+o;return a},cb=(e,t)=>{const n=e.scrollElement;if(!n)return;const r=e.targetWindow;if(!r)return;const a=i=>{const{width:l,height:u}=i;t({width:Math.round(l),height:Math.round(u)})};if(a(So(n)),!r.ResizeObserver)return()=>{};const o=new r.ResizeObserver(i=>{const l=()=>{const u=i[0];if(u?.borderBoxSize){const d=u.borderBoxSize[0];if(d){a({width:d.inlineSize,height:d.blockSize});return}}a(So(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(l):l()});return o.observe(n,{box:"border-box"}),()=>{o.unobserve(n)}},xn={passive:!0},ub=typeof window>"u"?!0:"onscrollend"in window,db=(e,t,n)=>{const r=e.scrollElement;if(!r)return;const a=e.targetWindow;if(!a)return;const o=e.options.useScrollendEvent&&ub;let i=0;const l=o?null:ob(a,()=>t(i,!1),e.options.isScrollingResetDelay),u=f=>()=>{i=n(r),l?.(),t(i,f)},d=u(!0),m=u(!1);return r.addEventListener("scroll",d,xn),o&&r.addEventListener("scrollend",m,xn),()=>{r.removeEventListener("scroll",d),o&&r.removeEventListener("scrollend",m)}},fb=(e,t)=>db(e,t,n=>{const{horizontal:r,isRtl:a}=e.options;return r?n.scrollLeft*(a&&-1||1):n.scrollTop}),mb=(e,t,n)=>{if(n.options.useCachedMeasurements){const r=n.indexFromElement(e),a=n.options.getItemKey(r);return n.itemSizeCache.get(a)??n.options.estimateSize(r)}if(t?.borderBoxSize){const r=t.borderBoxSize[0];if(r)return Math.round(r[n.options.horizontal?"inlineSize":"blockSize"])}if(!t){const r=n.indexFromElement(e),a=n.options.getItemKey(r),o=n.itemSizeCache.get(a);if(o!==void 0)return o}return e[n.options.horizontal?"offsetWidth":"offsetHeight"]},hb=(e,{adjustments:t=0,behavior:n},r)=>{var a,o;(o=(a=r.scrollElement)==null?void 0:a.scrollTo)==null||o.call(a,{[r.options.horizontal?"left":"top"]:e+t,behavior:n})},gb=hb;class pb{constructor(t){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this._flatMeasurements=null,this.itemSizeCache=new Map,this.itemSizeCacheVersion=0,this.laneAssignments=new Map,this.pendingMin=null,this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.pendingScrollAnchor=null,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._intendedScrollOffset=null,this.elementsCache=new Map,this.now=()=>{var n,r,a;return((a=(r=(n=this.targetWindow)==null?void 0:n.performance)==null?void 0:r.now)==null?void 0:a.call(r))??Date.now()},this.observer=(()=>{let n=null;const r=()=>n||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:n=new this.targetWindow.ResizeObserver(a=>{a.forEach(o=>{const i=()=>{const l=o.target,u=this.indexFromElement(l);if(!l.isConnected){this.observer.unobserve(l);for(const[d,m]of this.elementsCache)if(m===l){this.elementsCache.delete(d);break}return}this.shouldMeasureDuringScroll(u)&&this.resizeItem(u,this.options.measureElement(l,o,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(i):i()})}));return{disconnect:()=>{var a;(a=r())==null||a.disconnect(),n=null},observe:a=>{var o;return(o=r())==null?void 0:o.observe(a,{box:"border-box"})},unobserve:a=>{var o;return(o=r())==null?void 0:o.unobserve(a)}}})(),this.range=null,this.setOptions=n=>{var r,a;const o={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:ib,rangeExtractor:lb,onChange:()=>{},measureElement:mb,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,anchorTo:"start",followOnAppend:!1,scrollEndThreshold:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:"estimate",useCachedMeasurements:!1};for(const h in n){const x=n[h];x!==void 0&&(o[h]=x)}const i=this.options;let l=null,u=null,d=!1;if(i!==void 0&&i.enabled&&o.enabled&&o.anchorTo==="end"&&this.scrollElement!==null){const h=i.count,x=o.count,b=this.getMeasurements(),p=h>0?((r=b[0])==null?void 0:r.key)??i.getItemKey(0):null,v=h>0?((a=b[h-1])==null?void 0:a.key)??i.getItemKey(h-1):null;if(x!==h||h>0&&x>0&&(o.getItemKey(0)!==p||o.getItemKey(x-1)!==v)){d=!0;const j=h>0?this.getVirtualItemForOffset(this.getScrollOffset())??b[0]:null;j&&(l=[j.key,this.getScrollOffset()-j.start]);const w=o.followOnAppend===!0?"auto":o.followOnAppend||null;w&&x>h&&this.isAtEnd(i.scrollEndThreshold)&&(h===0||o.getItemKey(x-1)!==v)&&(u=w)}}this.options=o,d&&(this.pendingMin=0,this.itemSizeCacheVersion++);let m=!1,f=0;if(l&&this.scrollOffset!==null){const[h,x]=l,b=this.getMeasurements(),{count:p,getItemKey:v}=this.options;let g=0;for(;g<p&&v(g)!==h;)g++;if(g<p){const y=b[g];if(y){const j=y.start+x;j!==this.scrollOffset&&(f=j-this.scrollOffset,this.scrollOffset=j,m=!0)}}}(m||u)&&(this.pendingScrollAnchor=[m?l[0]:null,m?l[1]:0,u,f])},this.notify=n=>{var r,a;(a=(r=this.options).onChange)==null||a.call(r,this,n)},this.maybeNotify=es(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),n=>{this.notify(n)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(n=>n()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var n;const r=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==r){if(this.cleanup(),!r){this.maybeNotify();return}if(this.scrollElement=r,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((n=this.scrollElement)==null?void 0:n.window)??null,this.elementsCache.forEach(o=>{this.observer.observe(o)}),this.unsubs.push(this.options.observeElementRect(this,o=>{this.scrollRect=o,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(o,i)=>{if(i&&this._intendedScrollOffset===null&&o===this.scrollOffset)return;this._intendedScrollOffset!==null&&Math.abs(o-this._intendedScrollOffset)<1.5&&(o=this._intendedScrollOffset),this._intendedScrollOffset=null,this.scrollAdjustments=0;const l=this.getScrollOffset();this.scrollDirection=i?l===o?this.scrollDirection:l<o?"forward":"backward":null,this.scrollOffset=o,this.isScrolling=i,this._flushIosDeferredIfReady(),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),"addEventListener"in this.scrollElement){const o=this.scrollElement,i=()=>{this._iosTouching=!0,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)},l=()=>{this._iosTouching=!1,!(!ur()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};o.addEventListener("touchstart",i,xn),o.addEventListener("touchend",l,xn),this.unsubs.push(()=>{o.removeEventListener("touchstart",i),o.removeEventListener("touchend",l),this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)})}this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}const a=this.pendingScrollAnchor;if(this.pendingScrollAnchor=null,a&&this.scrollElement&&this.options.enabled){const[o,i,l,u]=a;o!==null&&!l&&(ur()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?u!==0&&(this._iosDeferredAdjustment+=u):this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})),l&&this.scrollToEnd({behavior:l})}},this._flushIosDeferredIfReady=()=>{if(this._iosDeferredAdjustment===0||this.isScrolling||this._iosTouching||this._iosJustTouchEnded)return;const n=this.getScrollOffset(),r=this.getMaxScrollOffset();if(n<0||n>r)return;const a=this._iosDeferredAdjustment;this._iosDeferredAdjustment=0,this._scrollToOffset(n,{adjustments:this.scrollAdjustments+=a,behavior:void 0})},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset=="function"?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getMeasurementOptions=es(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode,this.options.gap],(n,r,a,o,i,l,u,d)=>(this.prevLanes!==void 0&&this.prevLanes!==l&&(this.lanesChangedFlag=!0),this.prevLanes=l,this.pendingMin=null,{count:n,paddingStart:r,scrollMargin:a,getItemKey:o,enabled:i,lanes:l,laneAssignmentMode:u,gap:d}),{key:!1}),this.getMeasurements=es(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:n,paddingStart:r,scrollMargin:a,getItemKey:o,enabled:i,lanes:l,laneAssignmentMode:u,gap:d},m)=>{const f=this.itemSizeCache;if(!i)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>n)for(const g of this.laneAssignments.keys())g>=n&&this.laneAssignments.delete(g);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMin=null),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(g=>{this.itemSizeCache.set(g.key,g.size)}));const h=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===n&&(this.lanesSettling=!1),l===1){const g=n*2;let y=this._flatMeasurements;if(!y||y.length<g){const C=new Float64Array(g);y&&h>0&&C.set(y.subarray(0,h*2)),y=C,this._flatMeasurements=y}let j;if(h===0)j=r+a;else{const C=h-1;j=y[C*2]+y[C*2+1]+d}for(let C=h;C<n;C++){const k=o(C),S=f.get(k),N=typeof S=="number"?S:this.options.estimateSize(C);y[C*2]=j,y[C*2+1]=N,j+=N+d}const w=rb(n,y,o);return this.measurementsCache=w,w}const x=this.measurementsCache.slice(0,h),b=new Array(l).fill(void 0),p=new Float64Array(l);let v=0;for(let g=0;g<h;g++){const y=x[g];y&&(b[y.lane]===void 0&&v++,b[y.lane]=g,p[y.lane]=y.end)}for(let g=h;g<n;g++){const y=o(g),j=this.laneAssignments.get(g);let w,C;const k=u==="estimate"||f.has(y);if(j!==void 0&&this.options.lanes>1){w=j;const T=b[w],E=T!==void 0?x[T]:void 0;C=E?E.end+d:r+a}else if(v===l){let T=0,E=p[0],M=b[0];for(let R=1;R<l;R++){const A=p[R];(A<E||A===E&&b[R]<M)&&(T=R,E=A,M=b[R])}w=T,C=E+d,k&&this.laneAssignments.set(g,w)}else w=g%this.options.lanes,C=r+a,k&&this.laneAssignments.set(g,w);const S=f.get(y),N=typeof S=="number"?S:this.options.estimateSize(g),I=C+N;x[g]={index:g,start:C,size:N,end:I,key:y,lane:w},b[w]===void 0&&v++,b[w]=g,p[w]=I}return this.measurementsCache=x,x},{key:!1,debug:()=>this.options.debug}),this.calculateRange=es(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(n,r,a,o)=>n.length===0||r===0?(this.range=null,null):(this.range=bb(n,r,a,o,o===1&&this._flatMeasurements!=null?this._flatMeasurements:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=es(()=>{let n=null,r=null;const a=this.calculateRange();return a&&(n=a.startIndex,r=a.endIndex),this.maybeNotify.updateDeps([this.isScrolling,n,r]),[this.options.rangeExtractor,this.options.overscan,this.options.count,n,r]},(n,r,a,o,i)=>o===null||i===null?[]:n({startIndex:o,endIndex:i,overscan:r,count:a}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=n=>{const r=this.options.indexAttribute,a=n.getAttribute(r);return a?parseInt(a,10):(console.warn(`Missing attribute name '${r}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=n=>{var r;if(!this.scrollState||this.scrollState.behavior!=="smooth")return!0;const a=this.scrollState.index??((r=this.getVirtualItemForOffset(this.scrollState.lastTargetOffset))==null?void 0:r.index);if(a!==void 0&&this.range){const o=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),i=Math.max(0,a-o),l=Math.min(this.options.count-1,a+o);return n>=i&&n<=l}return!0},this.measureElement=n=>{if(!n){this.elementsCache.forEach((i,l)=>{i.isConnected||(this.observer.unobserve(i),this.elementsCache.delete(l))});return}const r=this.indexFromElement(n),a=this.options.getItemKey(r),o=this.elementsCache.get(a);o!==n&&(o&&this.observer.unobserve(o),this.observer.observe(n),this.elementsCache.set(a,n)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(r)&&this.resizeItem(r,this.options.measureElement(n,void 0,this))},this.resizeItem=(n,r)=>{var a,o;if(n<0||n>=this.options.count)return;let i,l,u;const d=this._flatMeasurements;if(this.options.lanes===1&&d!==null)u=this.options.getItemKey(n),l=d[n*2],i=d[n*2+1];else{const h=this.measurementsCache[n];if(!h)return;u=h.key,l=h.start,i=h.size}const m=this.itemSizeCache.get(u)??i,f=r-m;if(f!==0){const h=this.options.anchorTo==="end"&&((a=this.scrollState)==null?void 0:a.behavior)!=="smooth"&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,x=h?this.getTotalSize():0,b=((o=this.scrollState)==null?void 0:o.behavior)!=="smooth"&&(this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[n]??{index:n,key:u,start:l,size:i,end:l+i,lane:0},f,this):l<this.getScrollOffset()+this.scrollAdjustments&&(!this.itemSizeCache.has(u)||this.scrollDirection!=="backward"));(this.pendingMin===null||n<this.pendingMin)&&(this.pendingMin=n),this.itemSizeCache.set(u,r),this.itemSizeCacheVersion++,h?this.applyScrollAdjustment(this.getTotalSize()-x):b&&this.applyScrollAdjustment(f),this.notify(!1)}},this.getVirtualItems=es(()=>[this.getVirtualIndexes(),this.getMeasurements()],(n,r)=>{const a=[];for(let o=0,i=n.length;o<i;o++){const l=n[o],u=r[l];a.push(u)}return a},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=n=>{const r=this.getMeasurements();if(r.length===0)return;const a=this._flatMeasurements,o=this.options.lanes===1&&a!=null,i=fc(0,r.length-1,o?l=>a[l*2]:l=>jo(r[l]).start,n);return jo(r[i])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if("scrollHeight"in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{const n=this.scrollElement.document.documentElement;return this.options.horizontal?n.scrollWidth-this.scrollElement.innerWidth:n.scrollHeight-this.scrollElement.innerHeight}},this.getVirtualDistanceFromEnd=()=>Math.max(this.getTotalSize()-this.getSize()-this.getScrollOffset(),0),this.getDistanceFromEnd=()=>Math.max(this.getMaxScrollOffset()-this.getScrollOffset(),0),this.isAtEnd=(n=this.options.scrollEndThreshold)=>this.getDistanceFromEnd()<=n,this.getOffsetForAlignment=(n,r,a=0)=>{if(!this.scrollElement)return 0;const o=this.getSize(),i=this.getScrollOffset();r==="auto"&&(r=n>=i+o?"end":"start"),r==="center"?n+=(a-o)/2:r==="end"&&(n-=o);const l=this.getMaxScrollOffset();return Math.max(Math.min(l,n),0)},this.getOffsetForIndex=(n,r="auto")=>{n=Math.max(0,Math.min(n,this.options.count-1));const a=this.getSize(),o=this.getScrollOffset(),i=this.measurementsCache[n];if(!i)return;if(r==="auto")if(i.end>=o+a-this.options.scrollPaddingEnd)r="end";else if(i.start<=o+this.options.scrollPaddingStart)r="start";else return[o,r];if(r==="end"&&n===this.options.count-1)return[this.getMaxScrollOffset(),r];const l=r==="end"?i.end+this.options.scrollPaddingEnd:i.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(l,r,i.size),r]},this.scrollToOffset=(n,{align:r="start",behavior:a="auto"}={})=>{const o=this.getOffsetForAlignment(n,r),i=this.now();this.scrollState={index:null,align:r,behavior:a,startedAt:i,lastTargetOffset:o,stableFrames:0},this._scrollToOffset(o,{adjustments:void 0,behavior:a}),this.scheduleScrollReconcile()},this.scrollToIndex=(n,{align:r="auto",behavior:a="auto"}={})=>{n=Math.max(0,Math.min(n,this.options.count-1));const o=this.getOffsetForIndex(n,r);if(!o)return;const[i,l]=o,u=this.now();this.scrollState={index:n,align:l,behavior:a,startedAt:u,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:a}),this.scheduleScrollReconcile()},this.scrollBy=(n,{behavior:r="auto"}={})=>{const a=this.getScrollOffset()+n,o=this.now();this.scrollState={index:null,align:"start",behavior:r,startedAt:o,lastTargetOffset:a,stableFrames:0},this._scrollToOffset(a,{adjustments:void 0,behavior:r}),this.scheduleScrollReconcile()},this.scrollToEnd=({behavior:n="auto"}={})=>{if(this.options.count>0){this.scrollToIndex(this.options.count-1,{align:"end",behavior:n});return}this.scrollToOffset(Math.max(this.getTotalSize()-this.getSize(),0),{behavior:n})},this.getTotalSize=()=>{var n;const r=this.getMeasurements();let a;if(r.length===0)a=this.options.paddingStart;else if(this.options.lanes===1){const o=r.length-1,i=this._flatMeasurements;i!=null?a=i[o*2]+i[o*2+1]:a=((n=r[o])==null?void 0:n.end)??0}else{const o=Array(this.options.lanes).fill(null);let i=r.length-1;for(;i>=0&&o.some(l=>l===null);){const l=r[i];o[l.lane]===null&&(o[l.lane]=l.end),i--}a=Math.max(...o.filter(l=>l!==null))}return Math.max(a-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{const n=[];if(this.itemSizeCache.size===0)return n;const r=this.getMeasurements();for(const a of r)a&&this.itemSizeCache.has(a.key)&&n.push({index:a.index,key:a.key,start:a.start,size:a.size,end:a.end,lane:a.lane});return n},this._scrollToOffset=(n,{adjustments:r,behavior:a})=>{this._intendedScrollOffset=n+(r??0),this.options.scrollToFn(n,{behavior:a,adjustments:r},this)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(t)}applyScrollAdjustment(t,n){t!==0&&(ur()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?this._iosDeferredAdjustment+=t:(this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=t,behavior:n}),this.scrollOffset!==null&&(this.scrollOffset+=this.scrollAdjustments,this.scrollAdjustments=0)))}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId==null&&(this.rafId=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}))}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}const r=this.scrollState.index!=null?this.getOffsetForIndex(this.scrollState.index,this.scrollState.align):void 0,a=r?r[0]:this.scrollState.lastTargetOffset,o=1,i=a!==this.scrollState.lastTargetOffset;if(!i&&ab(a,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=o){this.getScrollOffset()!==a&&this._scrollToOffset(a,{adjustments:void 0,behavior:"auto"}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,i){const l=this.getSize()||600,u=Math.abs(a-this.getScrollOffset()),d=this.scrollState.behavior==="smooth"&&u>l;this.scrollState.lastTargetOffset=a,d||(this.scrollState.behavior="auto"),this._scrollToOffset(a,{adjustments:void 0,behavior:d?"smooth":"auto"})}this.scheduleScrollReconcile()}}const fc=(e,t,n,r)=>{for(;e<=t;){const a=(e+t)/2|0,o=n(a);if(o<r)e=a+1;else if(o>r)t=a-1;else return a}return e>0?e-1:0};function xb(e,t,n){let r=0;for(;r<=t;){const a=(r+t)/2|0,o=e[a*2];if(o<n)r=a+1;else if(o>n)t=a-1;else return a}return r>0?r-1:0}function bb(e,t,n,r,a){const o=e.length-1;if(e.length<=r)return{startIndex:0,endIndex:o};if(r===1&&a!==null){const d=xb(a,o,n);let m=d;const f=n+t;for(;m<o&&a[m*2]+a[m*2+1]<f;)m++;return{startIndex:d,endIndex:m}}let l=fc(0,o,d=>e[d].start,n),u=l;if(r===1)for(;u<o&&e[u].end<n+t;)u++;else if(r>1){const d=Array(r).fill(0);for(;u<o&&d.some(f=>f<n+t);){const f=e[u];d[f.lane]=f.end,u++}const m=Array(r).fill(n+t);for(;l>=0&&m.some(f=>f>=n);){const f=e[l];m[f.lane]=f.start,l--}l=Math.max(0,l-l%r),u=Math.min(o,u+(r-1-u%r))}return{startIndex:l,endIndex:u}}const dr=typeof document<"u"?c.useLayoutEffect:c.useEffect;function vb({useFlushSync:e=!0,directDomUpdates:t=!1,directDomUpdatesMode:n="transform",...r}){const a=c.useReducer(d=>d+1,0)[1],o=c.useRef({enabled:t,mode:n,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});o.current.enabled=t,o.current.mode=n;const i=d=>{const m=o.current;if(!m.enabled||!m.container)return;const f=d.getTotalSize();if(f!==m.lastSize){m.lastSize=f;const g=d.options.horizontal?"width":"height";m.container.style[g]=`${f}px`}const h=!!d.options.horizontal,x=m.mode==="transform",b=h?"left":"top",p=d.options.scrollMargin,v=d.getVirtualItems();for(const g of v){const y=g.start-p,j=d.elementsCache.get(g.key);j&&m.lastPositions.get(j)!==y&&(m.lastPositions.set(j,y),x?j.style.transform=h?`translate3d(${y}px, 0, 0)`:`translate3d(0, ${y}px, 0)`:j.style[b]=`${y}px`)}},l={...r,onChange:(d,m)=>{var f;const h=o.current;let x=!0;if(h.enabled){i(d);const b=d.range,p=h.prevRange;x=!p||p.isScrolling!==d.isScrolling||p.startIndex!==b?.startIndex||p.endIndex!==b?.endIndex,x&&(h.prevRange=b?{startIndex:b.startIndex,endIndex:b.endIndex,isScrolling:d.isScrolling}:null)}x&&(e&&m?Ar.flushSync(a):a()),(f=r.onChange)==null||f.call(r,d,m)}},[u]=c.useState(()=>{const d=new pb(l);return Object.assign(d,{containerRef:m=>{const f=o.current;if(f.container=m,f.lastSize=null,m&&f.enabled){const h=d.getTotalSize();f.lastSize=h;const x=d.options.horizontal?"width":"height";m.style[x]=`${h}px`}}})});return u.setOptions(l),dr(()=>u._didMount(),[]),dr(()=>u._willUpdate()),dr(()=>{i(u)}),u}function yb(e){return vb({observeElementRect:cb,observeElementOffset:fb,scrollToFn:gb,...e})}const mc=100,bn=async e=>e.then(t=>({ok:!0,value:t}),t=>({ok:!1,error:t})),wb=(e,t=mc)=>{if(e.length===0)return[];const n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n},jb=async(e,t,n,r)=>{const a=wb(e),o=e.length;let i=0;const l=[];for(let u=0;u<a.length;u++){if(r())return l.push(...a.slice(u).flat()),{done:i,failedIds:l,cancelled:!0};const d=a[u],m=await bn(t(d));if(!m.ok)return l.push(...a.slice(u).flat()),n({done:i,total:o}),{done:i,failedIds:l,cancelled:!1,error:m.error};const f=new Set(m.value.failedIds??[]);i+=d.length-f.size,l.push(...d.filter(h=>f.has(h))),n({done:i,total:o})}return{done:i,failedIds:l,cancelled:!1}},Sb=async(e,t,n,r,a)=>{let o=0;const i=[];let l;do{if(a())return{done:o,failedIds:i,cancelled:!0};const u=await bn(e(l));if(!u.ok)return{done:o,failedIds:i,cancelled:!1,error:u.error};const d=u.value;if(d.ids.length>0){const m=await bn(n(d.ids));if(!m.ok)return{done:o,failedIds:i,cancelled:!1,error:m.error};const f=new Set(m.value.failedIds??[]);o+=d.ids.length-f.size,i.push(...d.ids.filter(h=>f.has(h))),r({done:o,total:t})}l=d.continuationToken}while(l);return{done:o,failedIds:i,cancelled:!1}},kb=async(e,t,n)=>{let r=0,a;do{if(n())return{total:r,cancelled:!0};const o=await bn(e(a));if(!o.ok)return{total:r,cancelled:!1,error:o.error};const i=o.value;r+=i.ids.length,t(r),a=i.continuationToken}while(a);return{total:r,cancelled:!1}},Nb=e=>e.failedIds.length>0?{exit:!1,retryIds:e.failedIds}:e.cancelled||e.error?{exit:!1,retryIds:[]}:{exit:!0,retryIds:[]},Cb=100,Eb=({mailboxId:e,accountId:t,enabled:n,predicateKey:r,searchQuery:a})=>{const[o,i]=c.useState({kind:"idle"}),[l,u]=c.useState(!1),[d,m]=c.useState(void 0),f=c.useRef(!1),h=je(),{pushError:x}=qe();c.useEffect(()=>{f.current=!0,i({kind:"idle"})},[n,r]);const b=c.useRef(a);b.current=a;const p=c.useCallback(async k=>{const{data:S}=await Go({path:{mailboxId:e},query:{...b.current,continuationToken:k,limit:Cb},throwOnError:!0});return{ids:(S.items??[]).map(N=>N.messageId),continuationToken:S.continuationToken}},[e]),v=c.useCallback(async k=>{const{data:S}=await lu({body:{messageIds:k},throwOnError:!0});return S},[]),g=c.useCallback(()=>{h.invalidateQueries({queryKey:at({path:{mailboxId:e}})}),h.invalidateQueries({queryKey:gt({path:{mailboxId:e}})}),t&&h.invalidateQueries({queryKey:Bt({path:{accountId:t}})})},[h,e,t]),y=c.useCallback(()=>{f.current=!1,i({kind:"counting",countSoFar:0}),kb(p,k=>i({kind:"counting",countSoFar:k}),()=>f.current).then(k=>{if(k.error){x(zt("Couldn't count matching messages","The count didn't finish.",k.error)),i({kind:"idle"});return}if(k.cancelled){i({kind:"idle"});return}i({kind:"escalated",total:k.total})})},[p,x]),j=c.useCallback(()=>{f.current=!0},[]),w=c.useCallback(()=>{f.current=!0,i({kind:"idle"})},[]),C=c.useCallback(async k=>{f.current=!1,u(!0);const S=I=>m(I),N=k!==void 0?await jb(k,v,S,()=>f.current):await Sb(p,o.kind==="escalated"?o.total:0,v,S,()=>f.current);return u(!1),m(void 0),i({kind:"idle"}),N.error&&x(zt(N.done>0?`Stopped after ${N.done} — some messages weren't deleted`:"Couldn't delete these messages","The delete didn't finish.",N.error)),N.done>0&&g(),N},[v,p,o,x,g]);return{phase:o,escalate:y,stop:j,clear:w,isDeleting:l,deleteProgress:d,runDelete:C}},Ib=(e,t,n)=>{const r=e.indexOf(n);if(r===-1)return[];const a=t===void 0?-1:e.indexOf(t);if(a===-1)return[n];const o=Math.min(a,r),i=Math.max(a,r);return e.slice(o,i+1)},Rb=(e,t,n)=>{if(e.length===0)return;const r=t===void 0?-1:e.indexOf(t);if(r===-1)return n>0?e[0]:e[e.length-1];const a=Math.min(Math.max(r+n,0),e.length-1);return e[a]},Mb=e=>{const[t,n]=c.useState(new Set),[r,a]=c.useState(void 0),o=c.useCallback(b=>t.has(b),[t]),i=c.useCallback(b=>{a(b),n(p=>{const v=new Set(p);return v.has(b)?v.delete(b):v.add(b),v})},[]),l=c.useCallback(b=>{a(b),n(p=>{if(p.has(b))return p;const v=new Set(p);return v.add(b),v})},[]),u=c.useCallback(b=>{n(p=>{if(!p.has(b))return p;const v=new Set(p);return v.delete(b),v})},[]),d=c.useCallback(b=>{n(new Set(b))},[]),m=c.useCallback(()=>{a(void 0),n(new Set)},[]),f=c.useCallback(b=>{n(p=>b.every(g=>p.has(g))?new Set:new Set(b))},[]),h=c.useCallback(b=>{a(b)},[]),x=c.useCallback((b,p)=>{n(v=>{const g=Ib(b,r,p);if(g.length===0)return v;const y=new Set(v);for(const j of g)y.add(j);return y}),a(v=>v??p)},[r]);return{selectedIds:t,selectedCount:t.size,hasSelection:t.size>0,isSelected:o,toggle:i,select:l,deselect:u,selectAll:d,clearSelection:m,toggleAll:f,selectRange:x,setAnchor:h,anchorId:r}},hc=e=>e.query?`matching "${e.query}"`:e.from?`from "${e.from}"`:"matching your search",Tb=e=>`Select all ${hc(e)}`,Db=(e,t)=>`All ${ft(t)} ${hc(e)} selected`;function Ab(e,t){if(e.length!==0)return t!==void 0&&e.includes(t)?t:e[0]}const Ob=e=>{const t=pe(cu()),{mutate:n}=t;return{preview:c.useCallback(a=>{e&&n({path:{accountId:e},body:si(a)})},[e,n]),reset:t.reset,matchedCount:t.data?.matchedCount,messageIds:t.data?.messageIds,isPending:t.isPending,isError:t.isError,error:t.error}},Pb=new Set(["Complete","Failed"]),ko=e=>e!==void 0&&Pb.has(e),Lb=1e3,zb=15e3,Fb=e=>{const t=Math.max(0,e),n=Lb*2**t;return Math.min(n,zb)},_b=e=>{const[t,n]=c.useState(),r=pe({...uu(),onSuccess:f=>n(f.organizeJobId)}),{mutate:a}=r,o=ue({...du({path:{accountId:e??"",organizeJobId:t??""}}),enabled:!!e&&!!t,refetchInterval:f=>{const h=f.state.data?.state;return ko(h)?!1:Fb(f.state.dataUpdateCount)}}),i=c.useCallback(f=>{e&&(n(void 0),a({path:{accountId:e},body:si(f)}))},[e,a]),l=o.data,u=l?.state??r.data?.state,d=ko(l?.state),m={state:u,matchedCount:l?.matchedCount??0,appliedCount:l?.appliedCount??0,failedCount:l?.failedCount??0,errorMessage:l?.errorMessage??""};return{start:i,progress:m,isStarting:r.isPending,isRunning:!!t&&!d,isDone:d,isError:r.isError||o.isError,error:r.error??o.error}},Bb=({draft:e,scope:t,name:n,pickedDate:r})=>{if(!Ou(e))return"Pick a folder to move these into — labeling isn't available yet.";if((t==="standing"||t==="temporary")&&n.trim()==="")return"Name this filter so you can find it later.";if(t==="temporary"&&r==="")return"Pick the date this should stop on."},$b=(e,t)=>{switch(e){case"just-these":return`Move ${t} message${t===1?"":"s"}`;case"all-like-these":return`Organize ${t} message${t===1?"":"s"}`;case"standing":return"Always do this";case"temporary":return"Do this until then"}},Kb=(e,t,n)=>e==="just-these"?t:n,qb=[{id:"just-these",label:"Just these",caption:"the ones you selected"},{id:"all-like-these",label:"All like these",caption:"including the similar ones found now"},{id:"standing",label:"These and new mail like this",caption:"keeps working on future mail"},{id:"temporary",label:"Until a date",caption:"stops on its own"}];function Ub({accountId:e,mailboxId:t,selectedMessageIds:n,anchorMessageId:r,matchedCount:a,onClose:o}){const[i,l]=c.useState("all-like-these"),[u,d]=c.useState(""),[m,f]=c.useState(""),[h,x]=c.useState(""),{data:b}=ue({...rt({path:{accountId:e}}),staleTime:1/0}),p=c.useMemo(()=>ia(b?.items??[]).map(T=>({id:T.mailboxId,label:hn(T.fullPath)})),[b?.items]),v=c.useMemo(()=>({anchorMessageId:r,matchOperator:"And",literalClauses:[],moveMailboxId:u||void 0,expiresAt:i==="temporary"?Pu(h):void 0}),[r,u,i,h]),{moveMessages:g}=Ct({mailboxId:t,accountId:e}),y=_b(e),j=Lu(e),w=n.length,C=Kb(i,w,a),k=Bb({draft:v,scope:i,name:m,pickedDate:h}),S=()=>{if(!k)switch(i){case"just-these":u&&g(n,u),o();return;case"all-like-these":y.start(v);return;case"standing":j.createFilter(v,"standing",m.trim());return;case"temporary":j.createFilter(v,"temporary",m.trim());return}};if(y.isRunning||y.isDone)return s.jsx(Qb,{progress:y.progress,isDone:y.isDone,onClose:o});if(j.isSuccess)return s.jsxs("div",{className:"flex flex-col items-center gap-3 px-5 py-8 text-center",children:[s.jsx(Kr,{className:"size-8 text-positive"}),s.jsx("p",{className:"text-sm font-medium text-fg",children:"Filter saved"}),s.jsx("p",{className:"max-w-xs text-xs text-fg-muted",children:"You can see it, and when it expires, under Settings › Filters."}),s.jsx(G,{variant:"primary",onClick:o,className:"mt-2",children:"Done"})]});const N=i==="standing"||i==="temporary";return s.jsxs("div",{className:"flex min-h-0 flex-col",children:[s.jsxs("div",{className:"border-b border-line px-5 py-3",children:[s.jsx("h2",{className:"text-sm font-semibold text-fg",children:"Organize"}),s.jsxs("p",{className:"mt-0.5 text-xs text-fg-muted",children:[a," similar message",a===1?"":"s"," found",w>0?` from ${w} selected`:"","."]})]}),s.jsxs("div",{className:"min-h-0 flex-1 space-y-5 overflow-y-auto px-5 py-4",children:[s.jsxs("section",{className:"space-y-2 rounded-lg border border-line bg-surface-sunken p-3",children:[s.jsxs("p",{className:"text-sm leading-relaxed text-fg-muted",children:[i==="standing"&&s.jsx("span",{className:"font-semibold text-fg",children:"Always keep "}),i==="standing"?"":"Keep ",i==="just-these"?"these":"emails like these"," in"]}),s.jsxs(Au,{"aria-label":"Destination folder",value:u,onChange:I=>d(I.target.value),children:[s.jsx("option",{value:"",children:"Choose a folder…"}),p.map(I=>s.jsx("option",{value:I.id,children:I.label},I.id))]}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx(Ge,{tone:"neutral",children:"label them…"}),s.jsx("span",{className:"text-2xs text-fg-subtle",children:"Labeling isn't available yet — arrives with mail-labeling (RFC 031)."})]})]}),s.jsx("section",{className:"space-y-1.5",children:qb.map(I=>{const T=i===I.id;return s.jsxs("button",{type:"button",onClick:()=>l(I.id),className:`flex w-full items-start gap-3 rounded-lg border px-3 py-2.5 text-left transition-colors ${T?"border-accent-2 bg-accent-2-soft":"border-line bg-surface hover:bg-surface-sunken"}`,children:[s.jsx("span",{className:`mt-0.5 flex size-4 shrink-0 items-center justify-center rounded-full border ${T?"border-accent-2 bg-accent-2":"border-line bg-surface"}`,children:T&&s.jsx("span",{className:"size-1.5 rounded-full bg-white"})}),s.jsxs("span",{className:"min-w-0",children:[s.jsx("span",{className:`block text-sm font-medium ${T?"text-accent-2":"text-fg"}`,children:I.label}),s.jsx("span",{className:"block text-xs text-fg-subtle",children:I.caption})]})]},I.id)})}),N&&s.jsxs("section",{className:"space-y-2",children:[s.jsx(zo,{value:m,onChange:I=>f(I.target.value),placeholder:"Name this filter (e.g. Travel)","aria-label":"Filter name"}),i==="temporary"&&s.jsxs("label",{className:"flex items-center gap-2 text-xs text-fg-muted",children:["Until",s.jsx("input",{type:"date",value:h,onChange:I=>x(I.target.value),"aria-label":"Expiry date",className:"rounded-md border border-line bg-surface-sunken px-2 py-1 text-sm text-fg"})]})]})]}),s.jsxs("div",{className:"space-y-2 border-t border-line px-5 py-3",children:[k&&s.jsx("p",{className:"text-xs text-fg-subtle",role:"status",children:k}),j.isError&&s.jsx("p",{className:"text-xs text-danger",role:"alert",children:"Couldn't save the filter. Please try again."}),s.jsx(G,{variant:"primary",onClick:S,disabled:!!k||j.isPending||y.isStarting,className:"w-full",children:j.isPending?"Saving…":$b(i,C)}),s.jsx(G,{variant:"ghost",onClick:o,className:"w-full",children:"Not now"})]})]})}function Qb({progress:e,isDone:t,onClose:n}){const r=e.state==="Failed";return s.jsxs("div",{className:"flex flex-col items-center gap-3 px-5 py-8 text-center",children:[t?r?s.jsx("span",{className:"text-sm font-semibold text-danger",children:"Organize failed"}):s.jsx(Kr,{className:"size-8 text-positive"}):s.jsx(Kt,{className:"size-8 animate-spin text-accent-2"}),!t&&s.jsx("p",{className:"text-sm font-medium text-fg",children:"Organizing similar mail…"}),t&&!r&&s.jsxs("div",{className:"text-sm text-fg",children:[s.jsx("p",{className:"font-medium",children:"Done"}),s.jsxs("p",{className:"mt-1 text-xs text-fg-muted",children:[e.appliedCount," of ",e.matchedCount," moved",e.failedCount>0?` · ${e.failedCount} failed`:"","."]})]}),t&&r&&s.jsx("p",{className:"max-w-xs text-xs text-fg-muted",children:e.errorMessage||"Something went wrong. Please try again."}),t&&s.jsx(G,{variant:"primary",onClick:n,className:"mt-2",children:"Done"})]})}function Hb({open:e,accountId:t,mailboxId:n,selectedMessageIds:r,onClose:a}){const o=r[0],{preview:i,reset:l,matchedCount:u,isPending:d,isError:m,error:f}=Ob(t);c.useEffect(()=>{!e||!o||i({anchorMessageId:o,matchOperator:"And",literalClauses:[]})},[e,o,i]);const h=()=>{l(),a()};return e?s.jsx(Lo,{open:e,onClose:h,title:"Organize similar mail",children:d||u===void 0?m?s.jsxs("div",{className:"flex flex-col items-center gap-3 px-5 py-8 text-center",children:[s.jsx("p",{className:"text-sm font-medium text-danger",children:"Couldn't find similar messages"}),s.jsx("p",{className:"max-w-xs text-xs text-fg-muted",children:f instanceof Error?f.message:"Please try again."}),s.jsx(G,{variant:"ghost",onClick:h,className:"mt-2",children:"Close"})]}):s.jsxs("div",{className:"flex flex-col items-center gap-3 px-5 py-10 text-center",children:[s.jsx(Kt,{className:"size-8 animate-spin text-accent-2"}),s.jsx("p",{className:"text-sm font-medium text-fg",children:"Finding similar messages…"})]}):s.jsx(Ub,{accountId:t,mailboxId:n,selectedMessageIds:r,anchorMessageId:o,matchedCount:u,onClose:h})}):null}const Wb=({selectedCount:e,onDelete:t,onClearSelection:n,onMarkAsRead:r,onMove:a,onOrganize:o,isDeleting:i=!1,isMoving:l=!1,accountId:u,currentMailboxId:d,moveDisabledHint:m})=>{const f=i||l;if(e===0)return null;const h=!!a&&!!u&&!!d,x=!!o&&!!u&&!!d&&!m;return s.jsxs("div",{className:"sticky top-0 z-10 flex items-center justify-between px-3 py-2 bg-surface-sunken border-b border-line",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("button",{type:"button",onClick:n,className:"min-h-11 min-w-11 inline-flex items-center justify-center rounded hover:bg-surface-raised transition-colors","aria-label":"Clear selection",children:s.jsx(Ke,{className:"size-4 text-fg-muted"})}),s.jsxs("span",{className:"text-sm font-medium",children:[e," ",e===1?"message":"messages"," ","selected"]}),m&&s.jsx("span",{className:"text-xs text-fg-muted",role:"status","aria-live":"polite",children:m})]}),s.jsxs("div",{className:"flex items-center gap-1",children:[x&&o&&s.jsxs("button",{type:"button",onClick:f?void 0:o,className:"min-h-11 inline-flex items-center justify-center gap-1.5 px-3 rounded text-sm font-medium transition-colors hover:bg-surface-raised","aria-label":"Organize similar messages",children:[s.jsx(nt,{className:"size-4"}),s.jsx("span",{className:"hidden sm:inline",children:"Organize"})]}),r&&s.jsx("button",{type:"button",onClick:f?void 0:r,className:"min-h-11 min-w-11 inline-flex items-center justify-center rounded text-sm font-medium transition-colors hover:bg-surface-raised","aria-label":"Mark as read","aria-busy":f,children:s.jsx($s,{className:"size-4"})}),h&&a&&u&&d&&s.jsx(Qs,{accountId:u,currentMailboxId:d,onMove:f?()=>{}:a,disabledHint:m,variant:"icon-only",label:"Move selected messages"}),s.jsxs("button",{type:"button",onClick:f?void 0:t,className:de("min-h-11 min-w-11 inline-flex items-center justify-center gap-1.5 px-3 rounded text-sm font-medium transition-colors","bg-danger text-canvas hover:bg-danger/90"),"aria-label":"Delete selected messages","aria-busy":i,children:[i?s.jsx(Kt,{className:"size-4 animate-spin"}):s.jsx(ot,{className:"size-4"}),s.jsx("span",{className:"hidden sm:inline",children:i?"Deleting...":"Delete"})]})]})]})},Vb=8,Yb=({onLongPress:e,delayMs:t=500})=>{const n=c.useRef(null),r=c.useRef(null),a=c.useCallback(()=>{n.current&&(clearTimeout(n.current),n.current=null),r.current=null},[]),o=c.useCallback(d=>{a(),r.current={x:d.clientX,y:d.clientY},n.current=setTimeout(()=>{e(),a()},t)},[e,t,a]),i=c.useCallback(d=>{if(!r.current)return;const m=d.clientX-r.current.x,f=d.clientY-r.current.y;Math.sqrt(m*m+f*f)>Vb&&a()},[a]),l=c.useCallback(()=>{a()},[a]),u=c.useCallback(()=>{a()},[a]);return{handlers:{onPointerDown:o,onPointerMove:i,onPointerUp:l,onPointerCancel:u}}},Gb=(e,t)=>{const n=e.authenticity?.dkimMismatch===!0;return{id:e.messageId,accountId:e.accountConfigId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:Tt(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Tn(e.category),messageCount:t,suspicious:n}},Xb=({thread:e,mailboxId:t,accountId:n,isSelected:r,isFocused:a=!1,isTabStop:o=!1,onFocusRow:i,isChecked:l,onToggleCheck:u,onRowSelect:d,messageCount:m,isMultiSelectMode:f=!1,onLongPress:h,isDesktop:x=!0,density:b="comfortable"})=>{const p=je(),v=e.messageId,g=Gb(e,m),y=E=>{E.preventDefault(),E.stopPropagation(),u(e.messageId)},j=c.useCallback(E=>{if(!x)return;const M={shiftKey:E.shiftKey,metaKey:E.metaKey,ctrlKey:E.ctrlKey};d(v,M)&&(E.preventDefault(),E.stopPropagation(),M.shiftKey&&window.getSelection()?.removeAllRanges())},[x,d,v]),w=c.useCallback(E=>{x&&E.shiftKey&&E.preventDefault()},[x]),C=c.useCallback(()=>{h?.(v)},[h,v]),k=Yb({onLongPress:C,delayMs:500}),S=c.useCallback(()=>{p.prefetchQuery(_r({path:{messageId:e.messageId}}))},[p,e.messageId]),N=c.useCallback(()=>{S(),i?.(v)},[S,i,v]),I={"data-message-row":!0,"data-message-id":v,role:"option","aria-selected":l,tabIndex:o?0:-1,onClick:j,onMouseDown:w,onMouseEnter:S,onFocus:N},T=!e.isRead;return b==="compact"?s.jsx(mt,{to:"/mail/$mailboxId",params:{mailboxId:t},search:E=>({...E,selectedMessageId:e.messageId}),...I,...!x&&k.handlers,className:de(xi({active:r,focused:a}),"outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-inset",l&&"bg-accent-soft",!x&&"min-h-11"),children:s.jsx(bi,{thread:g})}):s.jsxs(mt,{to:"/mail/$mailboxId",params:{mailboxId:t},search:E=>({...E,selectedMessageId:e.messageId}),...I,...!x&&k.handlers,className:de("group",ms({active:r,focused:a}),"outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-inset",l&&"bg-accent-soft",!x&&"min-h-11"),children:[T&&s.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),s.jsxs("div",{className:"relative size-7 shrink-0",children:[s.jsx(Xe,{name:e.fromName??e.fromEmail??"?",email:e.fromEmail??void 0,size:"sm",className:de("absolute inset-0","sm:group-hover:opacity-0 transition-opacity",(l||f)&&"opacity-0")}),s.jsx("button",{type:"button",tabIndex:-1,onClick:y,className:de("absolute inset-0 size-7 rounded-full border items-center justify-center transition-opacity",f?"flex":"hidden sm:flex",l?"bg-accent border-accent text-accent-fg opacity-100":f?"border-fg-subtle/40 opacity-100 bg-canvas":"border-fg-subtle/40 opacity-0 group-hover:opacity-100 bg-canvas"),"aria-label":l?"Deselect message":"Select message",children:l&&s.jsx(Bs,{className:"size-3"})})]}),s.jsx(Ft,{thread:g,badge:e.autoMoved&&s.jsx(ml,{accountId:n,messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,autoMoved:e.autoMoved,size:"sm"})})]})},Jb=c.memo(Xb),Zb=e=>{const t=e.authenticity?.dkimMismatch===!0;return{id:e.messageId,accountId:e.accountConfigId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:Tt(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Tn(e.category),suspicious:t}},ev=({thread:e,mailboxId:t,accountId:n,isSelected:r,isFocused:a,isTabStop:o,onFocusRow:i,isChecked:l,onToggleCheck:u,onRowSelect:d,isMultiSelectMode:m,onLongPress:f,isDesktop:h,onDelete:x,onToggleRead:b,density:p})=>{const[v,g]=c.useState("none"),y=c.useCallback(C=>{navigator.vibrate?.(10),C==="trailing"?x(e.messageId):b(e.messageId,e.isRead),g("none")},[x,b,e.messageId,e.isRead]),j=c.useCallback(()=>{f(e.messageId)},[f,e.messageId]),w=c.useCallback(()=>{u(e.messageId)},[u,e.messageId]);return h||m?s.jsx(Jb,{thread:e,mailboxId:t,accountId:n,isSelected:r,isFocused:a,isTabStop:o,onFocusRow:i,isChecked:l,onToggleCheck:u,onRowSelect:d,isMultiSelectMode:m,onLongPress:f,isDesktop:h,density:p}):s.jsx(wi,{thread:Zb(e),selectionMode:!1,checked:!1,active:r,peek:v,onPeek:g,onToggleCheck:w,onLongPress:j,onOpen:()=>{},onAct:y,linkComponent:({onOpenClick:C,children:k,...S})=>s.jsx(mt,{...S,to:"/mail/$mailboxId",params:{mailboxId:t},search:N=>({...N,selectedMessageId:e.messageId}),"data-message-row":!0,onClick:C,children:k})})},tv=72,sv=32,nv=5,gc="remit:list-density",rv=()=>{try{const e=localStorage.getItem(gc);if(e==="compact"||e==="comfortable")return e}catch{}return"comfortable"},av=({query:e,count:t})=>s.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-line bg-surface-sunken/30",children:[s.jsx(Fs,{className:"size-4 text-fg-muted"}),s.jsxs("span",{className:"text-sm text-fg-muted",children:[t," ",t===1?"result":"results"," for “",e,"”"]})]}),ov=({mailboxId:e,threads:t,selectedMessageId:n,isLoading:r,isError:a=!1,error:o,onRetry:i,searchQuery:l,searchPredicate:u,onDeleteMessages:d,onMarkAsRead:m,onMoveMessages:f,isDeleting:h=!1,isMoving:x=!1,onLoadMore:b,hasMore:p=!1,isLoadingMore:v=!1,accountId:g,listTitle:y,listMeta:j,onTriageContextChange:w,commandsRef:C,hideHeader:k=!1})=>{const S=c.useRef(null),N=Me(),I=Qt(),[T,E]=c.useState(!1),[M,R]=c.useState(!1),A=!!l?.trim(),[D,F]=c.useState(n),[$,te]=c.useState(rv),q=c.useCallback(()=>{te(L=>{const Z=L==="comfortable"?"compact":"comfortable";try{localStorage.setItem(gc,Z)}catch{}return Z})},[]),{toggleReadFor:Q}=dl({mailboxId:e}),{selectedIds:X,selectedCount:ee,hasSelection:se,isSelected:P,toggle:_,select:H,clearSelection:W,selectRange:le,setAnchor:me,selectAll:J,toggleAll:Ie}=Mb(),[he,ke]=c.useState(null),Y=!I&&A&&!!u,U=`${e}|${JSON.stringify(u??{})}`,z=Eb({mailboxId:e,accountId:g,enabled:Y,predicateKey:U,searchQuery:u??{}}),[ne,Ue]=c.useState(null),[Qe,Pe]=c.useState(null),Te=c.useRef(null),xe=c.useRef(!1),ce=c.useRef(null),it=!r&&t.length>0,xt=he!==null;c.useEffect(()=>{T&&ee===0&&E(!1)},[T,ee]);const vs=c.useCallback(L=>{const{exit:Z,retryIds:ze}=Nb(L);if(Z){Pe(`${ft(L.done)} moved to Trash. Your mail server is still catching up.`),Ue(null),W();return}if(ze.length>0){Ue(L.done),J(ze);return}Ue(null)},[W,J]),lt=yb({count:t.length,getScrollElement:()=>S.current,estimateSize:()=>$==="compact"?sv:tv,overscan:nv}),Fe=n?t.findIndex(L=>L.messageId===n):-1,Le=D?t.findIndex(L=>L.messageId===D):-1,De=c.useCallback(L=>{if(L<0||L>=t.length)return;const Z=t[L];if(T){_(Z.messageId);return}Te.current=Z.messageId,xe.current=!1,F(Z.messageId)},[t,T,_]),Dt=c.useCallback(()=>{if(t.length===0)return;const L=Le<0?0:Math.min(Le+1,t.length-1);De(L)},[t.length,Le,De]),He=c.useCallback(()=>{if(t.length===0)return;const L=Le<=0?0:Le-1;De(L)},[t.length,Le,De]),ct=c.useCallback(()=>De(0),[De]),Ht=c.useCallback(()=>De(t.length-1),[De,t.length]),We=c.useCallback(()=>{D&&_(D)},[D,_]),Ee=c.useMemo(()=>t.map(L=>L.messageId),[t]),ys=c.useCallback((L,Z)=>Z.shiftKey?(le(Ee,L),!0):Z.metaKey||Z.ctrlKey?(_(L),!0):(W(),me(L),!1),[Ee,le,_,W,me]),Ze=c.useCallback(L=>{!d||L.length===0||(ce.current=D??null,ke({source:"ids",ids:L}))},[d,D]),V=c.useCallback(()=>{z.phase.kind==="escalated"&&(ce.current=D??null,ke({source:"predicate",total:z.phase.total}))},[z.phase,D]),oe=c.useCallback(L=>{const Z=Rb(Ee,D,L);Z!==void 0&&(le(Ee,Z),Te.current=Z,xe.current=!1,F(Z))},[Ee,D,le]),re=c.useCallback(()=>oe(-1),[oe]),ae=c.useCallback(()=>oe(1),[oe]),fe=c.useCallback(()=>{Ee.length>0&&J(Ee)},[Ee,J]),Ne=c.useCallback(()=>he!==null?!0:d?ee>0?(Ze(Array.from(X)),!0):D?(Ze([D]),!0):!1:!1,[he,d,ee,X,D,Ze]),be=c.useCallback(()=>{D&&N({to:"/mail/$mailboxId",params:{mailboxId:e},search:L=>({...L,selectedMessageId:D})})},[D,N,e]),ve=c.useCallback(()=>{ee>0&&Ze(Array.from(X))},[Ze,ee,X]),ye=c.useCallback(async L=>{ke(null),ce.current=null;const Z=await z.runDelete(L);vs(Z)},[z,vs]),Ae=c.useCallback(()=>{if(!he)return;if(he.source==="predicate"){ye(void 0);return}const{ids:L}=he;if(L.length===0){ke(null);return}if(L.length>mc){ye(L);return}const Z=new Set(L),ze=t.findIndex(O=>Z.has(O.messageId));let Ye;for(let O=ze+1;O<t.length;O++)if(!Z.has(t[O].messageId)){Ye=t[O].messageId;break}if(Ye===void 0){for(let O=ze-1;O>=0;O--)if(!Z.has(t[O].messageId)){Ye=t[O].messageId;break}}d?.(L),W(),ce.current=null,ke(null),Ye!==void 0&&(Te.current=Ye,xe.current=!1,F(Ye),N({to:"/mail/$mailboxId",params:{mailboxId:e},search:O=>({...O,selectedMessageId:Ye}),replace:!0}))},[he,t,d,W,N,e,ye]),_e=c.useCallback(()=>{const L=ce.current;ce.current=null,ke(null),L!==null&&(Te.current=L,xe.current=!1,F(L))},[]),Re=c.useCallback(()=>{m&&ee>0&&m(Array.from(X))},[m,ee,X]),ut=c.useCallback(L=>{!f||ee===0||(f(Array.from(X),L),W())},[f,ee,X,W]),Ve=c.useMemo(()=>{if(ee===0)return;const L=new Set;for(const Z of t)X.has(Z.messageId)&&L.add(Z.accountConfigId);if(L.size>1)return"Move only works within one account — clear selection or pick messages from a single account"},[ee,X,t]),Hs=c.useCallback(L=>{d?.([L])},[d]),ws=c.useCallback((L,Z)=>{Q([L],!Z)},[Q]),Ws=c.useCallback(L=>{I||(E(!0),H(L))},[I,H]),et=c.useCallback(()=>{E(!1),W()},[W]),Vs=c.useCallback(()=>{if(z.phase.kind==="escalated"){V();return}ve()},[z.phase,V,ve]),Fn=c.useCallback(()=>{if(z.isDeleting||z.phase.kind==="counting"){z.stop();return}z.phase.kind==="escalated"&&z.clear(),et()},[z,et]),Ys=c.useCallback(()=>{z.clear()},[z]),Gs=c.useCallback(()=>{ye(Array.from(X))},[ye,X]);c.useEffect(()=>{if(xe.current||!I&&n)return;const L=Le>=0?Le:Fe;L>=0&<.scrollToIndex(L,{align:"auto"})},[Le,Fe,lt,I,n]),c.useEffect(()=>{n&&(xe.current=!1,F(n))},[n]),c.useEffect(()=>{D&&(t.some(L=>L.messageId===D)||F(t[0]?.messageId))},[t,D]),c.useEffect(()=>{w?.({focusedMessageId:D,selectedIds:Array.from(X),hasList:it,blocksKeyboard:xt})},[D,X,it,xt,w]);const bt=c.useRef(w);bt.current=w,c.useEffect(()=>()=>bt.current?.({focusedMessageId:void 0,selectedIds:[],hasList:!1,blocksKeyboard:!1}),[]),c.useEffect(()=>{if(z.phase.kind!=="idle"||z.isDeleting)return;const L=new Set(t.map(ze=>ze.messageId));Array.from(X).some(ze=>!L.has(ze))&&W()},[t,X,W,z.phase,z.isDeleting]),c.useEffect(()=>{const L=S.current;if(!L||!p||!b)return;const Z=()=>{if(v)return;const{scrollTop:ze,scrollHeight:Ye,clientHeight:O}=L;ze+O>=Ye-200&&b()};return L.addEventListener("scroll",Z,{passive:!0}),Z(),()=>L.removeEventListener("scroll",Z)},[p,v,b]),c.useEffect(()=>{const L=Te.current;if(!L)return;const Z=S.current?.querySelector(`[data-message-id="${L}"]`);Z&&(Te.current=null,Z.focus({preventScroll:!0}))}),c.useEffect(()=>{if(C){if(!it){C.current=null;return}return C.current={focusNext:Dt,focusPrevious:He,focusFirst:ct,focusLast:Ht,openFocused:be,toggleSelect:We,extendSelectDown:ae,extendSelectUp:re,selectAll:fe,clearSelection:()=>se?(W(),!0):!1,requestDelete:Ne,toggleDensity:q},()=>{C.current=null}}},[C,it,Dt,He,ct,Ht,be,We,ae,re,fe,se,W,Ne,q]);const At=r?"loading":a?"error":t.length===0?"empty":"ready",Wt=a?ei(o):void 0,vt=c.useCallback(()=>{const L=zr(Lr());window.open(L,"_blank","noopener,noreferrer")},[]),_n=[{id:"inbox",threads:[]}],Bn=se&&I?s.jsx(Wb,{selectedCount:ee,onDelete:ve,onClearSelection:W,onMarkAsRead:m?Re:void 0,onMove:f?ut:void 0,onOrganize:()=>R(!0),isDeleting:h,isMoving:x,accountId:g,currentMailboxId:e,moveDisabledHint:Ve}):void 0,js=Ee.length>0&&Ee.every(L=>X.has(L)),yt=Y&&p&&js&&!h&&!x&&z.phase.kind==="idle"&&!z.isDeleting,$n=h||x||z.isDeleting,Kn=z.phase.kind==="escalated"?z.phase.total:ee,qn=z.isDeleting?`Deleting ${ft(z.deleteProgress?.done??0)} of ${ft(z.deleteProgress?.total??0)}…`:z.phase.kind==="counting"?z.phase.countSoFar>=5e3?`Counting… ${ft(z.phase.countSoFar)} so far. This is a big result set.`:`Counting… ${ft(z.phase.countSoFar)} so far`:z.phase.kind==="escalated"?Db(u??{},z.phase.total):void 0,Un=z.phase.kind!=="escalated"&&Ee.length>0?{checked:js,indeterminate:ee>0&&!js,onChange:()=>Ie(Ee)}:void 0,Qn=z.phase.kind==="counting"?{tone:"info",text:"",action:{label:"Stop",onClick:z.stop}}:z.phase.kind==="escalated"&&!z.isDeleting?{tone:"info",text:"",action:{label:"Clear selection",onClick:Ys}}:yt?{tone:"info",text:"",action:{label:Tb(u??{}),onClick:z.escalate}}:ne!==null&&ee>0?{tone:"danger",text:`${ft(ne)} moved to Trash. ${ft(ee)} couldn't be deleted.`,action:{label:`Retry ${ft(ee)}`,onClick:Gs}}:Ve?{tone:"warning",text:Ve}:void 0,Hn=T&&!I?s.jsx(yi,{count:Kn,onCancel:Fn,onDelete:Vs,onMarkRead:m&&z.phase.kind==="idle"?Re:void 0,isBusy:$n,isCounting:z.phase.kind==="counting",statusLabel:qn,selectAll:Un,progress:z.isDeleting&&z.deleteProgress?{value:z.deleteProgress.done,max:z.deleteProgress.total,tone:"danger"}:void 0,notice:Qn,moveSlot:z.phase.kind==="idle"&&!z.isDeleting&&f&&g&&e?s.jsxs(s.Fragment,{children:[!Ve&&s.jsx("button",{type:"button",onClick:()=>R(!0),className:"min-h-11 min-w-11 inline-flex shrink-0 items-center justify-center rounded text-fg-muted hover:bg-surface-raised","aria-label":"Organize similar messages",children:s.jsx(nt,{className:"size-4"})}),s.jsx(Qs,{accountId:g,currentMailboxId:e,onMove:h||x?()=>{}:ut,disabledHint:Ve,label:"Move selected messages"})]}):void 0}):void 0,Wn=Bn??Hn,Ot=Ab(Ee,D),Xs=c.useCallback(L=>{xe.current=!0,F(L)},[]),Js=s.jsxs(s.Fragment,{children:[A&&l&&s.jsx(av,{query:l,count:t.length}),s.jsxs("div",{ref:S,role:"listbox","aria-multiselectable":!0,"aria-label":y,className:"flex-1 overflow-y-auto",children:[s.jsx("div",{role:"presentation",className:"relative w-full",style:{height:`${lt.getTotalSize()}px`},children:lt.getVirtualItems().map(L=>{const Z=t[L.index];return s.jsx("div",{role:"presentation","data-index":L.index,ref:lt.measureElement,className:de("absolute left-0 top-0 w-full border-b border-line",z.isDeleting&&"pointer-events-none opacity-50"),style:{transform:`translateY(${L.start}px)`},children:s.jsx(ev,{thread:Z,mailboxId:e,accountId:g,isSelected:n===Z.messageId,isFocused:D===Z.messageId,isTabStop:Ot===Z.messageId,onFocusRow:Xs,isChecked:P(Z.messageId),onToggleCheck:_,onRowSelect:ys,isMultiSelectMode:T,onLongPress:Ws,isDesktop:I,onDelete:Hs,onToggleRead:ws,density:$})},L.key)})}),v&&s.jsx("div",{className:"flex justify-center py-4",children:s.jsx("div",{className:"h-5 w-5 animate-spin rounded-full border-2 border-fg-muted border-t-transparent"})})]})]}),Vn=he?he.source==="ids"?he.ids.length:he.total:0;return s.jsxs(s.Fragment,{children:[Qe&&!I&&s.jsx(Ls,{tone:"success",variant:"soft",className:"m-2 rounded-md",onDismiss:()=>Pe(null),children:Qe}),s.jsx(ji,{listTitle:y,listMeta:j,sections:_n,flatList:!0,listState:At,searchQuery:A?l:void 0,errorMessage:Wt,onRetry:i,onReportError:vt,density:$,selectedThreadId:n,onSelectThread:L=>N({to:"/mail/$mailboxId",params:{mailboxId:e},search:Z=>({...Z,selectedMessageId:L})}),onSelectBriefCategory:()=>{},isDesktop:I,hideHeader:k,selectionBar:Wn,listBody:At==="ready"?Js:void 0}),s.jsx(Jl,{isOpen:he!==null,title:Tu(Vn),description:"You can restore them from Trash later.",confirmLabel:"Move to Trash",destructive:!0,isBusy:h,onConfirm:Ae,onCancel:_e}),M&&g&&s.jsx(Hb,{open:M,accountId:g,mailboxId:e,selectedMessageIds:Array.from(X),onClose:()=>R(!1)})]})},iv=e=>Bt({path:{accountId:e}}),lv=e=>{const t=je(),n=zs(),r=pe({...fu(),onSuccess:()=>{n.recordEvent("sync.triggered"),t.invalidateQueries({queryKey:iv(e)})}});return{trigger:()=>{r.mutate({path:{accountId:e}})},triggerAsync:()=>r.mutateAsync({path:{accountId:e}}),isPending:r.isPending,error:r.error,reset:r.reset}},cv=({accountId:e,children:t})=>{const{triggerAsync:n,isPending:r}=lv(e);return s.jsx(Pf,{onRefresh:n,isRefreshing:r,children:t})};function uv({accountId:e,currentMailboxId:t,candidates:n,onMove:r,children:a}){const[o,i]=c.useState(!1),l=zs(),{t:u}=yn("mail",{useSuspense:!1}),d=c.useCallback((y,j)=>u(y,{defaultValue:j}),[u]),{inboxMailboxId:m}=ta(e),f=fl(e),{data:h}=ue({...rt({path:{accountId:e}}),staleTime:1/0}),x=c.useMemo(()=>{const y=ia(h?.items??[],f),j=fs(f);return y.map(w=>({id:w.mailboxId,label:os(w,j.get(w.mailboxId),d),searchValue:w.fullPath,isCurrent:w.mailboxId===t}))},[h?.items,f,t,d]),b=c.useMemo(()=>m||(x.find(j=>j.label.toLowerCase()==="inbox")?.id??x.find(j=>!j.isCurrent)?.id??""),[m,x]),p=c.useRef(!1);c.useEffect(()=>{p.current||(p.current=!0,kx(l,n.length))},[l,n.length]);const v=c.useCallback(()=>{Nx(l,n.length),i(!0)},[l,n.length]),g=c.useCallback((y,j)=>{Cx(l,{selected:y.length,total:n.length,toInbox:j===m}),r(y,j)},[l,n.length,m,r]);return s.jsxs("div",{className:"relative flex h-full min-h-0 flex-col",children:[s.jsx("div",{className:"shrink-0 px-row-inset pt-2",children:s.jsx(Ff,{count:n.length,onReview:v})}),s.jsx("div",{className:"min-h-0 flex-1",children:a}),s.jsx(Vf,{open:o,candidates:n,defaultDestinationId:b,availableFolders:x,onConfirmMove:g,onCancel:()=>i(!1)})]})}const dv="We can verify this sender";function fv(e){const{data:t}=ue({...mu({path:{mailboxId:e??""},query:{senderTrust:["vip","wellknown"],dkimMismatch:!1,results:!0,limit:500}}),enabled:!!e,staleTime:6e4});return{candidates:(t?.items??[]).map(r=>({id:r.messageId,senderName:r.fromName||r.fromEmail||"Unknown sender",senderAddress:r.fromEmail??"",subject:r.subject||"(no subject)",snippet:r.snippet??"",trustReason:dv,trustSubReason:Sx(r.senderTrust),senderTrust:r.senderTrust}))}}const Ms={action:null,nextPrefix:null,preventDefault:!1},mv={b:"goBrief",i:"goInbox",s:"goSent",f:"goFlagged",",":"goSettings"},hv={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 gv(e,t){const n=e.key.toLowerCase(),r=e.metaKey||e.ctrlKey;if(e.inEditable)return{...Ms,nextPrefix:t==="g"?null:t};if(e.onControl&&(n==="enter"||n===" "))return{...Ms,nextPrefix:t==="g"?null:t};if(r&&n==="n")return{action:"compose",nextPrefix:null,preventDefault:!0};if(r&&n==="a")return{action:"selectAll",nextPrefix:null,preventDefault:!0};if(r)return{...Ms,nextPrefix:t==="g"?null:t};if(n==="escape")return{action:"back",nextPrefix:null,preventDefault:!1};if(t==="g"){const i=mv[n===","?",":n]??null;return{action:i,nextPrefix:null,preventDefault:i!==null}}if(n==="g"&&!e.shiftKey)return{action:null,nextPrefix:"g",preventDefault:!0};if(e.shiftKey){const o=n==="j"||n==="arrowdown";if(o||(n==="k"||n==="arrowup"))return{action:o?"extendSelectDown":"extendSelectUp",nextPrefix:null,preventDefault:!0}}const a=hv[n];if(a){const o=a.requireShift===!0,i=n.length===1&&!/[a-z0-9]/.test(n);return!o&&e.shiftKey&&!i?Ms:{action:a.action,nextPrefix:null,preventDefault:!0}}return Ms}function pv(e){if(!(e instanceof HTMLElement))return!1;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"||e.isContentEditable}const xv="data-message-row",bv='button, a[href], summary, [role="button"], [role="menuitem"], [role="tab"], [role="switch"], [role="checkbox"]';function vv(e){if(!(e instanceof HTMLElement))return!1;const t=e.closest(bv);return t?!t.hasAttribute(xv):!1}function yv({handlers:e,enabled:t=!0,sequenceTimeoutMs:n=1e3}){const r=c.useRef(e);r.current=e;const a=c.useRef(null),o=c.useRef(null);c.useEffect(()=>{if(!t)return;const i=()=>{o.current!==null&&(clearTimeout(o.current),o.current=null)},l=u=>{const d=gv({key:u.key,shiftKey:u.shiftKey,metaKey:u.metaKey,ctrlKey:u.ctrlKey,altKey:u.altKey,inEditable:pv(u.target),onControl:vv(u.target)},a.current);if(i(),a.current=d.nextPrefix,d.nextPrefix!==null&&(o.current=setTimeout(()=>{a.current=null,o.current=null},n)),d.action===null)return;const m=r.current[d.action];m&&(d.preventDefault&&u.preventDefault(),m())};return window.addEventListener("keydown",l),()=>{window.removeEventListener("keydown",l),i(),a.current=null}},[t,n])}const No=(e,t,n)=>{if(!t)return null;const r=e.indexOf(t);if(r===-1)return null;const a=n==="next"?r+1:r-1;return a<0||a>=e.length?null:e[a]},pc="remit:intelligence-open";function wv(){try{return localStorage.getItem(pc)!=="closed"}catch{return!0}}function Co(e){try{localStorage.setItem(pc,e?"open":"closed")}catch{}}const jv=(e,t)=>e!==t,Sv=(e,t,n)=>{if(!(n||!t))return e.find(r=>r.messageId===t)},kv={unread:e=>!e.isRead,flagged:e=>e.hasStars===!0,attachment:e=>!!e.hasAttachment};function Nv(e,t,n){const r=Array.from(n).map(a=>kv[a]).filter(a=>a!=null);return t==="all"&&r.length===0?e:e.filter(a=>(t==="all"||a.category===t)&&r.every(o=>o(a)))}const xc=c.createContext(null);function zn(){const e=c.useContext(xc);if(!e)throw new Error("MailboxPane.* must be used inside <MailboxPane>");return e}function Cv({mailboxId:e,selectedMessageId:t,children:n}){const r=Me(),o=On()==="desktop",i=zs(),{accounts:l,searchQuery:u,searchInput:d,intelligenceOpen:m,onToggleIntelligence:f,onSetIntelligenceOpen:h}=Se(),x=ps(),b=la(u),p=b.length>0,{freeText:v,tokens:g}=xs(b,x),y=g.find(O=>O.type==="from"),j={order:"desc",...v?{query:v}:{},...y?{from:y.value}:{},...g.some(O=>O.type==="hasAttachment")?{attachments:!0}:{},...g.some(O=>O.type==="isUnread")?{unread:!0}:{}},w=p?gt({path:{mailboxId:e},query:j}):at({path:{mailboxId:e},query:{order:"desc"}}),{data:C,isLoading:k,isError:S,error:N,refetch:I,fetchNextPage:T,hasNextPage:E,isFetchingNextPage:M}=Qi({queryKey:w,queryFn:async({pageParam:O})=>{if(p){const{data:Be}=await Go({path:{mailboxId:e},query:{...j,continuationToken:O},throwOnError:!0});return Be}const{data:Oe}=await gu({path:{mailboxId:e},query:{order:"desc",continuationToken:O},throwOnError:!0});return Oe},initialPageParam:void 0,getNextPageParam:O=>O.continuationToken,enabled:p?b.length>0:!0,placeholderData:hu}),R=c.useCallback(O=>{t&&O.includes(t)&&r({to:"/mail/$mailboxId",params:{mailboxId:e},search:Oe=>({...Oe,selectedMessageId:void 0,selectedThreadId:void 0})})},[t,e,r]),{deleteMessages:A,isPending:D}=As({mailboxId:e,onAfterOptimisticRemove:R}),{accountId:F}=ul(e),$=tl({accounts:l}),{moveMessages:te,isPending:q}=Ct({mailboxId:e,accountId:F,onAfterOptimisticRemove:R}),Q=$g(C?.pages.flatMap(O=>O.items??[])??[]),[X,ee]=c.useState("all"),[se,P]=c.useState(new Set),_=c.useMemo(()=>Nv(Q,X,se),[Q,X,se]),H=c.useCallback(O=>{ee(O)},[]),W=c.useCallback(O=>{P(Oe=>{const Be=new Set(Oe);return Be.has(O)?Be.delete(O):Be.add(O),Be})},[]),le=c.useCallback(()=>{ee("all"),P(new Set)},[]),me=jv(d,u),J=Sv(Q,t,me),{selectedThreadId:Ie}=as({strict:!1}),he=c.useMemo(()=>ac(J,{messageId:t,threadId:me?void 0:Ie,mailboxId:e}),[J,t,Ie,me,e]),[ke,Y]=c.useState(void 0),[U,z]=c.useState([]),ne=c.useRef(null),[Ue,Qe]=c.useState(!1),[Pe,Te]=c.useState(!1),xe=c.useCallback(O=>{Y(O.focusedMessageId),z(O.selectedIds),Qe(O.hasList),Te(O.blocksKeyboard)},[]),ce=_.find(O=>O.messageId===ke)??J,it=c.useRef(null);c.useEffect(()=>{const O=J?.messageId??null;O&&it.current!==O&&J?.authenticity?.dkimMismatch&&(it.current=O,m||f())},[J?.messageId,J?.authenticity?.dkimMismatch,m,f]);const xt=c.useRef(!1);c.useEffect(()=>{xt.current||o&&J?.messageId&&(xt.current=!0,wv()&&!m&&h(!0))},[o,J?.messageId,m,h]);const lt=Kh({accounts:l})??Q.filter(O=>!O.isRead).length,Fe=je(),{pushError:Le}=qe(),{deleteMessages:De}=As({mailboxId:e,threadId:J?.threadId,onAfterOptimisticRemove:R}),{moveMessages:Dt}=Ct({mailboxId:e,threadId:J?.threadId,accountId:F,onAfterOptimisticRemove:R}),{draftsMailboxId:He}=_g(F),ct=He!==void 0&&He===e,{archiveMailboxId:Ht}=Fg(F),We=c.useCallback(O=>{const Oe=$t({path:{threadId:O.threadId}}),ma=Fe.getQueriesData({queryKey:Oe}).flatMap(([,Cc])=>Cc?.items.map(Ec=>Ec.messageId)??[]);return ma.length>0?ma:[O.messageId]},[Fe]),Ee=c.useCallback(()=>{if(!J)return;const O=We(J);De(O)},[J,We,De]),ys=c.useCallback(O=>{if(!J)return;const Oe=We(J);Dt(Oe,O)},[J,We,Dt]),{toggleStar:Ze}=Sr({threadId:J?.threadId??"",mailboxId:e}),V=c.useCallback(()=>{J&&Ze(J.messageId,J.hasStars)},[J,Ze]),[oe,re]=c.useState(null),ae=c.useCallback(()=>{re("reply")},[]),fe=c.useCallback(()=>{re("reply_all")},[]),Ne=c.useCallback(()=>{re("forward")},[]),be=c.useCallback(()=>{re(null)},[]),{state:ve,openCompose:ye,closeCompose:Ae}=It(),_e=c.useCallback(()=>{ye({mode:"new"})},[ye]),Re=pe({...jn(),onError:O=>{Le(zt("Couldn't discard draft","The draft wasn't deleted.",O))}}),ut=c.useCallback(()=>{const O=ve.outboxMessageId;O&&(Re.mutate({path:{outboxMessageId:O}}),Fe.invalidateQueries({queryKey:Br()}),Ae())},[ve.outboxMessageId,Re,Fe,Ae]),Ve=c.useCallback(()=>{ne.current?.clearSelection()||t&&r({to:"/mail/$mailboxId",params:{mailboxId:e},search:O=>({...O,selectedMessageId:void 0,selectedThreadId:void 0})})},[t,e,r]),Hs=c.useCallback(O=>O?We(O):[],[We]),{toggleStar:ws}=Sr({threadId:ce?.threadId??"",mailboxId:e}),{toggleReadFor:Ws}=dl({mailboxId:e,accountId:F}),{junkMailboxId:et}=sa(F),Vs=et!=null&&et===e,{candidates:Fn}=fv(Vs?et:void 0),{moveMessages:Ys}=Ct({mailboxId:e,threadId:ce?.threadId,accountId:F,onAfterOptimisticRemove:R}),{deleteMessages:Gs}=As({mailboxId:e,threadId:ce?.threadId,onAfterOptimisticRemove:R}),{addressId:bt,address:At}=tc(ce),{updateFlags:Wt}=sc({addressId:bt,senderEmail:ce?.fromEmail??void 0}),vt=c.useCallback(()=>t||!ke?!1:(r({to:"/mail/$mailboxId",params:{mailboxId:e},search:O=>({...O,selectedMessageId:ke})}),!0),[t,ke,e,r]),_n=c.useCallback(()=>{vt()||J&&re("reply")},[vt,J]),Bn=c.useCallback(()=>{vt()||J&&re("reply_all")},[vt,J]),js=c.useCallback(()=>{vt()||J&&re("forward")},[vt,J]),yt=c.useCallback(()=>U.length>0?U:Hs(ce),[U,Hs,ce]),$n=c.useCallback(()=>{if(ne.current?.requestDelete())return;const O=yt();O.length>0&&Gs(O)},[yt,Gs]),Kn=c.useCallback(()=>{if(!et)return;const O=yt();O.length!==0&&(rc(i,{count:O.length,senderTrust:ce?.senderTrust??"unknown",wasRescuable:ce?nc(ce):!1}),Ys(O,et))},[et,yt,Ys,i,ce]),qn=c.useCallback(()=>{if(U.length>0){const O=!(ce?.hasStars??!1),Oe=new Set(U);for(const Be of _)Oe.has(Be.messageId)&&Be.hasStars!==O&&ws(Be.messageId,Be.hasStars);return}ce&&ws(ce.messageId,ce.hasStars)},[U,_,ce,ws]),Un=c.useCallback(()=>{const O=yt();if(O.length===0)return;const Oe=!(ce?.isRead??!1);Ws(O,Oe)},[yt,ce,Ws]),Qn=c.useCallback(()=>{if(!bt)return;const O=At?.flags?.muted?.value!==!0;Wt({muted:{value:O}})},[bt,At,Wt]),Hn=c.useCallback(()=>{if(!bt)return;const O=At?.flags?.vip?.value!==!0;Wt({vip:{value:O}})},[bt,At,Wt]),Wn=c.useCallback(()=>{m||f()},[m,f]),Ot=c.useCallback(O=>{r({to:O})},[r]),Xs=ct?"drafts":Ht===e?"archive":et===e?"junk":"inbox",Js=c.useRef("");c.useEffect(()=>{const O=Js.current;Js.current=b,b.length>0&&O.length===0&&i.recordEvent("search.submitted",{mailboxType:Xs})},[b,Xs,i]);const Vn=ct&&ve.isOpen&&!!ve.outboxMessageId&&!J;yv({enabled:!ve.isOpen&&!Pe,handlers:{...Ue?{focusNext:()=>ne.current?.focusNext(),focusPrevious:()=>ne.current?.focusPrevious(),focusFirst:()=>ne.current?.focusFirst(),focusLast:()=>ne.current?.focusLast(),openFocused:()=>ne.current?.openFocused(),toggleSelect:()=>ne.current?.toggleSelect(),extendSelectDown:()=>ne.current?.extendSelectDown(),extendSelectUp:()=>ne.current?.extendSelectUp(),selectAll:()=>ne.current?.selectAll(),toggleDensity:()=>ne.current?.toggleDensity()}:{},back:Ve,reply:_n,replyAll:Bn,forward:js,delete:$n,toggleStar:qn,toggleRead:Un,muteSender:Qn,blockSender:Wn,vipSender:Hn,markJunk:Kn,toggleIntelligence:J?f:void 0,compose:_e,goBrief:()=>Ot("/mail"),goInbox:()=>Ot("/mail"),goSent:()=>Ot("/mail"),goFlagged:()=>Ot("/mail/flagged"),goSettings:()=>Ot("/settings")}}),ea({enabled:ve.isOpen,bindings:[{key:"Escape",handler:Ae,preventDefault:!0}]});const L=_.map(O=>O.messageId),Z=No(L,t,"next")??void 0,ze=No(L,t,"previous")??void 0,Ye={mailboxId:e,selectedMessageId:t,selectedThread:J,conversation:he,threads:_,isLoading:k,isError:S,error:N,mailboxAccountId:F,mailboxName:$,unreadCount:lt,isDraftsMailbox:ct,isSpamFolder:Vs,rescueCandidates:Fn,filterCategory:X,filterAttributes:se,onSelectFilterCategory:H,onToggleFilterAttribute:W,onClearFilters:le,intelligenceOpen:m,onToggleIntelligence:f,searchPredicate:p?j:void 0,onDeleteMessages:A,onMoveMessages:te,isDeleting:D,isMoving:q,onLoadMore:T,hasMore:E,isLoadingMore:M,onTriageContextChange:xe,listCommandsRef:ne,onRetry:()=>I(),toolbarComposeRequest:oe,onToolbarReply:ae,onToolbarReplyAll:fe,onToolbarForward:Ne,onClearComposeRequest:be,onToolbarDelete:Ee,onToolbarStar:V,onToolbarDiscardDraft:ut,onToolbarMove:ys,composeState:ve,closeCompose:Ae,hasRemitDraftOpen:Vn,onBack:Ve,nextMessageId:Z,previousMessageId:ze};return s.jsx(xc.Provider,{value:Ye,children:n})}function bc(){const{mailboxId:e,selectedMessageId:t,threads:n,isLoading:r,isError:a,error:o,onDeleteMessages:i,onMoveMessages:l,isDeleting:u,isMoving:d,onLoadMore:m,hasMore:f,isLoadingMore:h,mailboxAccountId:x,mailboxName:b,unreadCount:p,isDraftsMailbox:v,isSpamFolder:g,rescueCandidates:y,onTriageContextChange:j,listCommandsRef:w,onRetry:C,filterCategory:k,filterAttributes:S,onSelectFilterCategory:N,onToggleFilterAttribute:I,onClearFilters:T,searchPredicate:E}=zn(),{searchQuery:M,searchInput:R,accounts:A}=Se(),D=On(),F=Me(),$=b??"Inbox",te=c.useMemo(()=>Jf(),[]),q=c.useMemo(()=>n.map(ax),[n]),{hits:Q,isLoading:X}=ql({mailboxId:e,filterCategory:k}),ee=c.useMemo(()=>Wl(Q,n.map(le=>le.threadId)),[Q,n]),se=c.useCallback(le=>F({to:"/mail/$mailboxId",params:{mailboxId:le.mailboxId??e},search:me=>({...me,q:R||void 0,selectedMessageId:le.id,selectedThreadId:le.threadId})}),[e,F,R]);if(v&&x)return s.jsx(nb,{mailboxId:e,accountId:x,selectedMessageId:t,imapThreads:n,title:b??"Drafts",unreadCount:p??void 0});const P=s.jsx(ov,{mailboxId:e,threads:n,selectedMessageId:t,isLoading:r,isError:a,error:o,onRetry:C,searchQuery:M,searchPredicate:E,onDeleteMessages:i,onMoveMessages:l,isDeleting:u,isMoving:d,onLoadMore:m,hasMore:f,isLoadingMore:h,accountId:x,listTitle:$,hideHeader:!0,onTriageContextChange:j,commandsRef:w}),_=A[0]?.accountId,H=D==="phone"&&_?s.jsx(cv,{accountId:_,children:P}):P,W=g&&y.length>0&&x?s.jsx(uv,{accountId:x,currentMailboxId:e,candidates:y,onMove:l,children:H}):H;return s.jsx(lc,{title:$,unreadCount:p,preset:te,selectedCategory:k,activeFilters:S,onSelectCategory:N,onToggleFilter:I,onClearFilters:T,searchResults:q,searchLoading:r,relatedResults:ee,relatedLoading:X,onSelectSearchResult:se,children:W})}function Ev(){const{mailboxId:e,mailboxAccountId:t,selectedThread:n,conversation:r,hasRemitDraftOpen:a,intelligenceOpen:o,onToggleIntelligence:i,toolbarComposeRequest:l,onToolbarReply:u,onToolbarReplyAll:d,onToolbarForward:m,onClearComposeRequest:f,onToolbarDelete:h,onToolbarStar:x,onToolbarDiscardDraft:b,onToolbarMove:p,composeState:v}=zn(),g=ds()?.showIntelligencePane??!1,y=!!r,j=g&&y,w=v.isOpen&&!r?s.jsx(dc,{}):r?s.jsx(gs,{threadId:r.threadId,mailboxId:r.mailboxId,subject:r.subject,selectedMessageId:r.messageId,authenticity:r.authenticity,onOpenIntelligence:r.authenticity?.dkimMismatch?i:void 0,composeRequest:l,onComposeClose:f}):s.jsx(hs,{});return s.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[s.jsx(ca,{hasThread:y,intelligenceOpen:j&&o,canToggleIntelligence:j,onToggleIntelligence:i,onReply:y?u:void 0,onReplyAll:y?d:void 0,onForward:y?m:void 0,canDelete:y||a,onDelete:y?h:a?b:void 0,onToggleStar:y?x:void 0,isStarred:n?.hasStars,moveContext:y&&t?{accountId:t,currentMailboxId:e,onMove:p}:void 0}),s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:w})]})}function Iv(){const{mailboxId:e,mailboxAccountId:t,selectedThread:n,onToggleIntelligence:r}=zn();return s.jsx(bs,{onClose:r,thread:n,mailboxId:e,accountId:t})}function Rv(){const{mailboxId:e,selectedThread:t,conversation:n,intelligenceOpen:r,onToggleIntelligence:a,onBack:o,nextMessageId:i,previousMessageId:l,composeState:u}=zn(),d=Me();if(n){const m=f=>d({to:"/mail/$mailboxId",params:{mailboxId:e},search:h=>({...h,selectedMessageId:f,selectedThreadId:void 0})});return s.jsxs(s.Fragment,{children:[s.jsx(gs,{threadId:n.threadId,mailboxId:n.mailboxId,subject:n.subject,selectedMessageId:n.messageId,authenticity:n.authenticity,onBack:o,onOpenIntelligence:a,onSwipeNext:i?()=>m(i):void 0,onSwipePrevious:l?()=>m(l):void 0,mobileIntelligenceOpen:r}),s.jsx(Jr,{isOpen:r,onClose:a,ariaLabel:"Message details",side:"right",children:s.jsx(bs,{onClose:a,thread:t,hideCloseButton:!0})})]})}return u.isOpen?s.jsx("div",{className:"h-full",children:s.jsx(dc,{})}):s.jsx(bc,{})}const Ts=Object.assign(Cv,{List:bc,Reading:Ev,Intelligence:Iv,Phone:Rv}),vc=e=>e==="failed"||e==="blocked",yc=e=>e!=="draft"&&e!=="sent",da="remit.savedSearches",Mv=25;function vn(){try{const e=localStorage.getItem(da);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(n=>typeof n=="string"):[]}catch{return[]}}function Tv(e){const t=e.trim();if(!t)return vn();const n=[t,...vn().filter(r=>r!==t)].slice(0,Mv);try{localStorage.setItem(da,JSON.stringify(n))}catch{return n}return n}function Dv(e){const t=vn().filter(n=>n!==e);try{localStorage.setItem(da,JSON.stringify(t))}catch{return t}return t}const Eo=e=>/^\d/.test(e),Av=(e,t)=>{const n=Eo(e),r=Eo(t);return n&&!r?-1:!n&&r?1:e.localeCompare(t,void 0,{sensitivity:"base",numeric:!0})};function Ov(e,t,n){const r=[],a=[];for(const o of e)t.has(o.mailboxId)?r.push(o):a.push(o);return a.sort((o,i)=>Av(os(o,void 0,n),os(i,void 0,n))),{system:r,labels:a}}function Pv(e,t,n){const r=ju(t)&&e.unseenCount>0;return{id:e.mailboxId,name:os(e,t,n),unseen:r?e.unseenCount:void 0,role:t,fullPath:e.fullPath}}function Lv(){const e=In(),t=Fr({strict:!1});return e.pathname.startsWith("/mail/outbox")?"outbox":e.pathname.startsWith("/mail/flagged")?"flagged":t.mailboxId?t.mailboxId:e.pathname==="/mail"||e.pathname==="/mail/"?"brief":""}function Io({accounts:e,onMailboxSelect:t,variant:n="desktop"}){const r=je(),a=Me(),o=Lv(),{searchInput:i,onSearchChange:l}=Se(),[u,d]=c.useState(vn),{t:m}=yn("mail",{useSuspense:!1}),f=c.useCallback((N,I)=>m(N,{defaultValue:I}),[m]),h=Ut({queries:e.map(N=>({...rt({path:{accountId:N.accountId}}),staleTime:1/0}))}),{data:x}=ue(wn()),b=c.useMemo(()=>(x?.items??[]).filter(N=>yc(N.status)).length,[x?.items]),p=c.useMemo(()=>e.map((N,I)=>{const T=h[I],E=T?.data?.items??[],M=fs(N.folderAppointments),{system:R,labels:A}=Ov(E,M,f),D=T?.isError?"error":T?.isLoading?"loading":"ready";return{id:N.accountId,label:N.email,email:N.email,muted:!!N.muted,outboxPending:b,status:D,onRetry:()=>T?.refetch(),mailboxes:[...R,...A].map(F=>Pv(F,M.get(F.mailboxId),f))}}),[e,h,b,f]),v=N=>{r.invalidateQueries({queryKey:at({path:{mailboxId:N},query:{order:"desc"}})})},g=({navId:N,className:I,ariaLabel:T,title:E,children:M,onClick:R})=>N==="brief"?s.jsx(mt,{to:"/mail",search:{q:void 0,selectedMessageId:void 0},onClick:()=>R?.(),className:I,"aria-label":T,title:E,children:M}):N==="outbox"?s.jsx(mt,{to:"/mail/outbox",search:{q:void 0,selectedOutboxMessageId:void 0},onClick:()=>R?.(),className:I,"aria-label":T,title:E,children:M}):N==="flagged"?s.jsx(mt,{to:"/mail/flagged",search:{q:void 0,selectedMessageId:void 0},onClick:()=>R?.(),className:I,"aria-label":T,title:E,children:M}):s.jsx(mt,{to:"/mail/$mailboxId",params:{mailboxId:N},search:{q:void 0,selectedMessageId:void 0},onClick:()=>{v(N),R?.()},className:I,"aria-label":T,title:E,children:M}),y=()=>{l(""),t?.()},j=i.trim(),w=j.length>0&&!u.includes(j)?j:void 0,C=c.useCallback(()=>{w&&d(Tv(w))},[w]),k=c.useCallback(N=>{d(Dv(N))},[]),S=c.useCallback(N=>{l(N),a({to:"/mail",search:{q:N,selectedMessageId:void 0}}),t?.()},[l,a,t]);return s.jsx(Jd,{accounts:p,selectedNavId:o,onSelectNav:y,linkComponent:g,variant:n,savedSearches:u,saveableQuery:w,onSaveCurrentSearch:C,onSelectSavedSearch:S,onRemoveSavedSearch:k})}function zv({accounts:e,onMailboxSelect:t}){return ds()?.showNavPane??!0?s.jsx(Io,{accounts:e}):s.jsxs("div",{className:"flex h-full flex-col",children:[s.jsx("div",{className:"flex-1 overflow-y-auto",children:s.jsx(Io,{accounts:e,onMailboxSelect:t,variant:"drawer"})}),s.jsxs("div",{className:"border-t border-line px-2 py-2",children:[s.jsxs(mt,{to:"/settings/accounts",onClick:t,className:"flex w-full items-center gap-2 rounded-md px-2 py-1 text-sm text-fg-muted transition-colors hover:bg-surface hover:text-fg",children:[s.jsx(hi,{className:"size-4 shrink-0"}),s.jsx("span",{className:"flex-1 truncate text-left",children:"Settings"})]}),s.jsx(Yi,{variant:"drawer"}),s.jsx(Vi,{children:({signOut:a})=>s.jsxs("button",{type:"button",onClick:()=>{t?.(),a()},className:"flex min-h-11 w-full items-center gap-2 rounded-md px-2 py-1 text-sm text-fg-muted transition-colors hover:bg-surface hover:text-fg","data-testid":"sign-out-button",children:[s.jsx(ui,{className:"size-4 shrink-0"}),s.jsx("span",{className:"flex-1 truncate text-left",children:"Sign out"})]})})]})]})}function Fv(e,t){const n=t.trim().toLowerCase();if(n.length===0)return!0;const r=[e.subject,e.fromAddress,e.fromName,...e.toAddresses??[],...e.ccAddresses??[]].filter(a=>typeof a=="string").join(" ").toLowerCase();return n.split(/\s+/).every(a=>a.length===0||r.includes(a))}function _v(e){return e.tokens.length>0&&e.freeText.trim().length===0}const wc={queued:{icon:qr,label:"Queued",className:"text-warning"},sending:{icon:Kt,label:"Sending…",className:"text-accent-2"},sent:{icon:ai,label:"Sent",className:"text-positive"},failed:{icon:_t,label:"Failed",className:"text-danger"},blocked:{icon:Tr,label:"Blocked",className:"text-warning"}},Bv=e=>Du(e).toDateString()===new Date().toDateString()?gn(e,{hour:"numeric",minute:"2-digit"}):gn(e,{month:"short",day:"numeric"}),Ro=e=>gn(e,{dateStyle:"medium",timeStyle:"short"}),$v=e=>{const t=e.toAddresses??[];return t.length===0?"No recipients":t.length===1?t[0]:`${t[0]} +${t.length-1}`},jc=(e,t)=>t?"The outbox cannot filter on those terms":e?"No matching outbox messages":"No outbox messages",Sc=c.createContext(null);function fa(){const e=c.useContext(Sc);if(!e)throw new Error("OutboxPane.* must be used inside <OutboxPane>");return e}function Kv({children:e}){const t=Me(),{selectedOutboxMessageId:n}=as({strict:!1}),{data:r,isLoading:a}=ue(wn()),{searchQuery:o}=Se(),i=ps(),l=la(o),u=xs(l,i),d=l.length>0,m=_v(u),f=c.useMemo(()=>m?[]:(r?.items??[]).filter(p=>yc(p.status)).filter(p=>Fv(p,u.freeText)),[r,u.freeText,m]),h=c.useMemo(()=>f.find(p=>p.outboxMessageId===n),[f,n]),x=c.useCallback(p=>{t({to:"/mail/outbox",search:v=>({...v,selectedOutboxMessageId:p})})},[t]),b={messages:f,hasQuery:d,unsupportedQuery:m,isLoading:a,selectedMessageId:n,selectedMessage:h,onSelectMessage:x};return s.jsx(Sc.Provider,{value:b,children:e})}function kc({message:e,isSelected:t,onSelect:n}){const r=je(),{openCompose:a}=It(),{pushError:o}=qe(),i=c.useCallback(()=>{r.invalidateQueries({queryKey:Br()})},[r]),l=pe({...Qo(),onSuccess:i,onError:f=>{o(zt("Couldn't resend message","The message wasn't sent.",f))}}),u=pe({...jn(),onSuccess:i,onError:f=>{o(zt("Couldn't delete message","The message wasn't deleted.",f))}}),d=e.status;if(!wc[d])return null;const m=vc(e.status);return s.jsx(Af,{recipients:$v(e),subject:e.subject||"",time:Bv(e.sentAt??e.updatedAt),status:d,error:m?e.lastError??void 0:void 0,selected:t,onSelect:n,onRetry:d==="failed"?()=>l.mutate({path:{outboxMessageId:e.outboxMessageId}}):void 0,retrying:l.isPending,onEdit:()=>a({mode:"new",outboxMessageId:e.outboxMessageId}),onDelete:()=>u.mutate({path:{outboxMessageId:e.outboxMessageId}}),deleting:u.isPending})}function Nc({message:e,onBack:t}){const n=e.status,r=wc[n],a=r?.icon??_s,o=e.sentAt?Ro(e.sentAt):Ro(e.updatedAt);return s.jsxs("div",{className:"h-full overflow-y-auto bg-canvas",children:[s.jsxs("div",{className:"border-b border-line p-4",children:[t&&s.jsxs("button",{type:"button",onClick:t,className:"mb-3 inline-flex items-center gap-1 text-sm text-fg-muted hover:text-fg",children:[s.jsx(ni,{className:"size-4"}),s.jsx("span",{children:"Back"})]}),s.jsx("h1",{className:"text-xl font-semibold mb-3",children:e.subject||"(No subject)"}),s.jsxs("div",{className:"space-y-1 text-sm",children:[s.jsxs("div",{className:"flex gap-2",children:[s.jsx("span",{className:"text-fg-muted shrink-0 w-12",children:"From:"}),s.jsx("span",{className:"text-fg",children:e.fromName?`${e.fromName} <${e.fromAddress}>`:e.fromAddress})]}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx("span",{className:"text-fg-muted shrink-0 w-12",children:"To:"}),s.jsx("span",{className:"text-fg",children:(e.toAddresses??[]).join(", ")})]}),e.ccAddresses&&e.ccAddresses.length>0&&s.jsxs("div",{className:"flex gap-2",children:[s.jsx("span",{className:"text-fg-muted shrink-0 w-12",children:"Cc:"}),s.jsx("span",{className:"text-fg",children:e.ccAddresses.join(", ")})]}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx("span",{className:"text-fg-muted shrink-0 w-12",children:"Date:"}),s.jsx("span",{className:"text-fg",children:o})]}),r&&s.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[s.jsx(a,{className:de("size-4",r.className,n==="sending"&&"animate-spin")}),s.jsx("span",{className:de("text-xs font-medium",r.className),children:r.label}),vc(e.status)&&e.lastError&&s.jsxs("span",{className:"text-xs text-fg-muted",children:["— ",e.lastError]})]})]})]}),s.jsx("div",{className:"p-4",children:s.jsx(Bl,{html:e.htmlBody,text:e.textBody})})]})}function qv(){const{messages:e,hasQuery:t,unsupportedQuery:n,isLoading:r,selectedMessageId:a,onSelectMessage:o}=fa();return r?s.jsx("div",{className:"flex h-full items-center justify-center bg-canvas",children:s.jsx("span",{className:"text-fg-muted",children:"Loading..."})}):e.length===0?s.jsx("div",{className:"flex h-full bg-surface",children:s.jsx(hs,{message:jc(t,n),showHints:!1})}):s.jsxs("div",{className:"h-full flex flex-col bg-canvas",children:[s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[s.jsx(ua,{}),s.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:"Outbox"}),s.jsxs("span",{className:"shrink-0 text-2xs text-fg-subtle",children:[e.length," ",e.length===1?"message":"messages"]})]}),s.jsx("div",{className:"flex-1 overflow-y-auto",children:e.map(i=>s.jsx(kc,{message:i,isSelected:a===i.outboxMessageId,onSelect:()=>o(i.outboxMessageId)},i.outboxMessageId))})]})}function Uv(){const{selectedMessage:e}=fa();return s.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[s.jsx("header",{className:"flex h-pane-header shrink-0 items-center border-b border-line px-3"}),s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?s.jsx(Nc,{message:e}):s.jsx(hs,{message:"Select a message to read",showHints:!1})})]})}function Qv(){const{messages:e,hasQuery:t,unsupportedQuery:n,isLoading:r,selectedMessageId:a,selectedMessage:o,onSelectMessage:i}=fa();return r?s.jsx("div",{className:"flex h-full items-center justify-center bg-canvas",children:s.jsx("span",{className:"text-fg-muted",children:"Loading..."})}):o?s.jsx(Nc,{message:o,onBack:()=>i(void 0)}):e.length===0?s.jsx("div",{className:"flex h-full bg-surface",children:s.jsx(hs,{message:jc(t,n),showHints:!1})}):s.jsxs("div",{className:"h-full flex flex-col bg-canvas",children:[s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[s.jsx(ua,{}),s.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:"Outbox"}),s.jsxs("span",{className:"shrink-0 text-2xs text-fg-subtle",children:[e.length," ",e.length===1?"message":"messages"]})]}),s.jsx("div",{className:"flex-1 overflow-y-auto",children:e.map(l=>s.jsx(kc,{message:l,isSelected:a===l.outboxMessageId,onSelect:()=>i(l.outboxMessageId)},l.outboxMessageId))})]})}const ln=Object.assign(Kv,{List:qv,Reading:Uv,Phone:Qv}),Hv=({isOpen:e,onClose:t})=>{const n=c.useCallback(r=>{r.key==="Escape"&&(r.preventDefault(),t())},[t]);return c.useEffect(()=>{if(e)return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[e,n]),e?s.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",role:"dialog","aria-modal":"true","aria-label":"Keyboard shortcuts",onClick:t,onKeyDown:r=>r.key==="Escape"&&t(),children:[s.jsx("div",{className:"absolute inset-0 bg-canvas/80 backdrop-blur-sm"}),s.jsxs("div",{className:de("relative z-10 max-h-[85vh] w-full max-w-2xl overflow-y-auto","rounded-lg border border-line bg-surface shadow-lg","p-6"),onClick:r=>r.stopPropagation(),onKeyDown:r=>{r.key!=="Escape"&&r.stopPropagation()},children:[s.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[s.jsx("h2",{className:"text-lg font-semibold",children:"Keyboard shortcuts"}),s.jsx("button",{type:"button",onClick:t,className:"p-1 text-fg-muted transition-colors hover:text-fg","aria-label":"Close",children:s.jsx(Ke,{className:"size-5"})})]}),s.jsx("div",{className:"grid gap-x-8 gap-y-6 sm:grid-cols-2",children:sl.map(r=>s.jsxs("div",{children:[s.jsx("h3",{className:"mb-3 text-sm font-medium text-fg-muted",children:r.title}),s.jsx("div",{className:"space-y-2",children:r.hints.map(a=>s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"text-sm",children:a.description}),s.jsx("span",{className:"flex shrink-0 items-center gap-1",children:a.keys.map((o,i)=>s.jsxs(c.Fragment,{children:[i>0&&a.keys[0]==="g"&&s.jsx("span",{className:"text-2xs text-fg-subtle",children:"then"}),s.jsx(ns,{children:o})]},o))})]},`${a.action}-${a.keys.join("+")}`))})]},r.title))}),s.jsx("div",{className:"mt-6 border-t border-line pt-4",children:s.jsxs("p",{className:"text-center text-xs text-fg-muted",children:["Press ",s.jsx(ns,{children:"Esc"})," to close"]})})]})]}):null};function Wv(e){const t=new Map;for(const n of e){const r=n.email.toLowerCase(),a=r.split("@")[0];a&&!t.has(a)&&t.set(a,n.accountId),t.has(r)||t.set(r,n.accountId)}return t}function Vv(e){const t=new Map;for(const n of e)for(const r of n){const a=r.fullPath?.toLowerCase();if(!a)continue;const o=a.split("/").pop();t.has(a)||t.set(a,r.mailboxId),o&&!t.has(o)&&t.set(o,r.mailboxId)}return t}function Yv(e){const t=Ut({queries:e.map(n=>({...rt({path:{accountId:n.accountId}}),staleTime:1/0}))});return c.useMemo(()=>Vv(t.map(n=>n.data?.items??[])),[t])}var cn={exports:{}},Mo;function Gv(){if(Mo)return cn.exports;Mo=1;const e=(t,n,r)=>new Promise((a,o)=>{if(r=Object.assign({concurrency:1/0},r),typeof n!="function")throw new TypeError("Mapper function is required");const{concurrency:i}=r;if(!(typeof i=="number"&&i>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${i}\` (${typeof i})`);const l=[],u=t[Symbol.iterator]();let d=!1,m=!1,f=0,h=0;const x=()=>{if(d)return;const b=u.next(),p=h;if(h++,b.done){m=!0,f===0&&a(l);return}f++,Promise.resolve(b.value).then(v=>n(v,p)).then(v=>{l[p]=v,f--,x()},v=>{d=!0,o(v)})};for(let b=0;b<i&&(x(),!m);b++);});return cn.exports=e,cn.exports.default=e,cn.exports}var Xv=Gv();const Jv=pu(Xv),Zv=900*1e3,ey=300,ty=(e,t)=>{if(!e)return t;const n=Number.parseInt(e,10);return Number.isFinite(n)&&n>0?n:t},sy=60*1e3,ny=e=>Math.max(ty(e,ey)*1e3,sy),mn=ny(vu().mailboxPollIntervalSeconds),ry=5,Ir=new Set,ay=(e,t,n=Zv)=>e.filter(r=>{const a=r.lastSyncAt;return a==null?!0:t-a>n}).map(r=>r.accountId),oy=(e,t,n=mn)=>e-t>=n,iy=(e,t)=>e.filter(n=>!t.has(n)),To=(e,t)=>{if(Ir.delete(e),bu(t,{softError:!0})){Yo(t);return}console.warn("[remit] background mailbox sync failed",{accountId:e,error:t})},Do=(e,t)=>xu({path:{accountId:e},throwOnError:!0}).then(()=>{t.invalidateQueries({queryKey:Bt({path:{accountId:e}})})}),ly=e=>{const t=je(),n=c.useRef(e);n.current=e;const r=e.map(a=>a.accountId).join(",");c.useEffect(()=>{const a=Date.now(),i=ay(n.current,a).filter(l=>!Ir.has(l));if(i.length!==0)for(const l of i)Ir.add(l),Do(l,t).catch(u=>{To(l,u)})},[r,t]),c.useEffect(()=>{let a=Date.now(),o;const i=new Set,l=()=>{a=Date.now();const m=iy(n.current.map(f=>f.accountId),i);for(const f of m)i.add(f);Jv(m,f=>Do(f,t).catch(h=>{To(f,h)}).finally(()=>{i.delete(f)}),{concurrency:ry})},u=()=>{if(document.visibilityState==="visible"){l(),o=setTimeout(u,mn);return}},d=()=>{document.visibilityState==="visible"&&oy(Date.now(),a)&&(o!==void 0&&clearTimeout(o),l(),o=setTimeout(u,mn))};return o=setTimeout(u,mn),document.addEventListener("visibilitychange",d),()=>{o!==void 0&&clearTimeout(o),document.removeEventListener("visibilitychange",d)}},[r,t])};function cy(e,t,n){if(e!==t)return n}function uy(e,t){return e===""?"":t}function dy(e,t,n){return t!==e?!1:t!==n}function fy(){const{q:e=""}=as({from:"/mail"}),t=Me(),n=On(),r=Vl(n),[a,o]=c.useState(!1),[i,l]=c.useState(!1),[u,d]=c.useState(!1),m=c.useCallback(W=>{d(W),Co(W)},[]),[f,h]=c.useState(e),x=Xo(f,200),b=uy(f,x),p=c.useRef(e);p.current=e;const v=kt({select:W=>zh(W.matches)}),[g,y]=c.useState(v);if(g!==v){const W=cy(g,v,e);y(v),W!==void 0&&h(W)}c.useEffect(()=>{dy(f,b,p.current)&&t({to:".",search:W=>{const le=W.q===b;return{...W,q:b||void 0,...b&&!le?{selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0}:{}}},replace:!0})},[f,b,t]);const{data:j,isLoading:w,isError:C,error:k,refetch:S}=ue({...ht(),staleTime:1/0}),N=!!(j&&(j.accounts?.length??0)===0);c.useEffect(()=>{N&&t({to:"/onboarding",replace:!0})},[N,t]),ea({enabled:!a,bindings:[{key:"?",handler:()=>o(!0),noModifiers:!1,preventDefault:!0}]});const I=c.useCallback(W=>{h(W)},[]),T=c.useCallback(()=>{h("")},[]),E=c.useCallback(()=>{h("")},[]),M=c.useCallback(()=>{d(W=>{const le=!W;return Co(le),le})},[]),R=j?.accounts??[],A=Yv(R),D=c.useMemo(()=>Wv(R),[R]),F=kt({select:W=>W.matches.find(me=>"mailboxId"in me.params)?.params.mailboxId}),{selectedMessageId:$}=as({strict:!1}),te=kt({select:W=>Xr(W.matches)}),q=kt({select:W=>Rn(W.matches)}),Q=kt({select:W=>Mn(W.matches)});ly(R);const X=c.useCallback(()=>{l(!1)},[]),ee={accounts:R,mailboxNameIndex:A,accountNameIndex:D,searchQuery:b,searchInput:f,searchViewKey:v,onSearchChange:I,onSearchClear:T,onSearchClearQuery:E,intelligenceOpen:u,onToggleIntelligence:M,onSetIntelligenceOpen:m},se=s.jsx(zv,{accounts:R,onMailboxSelect:X}),P=r?s.jsx(Oh,{accounts:R}):void 0,_=r?void 0:s.jsx(Hh,{accounts:R}),H={navOpen:i,onOpenNav:()=>l(!0),onCloseNav:()=>l(!1)};return s.jsxs(yu.Provider,{value:ee,children:[C?s.jsx("div",{className:"flex h-full items-center justify-center bg-canvas p-4",children:s.jsx(Mt,{title:"Couldn't load your account",error:k,onRetry:()=>{S()}})}):te?s.jsx(Es,{selectedMessageId:$,children:r?s.jsx(wt,{nav:se,list:s.jsx(Es.Phone,{}),intelligenceOpen:u,overlay:P,skeleton:s.jsx(dt,{}),isLoading:w||N,...H}):s.jsx(wt,{nav:se,topBar:_,list:s.jsx(Es.List,{}),reading:s.jsx(Es.Reading,{}),intelligence:s.jsx(Es.Intelligence,{}),intelligenceOpen:u,hasThread:!!$,overlay:P,skeleton:s.jsx(dt,{}),isLoading:w||N,...H})}):q?s.jsx(Is,{selectedMessageId:$,children:r?s.jsx(wt,{nav:se,list:s.jsx(Is.Phone,{}),intelligenceOpen:u,overlay:P,skeleton:s.jsx(dt,{}),isLoading:w||N,...H}):s.jsx(wt,{nav:se,topBar:_,list:s.jsx(Is.List,{}),reading:s.jsx(Is.Reading,{}),intelligence:s.jsx(Is.Intelligence,{}),intelligenceOpen:u,hasThread:!!$,overlay:P,skeleton:s.jsx(dt,{}),isLoading:w||N,...H})}):F?s.jsx(Ts,{mailboxId:F,selectedMessageId:$,children:r?s.jsx(wt,{nav:se,list:s.jsx(Ts.Phone,{}),intelligenceOpen:u,overlay:P,skeleton:s.jsx(dt,{}),isLoading:w||N,...H}):s.jsx(wt,{nav:se,topBar:_,list:s.jsx(Ts.List,{}),reading:s.jsx(Ts.Reading,{}),intelligence:s.jsx(Ts.Intelligence,{}),intelligenceOpen:u,hasThread:!!$,overlay:P,skeleton:s.jsx(dt,{}),isLoading:w||N,...H})}):Q?s.jsx(ln,{children:r?s.jsx(wt,{nav:se,list:s.jsx(ln.Phone,{}),intelligenceOpen:!1,overlay:P,skeleton:s.jsx(dt,{}),isLoading:w||N,...H}):s.jsx(wt,{nav:se,topBar:_,list:s.jsx(ln.List,{}),reading:s.jsx(ln.Reading,{}),intelligenceOpen:!1,overlay:P,skeleton:s.jsx(dt,{}),isLoading:w||N,...H})}):s.jsx(dt,{}),s.jsx(Hv,{isOpen:a,onClose:()=>o(!1)}),s.jsx(wu,{})]})}const Ry=Object.freeze(Object.defineProperty({__proto__:null,component:fy,useMailContext:Se},Symbol.toStringTag,{value:"Module"}));export{Iy as S,Yu as U,Ry as m};
|