@remit/web-client-dist 0.0.22 → 0.0.24
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-Mf7X_Ldm.js → ComposeBody-BKGSbNpX.js} +1 -1
- package/assets/{ErrorState-Ig7wnww4.js → ErrorState-WeUwU_tg.js} +1 -1
- package/assets/{OnboardingWizard-BF6G1yFD.js → OnboardingWizard-ZYWlIIMZ.js} +1 -1
- package/assets/{account-form-helpers-CL9ETpps.js → account-form-helpers-owalSXUV.js} +1 -1
- package/assets/{accounts-1lAVZhDe.js → accounts-D-lm57RW.js} +1 -1
- package/assets/{advanced-BzFtlO0H.js → advanced-z42E1ElV.js} +1 -1
- package/assets/{appearance-CcqXsfaF.js → appearance-DOW34_wC.js} +1 -1
- package/assets/{avatar-BtEbqaC8.js → avatar-CgADwr5t.js} +1 -1
- package/assets/{browser-ponyfill-BMu3EQHd.js → browser-ponyfill-EbiW_3Dt.js} +1 -1
- package/assets/{filter-status-CJCSVhUD.js → filter-status-DE1t7HaU.js} +1 -1
- package/assets/{filters-y-AXvjtc.js → filters-hydJHYiy.js} +1 -1
- package/assets/{flagged-C8gk0gi1.js → flagged-Bmib8bVW.js} +1 -1
- package/assets/{folders-hvIGuA3u.js → folders-DGVjuKki.js} +1 -1
- package/assets/{index-CYQLpdZq.js → index-BfapQKzG.js} +60 -60
- package/assets/{index-B2qKuiUO.js → index-Bj2ED6Kz.js} +1 -1
- package/assets/{index-BkU-X8Kl.css → index-BycZKbRn.css} +1 -1
- package/assets/index-Dm1jiH2p.js +1 -0
- package/assets/{kbd-tO0aOXHj.js → kbd-CzuL3suc.js} +1 -1
- package/assets/mail-PPbmNxkG.js +112 -0
- package/assets/{onboarding-B6ocny2Z.js → onboarding-DnWjr_9B.js} +1 -1
- package/assets/{select-DpXTNzUb.js → select-mKaHoohK.js} +1 -1
- package/assets/{send-czY5qyvi.js → send-DH_jUZ-9.js} +1 -1
- package/assets/{senders-B0ZOprWL.js → senders-CmA4ANVB.js} +1 -1
- package/assets/settings-DHLVKxa1.js +1 -0
- package/assets/{settings-screen-vgzI9HJ0.js → settings-screen-kIyFCpgu.js} +1 -1
- package/assets/{star-DnZWg7eM.js → star-qu72Bdxx.js} +1 -1
- package/assets/{suggested-vips-wvvUataf.js → suggested-vips-DY6p-7ZI.js} +1 -1
- package/assets/{trash-2-B9avayrR.js → trash-2-SH6tyOV_.js} +1 -1
- package/assets/{useDebouncedValue-Cq7xqGlT.js → useDebouncedValue-Y6B7HSPj.js} +1 -1
- package/assets/{useMutation-BQHlSeFS.js → useMutation-BiD0avR-.js} +1 -1
- package/assets/{useSignature-C2IepeN8.js → useSignature-CyU_wzrw.js} +1 -1
- package/index.html +2 -2
- package/package.json +1 -1
- package/assets/index-Bs6Mv_aF.js +0 -1
- package/assets/mail-DP9YPkfI.js +0 -112
- package/assets/settings-DuhlUDFA.js +0 -1
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ComposeBody-BKGSbNpX.js","assets/index-BfapQKzG.js","assets/index-BycZKbRn.css","assets/folder-roles-XnseeyyD.js","assets/useDebouncedValue-Y6B7HSPj.js","assets/avatar-CgADwr5t.js","assets/kbd-CzuL3suc.js","assets/star-qu72Bdxx.js","assets/trash-2-SH6tyOV_.js","assets/account-form-helpers-owalSXUV.js","assets/send-DH_jUZ-9.js","assets/useMutation-BiD0avR-.js","assets/useSignature-CyU_wzrw.js","assets/ErrorState-WeUwU_tg.js","assets/format-BGdB831k.js","assets/select-mKaHoohK.js","assets/filter-status-DE1t7HaU.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{c as se,r as l,j as s,C as xt,X as Be,a as U,B as G,b as Ge,d as Rt,e as fc,f as oo,p as io,I as Jn,i as mc,g as lo,D as co,O as hc,S as gc,h as xc,F as Zn,k as uo,T as er,P as pc,l as fo,m as bc,R as tr,n as sr,_ as mt,o as mo,q as vc,Q as nr,s as yc,t as wc,u as jc,v as zn,w as Sc,x as Nc,y as je,z as kc,A as Cc,E as Ec,G as Ic,H as Rc,J as Mc,K as qr,L as Tc,M as Dc,N as Ac,U as ho,V as go,W as xo,Y as pt,Z as Re,$ as Je,a0 as ce,a1 as rr,a2 as ar,a3 as or,a4 as Me,a5 as Ss,a6 as oe,a7 as po,a8 as Oc,a9 as bo,aa as Pc,ab as an,ac as vo,ad as it,ae as He,af as Lc,ag as Ye,ah as yo,ai as ys,aj as on,ak as zc,al as lt,am as bt,an as ts,ao as ln,ap as Mt,aq as wo,ar as _c,as as Fc,at as Bc,au as jo,av as F,aw as cn,ax as Yt,ay as $c,az as ir,aA as Kc,aB as qc,aC as So,aD as lr,aE as cr,aF as _n,aG as Uc,aH as No,aI as ot,aJ as Hc,aK as ur,aL as Qc,aM as Wc,aN as Vc,aO as Yc,aP as dr,aQ as Gc,aR as Xc,aS as Jc,aT as Zc,aU as eu,aV as tu,aW as su,aX as nu,aY as ru,aZ as dt,a_ as at,a$ as au}from"./index-BfapQKzG.js";import{b as ss,R as Fn,g as en,l as Gt,s as ou}from"./folder-roles-XnseeyyD.js";import{S as Ns,u as ko}from"./useDebouncedValue-Y6B7HSPj.js";import{A as Ze,M as fr,C as iu}from"./avatar-CgADwr5t.js";import{K as Wt}from"./kbd-CzuL3suc.js";import{S as vt}from"./star-qu72Bdxx.js";import{T as et}from"./trash-2-SH6tyOV_.js";import{L as Tt,M as Co,a as lu}from"./account-form-helpers-owalSXUV.js";import{S as ks,F as cu,M as uu,A as du,a as Eo}from"./send-DH_jUZ-9.js";import{u as be}from"./useMutation-BiD0avR-.js";import{R as fu,u as mu}from"./useSignature-CyU_wzrw.js";import{E as yt,f as Io}from"./ErrorState-WeUwU_tg.js";import{f as Ro,a as wt,b as tn,c as hu,t as gu}from"./format-BGdB831k.js";import{C as Cs,S as xu}from"./select-mKaHoohK.js";import{b as Mo,h as pu,p as bu,u as vu}from"./filter-status-DE1t7HaU.js";const To=se("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);const yu=se("ArrowRight",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]);const un=se("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 wu=se("Ban",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m4.9 4.9 14.2 14.2",key:"1m5liu"}]]);const Do=se("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 ju=se("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 Ur=se("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 Xt=se("ChevronRight",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]);const Ao=se("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 mr=se("CircleCheck",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const hr=se("Clock",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]]);const Oo=se("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]);const Po=se("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 Su=se("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 Lo=se("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 zo=se("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 _o=se("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 Nu=se("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 Es=se("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=se("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 Cu=se("Minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);const dn=se("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 Eu=se("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 Fo=se("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 Bo=se("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 $o=se("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 Iu=se("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 Ko=se("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 Is=se("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 Rs=se("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 Ru=se("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 Mu=se("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 Xe=se("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 Tu=se("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 Du=se("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"}]]),Au=({address:e,showTrustedBadge:t=!1})=>{const n=t?s.jsx(un,{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]})},Ou=({label:e,addresses:t,showTrustedBadge:n=!1})=>{const[r,a]=l.useState(!1);if(t.length===0)return null;const o=t.length>3,i=c=>{const u=n&&c.flags?.trusted?.value===!0;return s.jsx(Au,{address:c,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((c,u)=>s.jsxs("span",{children:[i(c),u<t.length-1&&", "]},u))}):s.jsx("div",{className:"truncate",children:t.map((c,u)=>s.jsxs("span",{children:[i(c),u<t.length-1&&", "]},u))})}),o&&s.jsx("button",{type:"button",onClick:c=>{c.stopPropagation(),a(!r)},className:"shrink-0 text-fg-muted hover:text-fg transition-colors","aria-label":r?"Collapse":"Expand",children:r?s.jsx(xt,{className:"h-4 w-4"}):s.jsx(Xt,{className:"h-4 w-4"})})]})},Pu=({email:e,displayName:t,onRemove:n,className:r})=>s.jsxs("span",{className:U("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(Be,{className:"size-3"})})]}),Lu={unknown:{label:"Unknown sender",tone:"neutral"},wellknown:{label:"Known sender",tone:"positive"},vip:{label:"VIP",tone:"accent"}};function _t({label:e,children:t,className:n}){return s.jsxs("section",{className:U("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 zu({sender:e}){const t=Lu[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(Ze,{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 _u({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(Rs,{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(Ru,{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(Is,{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 Ft({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:U("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 Fu={sender:"matched: sender",recipient:"matched: recipient",subject:"matched: subject",attachment:"matched: attachment",body:"matched: body",entities:"matched: entities"};function qo({data:e,onClose:t,onShowSimilar:n,actions:r,similarState:a="ready",similarLinkComponent:o,className:i,hideCloseButton:c=!1}){const{sender:u,authenticity:d,category:f,flags:m={},similar:h}=e,p=d.verdict==="mismatch";return s.jsxs("aside",{className:U("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"}),!c&&s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(Be,{className:"size-3.5"}),onClick:t,"aria-label":"Collapse intelligence sidebar"})]}),s.jsx(_t,{label:"Sender",children:s.jsx(zu,{sender:u})}),s.jsx(_t,{label:"Authenticity",children:s.jsx(_u,{auth:d,onShowSimilar:n})}),s.jsx(_t,{label:"Category",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Ge,{tone:p?"danger":"neutral",children:f.value}),f.overridden&&s.jsx("span",{className:"text-2xs text-fg-subtle",children:"your override"}),s.jsx("button",{type:"button",className:U("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(_t,{label:"Quick actions",children:s.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[s.jsx(Ft,{icon:s.jsx(vt,{className:"size-3.5"}),label:"VIP",active:m.vip,onClick:r?.onToggleVip}),s.jsx(Ft,{icon:s.jsx(Do,{className:"size-3.5"}),label:"Mute",active:m.muted,onClick:r?.onToggleMute}),s.jsx(Ft,{icon:s.jsx(wu,{className:"size-3.5"}),label:"Block",active:m.blocked,danger:!0,onClick:r?.onToggleBlock}),s.jsx(Ft,{icon:s.jsx(ku,{className:"size-3.5"}),label:"Unsubscribe",active:m.unsubscribed,onClick:r?.onToggleUnsubscribe}),r?.onNotSpam&&s.jsx(Ft,{icon:s.jsx(Nu,{className:"size-3.5"}),label:"Not spam",onClick:r.onNotSpam}),r?.onMarkSpam&&s.jsx(Ft,{icon:s.jsx(Mu,{className:"size-3.5"}),label:"Mark spam",danger:!0,onClick:r.onMarkSpam})]})}),(a!=="ready"||h.length>0)&&s.jsx(_t,{label:"Similar messages",children:a==="loading"?s.jsx("div",{className:"animate-pulse space-y-2",children:Array.from({length:3}).map((b,x)=>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"})]},x))}):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 x="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:Fu[b.matched]})]});return s.jsx("li",{children:o?o({mailboxId:b.mailboxId,messageId:b.id,className:x,ariaLabel:v,children:g}):s.jsx("div",{className:x,children:g})},b.id)})})}),s.jsx(_t,{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(Xe,{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(Xe,{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 Bu=[{keys:["j","k"],label:"navigate"},{keys:["m"],label:"mute"},{keys:["?"],label:"all shortcuts"}];function Uo({hints:e=Bu,className:t}){return s.jsx("footer",{className:U("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($u,{hint:n},n.label))})}function $u({hint:e}){return s.jsxs("span",{className:"flex items-center gap-1",children:[e.keys.map(t=>s.jsx(Wt,{children:t},t)),s.jsx("span",{children:e.label})]})}function Ku(){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 qu({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 Uu({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(Rt,{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 Ho=({active:e,focused:t})=>U("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"),ns=({active:e,focused:t})=>U("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 Qo({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(Is,{className:"size-3.5 text-danger"}):e.starred?s.jsx(vt,{className:"size-3 fill-warning text-warning"}):t?s.jsx("span",{className:"size-1.5 rounded-full bg-accent"}):null}),s.jsx("span",{className:U("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:U(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(dn,{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 rs({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:U("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:U("truncate text-sm",n?"text-fg":"text-fg-muted"),children:e.subject}),e.suspicious&&s.jsx(Is,{className:"size-3.5 shrink-0 text-danger"}),e.starred&&s.jsx(vt,{className:"size-3 shrink-0 fill-warning text-warning"}),e.hasAttachment&&s.jsx(dn,{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:fc[e.category],className:"shrink-0",children:e.category}),t]})]})}function Wo({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(Ze,{name:e.fromName,email:e.fromEmail,size:"sm"}),s.jsx(rs,{thread:e})]})}function Hu({thread:e,active:t,onClick:n}){return s.jsx("button",{type:"button",onClick:n,className:Ho({active:t}),children:s.jsx(Qo,{thread:e})})}function Vo({thread:e,active:t,onClick:n}){return s.jsx("button",{type:"button",onClick:n,className:ns({active:t}),children:s.jsx(Wo,{thread:e})})}function Yo({count:e,onCancel:t,onMarkRead:n,onDelete:r,moveSlot:a,moveDisabledHint:o,isBusy:i=!1}){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:"sm",icon:s.jsx(Be,{className:"size-4"}),onClick:t,"aria-label":"Cancel selection",className:"-ml-1 shrink-0"}),s.jsxs("span",{className:"min-w-0 flex-1 truncate text-sm font-medium text-fg",children:[e," ",e===1?"message":"messages"," selected"]}),n&&s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(Es,{className:"size-4"}),onClick:i?void 0:n,"aria-label":"Mark as read","aria-busy":i||void 0,className:"shrink-0"}),a,s.jsx(G,{variant:"ghost",size:"sm",icon:i?s.jsx(Tt,{className:"size-4 animate-spin"}):s.jsx(et,{className:"size-4 text-danger"}),onClick:i?void 0:r,"aria-label":"Delete selected messages","aria-busy":i||void 0,className:"shrink-0"})]}),o&&s.jsx("p",{className:"px-row-inset pb-2 text-xs text-fg-muted",role:"status","aria-live":"polite",children:o})]})}const Jt=72,Hr=10;function Qr(e){return e==="leading"?Jt:e==="trailing"?-Jt:0}function Qu(e){return e>=Jt/2?"leading":e<=-Jt/2?"trailing":"none"}function Go({thread:e,selectionMode:t,checked:n,active:r,peek:a,onPeek:o,onToggleCheck:i,onLongPress:c,onOpen:u,onAct:d,linkComponent:f}){const m=l.useRef(void 0),h=l.useRef(null),[p,b]=l.useState(null),x=()=>clearTimeout(m.current),v=k=>{h.current={startX:k.clientX,startY:k.clientY,axis:"none",moved:!1},!t&&(m.current=setTimeout(()=>{h.current=null,b(null),c()},500))},g=k=>{if(t)return;const M=h.current;if(!M)return;const R=k.clientX-M.startX,D=k.clientY-M.startY;if(M.axis==="none"){if(Math.abs(D)>Hr&&Math.abs(D)>Math.abs(R)){M.axis="vertical",x(),h.current=null;return}Math.abs(R)>Hr&&(M.axis="horizontal",M.moved=!0,x(),k.currentTarget.setPointerCapture(k.pointerId))}if(M.axis!=="horizontal")return;const E=Qr(a),T=Math.max(-Jt,Math.min(Jt,E+R));b(T)},y=()=>{x();const k=h.current;h.current=null;const M=p;if(b(null),!!k){if(k.axis==="horizontal"&&M!==null){o(Qu(M));return}if(t){i();return}if(a!=="none"){o("none");return}f||u()}},w=k=>{a!=="none"&&k.preventDefault()},j=p??Qr(a),I=j>0?"leading":j<0?"trailing":"none",N=U("relative touch-pan-y bg-surface",ns({active:n||r})),S={transform:j!==0?`translateX(${j}px)`:void 0,transition:p===null?"transform 150ms ease":"none",minHeight:44},C=t?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:U("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(Cs,{className:"size-3.5"})}),s.jsx(rs,{thread:e})]}):s.jsx(Wo,{thread:e});return s.jsxs("div",{className:"relative overflow-hidden",children:[I==="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(Co,{className:"size-6"}):s.jsx(Es,{className:"size-6"})}),I==="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(et,{className:"size-6"})}),f&&!t?f({className:N,style:S,onPointerDown:v,onPointerMove:g,onPointerUp:y,onPointerCancel:y,onOpenClick:w,children:C}):s.jsx("button",{type:"button",onPointerDown:v,onPointerMove:g,onPointerUp:y,onPointerCancel:y,className:N,style:S,children:C})]})}function Wu({sections:e,selectedThreadId:t,selectionMode:n,checkedIds:r,initialPeek:a,onToggleCheck:o,onEnterSelection:i,onOpenThread:c,onRefresh:u,refreshing:d}){const[f,m]=l.useState(()=>e.flatMap(x=>x.threads)),[h,p]=l.useState(a&&a!=="none"&&f[1]?{id:f[1].id,side:a}:null),b=(x,v)=>{m(v==="trailing"?g=>g.filter(y=>y.id!==x):g=>g.map(y=>y.id===x?{...y,isRead:!y.isRead}:y)),p(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(Fo,{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(x=>s.jsx(Go,{thread:x,selectionMode:n,checked:r.has(x.id),active:x.id===t,peek:h?.id===x.id?h.side:"none",onPeek:v=>p(v==="none"?null:{id:x.id,side:v}),onToggleCheck:()=>o(x.id),onLongPress:()=>i(x.id),onOpen:()=>c(x.id),onAct:v=>b(x.id,v)},x.id))}),!n&&!d&&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 Xo({listTitle:e,listMeta:t,sections:n,briefFilters:r,flatList:a,listState:o="ready",searchQuery:i,errorMessage:c,onRetry:u,onReportError:d,briefCategory:f,selectedThreadId:m,density:h="comfortable",onSelectThread:p,onSelectBriefCategory:b,onOpenNav:x,isDesktop:v,initialTouchState:g,selectionBar:y,listBody:w,hideHeader:j=!1}){const I=h==="compact"?Hu:Vo,N=!v&&!r&&o==="ready",S=n.flatMap($=>$.threads),[C,k]=l.useState(g==="selection"),[M,R]=l.useState(()=>g==="selection"?new Set(S.slice(0,2).map($=>$.id)):new Set),[D,E]=l.useState(!1),T=g==="peek-trailing"?"trailing":g==="peek-leading"?"leading":void 0,O=$=>{R(ee=>{const te=new Set(ee);return te.has($)?te.delete($):te.add($),te.size===0&&k(!1),te})},B=$=>{k(!0),R(new Set([$]))},q=()=>{k(!1),R(new Set)},X=()=>{E(!0),setTimeout(()=>E(!1),1400)},z=!y&&N&&C&&M.size>0;return s.jsxs("section",{className:"flex h-full w-full flex-col bg-surface",children:[y??(z?s.jsx(Yo,{count:M.size,onCancel:q,onMarkRead:q,onDelete:q}):j?null:s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[x&&s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(fr,{className:"size-4"}),onClick:x,"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(Ku,{})}):o==="empty"?s.jsx(qu,{searchQuery:i}):o==="error"?s.jsx(Uu,{message:c,onRetry:u,onReport:d}):r?s.jsx(oo,{sections:n,briefCategory:f,selectedThreadId:m,Row:I,onSelectThread:p,onSelectBriefCategory:b}):w??(N?s.jsx(Wu,{sections:n,selectedThreadId:m,selectionMode:C,checkedIds:M,initialPeek:T,onToggleCheck:O,onEnterSelection:B,onOpenThread:$=>p?.($),onRefresh:X,refreshing:D}):s.jsx("div",{className:"flex-1 overflow-y-auto",children:n.map($=>s.jsxs("div",{children:[!a&&$.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:$.label}),s.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:$.threads.length})]}),s.jsx("div",{className:"divide-y divide-line",children:$.threads.map(ee=>s.jsx(I,{thread:ee,active:ee.id===m,onClick:()=>p?.(ee.id)},ee.id))})]},$.id))})),v&&s.jsx(Uo,{})]})}function Vu({triggerLabel:e,triggerIcon:t,items:n,align:r="end",touch:a=!0,className:o}){const[i,c]=l.useState(!1),u=l.useRef(null);return l.useEffect(()=>{if(!i)return;const d=m=>{u.current&&!u.current.contains(m.target)&&c(!1)},f=m=>{m.key==="Escape"&&c(!1)};return document.addEventListener("mousedown",d),document.addEventListener("keydown",f),()=>{document.removeEventListener("mousedown",d),document.removeEventListener("keydown",f)}},[i]),n.length===0?null:s.jsxs("div",{ref:u,className:U("relative",o),children:[s.jsx(G,{variant:"ghost",size:"sm",icon:t??s.jsx(Po,{className:"size-5"}),onClick:()=>c(d=>!d),"aria-label":e,"aria-haspopup":"menu","aria-expanded":i,className:U(a&&"min-h-11 min-w-11 px-0")}),i&&s.jsx("div",{role:"menu",className:U("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:()=>{c(!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 ds="min-h-11 min-w-11 px-0";function Jo({hasThread:e,onReply:t,onReplyAll:n,onForward:r,isStarred:a,onToggleStar:o,onDelete:i,isRead:c,onToggleRead:u,moveSlot:d,overflowItems:f=[],onUnavailable:m,unavailableHint:h,className:p}){const b=(v,g)=>()=>{if(!e){m?.(v);return}g?.()},x=u?[{key:"toggle-read",label:c?"Mark as unread":"Mark as read",icon:c?s.jsx(Co,{className:"size-4"}):s.jsx(Es,{className:"size-4"}),onSelect:b("toggleRead",u)}]:[];return s.jsxs("div",{className:U("relative",p),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($o,{className:"size-5"}),onClick:b("reply",t),"aria-label":"Reply",title:"Reply",className:ds}),s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(Bo,{className:"size-5"}),onClick:b("replyAll",n),"aria-label":"Reply all",title:"Reply all",className:ds}),s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(zo,{className:"size-5"}),onClick:b("forward",r),"aria-label":"Forward",title:"Forward",className:ds}),s.jsx("div",{className:"flex-1"}),s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(vt,{className:U("size-5",a&&"fill-warning text-warning")}),onClick:b("star",o),"aria-label":a?"Unstar":"Star","aria-pressed":a,title:a?"Unstar":"Star",className:ds}),d,s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(et,{className:"size-5"}),onClick:b("delete",i),"aria-label":"Move to Trash",title:"Move to Trash",className:ds}),s.jsx(Vu,{triggerLabel:"More actions",items:[...x,...f]})]}),!e&&h&&s.jsx("p",{role:"status",className:"border-b border-line bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:h})]})}function Yu({hasThread:e,onUnavailable:t,unavailableHint:n,isStarred:r,showTriage:a=!0,onReply:o,onReplyAll:i,onForward:c,onDelete:u,onToggleStar:d,moveSlot:f,onMove:m,replyTitle:h="Reply (r)",replyAllTitle:p="Reply all (a)",forwardTitle:b="Forward (f)",deleteTitle:x="Move to Trash (#)",flagTitle:v="Star (s)",children:g,className:y}){const w=(j,I)=>()=>{if(!e){t?.(j);return}I?.()};return s.jsxs("div",{className:"relative",children:[s.jsxs("header",{className:U("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($o,{className:"size-4"}),title:h,"aria-label":"Reply",onClick:w("reply",o)}),s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(Bo,{className:"size-4"}),title:p,"aria-label":"Reply all",onClick:w("replyAll",i)}),s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(zo,{className:"size-4"}),title:b,"aria-label":"Forward",onClick:w("forward",c)}),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(et,{className:"size-4"}),title:x,"aria-label":"Move to Trash",onClick:w("delete",u)}),f??s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(Lo,{className:"size-4"}),title:"Move to mailbox","aria-label":"Move to mailbox",onClick:w("move",m)}),s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(vt,{className:U("size-4",r&&"fill-warning text-warning")}),title:v,"aria-label":"Star",onClick:w("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 Gu=(e,t)=>{const r=e==="newsletter"||e==="marketing"||t;return{framed:r,isPlain:!r}},Xu=()=>`
|
|
3
|
+
/* Zero the UA default body margin and clamp the document to the iframe width so
|
|
4
|
+
wide author markup can't push the body (and the page) past the viewport. */
|
|
5
|
+
html, body {
|
|
6
|
+
margin: 0;
|
|
7
|
+
padding: 0;
|
|
8
|
+
max-width: 100%;
|
|
9
|
+
}
|
|
10
|
+
body {
|
|
11
|
+
overflow-wrap: anywhere;
|
|
12
|
+
word-break: break-word;
|
|
13
|
+
}
|
|
14
|
+
/* Media never wider than the frame; keep aspect ratio when width is capped. */
|
|
15
|
+
img, video, iframe, svg, canvas {
|
|
16
|
+
max-width: 100% !important;
|
|
17
|
+
height: auto;
|
|
18
|
+
}
|
|
19
|
+
/* Fixed-width author tables (\`<table width="600">\`) collapse to fit. */
|
|
20
|
+
table {
|
|
21
|
+
max-width: 100% !important;
|
|
22
|
+
table-layout: auto;
|
|
23
|
+
}
|
|
24
|
+
/* Cells carry the fixed widths in real newsletters (\`<td width="600">\`);
|
|
25
|
+
cap them too or the table can't actually shrink. */
|
|
26
|
+
td, th {
|
|
27
|
+
max-width: 100% !important;
|
|
28
|
+
}
|
|
29
|
+
/* \`max-width\` alone can't beat an inline \`min-width\`; zeroing the min lets
|
|
30
|
+
flex / grid / table children actually collapse to the clamped width. */
|
|
31
|
+
* {
|
|
32
|
+
min-width: 0;
|
|
33
|
+
}
|
|
34
|
+
/* Long unbroken strings (URLs, tokens) wrap instead of forcing a wide line. */
|
|
35
|
+
pre, code {
|
|
36
|
+
white-space: pre-wrap;
|
|
37
|
+
overflow-wrap: anywhere;
|
|
38
|
+
word-break: break-word;
|
|
39
|
+
}
|
|
40
|
+
`,Ju=e=>{const t=new Map;for(const n of e){if(!n.contentId||n.contentUrl.length===0)continue;const r=n.contentId.replace(/^<|>$/g,"");t.set(r,n.contentUrl)}return n=>t.get(n.replace(/^<|>$/g,""))},Zu=/^(none|transparent|inherit|initial|unset)\s*$/i,ed=e=>{const t=[],n=/<style[^>]*>([\s\S]*?)<\/style>/gi;let r;for(r=n.exec(e);r!==null;)t.push(r[1]),r=n.exec(e);return t},td=e=>{const t=/background(?:-color)?\s*:\s*([^;}\n]+)/gi;let n;for(n=t.exec(e);n!==null;){const r=n[1].trim();if(!Zu.test(r))return!0;n=t.exec(e)}return!1},sd=e=>{if(/\bstyle\s*=\s*["'][^"']*background/i.test(e)||/\bbgcolor\s*=/i.test(e))return!0;for(const t of ed(e))if(td(t))return!0;return!1},nd=["script","iframe","object","embed","form","input","button","textarea","select","meta","link","base"],rd=["onerror","onload","onclick","onmouseover","onmouseout","onfocus","onblur","onsubmit","onkeydown","onkeyup","formaction","xlink:href","data-bind"],ad="data:image/svg+xml,"+encodeURIComponent(`
|
|
41
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100">
|
|
42
|
+
<rect fill="#f0f0f0" width="100" height="100"/>
|
|
43
|
+
<text x="50" y="50" text-anchor="middle" dy=".3em" fill="#999" font-size="12">
|
|
44
|
+
Image blocked
|
|
45
|
+
</text>
|
|
46
|
+
</svg>
|
|
47
|
+
`),od=e=>e.replace(/url\s*\([^)]*\)/gi,"none").replace(/expression\s*\([^)]*\)/gi,"").replace(/-moz-binding\s*:[^;]*/gi,""),id=e=>e.replace(/@import[^;]*;/gi,"/* @import blocked */").replace(/url\s*\([^)]*\)/gi,"none").replace(/expression\s*\([^)]*\)/gi,"").replace(/-moz-binding\s*:[^;]*/gi,""),ld=(e={})=>{const t=io(),n={FORBID_TAGS:nd,FORBID_ATTR:rd,ALLOW_DATA_ATTR:!1,ALLOW_UNKNOWN_PROTOCOLS:!1};return t.addHook("afterSanitizeAttributes",r=>{if(r.tagName==="IMG"){const a=r.getAttribute("src")||"";if(a.startsWith("data:"))return;if(a.startsWith("cid:")){const i=a.slice(4).replace(/^<|>$/g,""),c=e.resolveCid?.(i);c&&(r.setAttribute("src",c),r.classList.add("inline-content"));return}e.allowExternalImages||(r.setAttribute("data-blocked-src",a),r.setAttribute("src",ad),r.setAttribute("alt","[Blocked image]"),r.classList.add("blocked-image"))}if(r.tagName==="A"){const a=r.getAttribute("href")||"";if(/^(javascript|data):/i.test(a)){r.removeAttribute("href");return}r.setAttribute("target","_blank"),r.setAttribute("rel","noopener noreferrer nofollow"),r.classList.add("external-link")}if(r.hasAttribute("style")){const a=r.getAttribute("style")||"";r.setAttribute("style",od(a))}}),t.addHook("uponSanitizeElement",(r,a)=>{if(a.tagName==="style"){const o=r.textContent||"";r.textContent=id(o)}}),r=>{const a=sd(r),o=t.sanitize(r,n);return{html:`<style>${Xu()}</style>${o}`,hasAuthorBackground:a}}},cd='"Geist Variable", "Geist", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',Wr={light:{fg:"oklch(0.3 0.025 235)",surface:"oklch(0.975 0.012 90)",accent:"oklch(0.55 0.14 150)"},dark:{fg:"oklch(0.88 0.02 90)",surface:"oklch(0.25 0.025 220)",accent:"oklch(0.78 0.16 150)"}},ud=/prefers-color-scheme\s*:\s*dark|color-scheme\s*:\s*[^;}"']*\bdark\b/i,Vr='<meta name="viewport" content="width=device-width, initial-scale=1">',dd=e=>{const t=e?Wr.dark:Wr.light;return`
|
|
48
|
+
/* Plain-email base: UI font-stack + theme-aware colors (#424) */
|
|
49
|
+
html, body {
|
|
50
|
+
font-family: ${cd};
|
|
51
|
+
font-size: 14px;
|
|
52
|
+
line-height: 1.6;
|
|
53
|
+
color: ${t.fg};
|
|
54
|
+
background-color: ${t.surface};
|
|
55
|
+
margin: 0;
|
|
56
|
+
padding: 0;
|
|
57
|
+
}
|
|
58
|
+
/* Strip author unreadable text colors and element backgrounds, scoped to body
|
|
59
|
+
descendants so the themed html/body surface above survives this reset. */
|
|
60
|
+
body * {
|
|
61
|
+
color: inherit !important;
|
|
62
|
+
background-color: transparent !important;
|
|
63
|
+
}
|
|
64
|
+
a, a:visited {
|
|
65
|
+
color: ${t.accent} !important;
|
|
66
|
+
text-decoration: underline;
|
|
67
|
+
}
|
|
68
|
+
`},fd=(e,t)=>e?t?"html,body{margin:0;color-scheme:dark light}":"html{margin:0;background-color:#ffffff;filter:invert(0.92) hue-rotate(180deg)}body{margin:0}img,picture,video,svg,canvas,[style*='background-image'],[background]{filter:invert(0.92) hue-rotate(180deg)}":"html,body{margin:0;background-color:#ffffff;color-scheme:light}",md=(e,t,n)=>{if(t==="plain")return`${Vr}<style>${dd(n)}</style>${e}`;const r=ud.test(e);return`${Vr}<style>${fd(n,r)}</style>${e}`},hd=5e4,gd=1e4,xd="(max-width: 640px)",pd=.4,bd="allow-same-origin allow-popups allow-popups-to-escape-sandbox",Yr=(e,t,n)=>Math.min(Math.ceil(Math.max(e,t)),n),vd=(e,t)=>e<=0||t<=0||e<=t?1:Math.max(pd,t/e),yd=e=>{const[t,n]=l.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return l.useEffect(()=>{if(typeof window>"u"||!window.matchMedia)return;const r=window.matchMedia(e);n(r.matches);const a=o=>n(o.matches);return r.addEventListener("change",a),()=>r.removeEventListener("change",a)},[e]),t},wd=new Set(["Enter","Escape","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End"]),jd=e=>e===" "?!1:e.length===1?!0:wd.has(e),Gr=e=>{if(e.metaKey||e.ctrlKey||e.altKey||!jd(e.key))return;const t=e.currentTarget??e.target,n=t?.defaultView?.parent;!n||n===t?.defaultView||n.dispatchEvent(new KeyboardEvent("keydown",{key:e.key,code:e.code,shiftKey:e.shiftKey,bubbles:!0,cancelable:!0}))},Xr=({html:e,variant:t="framed",isDark:n=!1,className:r})=>{const a=l.useRef(null),o=l.useRef(null),[i,c]=l.useState(0),[u,d]=l.useState(0),[f,m]=l.useState(0),h=yd(xd),p=l.useMemo(()=>md(e,t,n),[e,t,n]);l.useEffect(()=>{const w=a.current;if(!w)return;const j=()=>m(N=>N===w.clientWidth?N:w.clientWidth);j();const I=new ResizeObserver(j);return I.observe(w),()=>I.disconnect()},[]),l.useEffect(()=>{const w=o.current;if(!w)return;const j=()=>{const C=w.contentDocument;if(!C?.body)return;const k=C.documentElement,M=Yr(C.body.scrollHeight,k?.scrollHeight??0,hd);c(D=>D===M?D:M);const R=Yr(C.body.scrollWidth,k?.scrollWidth??0,gd);d(D=>D===R?D:R)};let I,N;const S=()=>{j();const C=w.contentDocument;C?.body&&(I=new ResizeObserver(j),I.observe(C.body),C.documentElement&&I.observe(C.documentElement),C.addEventListener("keydown",Gr),N=C)};return w.addEventListener("load",S),()=>{w.removeEventListener("load",S),N?.removeEventListener("keydown",Gr),I?.disconnect()}},[]);const b=h?vd(u,f):1,x=b<1,v=x?`${u}px`:h?"100%":t==="framed"&&u>0?`max(100%, ${u}px)`:u===0?"100%":`${u}px`,g=i===0?"1px":`${i}px`,y=s.jsx("iframe",{ref:o,title:"Email content",sandbox:bd,srcDoc:p,className:x?void 0:r,scrolling:"no",style:{width:v,maxWidth:x?"none":void 0,border:"none",display:"block",height:g,overflow:"hidden",transform:x?`scale(${b})`:void 0,transformOrigin:x?"top left":void 0,colorScheme:"normal"}});return s.jsx("div",{ref:a,className:x?r:void 0,children:x?s.jsx("div",{style:{width:"100%",height:`${Math.ceil(i*b)}px`,overflow:"hidden"},children:y}):y})},Jr=()=>s.jsx("p",{className:"text-fg-muted text-sm italic",children:"This message has no body content."}),Zo=({html:e,text:t,isDark:n=!1,category:r,allowImages:a=!1,resolveCid:o,className:i,renderBlockedNotice:c})=>{const u=l.useMemo(()=>!e||typeof document>"u"?null:ld({allowExternalImages:a,resolveCid:o})(e),[e,a,o]),d=u?.html??null,{framed:f,isPlain:m}=Gu(r,u?.hasAuthorBackground??!1),h=l.useMemo(()=>!d||a?0:(d.match(/data-blocked-src/g)||[]).length,[d,a]);return!d&&!t?s.jsx("div",{className:U("message-body",i),children:s.jsx(Jr,{})}):s.jsxs("div",{className:U("message-body",i),children:[h>0&&c?.(h),d?f?s.jsx("div",{className:"w-full max-w-full overflow-x-auto",children:s.jsx(Xr,{html:d,variant:"framed",isDark:n})}):s.jsx("div",{className:"max-w-full overflow-x-auto lg:max-w-2xl",children:s.jsx(Xr,{html:d,variant:m?"plain":"framed",isDark:n})}):t?s.jsx("pre",{className:"email-text whitespace-pre-wrap text-sm leading-relaxed",children:t}):s.jsx(Jr,{})]})};function as({message:e="Select a thread to read",icon:t,showHints:n=!0,className:r}){return s.jsxs("div",{className:U("flex flex-1 flex-col items-center justify-center text-center",r),children:[t??s.jsx(Jn,{className:"size-10 text-fg-subtle"}),s.jsx("p",{className:"mt-3 text-sm text-fg-muted",children:e}),n&&s.jsxs("p",{className:"text-2xs text-fg-subtle",children:[s.jsx(Wt,{children:"j"})," / ",s.jsx(Wt,{children:"k"})," to move, ",s.jsx(Wt,{children:"Enter"})," to open"]})]})}function ei({message:e,onClick:t,isFocused:n,isUnread:r,trailing:a}){const o=s.jsxs(s.Fragment,{children:[s.jsx(Xt,{className:"size-3.5 shrink-0 text-fg-subtle"}),s.jsxs("div",{className:"relative shrink-0",children:[s.jsx(Ze,{name:e.fromName,email:e.fromEmail,size:"md"}),r&&s.jsx("span",{className:"absolute -top-0.5 -right-0.5 size-2 rounded-full border border-canvas bg-accent"})]}),s.jsx("span",{className:U("w-36 shrink-0 truncate text-sm",r?"font-semibold text-fg":"font-medium text-fg-muted"),children:e.fromName}),s.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-fg-subtle",children:e.snippet}),a??s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.dateLabel})]}),i=U("group flex h-section-row w-full items-center gap-3 border-b border-line px-2 text-left transition-colors hover:bg-surface-sunken lg:px-4",n&&"bg-surface-sunken ring-1 ring-inset ring-accent/30");return t?s.jsx("div",{role:"button",tabIndex:0,"aria-expanded":!1,onClick:t,onKeyDown:c=>{mc(c)&&(c.preventDefault(),t())},className:U(i,"cursor-pointer"),children:o}):s.jsx("div",{className:i,children:o})}function ti({message:e,warning:t,onHeaderClick:n,isFocused:r,senderBadge:a,trailing:o,to:i,indicators:c,actionMenu:u,actionBar:d,body:f}){const m=s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[s.jsxs("span",{className:"text-sm font-semibold text-fg",children:[e.fromName,a]}),o??s.jsx("span",{className:"text-2xs text-fg-subtle",children:e.dateLabel})]}),s.jsx("div",{className:"text-xs text-fg-subtle",children:e.fromEmail}),i!==null&&s.jsx("div",{className:"text-xs text-fg-subtle",children:i??s.jsxs(s.Fragment,{children:["to ",e.toLabel]})})]});return s.jsxs("div",{className:U("px-2 py-3 lg:px-4",r&&"ring-1 ring-inset ring-accent/30"),children:[s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx(xt,{className:"mt-1 size-3.5 shrink-0 text-fg-subtle"}),s.jsx(Ze,{name:e.fromName,email:e.fromEmail,size:"md"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[n?s.jsx("button",{type:"button",onClick:n,className:"w-full text-left",children:m}):m,c]}),u&&s.jsx("div",{className:"shrink-0",children:u})]}),t&&s.jsxs("div",{className:"mt-3 flex items-start gap-3 rounded-md bg-danger-soft p-3",children:[s.jsx(Is,{className:"mt-0.5 size-4 shrink-0 text-danger"}),s.jsxs("div",{className:"text-sm text-fg",children:[s.jsx("span",{className:"font-semibold text-danger",children:"Caution: "}),t," ",s.jsx("button",{type:"button",className:"text-accent underline",children:"Why?"})]})]}),d&&s.jsx("div",{className:"mt-3 -mx-2 lg:-mx-4",children:d}),f??s.jsx(Zo,{className:"mt-3",html:e.bodyHtml,category:e.framed?"newsletter":"personal",allowImages:!0})]})}function Sd({thread:e,onBack:t,intelligence:n,intelligenceOpen:r,onToggleIntelligence:a,actions:o,children:i,touchHandlers:c}){const[u,d]=l.useState(!1),f=a!==void 0,m=f?r??!1:u,h=!!n||f,p=()=>{if(f){a?.();return}d(x=>!x)},b=()=>{if(f){m&&a?.();return}d(!1)};return s.jsxs("article",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line bg-surface px-row-inset",children:[s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(To,{className:"size-4"}),onClick:t,"aria-label":"Back to messages",className:"-ml-1 shrink-0"}),s.jsx("h2",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e.subject}),h&&s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(lo,{className:"size-4"}),onClick:p,"aria-label":m?"Hide intelligence panel":"Show intelligence panel","aria-pressed":m,title:"Intelligence",className:U("shrink-0",m&&"bg-accent-2-soft text-accent-2")})]}),s.jsx("div",{className:"flex-1 overflow-y-auto",style:c?{touchAction:"pan-y"}:void 0,...c,children:i??e.messages.map(x=>{const v=g=>g?()=>g(x.id):void 0;return x.expanded?s.jsx(ti,{message:x,warning:e.warning,onHeaderClick:v(o?.onToggleExpand),actionBar:s.jsx(Jo,{hasThread:!0,onReply:v(o?.onReply),onReplyAll:v(o?.onReplyAll),onForward:v(o?.onForward),onToggleStar:v(o?.onToggleStar),onDelete:v(o?.onDelete),onToggleRead:v(o?.onToggleRead),moveSlot:o?.moveSlot?.(x.id)})},x.id):s.jsx(ei,{message:x,onClick:v(o?.onToggleExpand)},x.id)})}),n&&!f&&s.jsx(co,{open:m,onClose:b,title:"Intelligence",anchor:"right",className:"p-0",children:s.jsx(qo,{data:n,onClose:b,className:"h-full w-full border-l-0"})})]})}function Nd({active:e,dimmed:t,indent:n}){return U("flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-sm transition-colors",n&&"pl-7",e?"bg-accent-2-soft font-medium text-accent-2":"text-fg-muted hover:bg-surface hover:text-fg",t&&"opacity-55")}function kd({icon:e,label:t,count:n,active:r}){return s.jsxs(s.Fragment,{children:[e&&s.jsx("span",{className:U("shrink-0",r?"text-accent-2":"text-fg-subtle"),children:e}),s.jsx("span",{className:"flex-1 truncate",children:t}),n!=null&&n>0&&s.jsx("span",{className:U("text-2xs tabular-nums",r?"text-accent-2":"text-fg-subtle"),children:n})]})}function bs({icon:e,label:t,count:n,active:r,dimmed:a,indent:o,navId:i,linkComponent:c,ariaLabel:u,title:d,onClick:f}){const m=Nd({active:r,dimmed:a,indent:o}),h=s.jsx(kd,{icon:e,label:t,count:n,active:r});return i&&c?c({navId:i,className:m,ariaLabel:u??t,title:d,onClick:f,children:h}):s.jsx("button",{type:"button",onClick:f,className:m,"aria-label":u,title:d,children:h})}const Zr={inbox:0,flagged:1,drafts:2,sent:3,archive:4,all:5,junk:6,trash:7};function Cd(e){switch(e){case"inbox":return s.jsx(Jn,{className:"size-4"});case"flagged":return s.jsx(vt,{className:"size-4"});case"drafts":return s.jsx(Eo,{className:"size-4"});case"sent":return s.jsx(ks,{className:"size-4"});case"archive":return s.jsx(du,{className:"size-4"});case"all":return s.jsx(uu,{className:"size-4"});case"junk":return s.jsx(hc,{className:"size-4"});case"trash":return s.jsx(et,{className:"size-4"})}}const ea=e=>e.role!=null,yn=8,ta="remit.nav.folders.open.",sa="remit.nav.account.open.";function na(e,t,n){if(typeof localStorage>"u")return n;const r=localStorage.getItem(e+t);return r===null?n:r!=="0"}function ra(e,t,n){typeof localStorage>"u"||localStorage.setItem(e+t,n?"1":"0")}function Ed({query:e,onSelect:t,onRemove:n}){return s.jsxs("div",{className:"group flex w-full items-center gap-1 rounded-md pr-1 hover:bg-surface",children:[s.jsxs("button",{type:"button",onClick:t,className:"flex min-w-0 flex-1 items-center gap-2 px-2 py-1 text-left text-sm text-fg-muted transition-colors hover:text-fg",children:[s.jsx(Ns,{className:"size-4 shrink-0 text-fg-subtle"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:e})]}),n&&s.jsx("button",{type:"button",onClick:n,"aria-label":`Remove saved search: ${e}`,className:"shrink-0 rounded-full p-1 text-fg-subtle opacity-0 transition-opacity hover:bg-surface-sunken hover:text-fg group-hover:opacity-100 focus-visible:opacity-100",children:s.jsx(Be,{className:"size-3.5"})})]})}function Id({savedSearches:e,saveableQuery:t,onSelectSavedSearch:n,onRemoveSavedSearch:r,onSaveCurrentSearch:a}){return e.length===0&&!t?null:s.jsxs("div",{className:"mt-3",children:[s.jsx("div",{className:"px-2 pb-1 text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Saved searches"}),t&&s.jsxs("button",{type:"button",onClick:a,className:"flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-sm text-accent transition-colors hover:bg-surface",children:[s.jsx(ju,{className:"size-4 shrink-0"}),s.jsxs("span",{className:"min-w-0 flex-1 truncate",children:["Save “",t,"”"]})]}),e.map(o=>s.jsx(Ed,{query:o,onSelect:()=>n?.(o),onRemove:r?()=>r(o):void 0},o))]})}function Rd({account:e,selectedNavId:t,onSelectNav:n,linkComponent:r}){const[a,o]=l.useState(()=>na(sa,e.id,!0)),[i,c]=l.useState(()=>na(ta,e.id,!0)),[u,d]=l.useState(!1),f=()=>{o(y=>{const w=!y;return ra(sa,e.id,w),w})},m=()=>{c(y=>{const w=!y;return ra(ta,e.id,w),w})},h=e.mailboxes.filter(ea).sort((y,w)=>Zr[y.role]-Zr[w.role]),p=e.mailboxes.filter(y=>!ea(y)),b=u||p.length<=yn?p:p.slice(0,yn),x=p.length-b.length,v=e.status??"ready",g=v==="ready"&&h.length===0&&p.length===0;return s.jsxs("div",{className:"mt-3",children:[s.jsxs("button",{type:"button",onClick:f,"aria-expanded":a,className:U("flex w-full items-center gap-1.5 px-2 pb-1 text-left transition-colors hover:text-fg",e.muted&&"opacity-55"),children:[a?s.jsx(xt,{className:"size-3 shrink-0 text-fg-subtle"}):s.jsx(Xt,{className:"size-3 shrink-0 text-fg-subtle"}),s.jsx("span",{className:"truncate text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e.label}),e.muted&&s.jsxs(s.Fragment,{children:[s.jsx(Do,{className:"size-3 shrink-0 text-fg-subtle"}),s.jsx("span",{className:"text-2xs text-fg-subtle",children:"muted"})]})]}),a&&s.jsxs(s.Fragment,{children:[v==="loading"&&s.jsx("div",{className:"px-2 py-1 text-sm text-fg-muted",children:"Loading…"}),v==="error"&&s.jsxs("div",{role:"alert",className:"mx-2 my-1 flex items-start gap-2 rounded-md border border-danger/40 bg-danger-soft px-2 py-1.5 text-sm",children:[s.jsx(Rt,{className:"mt-0.5 size-4 shrink-0 text-danger","aria-hidden":"true"}),s.jsx("div",{className:"min-w-0 flex-1",children:s.jsx("p",{className:"font-medium text-danger",children:"Couldn't load mailboxes"})}),e.onRetry&&s.jsx("button",{type:"button",onClick:e.onRetry,className:"shrink-0 text-sm font-medium text-accent hover:underline",children:"Retry"})]}),g&&s.jsx("div",{className:"px-2 py-1 text-sm text-fg-muted",children:"No mailboxes"}),v==="ready"&&s.jsxs(s.Fragment,{children:[h.map(y=>s.jsx(bs,{navId:y.id,linkComponent:r,icon:Cd(y.role),label:y.name,ariaLabel:y.name,title:y.fullPath??y.name,count:y.unseen,active:t===y.id,dimmed:e.muted,onClick:()=>n?.(y.id)},y.id)),e.outboxPending!==void 0&&s.jsx(bs,{navId:"outbox",linkComponent:r,icon:s.jsx(ks,{className:"size-4"}),label:"Outbox",ariaLabel:"Outbox",count:e.outboxPending>0?e.outboxPending:void 0,active:t==="outbox",dimmed:e.muted,onClick:()=>n?.("outbox")}),p.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs("button",{type:"button",onClick:m,"aria-expanded":i,className:"mt-1 flex w-full items-center gap-1 px-2 py-1 text-left text-2xs font-semibold uppercase tracking-wider text-fg-subtle transition-colors hover:text-fg",children:[i?s.jsx(xt,{className:"size-3 shrink-0"}):s.jsx(Xt,{className:"size-3 shrink-0"}),s.jsx("span",{className:"flex-1",children:"Folders"}),s.jsx("span",{className:"tabular-nums opacity-70",children:p.length})]}),i&&s.jsxs(s.Fragment,{children:[b.map(y=>s.jsx(bs,{navId:y.id,linkComponent:r,icon:s.jsx(cu,{className:"size-4"}),label:y.name,ariaLabel:y.name,title:y.fullPath??y.name,count:y.unseen,active:t===y.id,dimmed:e.muted,onClick:()=>n?.(y.id)},y.id)),(x>0||u)&&p.length>yn&&s.jsx("button",{type:"button",onClick:()=>d(y=>!y),className:"ml-7 flex items-center px-2 py-1 text-2xs font-medium text-accent transition-colors hover:underline",children:u?"Show less":`Show all (${p.length})`})]})]})]})]})]})}function Md({accounts:e,selectedNavId:t,briefUnseen:n,onSelectNav:r,variant:a="desktop",linkComponent:o,savedSearches:i=[],saveableQuery:c,onSelectSavedSearch:u,onRemoveSavedSearch:d,onSaveCurrentSearch:f}){const m=s.jsxs("nav",{className:a==="drawer"?"px-2 py-2":"flex-1 overflow-y-auto px-2 py-2","aria-label":"Mailboxes",children:[s.jsx(bs,{navId:"brief",linkComponent:o,icon:s.jsx(Xe,{className:"size-4"}),label:"Daily brief",ariaLabel:"Daily brief",count:n,active:t==="brief",onClick:()=>r?.("brief")}),s.jsx(bs,{navId:"flagged",linkComponent:o,icon:s.jsx(vt,{className:"size-4"}),label:"Starred",ariaLabel:"Starred",active:t==="flagged",onClick:()=>r?.("flagged")}),s.jsx(Id,{savedSearches:i,saveableQuery:c,onSelectSavedSearch:u,onRemoveSavedSearch:d,onSaveCurrentSearch:f}),e.length===0?s.jsx("div",{className:"px-2 py-4 text-center text-sm text-fg-muted",children:"No accounts configured"}):e.map(h=>s.jsx(Rd,{account:h,selectedNavId:t,onSelectNav:r,linkComponent:o},h.id))]});return a==="drawer"?m:s.jsx("aside",{className:"flex h-full w-full flex-col bg-surface-sunken",children:m})}function Td({leading:e,search:t,actions:n,className:r}){return s.jsxs("header",{className:U("flex min-h-16 w-full shrink-0 items-center gap-3 border-b border-line bg-canvas px-3 py-2",r),children:[e&&s.jsx("div",{className:"flex shrink-0 items-center gap-2",children:e}),s.jsx("div",{className:"flex min-w-0 flex-1 justify-start",children:s.jsx("div",{className:"w-full max-w-2xl",children:t})}),n&&s.jsx("div",{className:"flex shrink-0 items-center gap-1",children:n})]})}function Dd({label:e,size:t="sm",onUndo:n,undoLabel:r="Undo",className:a}){return s.jsxs(Ge,{tone:"accent",className:U(t==="md"&&"py-1 text-xs",a),children:[s.jsx(Du,{className:U(t==="sm"?"size-3":"size-3.5","shrink-0"),"aria-hidden":!0}),s.jsx("span",{children:e}),n&&s.jsx("button",{type:"button",onClick:o=>{o.stopPropagation(),n()},className:"font-semibold underline decoration-dotted underline-offset-2 hover:decoration-solid",children:r})]})}const Ad=320,Od="cubic-bezier(0.32, 0.9, 0.3, 1)",Pd=.5,Ld=.4,zd=360;function _d(e){return Math.sign(e)*Math.sqrt(Math.abs(e))*4}function Fd({open:e,onClose:t,children:n,dismissLabel:r="Dismiss"}){const a=l.useRef(null),[o,i]=l.useState(zd),[c,u]=l.useState(null);l.useLayoutEffect(()=>{const g=a.current;if(!g)return;const y=()=>i(g.offsetHeight);y();const w=new ResizeObserver(y);return w.observe(g),()=>w.disconnect()},[]);const d=l.useRef(null),f=l.useCallback(g=>{g.currentTarget.setPointerCapture(g.pointerId),d.current={startY:g.clientY,lastY:g.clientY,lastT:g.timeStamp,velocity:0,moved:!1},u(0)},[]),m=l.useCallback(g=>{const y=d.current;if(!y)return;const w=g.timeStamp-y.lastT;w>0&&(y.velocity=(g.clientY-y.lastY)/w),y.lastY=g.clientY,y.lastT=g.timeStamp;const j=g.clientY-y.startY;Math.abs(j)>4&&(y.moved=!0);const I=j<0?_d(j):j;u(I)},[]),h=l.useCallback(()=>{const g=d.current;if(d.current=null,!g)return;const y=g.lastY-g.startY,j=g.velocity>Pd||y>o*Ld;u(null),j&&t()},[o,t]),p=c!==null,b=e?c??0:o,x=Math.min(Math.max(1-b/o,0),1),v=p?"none":`transform ${Ad}ms ${Od}`;return s.jsxs("div",{className:U("absolute inset-0 z-40 select-none overflow-hidden",e||p?"":"pointer-events-none"),children:[s.jsx("button",{type:"button","aria-label":r,tabIndex:-1,onClick:t,className:U("absolute inset-0 bg-black/40",x>0?"pointer-events-auto":"pointer-events-none"),style:{opacity:x*.6,transition:v.replace("transform","opacity")}}),s.jsxs("div",{ref:a,className:"absolute inset-x-0 bottom-0 flex max-h-[92%] flex-col rounded-t-3xl border-t border-line bg-surface shadow-2xl shadow-black/30",style:{transform:`translateY(${b}px)`,transition:v},children:[s.jsx("div",{role:"slider","aria-label":"Drag down to dismiss","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(x*100),tabIndex:0,onPointerDown:f,onPointerMove:m,onPointerUp:h,onPointerCancel:h,className:"flex cursor-grab touch-none justify-center pb-1 pt-2.5 active:cursor-grabbing",children:s.jsx("div",{className:"h-1 w-10 rounded-full bg-fg-subtle/40"})}),s.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden",children:n})]})]})}const Bd="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",aa="pointer-events-none absolute inset-0 m-auto size-3.5 text-accent-fg";function si({label:e,description:t,indeterminate:n=!1,checked:r,onChange:a,className:o,...i}){const c=l.useRef(null);l.useEffect(()=>{c.current&&(c.current.indeterminate=n)},[n]);const u=s.jsxs("span",{className:"relative inline-flex",children:[s.jsx("input",{ref:c,type:"checkbox",checked:r,onChange:a,className:Bd,...i}),s.jsx(Cs,{className:U(aa,"hidden peer-checked:block"),"aria-hidden":!0}),s.jsx(Cu,{className:U(aa,"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:U("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 $d=({status:e})=>e==="saving"?s.jsx("span",{className:"animate-pulse text-xs text-fg-muted",children:"Saving..."}):e==="saved"?s.jsx("span",{className:"text-xs text-fg-muted",children:"Draft saved"}):e==="error"?s.jsx("span",{className:"text-xs text-danger",children:"Save failed"}):null;function Kd({onSend:e,onDiscard:t,sending:n,canSend:r,saveStatus:a="idle",unavailableReason:o,onUnavailable:i}){return s.jsxs("div",{className:"flex items-center justify-between border-t border-line px-3 py-2",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx(G,{variant:"primary",size:"md","aria-busy":n,title:r?void 0:o,className:"min-h-11 rounded-full px-4",icon:n?s.jsx(Tt,{className:"size-4 animate-spin"}):s.jsx(ks,{className:"size-4"}),onClick:()=>{if(!n){if(!r){o&&i?.(o);return}e()}},children:"Send"}),s.jsx($d,{status:a})]}),s.jsx(G,{variant:"ghost",size:"md","aria-busy":n,"aria-label":"Discard",className:"min-h-11 min-w-11 px-2 hover:text-danger",icon:s.jsx(et,{className:"size-4"}),onClick:()=>{n||t()}})]})}function qd({banner:e,header:t,children:n,quoted:r,actionBar:a}){return s.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e,t,s.jsxs("div",{className:"min-h-0 flex-1 overflow-auto",children:[n,r&&s.jsx("div",{className:"px-3 pb-2",children:r})]}),a]})}function Ud({key:e,shiftKey:t=!1,repeat:n=!1,caretAtStart:r,hasValue:a,chipCount:o}){const i=o-1;return e==="Escape"?a?{type:"clearQuery"}:{type:"blur"}:e==="Tab"&&t?o===0?{type:"none"}:{type:"focusChip",index:i}:e==="Backspace"||e==="ArrowLeft"?!r||o===0?{type:"none"}:n?{type:"none"}:{type:"focusChip",index:i}:{type:"none"}}function Hd({key:e,repeat:t=!1,index:n,chipCount:r}){return e==="Backspace"||e==="Delete"?t?{type:"none"}:{type:"removeChip",index:n}:e==="ArrowLeft"?n===0?{type:"none"}:{type:"focusChip",index:n-1}:e==="ArrowRight"?n>=r-1?{type:"focusInput"}:{type:"focusChip",index:n+1}:e==="Enter"||e===" "?{type:"activateChip",index:n}:e==="Escape"?{type:"focusInput"}:{type:"none"}}function Qd(e,t){const n=t-1;return n<=0?null:e<n?e:n-1}const Wd=e=>e instanceof HTMLElement?e.tagName==="INPUT"||e.tagName==="TEXTAREA"||e.isContentEditable:!1,Vd=({chips:e=[],onRemoveChip:t,onActivateChip:n,value:r,onChange:a,onClear:o,onClearQuery:i,placeholder:c="Search mail...",globalFocusKey:u=!0,showClearButton:d=!0,size:f="sm",inputId:m,chipsLabel:h="Search filters",className:p})=>{const b=l.useId(),x=m??b,v=l.useRef(null),g=l.useRef([]),y=i??o,[w,j]=l.useState(null),I=l.useRef(void 0),[N,S]=l.useState(""),C=e.length>0;l.useEffect(()=>{j(T=>T!==null&&T>=e.length?null:T)},[e.length]),l.useEffect(()=>{const T=I.current;if(T!==void 0){if(I.current=void 0,T===null){v.current?.focus();return}g.current[T]?.focus()}});const k=l.useCallback(T=>{j(T),I.current=T},[]),M=l.useCallback(T=>{const O=e[T];O&&t&&(k(Qd(T,e.length)),S(`${O.label} removed`),t(O.id))},[e,t,k]),R=l.useCallback(()=>{k(null),o()},[o,k]),D=l.useCallback(T=>{const O=T.currentTarget,B=Ud({key:T.key,shiftKey:T.shiftKey,repeat:T.repeat,caretAtStart:O.selectionStart===0&&O.selectionEnd===0,hasValue:r.length>0,chipCount:e.length});switch(B.type){case"focusChip":T.preventDefault(),k(B.index);return;case"clearQuery":y();return;case"blur":O.blur();return;case"none":return}},[e.length,r,y,k]),E=l.useCallback(T=>O=>{const B=Hd({key:O.key,repeat:O.repeat,index:T,chipCount:e.length});switch(B.type!=="none"&&O.preventDefault(),B.type){case"removeChip":M(B.index);return;case"focusChip":k(B.index);return;case"focusInput":k(null);return;case"activateChip":{const q=e[B.index];q&&n&&n(q.id);return}case"none":return}},[e,M,k,n]);return l.useEffect(()=>{if(!u)return;const T=O=>{O.key!=="/"||O.metaKey||O.ctrlKey||O.altKey||Wd(O.target)||(O.preventDefault(),v.current?.focus())};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[u]),s.jsxs("label",{htmlFor:x,className:U("flex w-full items-center gap-1.5 text-sm","bg-surface-sunken/50 border border-transparent","focus-within:bg-canvas focus-within:border-line focus-within:ring-2 focus-within:ring-ring","transition-colors",f==="lg"?"rounded-xl px-4 py-2":"rounded-md px-2.5 py-1",p),children:[s.jsx(Ns,{className:U("shrink-0 text-fg-muted pointer-events-none",f==="lg"?"size-5":"size-4")}),s.jsxs("div",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-1",children:[C&&s.jsx("div",{role:"grid","aria-label":h,className:"flex min-w-0 flex-wrap items-center gap-1",children:e.map((T,O)=>s.jsx(gc,{ref:B=>{g.current[O]=B},label:T.label,tone:T.tone,focused:w===O,onFocusLabel:()=>j(O),onKeyDown:E(O),onRemove:()=>M(O),onActivate:n?()=>n(T.id):void 0},T.id))}),s.jsx("input",{ref:v,id:x,name:"q",type:"text","aria-label":"Search mail",autoComplete:"off",value:r,tabIndex:w===null?0:-1,onChange:T=>a(T.target.value),onKeyDown:D,onFocus:()=>j(null),placeholder:C?void 0:c,className:"min-w-24 flex-1 bg-transparent text-fg outline-none placeholder:text-fg-muted"})]}),(r||C)&&d&&s.jsx("button",{type:"button",onClick:R,className:"shrink-0 rounded p-0.5 hover:bg-surface-raised transition-colors","aria-label":"Clear search",children:s.jsx(Be,{className:U("text-fg-muted",f==="lg"?"size-5":"size-4")})}),s.jsx("span",{role:"status","aria-live":"polite",className:"sr-only",children:N})]})},gr=({value:e,onChange:t,onClear:n,onClearQuery:r,chips:a,onRemoveChip:o,placeholder:i="Search mail...",globalFocusKey:c=!0,showClearButton:u=!0,size:d,inputId:f,className:m})=>s.jsx(Vd,{value:e,onChange:t,onClear:n,onClearQuery:r,chips:a,onRemoveChip:o,placeholder:i,globalFocusKey:c,showClearButton:u,size:d,inputId:f,className:m});function Yd({title:e,unreadCount:t,isDesktop:n,onMenuClick:r,searchValue:a,onSearchChange:o,onSearchClear:i,searchOpen:c,onSearchOpenChange:u,showSearch:d=!0}){const f=`${t.toLocaleString()} unread`,m=i??(()=>o("")),h=()=>{m(),u(!1)},p=x=>s.jsx(gr,{value:a,onChange:o,onClear:m,globalFocusKey:!1,showClearButton:x}),b=s.jsx(G,{variant:"ghost",icon:s.jsx(fr,{className:"size-5"}),onClick:r,"aria-label":"Menu",className:"min-h-11 min-w-11 shrink-0 px-0"});return s.jsx("header",{className:"flex shrink-0 flex-col bg-canvas",children:s.jsx("div",{className:"flex h-12 items-center gap-2 px-row-inset",children:d?n?s.jsxs(s.Fragment,{children:[b,s.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e}),s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle",children:f}),s.jsx("div",{className:"w-64 max-w-[40%] shrink-0",children:p(!0)})]}):c||a.trim().length>0?s.jsxs("div",{className:"flex flex-1 items-center gap-1",children:[s.jsx("div",{className:"flex-1",children:p(!1)}),s.jsx(G,{variant:"ghost",icon:s.jsx(Be,{className:"size-5"}),onClick:h,"aria-label":"Close search",className:"min-h-11 min-w-11 shrink-0 px-0"})]}):s.jsxs(s.Fragment,{children:[b,s.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e}),s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle",children:f}),s.jsx(G,{variant:"ghost",icon:s.jsx(Ns,{className:"size-5"}),onClick:()=>u(!0),"aria-label":"Search",className:"min-h-11 min-w-11 shrink-0 px-0"})]}):s.jsxs(s.Fragment,{children:[b,s.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e}),s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle",children:f})]})})})}const Gd=(e,t)=>e==="vip"?"vip":e==="unknown"&&t==="md"?"unknown-pill":"hidden",ni=({senderTrust:e,size:t="sm",className:n})=>{const r=Gd(e,t);return r==="vip"?s.jsx(Xe,{className:U("text-warning shrink-0",t==="sm"&&"size-3.5",t==="md"&&"size-4",n),"aria-label":"VIP sender","data-testid":"sender-trust-vip"}):r==="unknown-pill"?s.jsx("span",{className:U("inline-flex items-center rounded border border-dashed border-fg-subtle/40 font-medium uppercase tracking-wide text-fg-muted/80 shrink-0","px-2 py-0.5 text-xs",n),title:"First message from this sender","aria-label":"First message from this sender","data-testid":"sender-trust-unknown",children:"new"}):null};function oa(e,t){const n=t?.trim();if(!n)return e;const r=e.toLowerCase(),a=n.toLowerCase(),o=[];let i=0,c=r.indexOf(a,i),u=0;for(;c!==-1;)c>i&&o.push(e.slice(i,c)),o.push(s.jsx("mark",{className:"bg-transparent font-semibold text-fg",children:e.slice(c,c+a.length)},u++)),i=c+a.length,c=r.indexOf(a,i);return i<e.length&&o.push(e.slice(i)),o}function Xd({result:e,onClick:t,query:n}){return s.jsxs("button",{type:"button",onClick:t,className:"flex w-full flex-col gap-0.5 border-b border-line px-row-inset py-2.5 text-left transition-colors hover:bg-surface-sunken",children:[s.jsxs("div",{className:"flex items-baseline gap-2",children:[s.jsx("span",{className:U("min-w-0 flex-1 truncate text-sm",e.unread?"font-semibold text-fg":"font-medium text-fg-muted"),children:e.sender}),s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.date})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:U("min-w-0 flex-1 truncate text-sm",e.unread?"text-fg":"text-fg-muted"),children:oa(e.subject,n)}),e.flagged&&s.jsx(Su,{className:"size-3.5 shrink-0 fill-warning text-warning"})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-fg-subtle",children:oa(e.snippet,n)}),e.category&&s.jsx(Ge,{tone:e.category.tone??"neutral",className:"shrink-0",children:e.category.label}),e.matchedChunkLabel&&s.jsx(Ge,{tone:"neutral",className:"shrink-0",children:`matched: ${e.matchedChunkLabel}`}),e.score!=null&&s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.score.toFixed(2)})]})]})}const ia=6;function Jd({section:e,query:t,onSelectResult:n}){const[r,a]=l.useState(e.initialCollapsed??!1),[o,i]=l.useState(!1),c=e.results.length>ia,d=!o&&c?e.results.slice(0,ia):e.results,f=e.results.length-d.length;return s.jsxs("div",{children:[s.jsxs("button",{type:"button","aria-expanded":!r,onClick:()=>a(m=>!m),className:"sticky top-0 z-10 flex h-section-row w-full items-center gap-1.5 border-b border-line bg-surface-sunken px-row-inset text-left transition-colors hover:bg-surface",children:[s.jsx("span",{className:"flex-1 text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e.label}),s.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:e.results.length}),s.jsx(xt,{className:U("size-3 shrink-0 text-fg-subtle transition-transform duration-200",r?"rotate-0":"rotate-180")})]}),!r&&s.jsxs(s.Fragment,{children:[d.map(m=>s.jsx(Xd,{result:m,query:t,onClick:n?()=>n(m):void 0},m.id)),c&&s.jsxs("button",{type:"button",onClick:()=>i(m=>!m),className:"flex w-full items-center justify-center border-b border-line px-row-inset py-1.5 text-2xs font-medium text-accent transition-colors hover:bg-surface",children:[o?"Show less":`Show ${f} more`,!o&&s.jsx(xt,{className:"ml-1 size-3"})]})]})]})}function ri({value:e,recentSearches:t,onPickRecent:n,sections:r,loading:a,onSelectResult:o,tokens:i}){const c=e.trim().length>0,u=(r??[]).some(f=>f.results.length>0);if(!c)return t&&t.length>0?s.jsxs("div",{className:"flex flex-col",children:[s.jsx("h3",{className:"px-row-inset pb-1 pt-3 text-2xs font-semibold uppercase tracking-wide text-fg-subtle",children:"Recent searches"}),t.map(f=>s.jsxs("button",{type:"button",onClick:()=>n?.(f),className:"flex w-full items-center gap-2.5 border-b border-line px-row-inset py-2.5 text-left transition-colors hover:bg-surface-sunken",children:[s.jsx(hr,{className:"size-4 shrink-0 text-fg-subtle"}),s.jsx("span",{className:"min-w-0 flex-1 truncate text-sm text-fg-muted",children:f})]},f))]}):s.jsx("p",{className:"px-row-inset py-6 text-center text-sm text-fg-subtle",children:"Search across your mail by sender, subject or words in the message."});const d=i&&i.length>0&&s.jsx(xc,{tokens:i});return a?s.jsxs("div",{className:"flex flex-col",children:[d,s.jsx("div",{className:"flex flex-col gap-3 px-row-inset py-4",children:[0,1,2,3].map(f=>s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("div",{className:"h-3 w-1/3 animate-pulse rounded bg-surface-sunken"}),s.jsx("div",{className:"h-3 w-2/3 animate-pulse rounded bg-surface-sunken"}),s.jsx("div",{className:"h-2.5 w-1/2 animate-pulse rounded bg-surface-sunken"})]},f))})]}):u?s.jsxs("div",{className:"flex flex-col",children:[d,r?.filter(f=>f.results.length>0).map(f=>s.jsx(Jd,{section:f,query:e,onSelectResult:o},f.id))]}):s.jsxs("div",{className:"flex flex-col",children:[d,s.jsxs("div",{className:"px-row-inset py-10 text-center",children:[s.jsxs("p",{className:"text-sm font-medium text-fg",children:["No matches for “",e,"”"]}),s.jsx("p",{className:"mt-1 text-xs text-fg-subtle",children:"Try a different word, or adjust the filters above."})]})]})}function Zd({value:e,onChange:t,onClear:n,onCancel:r,filter:a,recentSearches:o,onPickRecent:i,sections:c,loading:u,onSelectResult:d,tokens:f,chips:m,onRemoveChip:h}){const p=s.jsx(ri,{value:e,recentSearches:o,onPickRecent:i,sections:c,loading:u,onSelectResult:d,tokens:f});return s.jsxs("article",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line bg-surface px-row-inset",children:[s.jsx("div",{className:"min-w-0 flex-1",children:s.jsx(gr,{value:e,onChange:t,onClear:n,chips:m,onRemoveChip:h,globalFocusKey:!1,showClearButton:!1})}),s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(Be,{className:"size-4"}),onClick:r,"aria-label":"Clear and close search",className:"-mr-1 shrink-0"})]}),a?s.jsx(Zn,{...a,children:p}):s.jsx("div",{className:"flex-1 overflow-y-auto",children:p})]})}const la="w-full text-left px-3 py-2.5 min-h-11 flex items-center gap-2 transition-colors text-sm rounded-md focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-canvas",ef={searchPlaceholder:"Move to…",searchAriaLabel:"Filter folders",listAriaLabel:"Destination folders",currentSuffix:"(current folder)",currentTag:"current",emptyMessage:e=>`No folders match "${e}"`,optionLabel:e=>`Move to ${e}`},wn=e=>{for(let t=0;t<e.length;t+=1)if(!e[t]?.isCurrent)return t;return-1},tf=e=>{for(let t=e.length-1;t>=0;t-=1)if(!e[t]?.isCurrent)return t;return-1},ca=(e,t,n)=>{const r=e.length;if(r<=0)return-1;const a=t<0?n===1?-1:r:t;for(let o=1;o<=r;o+=1){const i=((a+n*o)%r+r)%r;if(!e[i]?.isCurrent)return i}return-1},sf=(e,t)=>e.label.toLowerCase().includes(t)?!0:e.searchValue?.toLowerCase().includes(t)??!1,ai=({mailboxes:e,onSelect:t,onCancel:n,autoFocus:r=!1,labels:a})=>{const o={...ef,...a},[i,c]=l.useState(""),[u,d]=l.useState(()=>wn(e)),f=l.useRef(null),m=l.useRef([]);l.useEffect(()=>{r&&f.current?.focus()},[r]);const h=i.trim().toLowerCase(),p=l.useMemo(()=>h?e.filter(g=>sf(g,h)):[...e],[e,h]);l.useEffect(()=>{d(g=>g>=0&&g<p.length&&!p[g]?.isCurrent?g:wn(p))},[p]),l.useEffect(()=>{if(u<0)return;const g=m.current[u];g&&document.activeElement!==f.current&&g.focus()},[u]);const b=l.useCallback(()=>{if(u<0)return;const g=p[u];!g||g.isCurrent||t(g.id)},[u,p,t]),x=l.useCallback(g=>{switch(g.key){case"ArrowDown":g.preventDefault(),d(y=>ca(p,y,1));return;case"ArrowUp":g.preventDefault(),d(y=>ca(p,y,-1));return;case"Home":g.preventDefault(),d(wn(p));return;case"End":g.preventDefault(),d(tf(p));return;case"Enter":case" ":g.preventDefault(),b();return;case"Escape":g.preventDefault(),n?.();return;default:return}},[p,b,n]),v=l.useCallback(g=>{if(g.key==="ArrowDown"){if(g.preventDefault(),p.length===0)return;m.current[u>=0?u:0]?.focus();return}g.key==="Escape"&&(g.preventDefault(),n?.())},[p.length,u,n]);return s.jsxs("div",{className:"flex flex-col",children:[s.jsx(uo,{variant:"inline",className:"border-b border-line px-3 py-2",icon:s.jsx(Ns,{className:"size-4","aria-hidden":"true"}),ref:f,type:"search",value:i,onChange:g=>c(g.target.value),onKeyDown:v,placeholder:o.searchPlaceholder,"aria-label":o.searchAriaLabel}),s.jsx("div",{className:"flex-1 overflow-y-auto py-1",role:"listbox","aria-label":o.listAriaLabel,onKeyDown:x,children:p.length===0?s.jsx("div",{className:"px-3 py-3 text-sm text-fg-muted","aria-live":"polite",children:o.emptyMessage(i)}):p.map((g,y)=>{const w=g.isCurrent??!1,j=y===u;return w?s.jsx("div",{children:s.jsxs("div",{role:"option","aria-selected":!1,"aria-current":"true","aria-label":`${g.label} ${o.currentSuffix}`,className:U(la,"opacity-60 bg-surface-sunken/40"),children:[s.jsx("span",{className:"truncate flex-1",children:g.label}),s.jsx("span",{className:"text-xs text-fg-muted shrink-0",children:o.currentTag})]})},g.id):s.jsx("div",{children:s.jsx("button",{ref:I=>{m.current[y]=I},type:"button",role:"option","aria-selected":!1,tabIndex:j?0:-1,onClick:()=>t(g.id),onFocus:()=>d(y),"aria-label":o.optionLabel(g.label),className:U(la,"hover:bg-surface-raised"),children:s.jsx("span",{className:"truncate flex-1",children:g.label})})},g.id)})})]})},nf={queued:{icon:hr,label:"Queued",className:"text-warning"},sending:{icon:Tt,label:"Sending…",className:"text-accent-2",spin:!0},sent:{icon:Ao,label:"Sent",className:"text-positive"},failed:{icon:Rt,label:"Failed",className:"text-danger"},blocked:{icon:er,label:"Blocked",className:"text-warning"}};function ua({status:e,iconOnly:t,className:n}){const r=nf[e],a=r.icon;return s.jsxs("span",{className:U("inline-flex items-center gap-1.5 text-xs font-medium",r.className,n),children:[s.jsx(a,{className:U("size-4",r.spin&&"animate-spin")}),!t&&r.label]})}const rf=(e,t)=>t?"bg-accent-2-soft":e==="failed"?"bg-danger-soft":e==="blocked"?"bg-warning/10":"";function af({recipients:e,subject:t,time:n,status:r,error:a,selected:o,onSelect:i,onRetry:c,retrying:u,onEdit:d,onDelete:f,deleting:m}){const h=r==="failed"||r==="blocked";return s.jsxs("div",{className:U("flex items-start gap-3 border-b border-line px-4 py-3 transition-colors hover:bg-surface-raised",rf(r,o)),children:[s.jsxs("button",{type:"button",onClick:i,className:"flex flex-1 min-w-0 items-start gap-3 text-left",children:[s.jsx("div",{className:"mt-0.5 shrink-0",children:s.jsx(ua,{status:r,iconOnly:!0})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"truncate text-sm font-medium",children:e}),s.jsx("span",{className:"shrink-0 text-xs text-fg-muted",children:n})]}),s.jsx("div",{className:"truncate text-sm",children:t||"No subject"}),s.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[s.jsx(ua,{status:r}),a&&s.jsxs("span",{className:"truncate text-xs text-fg-muted",children:["— ",a]})]})]})]}),h&&s.jsx("div",{className:"shrink-0",children:s.jsx(fu,{actions:[...r==="failed"&&c?[{label:"Retry sending",iconOnly:!0,icon:s.jsx(Iu,{className:"size-3.5"}),busy:u,onClick:c}]:[],{label:"Edit as draft",iconOnly:!0,icon:s.jsx(ks,{className:"size-3.5"}),onClick:d}],destructive:{label:"Delete message",iconOnly:!0,icon:s.jsx(et,{className:"size-3.5"}),busy:m,confirm:{prompt:"Delete this message?",confirmLabel:"Delete"},onClick:f}})})]})}const of=e=>{const[t,n]=l.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return l.useEffect(()=>{if(typeof window>"u"||!window.matchMedia)return;const r=window.matchMedia(e);n(r.matches);const a=o=>n(o.matches);return r.addEventListener("change",a),()=>r.removeEventListener("change",a)},[e]),t},lf=({children:e,onRefresh:t,isRefreshing:n})=>of("(min-width: 1024px)")?e:s.jsx(pc,{onRefresh:t,isPullable:!n,children:e}),cf=({text:e,html:t,senderName:n,date:r})=>{const[a,o]=l.useState(!1);if(!e&&!t)return null;const i=[n,r].filter(Boolean).join(" on ");return s.jsxs("div",{className:"mt-2 px-3 pb-2",children:[s.jsxs("button",{type:"button",onClick:()=>o(!a),"aria-expanded":a,className:"flex items-center gap-1 text-xs text-fg-muted hover:text-fg transition-colors",children:[a?s.jsx(xt,{className:"size-3"}):s.jsx(Xt,{className:"size-3"}),i?`${i} wrote:`:"Show quoted text"]}),a&&s.jsx("blockquote",{className:"mt-2 pl-3 border-l-2 border-fg-subtle/30 text-sm text-fg-muted [&_a]:text-accent [&_a]:underline [&_blockquote]:pl-3 [&_blockquote]:border-l-2 [&_blockquote]:border-fg-subtle/30",children:t?s.jsx("div",{dangerouslySetInnerHTML:{__html:t}}):e.split(`
|
|
69
|
+
`).map((c,u)=>s.jsx("p",{className:"min-h-[1.2em]",children:c},u))})]})},uf=e=>e===1?"message":"messages";function df({count:e,onReview:t,onDismiss:n,actionLabel:r="Review & rescue"}){return s.jsx(fo,{tone:"info",variant:"soft",onDismiss:n,children:s.jsxs("div",{className:"flex flex-col gap-2",children:[s.jsxs("p",{className:"flex items-start gap-2 text-sm text-fg",children:[s.jsx(Rs,{className:"mt-0.5 size-4 shrink-0 text-positive","aria-hidden":!0}),s.jsxs("span",{children:[s.jsx("span",{className:"font-semibold text-fg",children:`${e} ${uf(e)} here`})," ","may not be spam — they're from senders we can verify."]})]}),s.jsx(G,{variant:"primary",size:"sm",onClick:t,className:"self-start",children:r})]})})}function ff({candidate:e,selected:t,onToggle:n,hideSender:r=!1}){const{senderName:a,senderAddress:o,subject:i,snippet:c,trustReason:u,trustSubReason:d,senderTrust:f}=e;return s.jsxs("label",{className:U("flex w-full cursor-pointer items-start gap-3 px-3 py-2.5 text-left transition-colors",r&&"pl-11",t?"bg-positive/10":"bg-surface hover:bg-surface-sunken"),children:[s.jsx(si,{className:"mt-0.5",checked:t,onChange:n,"aria-label":`${t?"Deselect":"Select"} ${r?i:`message from ${a}`}`}),!r&&s.jsx(Ze,{name:a,email:o,size:"sm"}),s.jsxs("span",{className:"min-w-0 flex-1",children:[!r&&s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"truncate text-sm font-medium text-fg",children:a}),f&&s.jsx(ni,{senderTrust:f,size:"sm"}),s.jsx("span",{className:"truncate text-2xs text-fg-subtle",children:o})]}),s.jsx("span",{className:"block truncate text-sm text-fg-muted",children:i}),s.jsx("span",{className:"block line-clamp-1 text-xs text-fg-subtle",children:c}),!r&&s.jsxs("span",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[s.jsxs(Ge,{tone:"positive",children:[s.jsx(Rs,{className:"size-3","aria-hidden":!0}),u]}),s.jsx("span",{className:"text-2xs text-fg-subtle",children:d})]})]})]})}const mf=e=>{const t=new Map,n=[];for(const r of e){const a=(r.senderAddress||r.senderName).toLowerCase(),o=t.get(a);if(o){o.messages.push(r);continue}t.set(a,{key:a,senderName:r.senderName,senderAddress:r.senderAddress,trustReason:r.trustReason,trustSubReason:r.trustSubReason,senderTrust:r.senderTrust,messages:[r]}),n.push(a)}return n.map(r=>t.get(r)).sort((r,a)=>a.messages.length-r.messages.length)},hf=(e,t)=>{const n=e.messages.filter(r=>t.has(r.id)).length;return n===0?"none":n===e.messages.length?"all":"some"},da=e=>e===1?"message":"messages";function gf({group:e,selected:t,onToggleGroup:n,onToggleMessage:r}){const[a,o]=l.useState(!1),i=hf(e,t),c=e.messages.length,u=a?xt:Xt;return s.jsxs("div",{className:U(i!=="none"?"bg-positive/10":"bg-surface"),children:[s.jsxs("div",{className:"flex w-full items-start gap-3 px-3 py-2.5",children:[s.jsx(si,{className:"mt-0.5",checked:i==="all",indeterminate:i==="some",onChange:()=>n(e,i!=="all"),"aria-label":`${i==="all"?"Deselect":"Select"} all ${c} ${da(c)} from ${e.senderName}`}),s.jsx(Ze,{name:e.senderName,email:e.senderAddress,size:"sm"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"truncate text-sm font-medium text-fg",children:e.senderName}),e.senderTrust&&s.jsx(ni,{senderTrust:e.senderTrust,size:"sm"}),s.jsx("span",{className:"truncate text-2xs text-fg-subtle",children:e.senderAddress})]}),s.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[s.jsxs(Ge,{tone:"positive",children:[s.jsx(Rs,{className:"size-3","aria-hidden":!0}),e.trustReason]}),s.jsx("span",{className:"text-2xs text-fg-subtle",children:e.trustSubReason})]})]}),s.jsxs("button",{type:"button",onClick:()=>o(d=>!d),"aria-expanded":a,className:"flex shrink-0 items-center gap-1 rounded-md px-1.5 py-1 text-2xs text-fg-muted transition-colors hover:bg-surface-sunken hover:text-fg",children:[`${c} ${da(c)}`,s.jsx(u,{className:"size-3.5","aria-hidden":!0})]})]}),a&&s.jsx("div",{className:"divide-y divide-line border-t border-line",children:e.messages.map(d=>s.jsx(ff,{candidate:d,selected:t.has(d.id),onToggle:()=>r(d.id),hideSender:!0},d.id))})]})}const xr=e=>e===1?"message":"messages",xf=(e,t)=>`Moves ${e===1?"this message":`these ${e} ${xr(e)}`} out of Spam to ${t} now. Nothing later.`,Bn=(e,t)=>e.find(n=>n.id===t)?.label??"Inbox";function pf(){return s.jsx(fo,{tone:"info",variant:"soft",children:s.jsx("p",{className:"text-2xs text-fg-muted",children:"We list a message here only when we can confirm the sender is who they say — usually someone you've emailed before, write to often, or a service that consistently checks out. We never guess from words in the subject. Anything we can't confirm stays in Spam."})})}function bf({candidates:e,selected:t,onToggle:n,onToggleGroup:r,onSelectAll:a,onSelectNone:o,onContinue:i,onCancel:c}){const[u,d]=l.useState(!1),f=t.size,m=l.useMemo(()=>mf(e),[e]);return s.jsxs("div",{className:"flex min-h-0 flex-col",children:[s.jsxs("div",{className:"px-row-inset pb-2 pt-1",children:[s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs("h2",{className:"flex items-center gap-2 text-sm font-semibold text-fg",children:[s.jsx(Rs,{className:"size-4 text-positive","aria-hidden":!0}),"Rescue from Spam"]}),s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(iu,{className:"size-3.5"}),onClick:()=>d(h=>!h),className:"-mr-1.5 -mt-0.5",children:"Why these?"})]}),s.jsx("p",{className:"mt-1 text-2xs text-fg-subtle",children:"These look safe — from senders we can verify. Uncheck any sender that belongs in Spam, or open a sender to pick individual messages."}),u&&s.jsx("div",{className:"mt-2",children:s.jsx(pf,{})})]}),s.jsxs("div",{className:"flex items-center justify-between px-row-inset pb-1.5",children:[s.jsx("span",{className:"text-2xs font-medium text-fg-muted",children:`${f} of ${e.length} selected · ${m.length} ${m.length===1?"sender":"senders"}`}),s.jsxs("span",{className:"flex gap-1",children:[s.jsx(G,{variant:"ghost",size:"sm",onClick:a,children:"Select all"}),s.jsx(G,{variant:"ghost",size:"sm",onClick:o,children:"Select none"})]})]}),s.jsx("div",{className:"min-h-0 flex-1 divide-y divide-line overflow-y-auto border-y border-line",children:m.map(h=>s.jsx(gf,{group:h,selected:t,onToggleGroup:r,onToggleMessage:n},h.key))}),s.jsxs("div",{className:"space-y-2 border-t border-line bg-surface px-row-inset py-3",children:[s.jsx(G,{variant:"primary",onClick:i,className:"h-11 w-full font-semibold",children:`Continue with ${f} ${xr(f)}`}),s.jsx(G,{variant:"ghost",onClick:c,className:"h-11 w-full",children:"Cancel"})]})]})}function vf({count:e,folders:t,destination:n,onPick:r,onMove:a,onBack:o}){const[i,c]=l.useState(!1);return s.jsxs("div",{className:"flex min-h-0 flex-col",children:[s.jsxs("div",{className:"px-row-inset pb-2 pt-1",children:[s.jsx("h2",{className:"text-sm font-semibold text-fg",children:"Where should they go?"}),s.jsx("p",{className:"mt-1 text-2xs text-fg-subtle",children:"Pick a folder, then we move them out of Spam."})]}),s.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-row-inset py-2",children:i?s.jsx("div",{className:"overflow-hidden rounded-xl border border-line bg-surface",children:s.jsx(ai,{mailboxes:t,autoFocus:!0,onSelect:u=>{r(u),c(!1)},onCancel:()=>c(!1)})}):s.jsxs("div",{className:"rounded-xl border border-line bg-surface-sunken p-3",children:[s.jsx("p",{className:"text-2xs text-fg-subtle",children:"Destination"}),s.jsx("p",{className:"mt-0.5 text-sm font-medium text-fg",children:Bn(t,n)}),s.jsx(G,{variant:"ghost",size:"sm",onClick:()=>c(!0),className:"mt-2 px-0",children:"Move to a different folder"})]})}),s.jsxs("div",{className:"space-y-2 border-t border-line bg-surface px-row-inset py-3",children:[s.jsx("p",{className:"text-2xs text-fg-subtle",children:xf(e,Bn(t,n))}),s.jsx(G,{variant:"primary",onClick:a,className:"h-11 w-full font-semibold",children:`Move ${e} out of Spam`}),s.jsx(G,{variant:"ghost",onClick:o,className:"h-11 w-full",children:"Back"})]})]})}function yf({count:e,destinationLabel:t,onClose:n}){return s.jsxs("div",{className:"flex min-h-0 flex-col",children:[s.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 px-row-inset py-10 text-center",children:[s.jsx(mr,{className:"size-10 text-positive","aria-hidden":!0}),s.jsx("p",{className:"text-base font-semibold text-fg",children:`Moved ${e} ${xr(e)} out of Spam.`}),s.jsx("p",{className:"text-2xs text-fg-subtle",children:`You'll find them in ${t}.`})]}),s.jsx("div",{className:"border-t border-line bg-surface px-row-inset py-3",children:s.jsx(G,{variant:"primary",onClick:n,className:"h-11 w-full font-semibold",children:"Done"})})]})}function wf({open:e,candidates:t,defaultDestinationId:n,availableFolders:r,onConfirmMove:a,onCancel:o}){const[i,c]=l.useState("review"),[u,d]=l.useState(()=>e?new Set(t.map(w=>w.id)):new Set),[f,m]=l.useState(n),[h,p]=l.useState(0),b=l.useRef(!1);l.useEffect(()=>{e&&!b.current&&(c("review"),d(new Set(t.map(w=>w.id))),m(n),p(0)),b.current=e},[e,t,n]);const x=u.size,v=w=>{d(j=>{const I=new Set(j);return I.has(w)?I.delete(w):I.add(w),I})},g=(w,j)=>{d(I=>{const N=new Set(I);for(const S of w.messages)j?N.add(S.id):N.delete(S.id);return N})},y=()=>{const w=Array.from(u);p(w.length),a(w,f),c("done")};return s.jsxs(Fd,{open:e,onClose:o,dismissLabel:"Close rescue",children:[i==="review"&&s.jsx(bf,{candidates:t,selected:u,onToggle:v,onToggleGroup:g,onSelectAll:()=>d(new Set(t.map(w=>w.id))),onSelectNone:()=>d(new Set),onContinue:()=>c("destination"),onCancel:o}),i==="destination"&&s.jsx(vf,{count:x,folders:r,destination:f,onPick:m,onMove:y,onBack:()=>c("review")}),i==="done"&&s.jsx(yf,{count:h,destinationLabel:Bn(r,f),onClose:o})]})}const pr=[{id:"all",label:"All",tone:"neutral"},{id:"personal",label:"Personal",tone:"accent"},{id:"transactional",label:"Transactional",tone:"positive"},{id:"newsletter",label:"Newsletter",tone:"neutral"},{id:"marketing",label:"Marketing",tone:"warning"},{id:"social",label:"Social",tone:"warning"},{id:"automated",label:"Automated",tone:"neutral"}],oi={id:"unread",label:"Unread"},jf={id:"flagged",label:"Starred"},ii={id:"attachment",label:"Has attachment"};function Sf(e){if(!(e.length<=1))return e.map(t=>({id:t.id,label:t.label,count:t.count,active:t.active}))}function Nf(e=[]){return{categories:[...pr],filters:bc,sources:Sf(e)}}function kf(){return{categories:[...pr],filters:[oi,jf,ii]}}function Cf(){return{categories:[...pr],filters:[oi,ii]}}function ht(e,t,{checkForDefaultPrevented:n=!0}={}){return function(a){if(e?.(a),n===!1||!a||!a.defaultPrevented)return t?.(a)}}function fa(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Ef(...e){return t=>{let n=!1;const r=e.map(a=>{const o=fa(a,t);return!n&&typeof o=="function"&&(n=!0),o});if(n)return()=>{for(let a=0;a<r.length;a++){const o=r[a];typeof o=="function"?o():fa(e[a],null)}}}}function Dt(...e){return l.useCallback(Ef(...e),e)}function If(e,t=[]){let n=[];function r(o,i){const c=l.createContext(i);c.displayName=o+"Context";const u=n.length;n=[...n,i];const d=m=>{const{scope:h,children:p,...b}=m,x=h?.[e]?.[u]||c,v=l.useMemo(()=>b,Object.values(b));return s.jsx(x.Provider,{value:v,children:p})};d.displayName=o+"Provider";function f(m,h,p={}){const{optional:b=!1}=p,x=h?.[e]?.[u]||c,v=l.useContext(x);if(v)return v;if(i!==void 0)return i;if(!b)throw new Error(`\`${m}\` must be used within \`${o}\``)}return[d,f]}const a=()=>{const o=n.map(i=>l.createContext(i));return function(c){const u=c?.[e]||o;return l.useMemo(()=>({[`__scope${e}`]:{...c,[e]:u}}),[c,u])}};return a.scopeName=e,[r,Rf(a,...t)]}function Rf(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(a=>({useScope:a(),scopeName:a.scopeName}));return function(o){const i=r.reduce((c,{useScope:u,scopeName:d})=>{const m=u(o)[`__scope${d}`];return{...c,...m}},{});return l.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var ws=globalThis?.document?l.useLayoutEffect:()=>{},Mf=tr[" useInsertionEffect ".trim().toString()]||ws;function Tf({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[a,o,i]=Df({defaultProp:t,onChange:n}),c=e!==void 0,u=c?e:a;{const f=l.useRef(e!==void 0);l.useEffect(()=>{const m=f.current;m!==c&&console.warn(`${r} is changing from ${m?"controlled":"uncontrolled"} to ${c?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),f.current=c},[c,r])}const d=l.useCallback(f=>{if(c){const m=Af(f)?f(e):f;m!==e&&i.current?.(m)}else o(f)},[c,e,o,i]);return[u,d]}function Df({defaultProp:e,onChange:t}){const[n,r]=l.useState(e),a=l.useRef(n),o=l.useRef(t);return Mf(()=>{o.current=t},[t]),l.useEffect(()=>{a.current!==n&&(o.current?.(n),a.current=n)},[n,a]),[n,r,o]}function Af(e){return typeof e=="function"}function br(e){const t=l.forwardRef((n,r)=>{let{children:a,...o}=n,i=null,c=!1;const u=[];ma(a)&&typeof _s=="function"&&(a=_s(a._payload)),l.Children.forEach(a,h=>{if(_f(h)){c=!0;const p=h;let b="child"in p.props?p.props.child:p.props.children;ma(b)&&typeof _s=="function"&&(b=_s(b._payload)),i=Pf(p,b),u.push(i?.props?.children)}else u.push(h)}),i?i=l.cloneElement(i,void 0,u):!c&&l.Children.count(a)===1&&l.isValidElement(a)&&(i=a);const d=i?zf(i):void 0,f=Dt(r,d);if(!i){if(a||a===0)throw new Error(c?Kf(e):$f(e));return a}const m=Lf(o,i.props??{});return i.type!==l.Fragment&&(m.ref=r?f:d),l.cloneElement(i,m)});return t.displayName=`${e}.Slot`,t}var Lv=br("Slot"),Of=Symbol.for("radix.slottable"),Pf=(e,t)=>{if("child"in e.props){const n=e.props.child;return l.isValidElement(n)?l.cloneElement(n,void 0,e.props.children(n.props.children)):null}return l.isValidElement(t)?t:null};function Lf(e,t){const n={...t};for(const r in t){const a=e[r],o=t[r];/^on[A-Z]/.test(r)?a&&o?n[r]=(...c)=>{const u=o(...c);return a(...c),u}:a&&(n[r]=a):r==="style"?n[r]={...a,...o}:r==="className"&&(n[r]=[a,o].filter(Boolean).join(" "))}return{...e,...n}}function zf(e){let t=Object.getOwnPropertyDescriptor(e.props,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=Object.getOwnPropertyDescriptor(e,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}function _f(e){return l.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===Of}var Ff=Symbol.for("react.lazy");function ma(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===Ff&&"_payload"in e&&Bf(e._payload)}function Bf(e){return typeof e=="object"&&e!==null&&"then"in e}var $f=e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,Kf=e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,_s=tr[" use ".trim().toString()],qf=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],ct=qf.reduce((e,t)=>{const n=br(`Primitive.${t}`),r=l.forwardRef((a,o)=>{const{asChild:i,...c}=a,u=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),s.jsx(u,{...c,ref:o})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Uf(e,t){e&&sr.flushSync(()=>e.dispatchEvent(t))}function js(e){const t=l.useRef(e);return l.useEffect(()=>{t.current=e}),l.useMemo(()=>((...n)=>t.current?.(...n)),[])}var Hf="DismissableLayer",$n="dismissableLayer.update",Qf="dismissableLayer.pointerDownOutside",Wf="dismissableLayer.focusOutside",ha,vr=l.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),li=l.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,deferPointerDownOutside:r=!1,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:i,onInteractOutside:c,onDismiss:u,...d}=e,f=l.useContext(vr),[m,h]=l.useState(null),p=m?.ownerDocument??globalThis?.document,[,b]=l.useState({}),x=Dt(t,h),v=Array.from(f.layers),[g]=[...f.layersWithOutsidePointerEventsDisabled].slice(-1),y=g?v.indexOf(g):-1,w=m?v.indexOf(m):-1,j=f.layersWithOutsidePointerEventsDisabled.size>0,I=w>=y,N=l.useRef(!1),S=Jf(R=>{o?.(R),c?.(R),R.defaultPrevented||u?.()},{ownerDocument:p,deferPointerDownOutside:r,isDeferredPointerDownOutsideRef:N,dismissableSurfaces:f.dismissableSurfaces,shouldHandlePointerDownOutside:l.useCallback(R=>{if(!(R instanceof Node))return!1;const D=[...f.branches].some(E=>E.contains(R));return I&&!D},[f.branches,I])}),C=Zf(R=>{if(r&&N.current)return;const D=R.target;[...f.branches].some(T=>T.contains(D))||(i?.(R),c?.(R),R.defaultPrevented||u?.())},p),k=m?w===v.length-1:!1,M=js(R=>{R.key==="Escape"&&(a?.(R),!R.defaultPrevented&&u&&(R.preventDefault(),u()))});return l.useEffect(()=>{if(k)return p.addEventListener("keydown",M,{capture:!0}),()=>p.removeEventListener("keydown",M,{capture:!0})},[p,k,M]),l.useEffect(()=>{if(m)return n&&(f.layersWithOutsidePointerEventsDisabled.size===0&&(ha=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),f.layersWithOutsidePointerEventsDisabled.add(m)),f.layers.add(m),ga(),()=>{n&&(f.layersWithOutsidePointerEventsDisabled.delete(m),f.layersWithOutsidePointerEventsDisabled.size===0&&(p.body.style.pointerEvents=ha))}},[m,p,n,f]),l.useEffect(()=>()=>{m&&(f.layers.delete(m),f.layersWithOutsidePointerEventsDisabled.delete(m),ga())},[m,f]),l.useEffect(()=>{const R=()=>b({});return document.addEventListener($n,R),()=>document.removeEventListener($n,R)},[]),s.jsx(ct.div,{...d,ref:x,style:{pointerEvents:j?I?"auto":"none":void 0,...e.style},onFocusCapture:ht(e.onFocusCapture,C.onFocusCapture),onBlurCapture:ht(e.onBlurCapture,C.onBlurCapture),onPointerDownCapture:ht(e.onPointerDownCapture,S.onPointerDownCapture)})});li.displayName=Hf;var Vf="DismissableLayerBranch",Yf=l.forwardRef((e,t)=>{const n=l.useContext(vr),r=l.useRef(null),a=Dt(t,r);return l.useEffect(()=>{const o=r.current;if(o)return n.branches.add(o),()=>{n.branches.delete(o)}},[n.branches]),s.jsx(ct.div,{...e,ref:a})});Yf.displayName=Vf;function Gf(){const e=l.useContext(vr),[t,n]=l.useState(null);return l.useEffect(()=>{if(t)return e.dismissableSurfaces.add(t),()=>{e.dismissableSurfaces.delete(t)}},[t,e.dismissableSurfaces]),n}var Xf=()=>!0;function Jf(e,t){const{ownerDocument:n=globalThis?.document,deferPointerDownOutside:r=!1,isDeferredPointerDownOutsideRef:a,dismissableSurfaces:o,shouldHandlePointerDownOutside:i=Xf}=t,c=js(e),u=l.useRef(!1),d=l.useRef(!1),f=l.useRef(new Map),m=l.useRef(()=>{});return l.useEffect(()=>{function h(){d.current=!1,a.current=!1,f.current.clear()}function p(){return Array.from(f.current.values()).some(Boolean)}function b(w){if(!d.current)return;const j=w.target;j instanceof Node&&[...o].some(N=>N.contains(j))||f.current.set(w.type,!0),w.type==="click"&&window.setTimeout(()=>{d.current&&m.current()},0)}function x(w){d.current&&f.current.set(w.type,!1)}const v=w=>{if(w.target&&!u.current){let j=function(){n.removeEventListener("click",m.current);const N=p();h(),N||ci(Qf,c,I,{discrete:!0})};if(!i(w.target)){n.removeEventListener("click",m.current),h(),u.current=!1;return}const I={originalEvent:w};d.current=!0,a.current=r&&w.button===0,f.current.clear(),!r||w.button!==0?j():(n.removeEventListener("click",m.current),m.current=j,n.addEventListener("click",m.current,{once:!0}))}else n.removeEventListener("click",m.current),h();u.current=!1},g=["pointerup","mousedown","mouseup","touchstart","touchend","click"];for(const w of g)n.addEventListener(w,b,!0),n.addEventListener(w,x);const y=window.setTimeout(()=>{n.addEventListener("pointerdown",v)},0);return()=>{window.clearTimeout(y),n.removeEventListener("pointerdown",v),n.removeEventListener("click",m.current);for(const w of g)n.removeEventListener(w,b,!0),n.removeEventListener(w,x)}},[n,c,r,a,o,i]),{onPointerDownCapture:()=>u.current=!0}}function Zf(e,t=globalThis?.document){const n=js(e),r=l.useRef(!1);return l.useEffect(()=>{const a=o=>{o.target&&!r.current&&ci(Wf,n,{originalEvent:o},{discrete:!1})};return t.addEventListener("focusin",a),()=>t.removeEventListener("focusin",a)},[t,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function ga(){const e=new CustomEvent($n);document.dispatchEvent(e)}function ci(e,t,n,{discrete:r}){const a=n.originalEvent.target,o=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});t&&a.addEventListener(e,t,{once:!0}),r?Uf(a,o):a.dispatchEvent(o)}var Fs=0,Bt=null;function em(){l.useEffect(()=>{Bt||(Bt={start:xa(),end:xa()});const{start:e,end:t}=Bt;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==t&&document.body.insertAdjacentElement("beforeend",t),Fs++,()=>{Fs===1&&(Bt?.start.remove(),Bt?.end.remove(),Bt=null),Fs=Math.max(0,Fs-1)}},[])}function xa(){const e=document.createElement("span");return e.setAttribute("data-radix-focus-guard",""),e.tabIndex=0,e.style.outline="none",e.style.opacity="0",e.style.position="fixed",e.style.pointerEvents="none",e}var jn="focusScope.autoFocusOnMount",Sn="focusScope.autoFocusOnUnmount",pa={bubbles:!1,cancelable:!0},tm="FocusScope",ui=l.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:a,onUnmountAutoFocus:o,...i}=e,[c,u]=l.useState(null),d=js(a),f=js(o),m=l.useRef(null),h=Dt(t,u),p=l.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;l.useEffect(()=>{if(r){let x=function(w){if(p.paused||!c)return;const j=w.target;c.contains(j)?m.current=j:ft(m.current,{select:!0})},v=function(w){if(p.paused||!c)return;const j=w.relatedTarget;j!==null&&(c.contains(j)||ft(m.current,{select:!0}))},g=function(w){if(document.activeElement===document.body)for(const I of w)I.removedNodes.length>0&&ft(c)};document.addEventListener("focusin",x),document.addEventListener("focusout",v);const y=new MutationObserver(g);return c&&y.observe(c,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",x),document.removeEventListener("focusout",v),y.disconnect()}}},[r,c,p.paused]),l.useEffect(()=>{if(c){va.add(p);const x=document.activeElement;if(!c.contains(x)){const g=new CustomEvent(jn,pa);c.addEventListener(jn,d),c.dispatchEvent(g),g.defaultPrevented||(sm(im(di(c)),{select:!0}),document.activeElement===x&&ft(c))}return()=>{c.removeEventListener(jn,d),setTimeout(()=>{const g=new CustomEvent(Sn,pa);c.addEventListener(Sn,f),c.dispatchEvent(g),g.defaultPrevented||ft(x??document.body,{select:!0}),c.removeEventListener(Sn,f),va.remove(p)},0)}}},[c,d,f,p]);const b=l.useCallback(x=>{if(!n&&!r||p.paused)return;const v=x.key==="Tab"&&!x.altKey&&!x.ctrlKey&&!x.metaKey,g=document.activeElement;if(v&&g){const y=x.currentTarget,[w,j]=nm(y);w&&j?!x.shiftKey&&g===j?(x.preventDefault(),n&&ft(w,{select:!0})):x.shiftKey&&g===w&&(x.preventDefault(),n&&ft(j,{select:!0})):g===y&&x.preventDefault()}},[n,r,p.paused]);return s.jsx(ct.div,{tabIndex:-1,...i,ref:h,onKeyDown:b})});ui.displayName=tm;function sm(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(ft(r,{select:t}),document.activeElement!==n)return}function nm(e){const t=di(e),n=ba(t,e),r=ba(t.reverse(),e);return[n,r]}function di(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const a=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||a?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function ba(e,t){const n=typeof t.checkVisibility=="function"&&t.checkVisibility({checkVisibilityCSS:!0});for(const r of e)if(!(n?!r.checkVisibility({checkVisibilityCSS:!0}):rm(r,{upTo:t})))return r}function rm(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}function am(e){return e instanceof HTMLInputElement&&"select"in e}function ft(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&am(e)&&t&&e.select()}}var va=om();function om(){let e=[];return{add(t){const n=e[0];t!==n&&n?.pause(),e=ya(e,t),e.unshift(t)},remove(t){e=ya(e,t),e[0]?.resume()}}}function ya(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function im(e){return e.filter(t=>t.tagName!=="A")}var lm=tr[" useId ".trim().toString()]||(()=>{}),cm=0;function Nn(e){const[t,n]=l.useState(lm());return ws(()=>{n(r=>r??String(cm++))},[e]),e||(t?`radix-${t}`:"")}var um="Portal",fi=l.forwardRef((e,t)=>{const{container:n,...r}=e,[a,o]=l.useState(!1);ws(()=>o(!0),[]);const i=n||a&&globalThis?.document?.body;return i?sr.createPortal(s.jsx(ct.div,{...r,ref:t}),i):null});fi.displayName=um;function dm(e,t){return l.useReducer((n,r)=>t[n][r]??n,e)}var fn=e=>{const{present:t,children:n}=e,r=fm(t),a=typeof n=="function"?n({present:r.isPresent}):l.Children.only(n),o=mm(r.ref,hm(a));return typeof n=="function"||r.isPresent?l.cloneElement(a,{ref:o}):null};fn.displayName="Presence";function fm(e){const[t,n]=l.useState(),r=l.useRef(null),a=l.useRef(e),o=l.useRef("none"),i=l.useRef(void 0),c=e?"mounted":"unmounted",[u,d]=dm(c,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return l.useEffect(()=>{u==="mounted"?(o.current=i.current??fs(r.current),i.current=void 0):o.current="none"},[u]),ws(()=>{const f=r.current,m=a.current;if(m!==e){const p=o.current,b=fs(f);e?(i.current=b,d("MOUNT")):b==="none"||f?.display==="none"?d("UNMOUNT"):d(m&&p!==b?"ANIMATION_OUT":"UNMOUNT"),a.current=e}},[e,d]),ws(()=>{if(t){let f;const m=t.ownerDocument.defaultView??window,h=b=>{const v=fs(r.current).includes(CSS.escape(b.animationName));if(b.target===t&&v&&(d("ANIMATION_END"),!a.current)){const g=t.style.animationFillMode;t.style.animationFillMode="forwards",f=m.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=g)})}},p=b=>{b.target===t&&(o.current=fs(r.current))};return t.addEventListener("animationstart",p),t.addEventListener("animationcancel",h),t.addEventListener("animationend",h),()=>{m.clearTimeout(f),t.removeEventListener("animationstart",p),t.removeEventListener("animationcancel",h),t.removeEventListener("animationend",h)}}else d("ANIMATION_END")},[t,d]),{isPresent:["mounted","unmountSuspended"].includes(u),ref:l.useCallback(f=>{if(f){const m=getComputedStyle(f);r.current=m,i.current=fs(m)}else r.current=null;n(f)},[])}}function wa(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function mm(...e){const t=l.useRef(e);return t.current=e,l.useCallback(n=>{const r=t.current;let a=!1;const o=r.map(i=>{const c=wa(i,n);return!a&&typeof c=="function"&&(a=!0),c});if(a)return()=>{for(let i=0;i<o.length;i++){const c=o[i];typeof c=="function"?c():wa(r[i],null)}}},[])}function fs(e){return e?.animationName||"none"}function hm(e){let t=Object.getOwnPropertyDescriptor(e.props,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=Object.getOwnPropertyDescriptor(e,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var gm=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},$t=new WeakMap,Bs=new WeakMap,$s={},kn=0,mi=function(e){return e&&(e.host||mi(e.parentNode))},xm=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=mi(n);return r&&e.contains(r)?r:(console.error("aria-hidden",n,"in not contained inside",e,". Doing nothing"),null)}).filter(function(n){return!!n})},pm=function(e,t,n,r){var a=xm(t,Array.isArray(e)?e:[e]);$s[n]||($s[n]=new WeakMap);var o=$s[n],i=[],c=new Set,u=new Set(a),d=function(m){!m||c.has(m)||(c.add(m),d(m.parentNode))};a.forEach(d);var f=function(m){!m||u.has(m)||Array.prototype.forEach.call(m.children,function(h){if(c.has(h))f(h);else try{var p=h.getAttribute(r),b=p!==null&&p!=="false",x=($t.get(h)||0)+1,v=(o.get(h)||0)+1;$t.set(h,x),o.set(h,v),i.push(h),x===1&&b&&Bs.set(h,!0),v===1&&h.setAttribute(n,"true"),b||h.setAttribute(r,"true")}catch(g){console.error("aria-hidden: cannot operate on ",h,g)}})};return f(t),c.clear(),kn++,function(){i.forEach(function(m){var h=$t.get(m)-1,p=o.get(m)-1;$t.set(m,h),o.set(m,p),h||(Bs.has(m)||m.removeAttribute(r),Bs.delete(m)),p||m.removeAttribute(n)}),kn--,kn||($t=new WeakMap,$t=new WeakMap,Bs=new WeakMap,$s={})}},bm=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),a=gm(e);return a?(r.push.apply(r,Array.from(a.querySelectorAll("[aria-live], script"))),pm(r,a,n,"aria-hidden")):function(){return null}},Xs="right-scroll-bar-position",Js="width-before-scroll-bar",vm="with-scroll-bars-hidden",ym="--removed-body-scroll-bar-size";function Cn(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function wm(e,t){var n=l.useState(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(r){var a=n.value;a!==r&&(n.value=r,n.callback(r,a))}}}})[0];return n.callback=t,n.facade}var jm=typeof window<"u"?l.useLayoutEffect:l.useEffect,ja=new WeakMap;function Sm(e,t){var n=wm(null,function(r){return e.forEach(function(a){return Cn(a,r)})});return jm(function(){var r=ja.get(n);if(r){var a=new Set(r),o=new Set(e),i=n.current;a.forEach(function(c){o.has(c)||Cn(c,null)}),o.forEach(function(c){a.has(c)||Cn(c,i)})}ja.set(n,e)},[e]),n}function Nm(e){return e}function km(e,t){t===void 0&&(t=Nm);var n=[],r=!1,a={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(o){var i=t(o,r);return n.push(i),function(){n=n.filter(function(c){return c!==i})}},assignSyncMedium:function(o){for(r=!0;n.length;){var i=n;n=[],i.forEach(o)}n={push:function(c){return o(c)},filter:function(){return n}}},assignMedium:function(o){r=!0;var i=[];if(n.length){var c=n;n=[],c.forEach(o),i=n}var u=function(){var f=i;i=[],f.forEach(o)},d=function(){return Promise.resolve().then(u)};d(),n={push:function(f){i.push(f),d()},filter:function(f){return i=i.filter(f),n}}}};return a}function Cm(e){e===void 0&&(e={});var t=km(null);return t.options=mt({async:!0,ssr:!1},e),t}var hi=function(e){var t=e.sideCar,n=mo(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return l.createElement(r,mt({},n))};hi.isSideCarExport=!0;function Em(e,t){return e.useMedium(t),hi}var gi=Cm(),En=function(){},mn=l.forwardRef(function(e,t){var n=l.useRef(null),r=l.useState({onScrollCapture:En,onWheelCapture:En,onTouchMoveCapture:En}),a=r[0],o=r[1],i=e.forwardProps,c=e.children,u=e.className,d=e.removeScrollBar,f=e.enabled,m=e.shards,h=e.sideCar,p=e.noRelative,b=e.noIsolation,x=e.inert,v=e.allowPinchZoom,g=e.as,y=g===void 0?"div":g,w=e.gapMode,j=mo(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),I=h,N=Sm([n,t]),S=mt(mt({},j),a);return l.createElement(l.Fragment,null,f&&l.createElement(I,{sideCar:gi,removeScrollBar:d,shards:m,noRelative:p,noIsolation:b,inert:x,setCallbacks:o,allowPinchZoom:!!v,lockRef:n,gapMode:w}),i?l.cloneElement(l.Children.only(c),mt(mt({},S),{ref:N})):l.createElement(y,mt({},S,{className:u,ref:N}),c))});mn.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};mn.classNames={fullWidth:Js,zeroRight:Xs};var Im=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Rm(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Im();return t&&e.setAttribute("nonce",t),e}function Mm(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Tm(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Dm=function(){var e=0,t=null;return{add:function(n){e==0&&(t=Rm())&&(Mm(t,n),Tm(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Am=function(){var e=Dm();return function(t,n){l.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},xi=function(){var e=Am(),t=function(n){var r=n.styles,a=n.dynamic;return e(r,a),null};return t},Om={left:0,top:0,right:0,gap:0},In=function(e){return parseInt(e||"",10)||0},Pm=function(e){var t=window.getComputedStyle(document.body),n=t[e==="padding"?"paddingLeft":"marginLeft"],r=t[e==="padding"?"paddingTop":"marginTop"],a=t[e==="padding"?"paddingRight":"marginRight"];return[In(n),In(r),In(a)]},Lm=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Om;var t=Pm(e),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-n+t[2]-t[0])}},zm=xi(),Vt="data-scroll-locked",_m=function(e,t,n,r){var a=e.left,o=e.top,i=e.right,c=e.gap;return n===void 0&&(n="margin"),`
|
|
70
|
+
.`.concat(vm,` {
|
|
71
|
+
overflow: hidden `).concat(r,`;
|
|
72
|
+
padding-right: `).concat(c,"px ").concat(r,`;
|
|
73
|
+
}
|
|
74
|
+
body[`).concat(Vt,`] {
|
|
75
|
+
overflow: hidden `).concat(r,`;
|
|
76
|
+
overscroll-behavior: contain;
|
|
77
|
+
`).concat([t&&"position: relative ".concat(r,";"),n==="margin"&&`
|
|
78
|
+
padding-left: `.concat(a,`px;
|
|
79
|
+
padding-top: `).concat(o,`px;
|
|
80
|
+
padding-right: `).concat(i,`px;
|
|
81
|
+
margin-left:0;
|
|
82
|
+
margin-top:0;
|
|
83
|
+
margin-right: `).concat(c,"px ").concat(r,`;
|
|
84
|
+
`),n==="padding"&&"padding-right: ".concat(c,"px ").concat(r,";")].filter(Boolean).join(""),`
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.`).concat(Xs,` {
|
|
88
|
+
right: `).concat(c,"px ").concat(r,`;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.`).concat(Js,` {
|
|
92
|
+
margin-right: `).concat(c,"px ").concat(r,`;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.`).concat(Xs," .").concat(Xs,` {
|
|
96
|
+
right: 0 `).concat(r,`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.`).concat(Js," .").concat(Js,` {
|
|
100
|
+
margin-right: 0 `).concat(r,`;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
body[`).concat(Vt,`] {
|
|
104
|
+
`).concat(ym,": ").concat(c,`px;
|
|
105
|
+
}
|
|
106
|
+
`)},Sa=function(){var e=parseInt(document.body.getAttribute(Vt)||"0",10);return isFinite(e)?e:0},Fm=function(){l.useEffect(function(){return document.body.setAttribute(Vt,(Sa()+1).toString()),function(){var e=Sa()-1;e<=0?document.body.removeAttribute(Vt):document.body.setAttribute(Vt,e.toString())}},[])},Bm=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,a=r===void 0?"margin":r;Fm();var o=l.useMemo(function(){return Lm(a)},[a]);return l.createElement(zm,{styles:_m(o,!t,a,n?"":"!important")})},Kn=!1;if(typeof window<"u")try{var Ks=Object.defineProperty({},"passive",{get:function(){return Kn=!0,!0}});window.addEventListener("test",Ks,Ks),window.removeEventListener("test",Ks,Ks)}catch{Kn=!1}var Kt=Kn?{passive:!1}:!1,$m=function(e){return e.tagName==="TEXTAREA"},pi=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!$m(e)&&n[t]==="visible")},Km=function(e){return pi(e,"overflowY")},qm=function(e){return pi(e,"overflowX")},Na=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var a=bi(e,r);if(a){var o=vi(e,r),i=o[1],c=o[2];if(i>c)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Um=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},Hm=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},bi=function(e,t){return e==="v"?Km(t):qm(t)},vi=function(e,t){return e==="v"?Um(t):Hm(t)},Qm=function(e,t){return e==="h"&&t==="rtl"?-1:1},Wm=function(e,t,n,r,a){var o=Qm(e,window.getComputedStyle(t).direction),i=o*r,c=n.target,u=t.contains(c),d=!1,f=i>0,m=0,h=0;do{if(!c)break;var p=vi(e,c),b=p[0],x=p[1],v=p[2],g=x-v-o*b;(b||g)&&bi(e,c)&&(m+=g,h+=b);var y=c.parentNode;c=y&&y.nodeType===Node.DOCUMENT_FRAGMENT_NODE?y.host:y}while(!u&&c!==document.body||u&&(t.contains(c)||t===c));return(f&&Math.abs(m)<1||!f&&Math.abs(h)<1)&&(d=!0),d},qs=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},ka=function(e){return[e.deltaX,e.deltaY]},Ca=function(e){return e&&"current"in e?e.current:e},Vm=function(e,t){return e[0]===t[0]&&e[1]===t[1]},Ym=function(e){return`
|
|
107
|
+
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
108
|
+
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
109
|
+
`)},Gm=0,qt=[];function Xm(e){var t=l.useRef([]),n=l.useRef([0,0]),r=l.useRef(),a=l.useState(Gm++)[0],o=l.useState(xi)[0],i=l.useRef(e);l.useEffect(function(){i.current=e},[e]),l.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(a));var x=vc([e.lockRef.current],(e.shards||[]).map(Ca),!0).filter(Boolean);return x.forEach(function(v){return v.classList.add("allow-interactivity-".concat(a))}),function(){document.body.classList.remove("block-interactivity-".concat(a)),x.forEach(function(v){return v.classList.remove("allow-interactivity-".concat(a))})}}},[e.inert,e.lockRef.current,e.shards]);var c=l.useCallback(function(x,v){if("touches"in x&&x.touches.length===2||x.type==="wheel"&&x.ctrlKey)return!i.current.allowPinchZoom;var g=qs(x),y=n.current,w="deltaX"in x?x.deltaX:y[0]-g[0],j="deltaY"in x?x.deltaY:y[1]-g[1],I,N=x.target,S=Math.abs(w)>Math.abs(j)?"h":"v";if("touches"in x&&S==="h"&&N.type==="range")return!1;var C=window.getSelection(),k=C&&C.anchorNode,M=k?k===N||k.contains(N):!1;if(M)return!1;var R=Na(S,N);if(!R)return!0;if(R?I=S:(I=S==="v"?"h":"v",R=Na(S,N)),!R)return!1;if(!r.current&&"changedTouches"in x&&(w||j)&&(r.current=I),!I)return!0;var D=r.current||I;return Wm(D,v,x,D==="h"?w:j)},[]),u=l.useCallback(function(x){var v=x;if(!(!qt.length||qt[qt.length-1]!==o)){var g="deltaY"in v?ka(v):qs(v),y=t.current.filter(function(I){return I.name===v.type&&(I.target===v.target||v.target===I.shadowParent)&&Vm(I.delta,g)})[0];if(y&&y.should){v.cancelable&&v.preventDefault();return}if(!y){var w=(i.current.shards||[]).map(Ca).filter(Boolean).filter(function(I){return I.contains(v.target)}),j=w.length>0?c(v,w[0]):!i.current.noIsolation;j&&v.cancelable&&v.preventDefault()}}},[]),d=l.useCallback(function(x,v,g,y){var w={name:x,delta:v,target:g,should:y,shadowParent:Jm(g)};t.current.push(w),setTimeout(function(){t.current=t.current.filter(function(j){return j!==w})},1)},[]),f=l.useCallback(function(x){n.current=qs(x),r.current=void 0},[]),m=l.useCallback(function(x){d(x.type,ka(x),x.target,c(x,e.lockRef.current))},[]),h=l.useCallback(function(x){d(x.type,qs(x),x.target,c(x,e.lockRef.current))},[]);l.useEffect(function(){return qt.push(o),e.setCallbacks({onScrollCapture:m,onWheelCapture:m,onTouchMoveCapture:h}),document.addEventListener("wheel",u,Kt),document.addEventListener("touchmove",u,Kt),document.addEventListener("touchstart",f,Kt),function(){qt=qt.filter(function(x){return x!==o}),document.removeEventListener("wheel",u,Kt),document.removeEventListener("touchmove",u,Kt),document.removeEventListener("touchstart",f,Kt)}},[]);var p=e.removeScrollBar,b=e.inert;return l.createElement(l.Fragment,null,b?l.createElement(o,{styles:Ym(a)}):null,p?l.createElement(Bm,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Jm(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const Zm=Em(gi,Xm);var yi=l.forwardRef(function(e,t){return l.createElement(mn,mt({},e,{ref:t,sideCar:Zm}))});yi.classNames=mn.classNames;var eh=class extends nr{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:c}=r,u=n.fetchMeta?.fetchMore?.direction,d=i&&u==="forward",f=a&&u==="forward",m=i&&u==="backward",h=a&&u==="backward";return{...r,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:wc(t,n.data),hasPreviousPage:yc(t,n.data),isFetchNextPageError:d,isFetchingNextPage:f,isFetchPreviousPageError:m,isFetchingPreviousPage:h,isRefetchError:c&&!d&&!m,isRefetching:o&&!f&&!h}}};function Ea(e,t){const n=new Set(t);return e.filter(r=>!n.has(r))}function th(e,t,n){const r=e.slice(0);return r[t]=n,r}var sh=class extends jc{#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,zn.batch(()=>{const n=this.#t,r=this.#f(this.#a);r.forEach(f=>f.observer.setOptions(f.defaultedQueryOptions));const a=r.map(f=>f.observer),o=a.map(f=>f.getCurrentResult()),i=n.length!==a.length,c=a.some((f,m)=>f!==n[m]),u=i||c,d=u?!0:o.some((f,m)=>{const h=this.#e[m];return!h||!Sc(f,h)});!u&&!d||(u&&(this.#c=r,this.#t=a),this.#e=o,this.hasListeners()&&(u&&(Ea(n,a).forEach(f=>{f.destroy()}),Ea(a,n).forEach(f=>{f.subscribe(m=>{this.#m(f,m)})})),this.#h()))})}getCurrentResult(){return this.#e}getQueries(){return this.#t.map(e=>e.getCurrentQuery())}getObservers(){return this.#t}getOptimisticResult(e,t){const n=this.#f(e),r=n.map(o=>o.observer.getOptimisticResult(o.defaultedQueryOptions)),a=n.map(o=>o.defaultedQueryOptions.queryHash);return[r,o=>this.#d(o??r,t,a),()=>this.#u(r,n)]}#u(e,t){return t.map((n,r)=>{const a=e[r];return n.defaultedQueryOptions.notifyOnChangeProps?a:n.observer.trackResult(a,o=>{t.forEach(i=>{i.observer.trackProp(o)})})})}#d(e,t,n){if(t){const r=this.#l,a=n!==void 0&&r!==void 0&&(r.length!==n.length||n.some((o,i)=>o!==r[i]));return(!this.#s||this.#e!==this.#i||a||t!==this.#o)&&(this.#o=t,this.#i=this.#e,n!==void 0&&(this.#l=n),this.#s=Nc(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 nr(this.#r,a);n.push({defaultedQueryOptions:a,observer:i})}),n}#m(e,t){const n=this.#t.indexOf(e);n!==-1&&(this.#e=th(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)&&zn.batch(()=>{this.listeners.forEach(a=>{a(this.#e)})})}}};function At({queries:e,...t},n){const r=je(),a=kc(),o=Cc(),i=l.useMemo(()=>e.map(x=>{const v=r.defaultQueryOptions(x);return v._optimisticResults=a?"isRestoring":"optimistic",v}),[e,r,a]);i.forEach(x=>{Ec(x);const v=r.getQueryCache().get(x.queryHash);Ic(x,o,v)}),Rc(o);const[c]=l.useState(()=>new sh(r,i,t)),[u,d,f]=c.getOptimisticResult(i,t.combine),m=!a&&t.subscribed!==!1;l.useSyncExternalStore(l.useCallback(x=>m?c.subscribe(zn.batchCalls(x)):Mc,[c,m]),()=>c.getCurrentResult(),()=>c.getCurrentResult()),l.useEffect(()=>{c.setQueries(i,t)},[i,t,c]);const p=u.some((x,v)=>qr(i[v],x))?u.flatMap((x,v)=>{const g=i[v];if(g&&qr(g,x)){const y=new nr(r,g);return Tc(g,y,o)}return[]}):[];if(p.length>0)throw Promise.all(p);const b=u.find((x,v)=>{const g=i[v];return g&&Dc({result:x,errorResetBoundary:o,throwOnError:g.throwOnError,query:r.getQueryCache().get(g.queryHash),suspense:g.suspense})});if(b?.error)throw b.error;return d(f())}function wi(e,t){return Ac(e,eh)}function Us(e){const t=ho({warn:e?.router===void 0}),n=e?.router||t;return go(n.stores.__store,xo(e,n))}function hn(e){const t=ho();return go(t.stores.location,xo(e,t))}const nh=new Set(["outbox","flagged"]),rh=e=>{const[,t,n]=e.split(/[?#]/)[0].split("/");return t!=="mail"||!n?!1:!nh.has(n)};function ah(e){const t=At({queries:e.map(n=>({...Je({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=ss(r.folderAppointments);return(o.find(u=>i.get(u.mailboxId)==="inbox")??o[0])?.mailboxId}}function ji(e){const{openCompose:t}=pt(),n=Re(),r=hn(),a=ah(e);return l.useCallback(()=>{if(rh(r.pathname)){l.startTransition(()=>{t({mode:"new"})});return}a&&(l.startTransition(()=>{t({mode:"new"})}),n({to:"/mail/$mailboxId",params:{mailboxId:a}}))},[t,n,r.pathname,a])}const oh=e=>e.startsWith("/mail")||e.startsWith("/settings"),ih=({accounts:e})=>{const{state:t}=pt(),n=hn(),r=ji(e),a=n.search,o=typeof a?.selectedMessageId=="string"&&a.selectedMessageId.length>0;return!oh(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(Eu,{className:"size-6"})})},Si=({trigger:e,children:t,align:n="right"})=>{const[r,a]=l.useState(!1),o=l.useRef(null),i=l.useCallback(u=>{o.current&&!o.current.contains(u.target)&&a(!1)},[]),c=l.useCallback(u=>{u.key==="Escape"&&a(!1)},[]);return l.useEffect(()=>(r&&(document.addEventListener("mousedown",i),document.addEventListener("keydown",c)),()=>{document.removeEventListener("mousedown",i),document.removeEventListener("keydown",c)}),[r,i,c]),s.jsxs("div",{ref:o,className:"relative",children:[s.jsx("button",{type:"button",onClick:u=>{u.stopPropagation(),a(!r)},className:ce("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:ce("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})]})},Qt=({onClick:e,disabled:t,destructive:n,children:r})=>s.jsx("button",{type:"button",onClick:a=>{a.stopPropagation(),t||e()},disabled:t,className:ce("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}),qn=()=>s.jsx("div",{className:"my-1 h-px bg-line"}),Ni=({children:e})=>{const{Account:t}=rr();return s.jsx(t,{children:e})},lh=({email:e,onSignOut:t})=>{const n=Re(),r=e??"Account";return s.jsxs(Si,{trigger:s.jsx(Ze,{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(qn,{})]}),s.jsxs(Qt,{onClick:()=>n({to:"/settings/accounts"}),children:[s.jsx(Ko,{className:"size-4"}),"Settings"]}),s.jsx(qn,{}),s.jsxs(Qt,{onClick:t,children:[s.jsx(_o,{className:"size-4"}),"Sign out"]})]})},ch=()=>s.jsx(Ni,{children:({email:e,signOut:t})=>s.jsx(lh,{email:e,onSignOut:t})}),Ia=()=>{const e=ar(),t=or(e);window.open(t,"_blank","noopener,noreferrer")};function ki({variant:e="icon"}){return e==="drawer"?s.jsxs("button",{type:"button",onClick:Ia,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(Ur,{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(Ur,{className:"size-4"}),title:"Report a bug","aria-label":"Report a bug",onClick:Ia})}const Ci=[{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 Ci){const n=t.hints.find(r=>r.action===e);if(n)return n.keys}}function Ht(e){const t=uh(e);return!t||t.length===0?"":t.length===1?`(${t[0]})`:t[0]==="g"?`(${t.join(" then ")})`:`(${t.join("")})`}function dh({accounts:e}){const{searchInput:t,onSearchChange:n,onSearchClear:r,onSearchClearQuery:a}=Me(),o=ji(e);return s.jsx(Td,{leading:s.jsx("span",{className:"px-1 text-sm font-semibold tracking-tight text-fg",children:"remit"}),search:s.jsx(gr,{value:t,onChange:n,onClear:r,onClearQuery:a,placeholder:"Search all mail",size:"lg"}),actions:s.jsxs(s.Fragment,{children:[s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(Tu,{className:"size-4"}),title:`Compose ${Ht("compose")}`,"aria-label":"Compose",onClick:o}),s.jsx(ki,{}),s.jsx(ch,{})]})})}const yr=({isOpen:e,onClose:t,children:n,ariaLabel:r="Navigation",side:a="left",widthClassName:o="w-[80vw] max-w-[320px]"})=>{const i=l.useRef(null),c=l.useRef(null);if(l.useEffect(()=>{if(!e)return;c.current=document.activeElement;const d=h=>{h.key==="Escape"&&(h.preventDefault(),t())};document.addEventListener("keydown",d),i.current?.querySelector("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])")?.focus();const m=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",d),document.body.style.overflow=m,c.current?.focus()}},[e,t]),!e)return null;const u=a==="left"?"left-0 border-r animate-in slide-in-from-left duration-150":"right-0 border-l animate-in slide-in-from-right duration-150";return 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:ce("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(Be,{className:"size-5"})})}),s.jsx("div",{className:"flex-1 overflow-y-auto",children:n})]})]})},fh=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},Un={all:["messages"],detail:e=>[...Un.all,"detail",e],body:e=>[...Un.detail(e),"body"]};class It 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 mh=e=>{const t=Number.parseInt(e??"",10);return!Number.isFinite(t)||t<=0?1:Math.min(t,30)},hh=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"},ph=(e,t)=>(t??"").toLowerCase().startsWith("text/html")?/<div\s+id=["']root["']/i.test(e):!1,bh=(e,t)=>{const n=(t??"").toLowerCase();return!!(e==="text"&&n.startsWith("text/html"))},vh=async(e,t,n=async()=>null)=>{const r={},a=await n();a&&(r.Authorization=`Bearer ${a}`);const o=await Oc(e,{headers:r});if(o.status===202)throw new It("not-ready","Message body is still syncing",202,mh(o.headers.get("Retry-After")));if(!o.ok){const u=o.headers.get(gh),d=xh(o.status,u);throw new It(d,`Failed to load message body (${o.status} ${o.statusText})`,o.status)}const i=o.headers.get("content-type");if(bh(t,i))throw new It("content-type-mismatch",`Refusing to render message body — expected ${t}, got Content-Type ${i}`);const c=await o.text();if(ph(c,i))throw new It("spa-shell-leak","Refusing to render message body — response looks like the SPA shell (CloudFront 403/404 fallback leaked through to /content/*)");return c},yh=async(e,t)=>(t.isRetryAfterNotReady&&await e.refetchDescribeMessage(),e.fetchContent(t.contentUrl,t.kind)),Ei=({messageId:e,bodyParts:t,enabled:n=!0})=>{const r=t?fh(t):null,a=Ss(),{getToken:o}=rr(),i=l.useRef(null),c=je(),u=l.useRef(!1),d=l.useRef(null),f=e&&r?`${e}:${r.contentUrl}`:null;d.current!==f&&(d.current=f,u.current=!1);const m=oe({queryKey:e?[...Un.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,yh({fetchContent:(x,v)=>vh(x,v,o),refetchDescribeMessage:()=>c.refetchQueries({queryKey:po({path:{messageId:e}})})},{contentUrl:r.contentUrl,kind:r.kind,isRetryAfterNotReady:b})},enabled:n&&!!e&&!!r,staleTime:300*1e3,gcTime:1800*1e3,retry:(b,x)=>x instanceof It&&x.reason==="not-ready"?b<hh:b<1,retryDelay:(b,x)=>x instanceof It&&x.reason==="not-ready"?(u.current=!0,(x.retryAfterSeconds??1)*1e3):1e3,meta:{softError:!0}}),h=m.isLoading&&!!r;l.useEffect(()=>{h&&(i.current=performance.now())},[h]),l.useEffect(()=>{m.isSuccess&&i.current!==null&&(a.recordTiming("message.body.load",Math.round(performance.now()-i.current)),i.current=null)},[m.isSuccess,a]);const p=m.data&&r?{kind:r.kind,body:m.data}:void 0;return{picked:r,data:p,isLoading:h,isError:m.isError,error:m.error,refetch:m.refetch}},wh=({outboxMessageId:e,onDraftCreated:t})=>{const[n,r]=l.useState("idle"),[a,o]=l.useState(null),i=l.useRef(void 0),c=je(),u=be(bo()),d=be(Pc()),f=l.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 x=await u.mutateAsync({body:{...b,sendImmediately:!1}});return t(x.outboxMessageId),r("saved"),c.invalidateQueries({queryKey:an().queryKey}),x},[e,u,d,t,c]),m=l.useCallback(b=>{i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{f(b).catch(x=>{o(x),r("error")})},2e3)},[f]),h=l.useCallback(b=>(i.current&&clearTimeout(i.current),f(b)),[f]),p=l.useCallback(()=>{i.current&&clearTimeout(i.current)},[]);return{saveStatus:n,saveError:a,saveDraft:m,saveImmediately:h,cancelAutoSave:p}},Ii=e=>"text"in e&&!("children"in e),Ri=e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),jh=e=>{let t=Ri(e.text);return e.bold&&(t=`<strong>${t}</strong>`),e.italic&&(t=`<em>${t}</em>`),t},Mi=e=>{const t=e.children.map(n=>Ii(n)?jh(n):Mi(n)).join("");switch(e.type){case"blockquote":return`<blockquote>${t}</blockquote>`;case"a":{const n=e.url??"";return`<a href="${Ri(n)}">${t}</a>`}default:return`<p>${t}</p>`}},Ra=e=>e.map(Mi).join(""),Ti=e=>Ii(e)?e.text:e.children.map(Ti).join(""),Hn=e=>e.map(Ti).join(`
|
|
110
|
+
`),Sh=e=>e.displayName?`${e.displayName} <${e.normalizedEmail}>`:e.normalizedEmail,Ma=e=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.trim()),Nh=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(Ma(a))return{email:a,displayName:r}}if(Ma(t))return{email:t}},Rn=({label:e,addresses:t,onChange:n,placeholder:r})=>{const[a,o]=l.useState(""),[i,c]=l.useState(-1),[u,d]=l.useState(!1),f=l.useRef(null),m=l.useRef(null),h=ko(a,200),{data:p}=oe({...vo({query:{q:h,limit:8}}),enabled:h.length>=2}),b=p?.items??[],x=new Set(t.map(S=>S.email.toLowerCase())),v=b.filter(S=>!x.has(S.normalizedEmail.toLowerCase()));l.useEffect(()=>{c(-1),d(v.length>0&&a.length>=2)},[v.length,a.length]);const g=l.useCallback(S=>{x.has(S.email.toLowerCase())||(n([...t,S]),o(""),d(!1))},[t,x,n]),y=l.useCallback(S=>{n(t.filter((C,k)=>k!==S))},[t,n]),w=l.useCallback(S=>{g({email:S.normalizedEmail,displayName:S.displayName}),f.current?.focus()},[g]),j=l.useCallback(()=>{const S=Nh(a);S&&g(S)},[a,g]),I=l.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(),w(v[i]);return}a.trim()&&(S.preventDefault(),j());return}if(S.key==="ArrowDown"&&u){S.preventDefault(),c(C=>C<v.length-1?C+1:0);return}if(S.key==="ArrowUp"&&u){S.preventDefault(),c(C=>C>0?C-1:v.length-1);return}S.key==="Escape"&&(d(!1),c(-1))},[a,t.length,i,v,u,y,w,j]),N=l.useCallback(()=>{setTimeout(()=>{j(),d(!1)},150)},[j]);return s.jsxs("div",{className:"relative",children:[s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("label",{htmlFor:`address-field-${e}`,className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:[e,":"]}),s.jsxs("div",{className:"flex-1 flex flex-wrap items-center gap-1 min-h-[36px] px-2 py-1 border rounded-md bg-canvas cursor-text",onClick:()=>f.current?.focus(),onKeyDown:S=>{(S.key==="Enter"||S.key===" ")&&f.current?.focus()},children:[t.map((S,C)=>s.jsx(Pu,{email:S.email,displayName:S.displayName,onRemove:()=>y(C)},S.email)),s.jsx("input",{ref:f,id:`address-field-${e}`,type:"text",value:a,onChange:S=>o(S.target.value),onKeyDown:I,onBlur:N,placeholder:t.length===0?r:"",className:"flex-1 min-w-[120px] bg-transparent outline-none text-sm py-0.5"})]})]}),u&&v.length>0&&s.jsx("ul",{ref:m,className:"absolute left-12 right-0 mt-1 bg-surface border border-line rounded-md shadow-lg z-50 max-h-[200px] overflow-auto",children:v.map((S,C)=>s.jsx("li",{className:ce("px-3 py-2 text-sm cursor-pointer transition-colors",C===i&&"bg-accent-2-soft"),onMouseDown:k=>{k.preventDefault(),w(S)},onMouseEnter:()=>c(C),children:Sh(S)},S.addressId))})]})},kh=({accountId:e})=>{const t=Re();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(er,{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(yu,{className:"size-3","aria-hidden":"true"})]})]})]})},Qn=e=>{const[t,n]=l.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return l.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},Ot=()=>Qn("(min-width: 1024px)"),Ta=150,Ch=()=>{const[e,t]=l.useState(()=>{if(typeof window>"u"||!window.visualViewport)return{viewportHeight:0,isKeyboardOpen:!1};const n=window.visualViewport.height;return{viewportHeight:n,isKeyboardOpen:window.innerHeight-n>Ta}});return l.useEffect(()=>{if(typeof window>"u"||!window.visualViewport)return;const n=window.visualViewport,r=()=>{const a=n.height;t({viewportHeight:a,isKeyboardOpen:window.innerHeight-a>Ta})};return r(),n.addEventListener("resize",r),()=>n.removeEventListener("resize",r)},[]),e},Eh=({selectedAccountId:e,onSelect:t})=>{const{data:n}=oe({...it(),staleTime:1/0}),r=n?.accounts??[];if(l.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))})]})},Ih=({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})]}),Rh=["p","br","strong","b","em","i","a","blockquote","ul","ol","li"],Mh=["href"],Th=e=>io.sanitize(e,{ALLOWED_TAGS:Rh,ALLOWED_ATTR:Mh}),Dh=l.lazy(()=>zc(()=>import("./ComposeBody-BKGSbNpX.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}))),Ah=()=>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"})]}),Di=[{type:"p",children:[{text:""}]}],Oh=[{type:"p",children:[{text:""}]},{type:"p",children:[{text:"-- "}]}],Ph=e=>e?[...Oh,{type:"p",children:[{text:e}]}]:Di,Lh=e=>e?/^re:\s/i.test(e)?e:`Re: ${e}`:"Re: ",zh=e=>e?/^fwd?:\s/i.test(e)?e:`Fwd: ${e}`:"Fwd: ",_h=(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(),c=new Set(o.map(d=>d.email.toLowerCase())),u=[...r.to,...r.cc].filter(d=>d.normalizedEmail.toLowerCase()!==i&&!c.has(d.normalizedEmail.toLowerCase())).map(d=>({email:d.normalizedEmail,displayName:d.displayName}));return{to:o,cc:u}},Fh=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}},Bh=(e,t,n,r,a)=>e.length===0&&t.length===0&&n.length===0&&r.trim()===""&&Hn(a).trim()==="",$h=({selectedAccountId:e,onAccountChange:t,toAddresses:n,setToAddresses:r,ccAddresses:a,setCcAddresses:o,bccAddresses:i,setBccAddresses:c,showCc:u,setShowCc:d,showBcc:f,setShowBcc:m,subject:h,setSubject:p})=>{const b=Ot(),{isKeyboardOpen:x}=Ch();if(!b&&x){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(Eh,{selectedAccountId:e,onSelect:t}),s.jsx(Rn,{label:"To",addresses:n,onChange:r,placeholder:"Recipients"}),u?s.jsx(Rn,{label:"Cc",addresses:a,onChange:o}):s.jsxs("div",{className:"flex gap-2 pl-14",children:[s.jsx("button",{type:"button",onClick:()=>d(!0),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:"Cc"}),s.jsx("button",{type:"button",onClick:()=>m(!0),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:"Bcc"})]}),u&&!f&&s.jsx("div",{className:"pl-14",children:s.jsx("button",{type:"button",onClick:()=>m(!0),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:"Bcc"})}),f&&s.jsx(Rn,{label:"Bcc",addresses:i,onChange:c}),s.jsx(Ih,{value:h,onChange:p})]})},wr=({mode:e,account:t,sourceMessage:n,onClose:r,onAccountChange:a})=>{const{state:o,setOutboxMessageId:i,startSendPolling:c}=pt(),{pushError:u}=He(),{outboxMessageId:d}=o,[f,m]=l.useState([]),[h,p]=l.useState([]),[b,x]=l.useState([]),[v,g]=l.useState(""),[y,w]=l.useState(!1),[j,I]=l.useState(!1),[N,S]=l.useState(t?.accountId),[C,k]=l.useState(!1),M=l.useRef(d);l.useEffect(()=>{M.current!==d&&(M.current=d,d&&(m([]),p([]),x([]),g(""),w(!1),I(!1),E(Di),k(!1)))},[d]);const{signature:R}=mu(N),[D,E]=l.useState(()=>Ph(R.plainText)),{data:T}=oe({...Lc({path:{outboxMessageId:d??""}}),enabled:!!d&&!C});l.useEffect(()=>{!T||C||(m(T.toAddresses.map(W=>({email:W,displayName:void 0}))),T.ccAddresses&&T.ccAddresses.length>0&&(p(T.ccAddresses.map(W=>({email:W,displayName:void 0}))),w(!0)),T.bccAddresses&&T.bccAddresses.length>0&&(x(T.bccAddresses.map(W=>({email:W,displayName:void 0}))),I(!0)),T.subject&&g(T.subject),T.textBody&&E([{type:"p",children:[{text:T.textBody}]}]),S(T.accountId),k(!0))},[T,C]),l.useEffect(()=>{if(n){if(e==="reply"||e==="reply_all"){const{to:W,cc:Y}=_h(n,e,t?.email);m(W),p(Y),Y.length>0&&w(!0),g(Lh(n.envelope.subject))}e==="forward"&&g(zh(n.envelope.subject))}},[e,n,t?.email]);const O=e==="reply"||e==="reply_all"||e==="forward",{data:B}=Ei({messageId:n?.message.messageId,bodyParts:n?.bodyParts,enabled:O&&!!n}),q=B?.kind==="text"?B.body:"",X=B?.kind==="html"?Th(B.body):void 0,z=n?.envelope.from[0]?.displayName??n?.envelope.from[0]?.normalizedEmail,{saveStatus:$,saveError:ee,saveDraft:te,cancelAutoSave:A}=wh({outboxMessageId:d,onDraftCreated:i});l.useEffect(()=>{ee&&u({title:"Couldn't save draft",detail:Ye(ee)??"Saving the draft failed.",error:ee})},[ee,u]);const P=be(bo()),K=be(yo()),ie=be({...on(),onError:W=>{u(ys("Couldn't discard draft","The draft wasn't discarded.",W))}}),{data:me}=oe({...it(),staleTime:1/0}),he=me?.accounts.find(W=>W.accountId===N),ue=he?lu(he):!1,Ne=P.isPending||K.isPending,V=f.length>0&&!!N&&!ue;l.useEffect(()=>{if(!N||d&&!C||Bh(f,h,b,v,D))return;const W=Hn(D),Y=Ra(D);te({accountId:N,toAddresses:f.map(ne=>ne.email),ccAddresses:h.length>0?h.map(ne=>ne.email):void 0,bccAddresses:b.length>0?b.map(ne=>ne.email):void 0,subject:v||void 0,textBody:W||void 0,htmlBody:Y||void 0})},[N,d,C,f,h,b,v,D,te]);const Ce=l.useCallback(async()=>{if(!N||f.length===0)return;A();const W=n&&(e==="reply"||e==="reply_all")?Fh(n):{};let Y=d,ne=!1;if(!Y){const $e=Hn(D),Ae=Ra(D),We=await P.mutateAsync({body:{accountId:N,toAddresses:f.map(Ee=>Ee.email),ccAddresses:h.length>0?h.map(Ee=>Ee.email):void 0,bccAddresses:b.length>0?b.map(Ee=>Ee.email):void 0,subject:v||void 0,textBody:$e||void 0,htmlBody:Ae||void 0,sendImmediately:!0,...W}}).catch(Ee=>(u({title:"Couldn't send message",detail:Ye(Ee)??"Saving the draft failed.",error:Ee}),null));if(We===null)return;Y=We.outboxMessageId,ne=!0,i(Y)}await K.mutateAsync({path:{outboxMessageId:Y}}).catch($e=>(u({title:"Couldn't send message",detail:Ye($e)??(ne?"The draft was saved but the send request failed. Try again from the Outbox.":"The send request failed. Try again."),error:$e}),null))!==null&&(c(Y),r())},[N,f,h,b,v,D,e,n,d,P,K,A,c,i,u,r]),Pe=l.useCallback(()=>{A(),d&&ie.mutate({path:{outboxMessageId:d}}),r()},[A,d,ie,r]),H=l.useCallback(W=>{S(W.accountId),a?.(W)},[a]);return s.jsx(qd,{banner:he&&ue?s.jsx(kh,{accountId:he.accountId}):void 0,header:s.jsx($h,{selectedAccountId:N,onAccountChange:H,toAddresses:f,setToAddresses:m,ccAddresses:h,setCcAddresses:p,bccAddresses:b,setBccAddresses:x,showCc:y,setShowCc:w,showBcc:j,setShowBcc:I,subject:v,setSubject:g}),quoted:q||X?s.jsx(cf,{text:q,html:X,senderName:z}):void 0,actionBar:s.jsx(Kd,{onSend:Ce,onDiscard:Pe,sending:Ne,canSend:V,saveStatus:$,unavailableReason:ue?"SMTP not configured":void 0,onUnavailable:W=>u({title:"Can't send yet",detail:W})}),children:s.jsx(l.Suspense,{fallback:s.jsx(Ah,{}),children:s.jsx(Dh,{value:D,onChange:E,onSubmit:Ce,autoFocus:e==="new"})})})},Da=({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(wr,{mode:e,account:t,sourceMessage:n,onClose:r})}),Ai=({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})]}),jr=({enabled:e=!0,bindings:t,capture:n=!1})=>{const r=l.useCallback(a=>{const o=a.target;if(!(o.tagName==="INPUT"||o.tagName==="TEXTAREA"||o.isContentEditable))for(const i of t){if(!(a.key.toLowerCase()===i.key.toLowerCase())||i.requireShift!==void 0&&i.requireShift!==a.shiftKey)continue;const u=a.ctrlKey||a.metaKey;if(i.requireMeta!==void 0){if(i.requireMeta!==u)continue}else{const d=i.noModifiers??!0,f=u||a.altKey||i.requireShift===void 0&&a.shiftKey;if(d&&f)continue}i.preventDefault&&a.preventDefault(),i.stopPropagation&&(a.stopPropagation(),a.stopImmediatePropagation()),i.handler(a);return}},[t]);l.useEffect(()=>{if(e)return window.addEventListener("keydown",r,n),()=>window.removeEventListener("keydown",r,n)},[e,r,n])},Oi=e=>{const{data:t,isLoading:n}=oe({...it(),staleTime:1/0}),r=l.useMemo(()=>(t?.accounts??[]).map(c=>c.accountId),[t?.accounts]),a=At({queries:r.map(c=>({...Je({path:{accountId:c}}),staleTime:1/0,enabled:!!e}))}),o=n||a.some(c=>c.isLoading);return{accountId:l.useMemo(()=>{if(e){for(let c=0;c<r.length;c++)if((a[c].data?.items??[]).some(f=>f.mailboxId===e))return r[c]}},[e,r,a]),isLoading:o}},Kh=e=>typeof e=="object"&&e!==null&&Array.isArray(e.pages),qh=e=>typeof e=="object"&&e!==null&&Array.isArray(e.items),Zt=(e,t)=>e===void 0?e:Kh(e)?{...e,pages:e.pages.map(n=>({...n,items:t(n.items)}))}:qh(e)?{...e,items:t(e.items)}:e,Uh=(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]},Aa=(e,t,n)=>e.map(r=>t.has(r.messageId)?{...r,isRead:n}:r),Hh=(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),Qh=({messages:e,expandedIds:t,threadId:n,mailboxId:r,accountId:a})=>{const o=je(),{pushError:i}=He(),c=l.useRef(new Set),u=l.useRef(new Set),{mutate:d}=be({...ln(),onMutate:async h=>{const p=new Set(h.body.messageIds??[]),b=h.body.isRead??!0,x=Mt({path:{threadId:n}}),v=Uh(p,e,r),g=v.map(N=>lt({path:{mailboxId:N}})),y=v.map(N=>bt({path:{mailboxId:N}}));await Promise.all([o.cancelQueries({queryKey:x}),...g.map(N=>o.cancelQueries({queryKey:N})),...y.map(N=>o.cancelQueries({queryKey:N}))]);const w=o.getQueriesData({queryKey:x}).filter(N=>N[1]!==void 0).map(([N,S])=>({queryKey:N,data:S})),j=[...g,...y].flatMap(N=>o.getQueriesData({queryKey:N})).filter(N=>N[1]!==void 0).map(([N,S])=>({queryKey:N,data:S}));o.setQueriesData({queryKey:x},N=>N&&{...N,items:Aa(N.items,p,b)});const I=N=>Zt(N,S=>Aa(S,p,b));for(const N of[...g,...y])o.setQueriesData({queryKey:N},I);return{threadMessagesPrefix:x,threadsListPrefixes:g,threadsSearchPrefixes:y,previousThreadMessages:w,previousThreadsList:j}},onSuccess:(h,p)=>{const b=p.body.messageIds??[];for(const x of b)c.current.add(x),u.current.delete(x)},onError:(h,p,b)=>{const x=p.body.messageIds??[];for(const g of x)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=p.body.isRead??!0;i({title:v?"Couldn't mark as read":"Couldn't mark as unread",detail:Ye(h),error:h})},onSettled:(h,p,b,x)=>{if(x){o.invalidateQueries({queryKey:x.threadMessagesPrefix});for(const v of[...x.threadsListPrefixes,...x.threadsSearchPrefixes])o.invalidateQueries({queryKey:v});a&&o.invalidateQueries({queryKey:ts({path:{accountId:a}})})}}}),f=l.useCallback(h=>{const p=h.filter(b=>!c.current.has(b)&&!u.current.has(b));if(p.length!==0){for(const b of p)u.current.add(b);d({body:{messageIds:p,isRead:!0}})}},[d]),m=l.useMemo(()=>Hh(e,t,c.current,u.current),[e,t]);l.useEffect(()=>{m.length!==0&&f(m)},[m,f]),l.useEffect(()=>{c.current.clear(),u.current.clear()},[n])},Pi=e=>{const{mailboxId:t,accountId:n}=e,r=je(),{pushError:a}=He(),{mutate:o,isPending:i}=be({...ln(),onError:(u,d)=>{const f=d.body.isRead??!0;a({title:f?"Couldn't mark as read":"Couldn't mark as unread",detail:Ye(u),error:u})},onSettled:()=>{r.invalidateQueries({queryKey:lt({path:{mailboxId:t}})}),r.invalidateQueries({queryKey:bt({path:{mailboxId:t}})}),n&&r.invalidateQueries({queryKey:ts({path:{accountId:n}})})}});return{toggleReadFor:l.useCallback((u,d)=>{u.length!==0&&o({body:{messageIds:u,isRead:d}})},[o]),isPending:i}},Wh=60,Vh=1.5,Yh=(e,t,n)=>{const r=Math.abs(e),a=Math.abs(t);return r<n?{direction:null}:r<a*Vh?{direction:null}:{direction:e<0?"left":"right"}},Gh=({onSwipeLeft:e,onSwipeRight:t,thresholdPx:n=Wh})=>{const r=l.useRef(null),a=l.useCallback(u=>{if(u.pointerType==="mouse"){r.current=null;return}r.current={x:u.clientX,y:u.clientY}},[]),o=l.useCallback(()=>{},[]),i=l.useCallback(u=>{const d=r.current;if(r.current=null,!d)return;const{direction:f}=Yh(u.clientX-d.x,u.clientY-d.y,n);f==="left"&&e?.(),f==="right"&&t?.()},[e,t,n]),c=l.useCallback(()=>{r.current=null},[]);return{handlers:{onPointerDown:a,onPointerMove:o,onPointerUp:i,onPointerCancel:c}}},Xh=(e,t,n)=>t?.find(r=>r.messageId===e)?.mailboxId??n,Oa=(e,t,n)=>e.map(r=>r.messageId===t?{...r,hasStars:n}:r),Wn=({threadId:e,mailboxId:t,messages:n})=>{const r=je(),{pushError:a}=He(),{mutate:o,isPending:i,variables:c}=be({..._c(),onMutate:async d=>{const f=d.path.messageId,m=d.body.isStarred??!1,h=Mt({path:{threadId:e}}),p=Xh(f,n,t),b=lt({path:{mailboxId:p}}),x=bt({path:{mailboxId:p}}),v=wo();await Promise.all([r.cancelQueries({queryKey:h}),r.cancelQueries({queryKey:b}),r.cancelQueries({queryKey:x}),r.cancelQueries({queryKey:v})]);const g=r.getQueriesData({queryKey:h}).filter(N=>N[1]!==void 0).map(([N,S])=>({queryKey:N,data:S})),y=r.getQueriesData({queryKey:b}).concat(r.getQueriesData({queryKey:x})).filter(N=>N[1]!==void 0).map(([N,S])=>({queryKey:N,data:S})),w=r.getQueriesData({queryKey:v}).filter(N=>N[1]!==void 0).map(([N,S])=>({queryKey:N,data:S})),j=N=>Zt(N,S=>Oa(S,f,m));r.setQueriesData({queryKey:h},j),r.setQueriesData({queryKey:v},j);const I=N=>Zt(N,S=>Oa(S,f,m));return r.setQueriesData({queryKey:b},I),r.setQueriesData({queryKey:x},I),{threadMessagesPrefix:h,threadsListPrefix:b,threadsSearchPrefix:x,unifiedThreadsPrefix:v,previousThreadMessages:g,previousThreadsList:y,previousUnifiedThreads:w}},onError:(d,f,m)=>{if(m){for(const p of m.previousThreadMessages)r.setQueryData(p.queryKey,p.data);for(const p of m.previousThreadsList)r.setQueryData(p.queryKey,p.data);for(const p of m.previousUnifiedThreads)r.setQueryData(p.queryKey,p.data)}const h=f.body.isStarred??!1;a({title:h?"Couldn't star message":"Couldn't unstar message",detail:Ye(d),error:d})},onSettled:(d,f,m,h)=>{h&&(r.invalidateQueries({queryKey:h.threadMessagesPrefix}),r.invalidateQueries({queryKey:h.threadsListPrefix}),r.invalidateQueries({queryKey:h.threadsSearchPrefix}),r.invalidateQueries({queryKey:h.unifiedThreadsPrefix}))}});return{toggleStar:(d,f)=>{o({path:{messageId:d},body:{isStarred:!f}})},isPending:i,pendingMessageId:i?c?.path.messageId:void 0}};function gn(e){return e===void 0?"uncategorized":e}const Ve={uncategorized:"uncategorized",personal:"personal",newsletter:"newsletter",marketing:"marketing",automated:"automated",transactional:"transactional",social:"social"},Pa={MoveToInbox:"MoveToInbox",MoveToJunk:"MoveToJunk"},Jh={inbox:"Inbox",junk:"Junk"},Zh=e=>`Moved from ${Jh[e]??"another folder"} by Remit`,eg=(e,t)=>{if(e===Pa.MoveToInbox)return t.inboxMailboxId;if(e===Pa.MoveToJunk)return t.junkMailboxId},tg=(e,t,n)=>{if(!e||!t)return!1;const r=eg(e.action,n);return r!==void 0&&r===t},sg=(e,t)=>{if(e==="inbox")return t.inboxMailboxId;if(e==="junk")return t.junkMailboxId},xn=(e,t)=>{const{data:n,isLoading:r}=oe({...it(),staleTime:1/0,enabled:!!e});return{mailboxId:l.useMemo(()=>e?n?.accounts.find(i=>i.accountId===e)?.folderAppointments.find(i=>i.role===t)?.mailboxId:void 0,[n,e,t]),isLoading:r}},ng=e=>{const{mailboxId:t,isLoading:n}=xn(e,"Archive");return{archiveMailboxId:t,isLoading:n}},rg=e=>{const{mailboxId:t,isLoading:n}=xn(e,"Drafts");return{draftsMailboxId:t,isLoading:n}},Sr=e=>{const{mailboxId:t,isLoading:n}=xn(e,"Inbox");return{inboxMailboxId:t,isLoading:n}},Nr=e=>{const{mailboxId:t,isLoading:n}=xn(e,"Junk");return{junkMailboxId:t,isLoading:n}},Li=e=>{const{data:t}=oe({...it(),staleTime:1/0,enabled:!!e});return l.useMemo(()=>t?.accounts.find(n=>n.accountId===e)?.folderAppointments??[],[t,e])},La=(e,t)=>e.filter(n=>!t.has(n.messageId)),gt=({mailboxId:e,threadId:t,accountId:n,onAfterOptimisticRemove:r})=>{const a=je(),{pushError:o}=He(),{mutate:i,isPending:c}=be({...Fc(),onMutate:async d=>{const f=new Set(d.body.messageIds??[]),m=t?Mt({path:{threadId:t}}):[],h=lt({path:{mailboxId:e}}),p=bt({path:{mailboxId:e}});await Promise.all([...t?[a.cancelQueries({queryKey:m})]:[],a.cancelQueries({queryKey:h}),a.cancelQueries({queryKey:p})]);const b=t?a.getQueriesData({queryKey:m}).filter(g=>g[1]!==void 0).map(([g,y])=>({queryKey:g,data:y})):[],x=a.getQueriesData({queryKey:h}).concat(a.getQueriesData({queryKey:p})).filter(g=>g[1]!==void 0).map(([g,y])=>({queryKey:g,data:y}));t&&a.setQueriesData({queryKey:m},g=>g&&{...g,items:La(g.items,f)});const v=g=>Zt(g,y=>La(y,f));return a.setQueriesData({queryKey:h},v),a.setQueriesData({queryKey:p},v),r?.(Array.from(f)),{threadMessagesPrefix:m,threadsListPrefix:h,threadsSearchPrefix:p,previousThreadMessages:b,previousThreadsList:x}},onError:(d,f,m)=>{if(m){for(const p of m.previousThreadMessages)a.setQueryData(p.queryKey,p.data);for(const p of m.previousThreadsList)a.setQueryData(p.queryKey,p.data)}const h=f.body.messageIds?.length??0;o({title:h>1?`Couldn't move ${h} messages`:"Couldn't move this message",detail:Ye(d),error:d})},onSettled:(d,f,m,h)=>{h&&(t&&a.invalidateQueries({queryKey:h.threadMessagesPrefix}),a.invalidateQueries({queryKey:h.threadsListPrefix}),a.invalidateQueries({queryKey:h.threadsSearchPrefix}),n&&a.invalidateQueries({queryKey:ts({path:{accountId:n}})}))}});return{moveMessages:l.useCallback((d,f)=>{d.length!==0&&i({body:{messageIds:d,destinationMailboxId:f}})},[i]),isPending:c}},ag=({accountId:e,messageId:t,threadId:n,mailboxId:r,autoMoved:a})=>{const{inboxMailboxId:o}=Sr(e),{junkMailboxId:i}=Nr(e),{moveMessages:c,isPending:u}=gt({mailboxId:r,threadId:n,accountId:e}),d={inboxMailboxId:o,junkMailboxId:i},f=tg(a,r,d),m=a?sg(a.fromPlacement,d):void 0,h=l.useCallback(()=>{m&&c([t],m)},[c,t,m]);return!f||!a?{show:!1,label:"",isUndoing:!1}:{show:!0,label:Zh(a.fromPlacement),onUndo:m?h:void 0,isUndoing:u}};function zi({accountId:e,messageId:t,threadId:n,mailboxId:r,autoMoved:a,size:o="sm"}){const i=ag({accountId:e,messageId:t,threadId:n,mailboxId:r,autoMoved:a});return i.show?s.jsx(Dd,{label:i.label,size:o,onUndo:i.onUndo,undoLabel:i.isUndoing?"Undoing…":"Undo"}):null}const za=(e,t)=>e.filter(n=>!t.has(n.messageId)),og=e=>e.filter(t=>t.isDeleted!==!0),vs=({mailboxId:e,threadId:t,accountId:n,onAfterOptimisticRemove:r})=>{const a=je(),{pushError:o}=He(),{mutate:i,isPending:c}=be({...Bc(),onMutate:async d=>{const f=new Set(d.body.messageIds??[]),m=t?Mt({path:{threadId:t}}):[],h=lt({path:{mailboxId:e}}),p=bt({path:{mailboxId:e}});await Promise.all([a.cancelQueries({queryKey:m}),a.cancelQueries({queryKey:h}),a.cancelQueries({queryKey:p})]);const b=t?a.getQueriesData({queryKey:m}).filter(g=>g[1]!==void 0).map(([g,y])=>({queryKey:g,data:y})):[],x=a.getQueriesData({queryKey:h}).concat(a.getQueriesData({queryKey:p})).filter(g=>g[1]!==void 0).map(([g,y])=>({queryKey:g,data:y}));t&&a.setQueriesData({queryKey:m},g=>g&&{...g,items:za(g.items,f)});const v=g=>Zt(g,y=>za(y,f));return a.setQueriesData({queryKey:h},v),a.setQueriesData({queryKey:p},v),r?.(Array.from(f)),{threadMessagesPrefix:m,threadsListPrefix:h,threadsSearchPrefix:p,previousThreadMessages:b,previousThreadsList:x}},onError:(d,f,m)=>{if(m){for(const p of m.previousThreadMessages)a.setQueryData(p.queryKey,p.data);for(const p of m.previousThreadsList)a.setQueryData(p.queryKey,p.data)}const h=f.body.messageIds?.length??0;o({title:h>1?`Couldn't delete ${h} messages`:"Couldn't delete this message",detail:Ye(d),error:d})},onSettled:(d,f,m,h)=>{h&&(t&&a.invalidateQueries({queryKey:h.threadMessagesPrefix}),a.invalidateQueries({queryKey:h.threadsListPrefix}),a.invalidateQueries({queryKey:h.threadsSearchPrefix}),n&&a.invalidateQueries({queryKey:ts({path:{accountId:n}})}))}});return{deleteMessages:l.useCallback(d=>{d.length!==0&&i({body:{messageIds:d}})},[i]),isPending:c}},_i=(e,t=Date.now())=>({value:e,setAt:t}),ig=(e,t,n,r)=>{if(e.addressId!==t)return e;const a={...e.flags??{}};return n?a.trusted=_i(!0,r):delete a.trusted,{...e,flags:a}},lg=(e,t,n,r)=>{const a=o=>o.map(i=>ig(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)}}},kr=({messageId:e})=>{const t=je(),{pushError:n}=He(),{mutate:r,isPending:a,error:o,reset:i}=be({...jo(),onMutate:async u=>{const d=u.path.addressId,m=u.body.flags?.trusted?.value===!0,h=po({path:{messageId:e}});await t.cancelQueries({queryKey:h});const p=t.getQueriesData({queryKey:h}).filter(b=>b[1]!==void 0).map(([b,x])=>({queryKey:b,data:x}));return t.setQueriesData({queryKey:h},b=>b&&lg(b,d,m)),{describePrefix:h,previous:p}},onError:(u,d,f)=>{if(f)for(const m of f.previous)t.setQueryData(m.queryKey,m.data);n(ys("Couldn't trust sender","The change wasn't saved.",u))},onSettled:(u,d,f,m)=>{m&&t.invalidateQueries({queryKey:m.describePrefix})}});return{toggleTrusted:(u,d)=>{r({path:{addressId:u},body:{flags:{trusted:_i(!d)}}})},isPending:a,error:o,reset:i}};var pn="Dialog",[Fi]=If(pn),[cg,Qe]=Fi(pn),Bi=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:a,onOpenChange:o,modal:i=!0}=e,c=l.useRef(null),u=l.useRef(null),[d,f]=Tf({prop:r,defaultProp:a??!1,onChange:o,caller:pn});return s.jsx(cg,{scope:t,triggerRef:c,contentRef:u,contentId:Nn(),titleId:Nn(),descriptionId:Nn(),open:d,onOpenChange:f,onOpenToggle:l.useCallback(()=>f(m=>!m),[f]),modal:i,children:n})};Bi.displayName=pn;var $i="DialogTrigger",ug=l.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,a=Qe($i,n),o=Dt(t,a.triggerRef);return s.jsx(ct.button,{type:"button","aria-haspopup":"dialog","aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":Er(a.open),...r,ref:o,onClick:ht(e.onClick,a.onOpenToggle)})});ug.displayName=$i;var Cr="DialogPortal",[dg,Ki]=Fi(Cr,{forceMount:void 0}),qi=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:a}=e,o=Qe(Cr,t);return s.jsx(dg,{scope:t,forceMount:n,children:l.Children.map(r,i=>s.jsx(fn,{present:n||o.open,children:s.jsx(fi,{asChild:!0,container:a,children:i})}))})};qi.displayName=Cr;var sn="DialogOverlay",Ui=l.forwardRef((e,t)=>{const n=Ki(sn,e.__scopeDialog),{forceMount:r=n.forceMount,...a}=e,o=Qe(sn,e.__scopeDialog);return o.modal?s.jsx(fn,{present:r||o.open,children:s.jsx(mg,{...a,ref:t})}):null});Ui.displayName=sn;var fg=br("DialogOverlay.RemoveScroll"),mg=l.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,a=Qe(sn,n),o=Gf(),i=Dt(t,o);return s.jsx(yi,{as:fg,allowPinchZoom:!0,shards:[a.contentRef],children:s.jsx(ct.div,{"data-state":Er(a.open),...r,ref:i,style:{pointerEvents:"auto",...r.style}})})}),es="DialogContent",Hi=l.forwardRef((e,t)=>{const n=Ki(es,e.__scopeDialog),{forceMount:r=n.forceMount,...a}=e,o=Qe(es,e.__scopeDialog);return s.jsx(fn,{present:r||o.open,children:o.modal?s.jsx(hg,{...a,ref:t}):s.jsx(gg,{...a,ref:t})})});Hi.displayName=es;var hg=l.forwardRef((e,t)=>{const n=Qe(es,e.__scopeDialog),r=l.useRef(null),a=Dt(t,n.contentRef,r);return l.useEffect(()=>{const o=r.current;if(o)return bm(o)},[]),s.jsx(Qi,{...e,ref:a,trapFocus:n.open,disableOutsidePointerEvents:n.open,onCloseAutoFocus:ht(e.onCloseAutoFocus,o=>{o.preventDefault(),n.triggerRef.current?.focus()}),onPointerDownOutside:ht(e.onPointerDownOutside,o=>{const i=o.detail.originalEvent,c=i.button===0&&i.ctrlKey===!0;(i.button===2||c)&&o.preventDefault()}),onFocusOutside:ht(e.onFocusOutside,o=>o.preventDefault())})}),gg=l.forwardRef((e,t)=>{const n=Qe(es,e.__scopeDialog),r=l.useRef(!1),a=l.useRef(!1);return s.jsx(Qi,{...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()}})}),Qi=l.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:a,onCloseAutoFocus:o,...i}=e,c=Qe(es,n);return em(),s.jsx(s.Fragment,{children:s.jsx(ui,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:a,onUnmountAutoFocus:o,children:s.jsx(li,{role:"dialog",id:c.contentId,"aria-describedby":c.descriptionId,"aria-labelledby":c.titleId,"data-state":Er(c.open),...i,ref:t,deferPointerDownOutside:!0,onDismiss:()=>c.onOpenChange(!1)})})})}),Wi="DialogTitle",Vi=l.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,a=Qe(Wi,n);return s.jsx(ct.h2,{id:a.titleId,...r,ref:t})});Vi.displayName=Wi;var Yi="DialogDescription",xg=l.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,a=Qe(Yi,n);return s.jsx(ct.p,{id:a.descriptionId,...r,ref:t})});xg.displayName=Yi;var Gi="DialogClose",pg=l.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,a=Qe(Gi,n);return s.jsx(ct.button,{type:"button",...r,ref:t,onClick:ht(e.onClick,()=>a.onOpenChange(!1))})});pg.displayName=Gi;function Er(e){return e?"open":"closed"}function bg(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 Xi=F.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}),Ms=()=>{const e=F.useContext(Xi);if(!e)throw new Error("useDrawerContext must be used within a Drawer.Root");return e};bg(`[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
|
+
[data-state=closed]
|
|
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 vg(){const e=navigator.userAgent;return typeof window<"u"&&(/Firefox/.test(e)&&/Mobile/.test(e)||/FxiOS/.test(e))}function yg(){return Ir(/^Mac/)}function wg(){return Ir(/^iPhone/)}function _a(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function jg(){return Ir(/^iPad/)||yg()&&navigator.maxTouchPoints>1}function Ji(){return wg()||jg()}function Ir(e){return typeof window<"u"&&window.navigator!=null?e.test(window.navigator.platform):void 0}const Sg=24,Ng=typeof window<"u"?l.useLayoutEffect:l.useEffect;function Fa(...e){return(...t)=>{for(let n of e)typeof n=="function"&&n(...t)}}const Mn=typeof document<"u"&&window.visualViewport;function Ba(e){let t=window.getComputedStyle(e);return/(auto|scroll)/.test(t.overflow+t.overflowX+t.overflowY)}function Zi(e){for(Ba(e)&&(e=e.parentElement);e&&!Ba(e);)e=e.parentElement;return e||document.scrollingElement||document.documentElement}const kg=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);let Hs=0,Tn;function Cg(e={}){let{isDisabled:t}=e;Ng(()=>{if(!t)return Hs++,Hs===1&&Ji()&&(Tn=Eg()),()=>{Hs--,Hs===0&&Tn?.()}},[t])}function Eg(){let e,t=0,n=m=>{e=Zi(m.target),!(e===document.documentElement&&e===document.body)&&(t=m.changedTouches[0].pageY)},r=m=>{if(!e||e===document.documentElement||e===document.body){m.preventDefault();return}let h=m.changedTouches[0].pageY,p=e.scrollTop,b=e.scrollHeight-e.clientHeight;b!==0&&((p<=0&&h>t||p>=b&&h<t)&&m.preventDefault(),t=h)},a=m=>{let h=m.target;Vn(h)&&h!==document.activeElement&&(m.preventDefault(),h.style.transform="translateY(-2000px)",h.focus(),requestAnimationFrame(()=>{h.style.transform=""}))},o=m=>{let h=m.target;Vn(h)&&(h.style.transform="translateY(-2000px)",requestAnimationFrame(()=>{h.style.transform="",Mn&&(Mn.height<window.innerHeight?requestAnimationFrame(()=>{$a(h)}):Mn.addEventListener("resize",()=>$a(h),{once:!0}))}))},i=()=>{window.scrollTo(0,0)},c=window.pageXOffset,u=window.pageYOffset,d=Fa(Ig(document.documentElement,"paddingRight",`${window.innerWidth-document.documentElement.clientWidth}px`));window.scrollTo(0,0);let f=Fa(ms(document,"touchstart",n,{passive:!1,capture:!0}),ms(document,"touchmove",r,{passive:!1,capture:!0}),ms(document,"touchend",a,{passive:!1,capture:!0}),ms(document,"focus",o,!0),ms(window,"scroll",i));return()=>{d(),f(),window.scrollTo(c,u)}}function Ig(e,t,n){let r=e.style[t];return e.style[t]=n,()=>{e.style[t]=r}}function ms(e,t,n,r){return e.addEventListener(t,n,r),()=>{e.removeEventListener(t,n,r)}}function $a(e){let t=document.scrollingElement||document.documentElement;for(;e&&e!==t;){let n=Zi(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+Sg;o>i&&(n.scrollTop+=a-r)}e=n.parentElement}}function Vn(e){return e instanceof HTMLInputElement&&!kg.has(e.type)||e instanceof HTMLTextAreaElement||e instanceof HTMLElement&&e.isContentEditable}function Rg(e,t){typeof e=="function"?e(t):e!=null&&(e.current=t)}function Mg(...e){return t=>e.forEach(n=>Rg(n,t))}function el(...e){return l.useCallback(Mg(...e),e)}const tl=new WeakMap;function we(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 Tg(e,t){if(!e||!(e instanceof HTMLElement))return;let n=tl.get(e);n&&(e.style[t]=n[t])}const ve=e=>{switch(e){case"top":case"bottom":return!0;case"left":case"right":return!1;default:return e}};function Qs(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(", ")[ve(t)?13:12]):(a=r.match(/^matrix\((.+)\)$/),a?parseFloat(a[1].split(", ")[ve(t)?5:4]):null)}function Dg(e){return 8*(Math.log(e+1)-2)}function Dn(e,t){if(!e)return()=>{};const n=e.style.cssText;return Object.assign(e.style,t),()=>{e.style.cssText=n}}function Ag(...e){return(...t)=>{for(const n of e)typeof n=="function"&&n(...t)}}const fe={DURATION:.5,EASE:[.32,.72,0,1]},sl=.4,Og=.25,Pg=100,nl=8,Et=16,Yn=26,An="vaul-dragging";function rl(e){const t=F.useRef(e);return F.useEffect(()=>{t.current=e}),F.useMemo(()=>(...n)=>t.current==null?void 0:t.current.call(t,...n),[])}function Lg({defaultProp:e,onChange:t}){const n=F.useState(e),[r]=n,a=F.useRef(r),o=rl(t);return F.useEffect(()=>{a.current!==r&&(o(r),a.current=r)},[r,a,o]),n}function al({prop:e,defaultProp:t,onChange:n=()=>{}}){const[r,a]=Lg({defaultProp:t,onChange:n}),o=e!==void 0,i=o?e:r,c=rl(n),u=F.useCallback(d=>{if(o){const m=typeof d=="function"?d(e):d;m!==e&&c(m)}else a(d)},[o,e,a,c]);return[i,u]}function zg({activeSnapPointProp:e,setActiveSnapPointProp:t,snapPoints:n,drawerRef:r,overlayRef:a,fadeFromIndex:o,onSnapPointChange:i,direction:c="bottom",container:u,snapToSequentialPoint:d}){const[f,m]=al({prop:e,defaultProp:n?.[0],onChange:t}),[h,p]=F.useState(typeof window<"u"?{innerWidth:window.innerWidth,innerHeight:window.innerHeight}:void 0);F.useEffect(()=>{function S(){p({innerWidth:window.innerWidth,innerHeight:window.innerHeight})}return window.addEventListener("resize",S),()=>window.removeEventListener("resize",S)},[]);const b=F.useMemo(()=>f===n?.[n.length-1]||null,[n,f]),x=F.useMemo(()=>{var S;return(S=n?.findIndex(C=>C===f))!=null?S:null},[n,f]),v=n&&n.length>0&&(o||o===0)&&!Number.isNaN(o)&&n[o]===f||!n,g=F.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 C;return(C=n?.map(k=>{const M=typeof k=="string";let R=0;if(M&&(R=parseInt(k,10)),ve(c)){const E=M?R:h?k*S.height:0;return h?c==="bottom"?S.height-E:-S.height+E:E}const D=M?R:h?k*S.width:0;return h?c==="right"?S.width-D:-S.width+D:D}))!=null?C:[]},[n,h,u]),y=F.useMemo(()=>x!==null?g?.[x]:null,[g,x]),w=F.useCallback(S=>{var C;const k=(C=g?.findIndex(M=>M===S))!=null?C:null;i(k),we(r.current,{transition:`transform ${fe.DURATION}s cubic-bezier(${fe.EASE.join(",")})`,transform:ve(c)?`translate3d(0, ${S}px, 0)`:`translate3d(${S}px, 0, 0)`}),g&&k!==g.length-1&&o!==void 0&&k!==o&&k<o?we(a.current,{transition:`opacity ${fe.DURATION}s cubic-bezier(${fe.EASE.join(",")})`,opacity:"0"}):we(a.current,{transition:`opacity ${fe.DURATION}s cubic-bezier(${fe.EASE.join(",")})`,opacity:"1"}),m(n?.[Math.max(k,0)])},[r.current,n,g,o,a,m]);F.useEffect(()=>{if(f||e){var S;const C=(S=n?.findIndex(k=>k===e||k===f))!=null?S:-1;g&&C!==-1&&typeof g[C]=="number"&&w(g[C])}},[f,e,n,g,w]);function j({draggedDistance:S,closeDrawer:C,velocity:k,dismissible:M}){if(o===void 0)return;const R=c==="bottom"||c==="right"?(y??0)-S:(y??0)+S,D=x===o-1,E=x===0,T=S>0;if(D&&we(a.current,{transition:`opacity ${fe.DURATION}s cubic-bezier(${fe.EASE.join(",")})`}),!d&&k>2&&!T){M?C():w(g[0]);return}if(!d&&k>2&&T&&g&&n){w(g[n.length-1]);return}const O=g?.reduce((q,X)=>typeof q!="number"||typeof X!="number"?q:Math.abs(X-R)<Math.abs(q-R)?X:q),B=ve(c)?window.innerHeight:window.innerWidth;if(k>sl&&Math.abs(S)<B*.4){const q=T?1:-1;if(q>0&&b&&n){w(g[n.length-1]);return}if(E&&q<0&&M&&C(),x===null)return;w(g[x+q]);return}w(O)}function I({draggedDistance:S}){if(y===null)return;const C=c==="bottom"||c==="right"?y-S:y+S;(c==="bottom"||c==="right")&&C<g[g.length-1]||(c==="top"||c==="left")&&C>g[g.length-1]||we(r.current,{transform:ve(c)?`translate3d(0, ${C}px, 0)`:`translate3d(${C}px, 0, 0)`})}function N(S,C){if(!n||typeof x!="number"||!g||o===void 0)return null;const k=x===o-1;if(x>=o&&C)return 0;if(k&&!C)return 1;if(!v&&!k)return null;const R=k?x+1:x-1,D=k?g[R]-g[R-1]:g[R+1]-g[R],E=S/Math.abs(D);return k?1-E:E}return{isLastSnapPoint:b,activeSnapPoint:f,shouldFade:v,getPercentageDragged:N,setActiveSnapPoint:m,activeSnapPointIndex:x,onRelease:j,onDrag:I,snapPointsOffset:g}}const _g=()=>()=>{};function Fg(){const{direction:e,isOpen:t,shouldScaleBackground:n,setBackgroundColorOnScale:r,noBodyStyles:a}=Ms(),o=F.useRef(null),i=l.useMemo(()=>document.body.style.backgroundColor,[]);function c(){return(window.innerWidth-Yn)/window.innerWidth}F.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;Ag(r&&!a?Dn(document.body,{background:"black"}):_g,Dn(u,{transformOrigin:ve(e)?"top":"left",transitionProperty:"transform, border-radius",transitionDuration:`${fe.DURATION}s`,transitionTimingFunction:`cubic-bezier(${fe.EASE.join(",")})`}));const d=Dn(u,{borderRadius:`${nl}px`,overflow:"hidden",...ve(e)?{transform:`scale(${c()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`}:{transform:`scale(${c()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)`}});return()=>{d(),o.current=window.setTimeout(()=>{i?document.body.style.background=i:document.body.style.removeProperty("background")},fe.DURATION*1e3)}}},[t,n,i])}let hs=null;function Bg({isOpen:e,modal:t,nested:n,hasBeenOpened:r,preventScrollRestoration:a,noBodyStyles:o}){const[i,c]=F.useState(()=>typeof window<"u"?window.location.href:""),u=F.useRef(0),d=F.useCallback(()=>{if(_a()&&hs===null&&e&&!o){hs={position:document.body.style.position,top:document.body.style.top,left:document.body.style.left,height:document.body.style.height,right:"unset"};const{scrollX:m,innerHeight:h}=window;document.body.style.setProperty("position","fixed","important"),Object.assign(document.body.style,{top:`${-u.current}px`,left:`${-m}px`,right:"0px",height:"auto"}),window.setTimeout(()=>window.requestAnimationFrame(()=>{const p=h-window.innerHeight;p&&u.current>=h&&(document.body.style.top=`${-(u.current+p)}px`)}),300)}},[e]),f=F.useCallback(()=>{if(_a()&&hs!==null&&!o){const m=-parseInt(document.body.style.top,10),h=-parseInt(document.body.style.left,10);Object.assign(document.body.style,hs),window.requestAnimationFrame(()=>{if(a&&i!==window.location.href){c(window.location.href);return}window.scrollTo(h,m)}),hs=null}},[i]);return F.useEffect(()=>{function m(){u.current=window.scrollY}return m(),window.addEventListener("scroll",m),()=>{window.removeEventListener("scroll",m)}},[]),F.useEffect(()=>{if(t)return()=>{typeof document>"u"||document.querySelector("[data-vaul-drawer]")||f()}},[t,f]),F.useEffect(()=>{n||!r||(e?(!window.matchMedia("(display-mode: standalone)").matches&&d(),t||window.setTimeout(()=>{f()},500)):f())},[e,r,i,t,n,d,f]),{restorePositionSetting:f}}function $g({open:e,onOpenChange:t,children:n,onDrag:r,onRelease:a,snapPoints:o,shouldScaleBackground:i=!1,setBackgroundColorOnScale:c=!0,closeThreshold:u=Og,scrollLockTimeout:d=Pg,dismissible:f=!0,handleOnly:m=!1,fadeFromIndex:h=o&&o.length-1,activeSnapPoint:p,setActiveSnapPoint:b,fixed:x,modal:v=!0,onClose:g,nested:y,noBodyStyles:w=!1,direction:j="bottom",defaultOpen:I=!1,disablePreventScroll:N=!0,snapToSequentialPoint:S=!1,preventScrollRestoration:C=!1,repositionInputs:k=!0,onAnimationEnd:M,container:R,autoFocus:D=!1}){var E,T;const[O=!1,B]=al({defaultProp:I,prop:e,onChange:Q=>{t?.(Q),!Q&&!y&&is(),setTimeout(()=>{M?.(Q)},fe.DURATION*1e3),Q&&!v&&typeof window<"u"&&window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"}),Q||(document.body.style.pointerEvents="auto")}}),[q,X]=F.useState(!1),[z,$]=F.useState(!1),[ee,te]=F.useState(!1),A=F.useRef(null),P=F.useRef(null),K=F.useRef(null),ie=F.useRef(null),me=F.useRef(null),he=F.useRef(!1),ue=F.useRef(null),Ne=F.useRef(0),V=F.useRef(!1),Ce=F.useRef(!I),Pe=F.useRef(0),H=F.useRef(null),W=F.useRef(((E=H.current)==null?void 0:E.getBoundingClientRect().height)||0),Y=F.useRef(((T=H.current)==null?void 0:T.getBoundingClientRect().width)||0),ne=F.useRef(0),ge=F.useCallback(Q=>{o&&Q===ke.length-1&&(P.current=new Date)},[]),{activeSnapPoint:$e,activeSnapPointIndex:Ae,setActiveSnapPoint:We,onRelease:Ee,snapPointsOffset:ke,onDrag:xe,shouldFade:Ke,getPercentageDragged:tt}=zg({snapPoints:o,activeSnapPointProp:p,setActiveSnapPointProp:b,drawerRef:H,fadeFromIndex:h,overlayRef:A,onSnapPointChange:ge,direction:j,container:R,snapToSequentialPoint:S});Cg({isDisabled:!O||z||!v||ee||!q||!k||!N});const{restorePositionSetting:is}=Bg({isOpen:O,modal:v,nested:y??!1,hasBeenOpened:q,preventScrollRestoration:C,noBodyStyles:w});function st(){return(window.innerWidth-Yn)/window.innerWidth}function nt(Q){var re,ae;!f&&!o||H.current&&!H.current.contains(Q.target)||(W.current=((re=H.current)==null?void 0:re.getBoundingClientRect().height)||0,Y.current=((ae=H.current)==null?void 0:ae.getBoundingClientRect().width)||0,$(!0),K.current=new Date,Ji()&&window.addEventListener("touchend",()=>he.current=!1,{once:!0}),Q.target.setPointerCapture(Q.pointerId),Ne.current=ve(j)?Q.pageY:Q.pageX)}function jt(Q,re){var ae;let J=Q;const le=(ae=window.getSelection())==null?void 0:ae.toString(),Se=H.current?Qs(H.current,j):null,ye=new Date;if(J.tagName==="SELECT"||J.hasAttribute("data-vaul-no-drag")||J.closest("[data-vaul-no-drag]"))return!1;if(j==="right"||j==="left")return!0;if(P.current&&ye.getTime()-P.current.getTime()<500)return!1;if(Se!==null&&(j==="bottom"?Se>0:Se<0))return!0;if(le&&le.length>0)return!1;if(me.current&&ye.getTime()-me.current.getTime()<d&&Se===0||re)return me.current=ye,!1;for(;J;){if(J.scrollHeight>J.clientHeight){if(J.scrollTop!==0)return me.current=new Date,!1;if(J.getAttribute("role")==="dialog")return!0}J=J.parentNode}return!0}function St(Q){if(H.current&&z){const re=j==="bottom"||j==="right"?1:-1,ae=(Ne.current-(ve(j)?Q.pageY:Q.pageX))*re,J=ae>0,le=o&&!f&&!J;if(le&&Ae===0)return;const Se=Math.abs(ae),ye=document.querySelector("[data-vaul-drawer-wrapper]"),Le=j==="bottom"||j==="top"?W.current:Y.current;let pe=Se/Le;const ze=tt(Se,J);if(ze!==null&&(pe=ze),le&&pe>=1||!he.current&&!jt(Q.target,J))return;if(H.current.classList.add(An),he.current=!0,we(H.current,{transition:"none"}),we(A.current,{transition:"none"}),o&&xe({draggedDistance:ae}),J&&!o){const Te=Dg(ae),rt=Math.min(Te*-1,0)*re;we(H.current,{transform:ve(j)?`translate3d(0, ${rt}px, 0)`:`translate3d(${rt}px, 0, 0)`});return}const Ie=1-pe;if((Ke||h&&Ae===h-1)&&(r?.(Q,pe),we(A.current,{opacity:`${Ie}`,transition:"none"},!0)),ye&&A.current&&i){const Te=Math.min(st()+pe*(1-st()),1),rt=8-pe*8,Ct=Math.max(0,14-pe*14);we(ye,{borderRadius:`${rt}px`,transform:ve(j)?`scale(${Te}) translate3d(0, ${Ct}px, 0)`:`scale(${Te}) translate3d(${Ct}px, 0, 0)`,transition:"none"},!0)}if(!o){const Te=Se*re;we(H.current,{transform:ve(j)?`translate3d(0, ${Te}px, 0)`:`translate3d(${Te}px, 0, 0)`})}}}F.useEffect(()=>{window.requestAnimationFrame(()=>{Ce.current=!0})},[]),F.useEffect(()=>{var Q;function re(){if(!H.current||!k)return;const ae=document.activeElement;if(Vn(ae)||V.current){var J;const le=((J=window.visualViewport)==null?void 0:J.height)||0,Se=window.innerHeight;let ye=Se-le;const Le=H.current.getBoundingClientRect().height||0,pe=Le>Se*.8;ne.current||(ne.current=Le);const ze=H.current.getBoundingClientRect().top;if(Math.abs(Pe.current-ye)>60&&(V.current=!V.current),o&&o.length>0&&ke&&Ae){const Ie=ke[Ae]||0;ye+=Ie}if(Pe.current=ye,Le>le||V.current){const Ie=H.current.getBoundingClientRect().height;let Te=Ie;Ie>le&&(Te=le-(pe?ze:Yn)),x?H.current.style.height=`${Ie-Math.max(ye,0)}px`:H.current.style.height=`${Math.max(Te,le-ze)}px`}else vg()||(H.current.style.height=`${ne.current}px`);o&&o.length>0&&!V.current?H.current.style.bottom="0px":H.current.style.bottom=`${Math.max(ye,0)}px`}}return(Q=window.visualViewport)==null||Q.addEventListener("resize",re),()=>{var ae;return(ae=window.visualViewport)==null?void 0:ae.removeEventListener("resize",re)}},[Ae,o,ke]);function qe(Q){kt(),g?.(),Q||B(!1),setTimeout(()=>{o&&We(o[0])},fe.DURATION*1e3)}function Nt(){if(!H.current)return;const Q=document.querySelector("[data-vaul-drawer-wrapper]"),re=Qs(H.current,j);we(H.current,{transform:"translate3d(0, 0, 0)",transition:`transform ${fe.DURATION}s cubic-bezier(${fe.EASE.join(",")})`}),we(A.current,{transition:`opacity ${fe.DURATION}s cubic-bezier(${fe.EASE.join(",")})`,opacity:"1"}),i&&re&&re>0&&O&&we(Q,{borderRadius:`${nl}px`,overflow:"hidden",...ve(j)?{transform:`scale(${st()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`,transformOrigin:"top"}:{transform:`scale(${st()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)`,transformOrigin:"left"},transitionProperty:"transform, border-radius",transitionDuration:`${fe.DURATION}s`,transitionTimingFunction:`cubic-bezier(${fe.EASE.join(",")})`},!0)}function kt(){!z||!H.current||(H.current.classList.remove(An),he.current=!1,$(!1),ie.current=new Date)}function Pt(Q){if(!z||!H.current)return;H.current.classList.remove(An),he.current=!1,$(!1),ie.current=new Date;const re=Qs(H.current,j);if(!Q||!jt(Q.target,!1)||!re||Number.isNaN(re)||K.current===null)return;const ae=ie.current.getTime()-K.current.getTime(),J=Ne.current-(ve(j)?Q.pageY:Q.pageX),le=Math.abs(J)/ae;if(le>.05&&(te(!0),setTimeout(()=>{te(!1)},200)),o){Ee({draggedDistance:J*(j==="bottom"||j==="right"?1:-1),closeDrawer:qe,velocity:le,dismissible:f}),a?.(Q,!0);return}if(j==="bottom"||j==="right"?J>0:J<0){Nt(),a?.(Q,!0);return}if(le>sl){qe(),a?.(Q,!1);return}var Se;const ye=Math.min((Se=H.current.getBoundingClientRect().height)!=null?Se:0,window.innerHeight);var Le;const pe=Math.min((Le=H.current.getBoundingClientRect().width)!=null?Le:0,window.innerWidth),ze=j==="left"||j==="right";if(Math.abs(re)>=(ze?pe:ye)*u){qe(),a?.(Q,!1);return}a?.(Q,!0),Nt()}F.useEffect(()=>(O&&(we(document.documentElement,{scrollBehavior:"auto"}),P.current=new Date),()=>{Tg(document.documentElement,"scrollBehavior")}),[O]);function Ue(Q){const re=Q?(window.innerWidth-Et)/window.innerWidth:1,ae=Q?-Et:0;ue.current&&window.clearTimeout(ue.current),we(H.current,{transition:`transform ${fe.DURATION}s cubic-bezier(${fe.EASE.join(",")})`,transform:ve(j)?`scale(${re}) translate3d(0, ${ae}px, 0)`:`scale(${re}) translate3d(${ae}px, 0, 0)`}),!Q&&H.current&&(ue.current=setTimeout(()=>{const J=Qs(H.current,j);we(H.current,{transition:"none",transform:ve(j)?`translate3d(0, ${J}px, 0)`:`translate3d(${J}px, 0, 0)`})},500))}function ut(Q,re){if(re<0)return;const ae=(window.innerWidth-Et)/window.innerWidth,J=ae+re*(1-ae),le=-Et+re*Et;we(H.current,{transform:ve(j)?`scale(${J}) translate3d(0, ${le}px, 0)`:`scale(${J}) translate3d(${le}px, 0, 0)`,transition:"none"})}function ls(Q,re){const ae=ve(j)?window.innerHeight:window.innerWidth,J=re?(ae-Et)/ae:1,le=re?-Et:0;re&&we(H.current,{transition:`transform ${fe.DURATION}s cubic-bezier(${fe.EASE.join(",")})`,transform:ve(j)?`scale(${J}) translate3d(0, ${le}px, 0)`:`scale(${J}) translate3d(${le}px, 0, 0)`})}return F.useEffect(()=>{v||window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"})},[v]),F.createElement(Bi,{defaultOpen:I,onOpenChange:Q=>{!f&&!Q||(Q?X(!0):qe(!0),B(Q))},open:O},F.createElement(Xi.Provider,{value:{activeSnapPoint:$e,snapPoints:o,setActiveSnapPoint:We,drawerRef:H,overlayRef:A,onOpenChange:t,onPress:nt,onRelease:Pt,onDrag:St,dismissible:f,shouldAnimate:Ce,handleOnly:m,isOpen:O,isDragging:z,shouldFade:Ke,closeDrawer:qe,onNestedDrag:ut,onNestedOpenChange:Ue,onNestedRelease:ls,keyboardIsOpen:V,modal:v,snapPointsOffset:ke,activeSnapPointIndex:Ae,direction:j,shouldScaleBackground:i,setBackgroundColorOnScale:c,noBodyStyles:w,container:R,autoFocus:D}},n))}const ol=F.forwardRef(function({...e},t){const{overlayRef:n,snapPoints:r,onRelease:a,shouldFade:o,isOpen:i,modal:c,shouldAnimate:u}=Ms(),d=el(t,n),f=r&&r.length>0;if(!c)return null;const m=F.useCallback(h=>a(h),[a]);return F.createElement(Ui,{onMouseUp:m,ref:d,"data-vaul-overlay":"","data-vaul-snap-points":i&&f?"true":"false","data-vaul-snap-points-overlay":i&&o?"true":"false","data-vaul-animate":u?.current?"true":"false",...e})});ol.displayName="Drawer.Overlay";const il=F.forwardRef(function({onPointerDownOutside:e,style:t,onOpenAutoFocus:n,...r},a){const{drawerRef:o,onPress:i,onRelease:c,onDrag:u,keyboardIsOpen:d,snapPointsOffset:f,activeSnapPointIndex:m,modal:h,isOpen:p,direction:b,snapPoints:x,container:v,handleOnly:g,shouldAnimate:y,autoFocus:w}=Ms(),[j,I]=F.useState(!1),N=el(a,o),S=F.useRef(null),C=F.useRef(null),k=F.useRef(!1),M=x&&x.length>0;Fg();const R=(E,T,O=0)=>{if(k.current)return!0;const B=Math.abs(E.y),q=Math.abs(E.x),X=q>B,z=["bottom","right"].includes(T)?1:-1;if(T==="left"||T==="right"){if(!(E.x*z<0)&&q>=0&&q<=O)return X}else if(!(E.y*z<0)&&B>=0&&B<=O)return!X;return k.current=!0,!0};F.useEffect(()=>{M&&window.requestAnimationFrame(()=>{I(!0)})},[]);function D(E){S.current=null,k.current=!1,c(E)}return F.createElement(Hi,{"data-vaul-drawer-direction":b,"data-vaul-drawer":"","data-vaul-delayed-snap-points":j?"true":"false","data-vaul-snap-points":p&&M?"true":"false","data-vaul-custom-container":v?"true":"false","data-vaul-animate":y?.current?"true":"false",...r,ref:N,style:f&&f.length>0?{"--snap-point-height":`${f[m??0]}px`,...t}:t,onPointerDown:E=>{g||(r.onPointerDown==null||r.onPointerDown.call(r,E),S.current={x:E.pageX,y:E.pageY},i(E))},onOpenAutoFocus:E=>{n?.(E),w||E.preventDefault()},onPointerDownOutside:E=>{if(e?.(E),!h||E.defaultPrevented){E.preventDefault();return}d.current&&(d.current=!1)},onFocusOutside:E=>{if(!h){E.preventDefault();return}},onPointerMove:E=>{if(C.current=E,g||(r.onPointerMove==null||r.onPointerMove.call(r,E),!S.current))return;const T=E.pageY-S.current.y,O=E.pageX-S.current.x,B=E.pointerType==="touch"?10:2;R({x:O,y:T},b,B)?u(E):(Math.abs(O)>B||Math.abs(T)>B)&&(S.current=null)},onPointerUp:E=>{r.onPointerUp==null||r.onPointerUp.call(r,E),S.current=null,k.current=!1,c(E)},onPointerOut:E=>{r.onPointerOut==null||r.onPointerOut.call(r,E),D(C.current)},onContextMenu:E=>{r.onContextMenu==null||r.onContextMenu.call(r,E),C.current&&D(C.current)}})});il.displayName="Drawer.Content";const Kg=250,qg=120,ll=F.forwardRef(function({preventCycle:e=!1,children:t,...n},r){const{closeDrawer:a,isDragging:o,snapPoints:i,activeSnapPoint:c,setActiveSnapPoint:u,dismissible:d,handleOnly:f,isOpen:m,onPress:h,onDrag:p}=Ms(),b=F.useRef(null),x=F.useRef(!1);function v(){if(x.current){w();return}window.setTimeout(()=>{g()},qg)}function g(){if(o||e||x.current){w();return}if(w(),!i||i.length===0){d||a();return}if(c===i[i.length-1]&&d){a();return}const I=i.findIndex(S=>S===c);if(I===-1)return;const N=i[I+1];u(N)}function y(){b.current=window.setTimeout(()=>{x.current=!0},Kg)}function w(){b.current&&window.clearTimeout(b.current),x.current=!1}return F.createElement("div",{onClick:v,onPointerCancel:w,onPointerDown:j=>{f&&h(j),y()},onPointerMove:j=>{f&&p(j)},ref:r,"data-vaul-drawer-visible":m?"true":"false","data-vaul-handle":"","aria-hidden":"true",...n},F.createElement("span",{"data-vaul-handle-hitarea":"","aria-hidden":"true"},t))});ll.displayName="Drawer.Handle";function Ug(e){const t=Ms(),{container:n=t.container,...r}=e;return F.createElement(qi,{container:n,...r})}const Fe={Root:$g,Content:il,Overlay:ol,Portal:Ug,Handle:ll,Title:Vi},Hg=new Set(["outbox","postvak uit","boîte d'envoi","postausgang","buzón de salida","posta in uscita","送信トレイ","送件匣","发件箱","skrzynka nadawcza"]),Qg=e=>{const t=en(e.fullPath).trim().toLowerCase();return Hg.has(t)},Ka=Fn.length,Rr=(e,t=[])=>{const n=ss(t);return[...e.filter(a=>{const o=n.get(a.mailboxId);return o==="drafts"||o==="sent"?!1:!Qg(a)})].sort((a,o)=>{const i=n.has(a.mailboxId)?Fn.indexOf(n.get(a.mailboxId)??"inbox"):Ka,c=n.has(o.mailboxId)?Fn.indexOf(n.get(o.mailboxId)??"inbox"):Ka;return i!==c?i-c:en(a.fullPath).localeCompare(en(o.fullPath),void 0,{sensitivity:"base",numeric:!0})})},cl="inline-flex items-center justify-center transition-colors",Wg=ce(cl,"min-h-11 min-w-11 rounded hover:bg-surface-raised"),Vg=ce(cl,"min-h-11 gap-1.5 px-3 rounded text-sm font-medium hover:bg-surface-raised"),Ts=({accountId:e,currentMailboxId:t,onMove:n,disabled:r=!1,disabledHint:a,variant:o="icon-only",label:i})=>{const[c,u]=l.useState(!1),d=Ot(),f=l.useRef(null),m=i??"Move to folder",h=l.useId(),{t:p}=cn("mail",{useSuspense:!1}),b=l.useCallback((M,R)=>p(M,{defaultValue:R}),[p]),{data:x,isLoading:v,isError:g,error:y,refetch:w}=oe({...Je({path:{accountId:e}}),staleTime:1/0,enabled:c}),j=Li(e),I=l.useMemo(()=>{const M=Rr(x?.items??[],j),R=ss(j);return M.map(D=>({id:D.mailboxId,label:Gt(D,R.get(D.mailboxId),b),searchValue:D.fullPath,isCurrent:D.mailboxId===t}))},[x?.items,j,t,b]),N=l.useCallback(M=>{u(!1),n(M)},[n]);l.useEffect(()=>{if(!c||!d)return;const M=D=>{f.current&&!f.current.contains(D.target)&&u(!1)},R=D=>{D.key==="Escape"&&u(!1)};return document.addEventListener("mousedown",M),document.addEventListener("keydown",R),()=>{document.removeEventListener("mousedown",M),document.removeEventListener("keydown",R)}},[c,d]);const S=r||!!a,C=s.jsxs("button",{type:"button",onClick:M=>{M.stopPropagation(),!S&&u(R=>!R)},"aria-label":m,"aria-haspopup":d?"listbox":"dialog","aria-expanded":c,"aria-controls":c?h:void 0,title:a,className:o==="icon-only"?Wg:Vg,children:[s.jsx(Lo,{className:"size-4"}),o==="compact"&&s.jsx("span",{className:"hidden sm:inline",children:"Move"})]}),k=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(yt,{variant:"inline",title:"Couldn't load folders",error:y,onRetry:()=>w()})}):s.jsx(ai,{mailboxes:I,onSelect:N,onCancel:()=>u(!1),autoFocus:!d,labels:{searchPlaceholder:p("move_picker_placeholder",{defaultValue:"Move to…"}),searchAriaLabel:p("move_picker_filter_label",{defaultValue:"Filter folders"}),optionLabel:M=>`Move to ${M}`,currentSuffix:"(current folder)",currentTag:"current",emptyMessage:M=>`No folders match "${M}"`}});return d?s.jsxs("div",{ref:f,className:"relative inline-block",children:[C,c&&s.jsx("div",{id:h,className:ce("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:k})]}):s.jsxs(s.Fragment,{children:[C,s.jsx(Fe.Root,{open:c,onOpenChange:u,children:s.jsxs(Fe.Portal,{children:[s.jsx(Fe.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),s.jsxs(Fe.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(Fe.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-subtle/30"}),s.jsx(Fe.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:k})]})]})})]})},Yg=({messageId:e,threadId:t,mailboxId:n,isRead:r,accountId:a,fromAddressId:o,isTrusted:i=!1,showRaw:c=!1,onToggleRaw:u})=>{const d=je(),f=Re(),{pushError:m}=He(),{selectedMessageId:h}=Yt({strict:!1}),{mutate:p,isPending:b}=be({...ln(),onMutate:async O=>{const B=O.body.isRead??!0,q=new Set(O.body.messageIds??[]),X=Mt({path:{threadId:t}}),z=lt({path:{mailboxId:n}}),$=bt({path:{mailboxId:n}});await Promise.all([d.cancelQueries({queryKey:X}),d.cancelQueries({queryKey:z}),d.cancelQueries({queryKey:$})]);const ee=d.getQueriesData({queryKey:X}).filter(P=>P[1]!==void 0).map(([P,K])=>({queryKey:P,data:K})),te=d.getQueriesData({queryKey:z}).concat(d.getQueriesData({queryKey:$})).filter(P=>P[1]!==void 0).map(([P,K])=>({queryKey:P,data:K}));d.setQueriesData({queryKey:X},P=>P&&{...P,items:P.items.map(K=>q.has(K.messageId)?{...K,isRead:B}:K)});const A=P=>Zt(P,K=>K.map(ie=>q.has(ie.messageId)?{...ie,isRead:B}:ie));return d.setQueriesData({queryKey:z},A),d.setQueriesData({queryKey:$},A),{threadMessagesPrefix:X,threadsListPrefix:z,threadsSearchPrefix:$,previousThreadMessages:ee,previousThreadsList:te}},onError:(O,B,q)=>{if(q){for(const z of q.previousThreadMessages)d.setQueryData(z.queryKey,z.data);for(const z of q.previousThreadsList)d.setQueryData(z.queryKey,z.data)}const X=B.body.isRead??!0;m({title:X?"Couldn't mark as read":"Couldn't mark as unread",detail:Ye(O),error:O})},onSettled:(O,B,q,X)=>{X&&(d.invalidateQueries({queryKey:X.threadMessagesPrefix}),d.invalidateQueries({queryKey:X.threadsListPrefix}),d.invalidateQueries({queryKey:X.threadsSearchPrefix}))}}),x=l.useCallback(O=>{h&&O.includes(h)&&f({to:"/mail/$mailboxId",params:{mailboxId:n},search:B=>({...B,selectedMessageId:void 0})})},[h,n,f]),{deleteMessages:v,isPending:g}=vs({mailboxId:n,threadId:t,onAfterOptimisticRemove:x}),{moveMessages:y,isPending:w}=gt({mailboxId:n,threadId:t,accountId:a,onAfterOptimisticRemove:x}),{toggleTrusted:j,isPending:I,error:N,reset:S}=kr({messageId:e}),C=()=>{p({body:{messageIds:[e],isRead:!1}})},k=()=>{v([e])},M=()=>{o&&j(o,i)},R=b||g||w||I,D=R||!o,E=l.useCallback(O=>{y([e],O)},[y,e]),T=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(Ts,{accountId:a,currentMailboxId:n,onMove:E,disabled:R,label:"Move this message"}),s.jsxs(Si,{trigger:s.jsx(Po,{className:"size-4"}),children:[s.jsxs(Qt,{onClick:M,disabled:D,children:[i?s.jsx(un,{className:"size-4 text-positive"}):s.jsx(Cs,{className:"size-4 opacity-0"}),s.jsx("span",{title:T,children:"Trusted sender"})]}),r&&s.jsxs(Qt,{onClick:C,disabled:R,children:[s.jsx(Es,{className:"size-4"}),"Mark as unread"]}),u&&s.jsxs(Qt,{onClick:u,children:[s.jsx(Oo,{className:"size-4"}),c?"Show formatted":"Show raw email"]}),s.jsx(qn,{}),s.jsxs(Qt,{onClick:k,disabled:R,destructive:!0,children:[s.jsx(et,{className:"size-4"}),"Delete"]})]})]}),N&&s.jsx("div",{className:"w-64",children:s.jsx(yt,{variant:"inline",title:"Couldn't update trust",error:N,onRetry:()=>{S(),M()}})})]})},Gg=()=>{const[e,t]=l.useState(()=>typeof document<"u"&&document.documentElement.classList.contains("dark"));return l.useEffect(()=>{const n=document.documentElement,r=new MutationObserver(()=>{t(n.classList.contains("dark"))});return r.observe(n,{attributes:!0,attributeFilter:["class"]}),()=>r.disconnect()},[]),e},Xg=({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"})]})]}),Jg=(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}}},Zg=e=>e instanceof It?e.reason:"generic",ex=e=>e instanceof Error?e.message:typeof e=="string"?e:"An unexpected error occurred while loading the message body.",tx=({error:e,onRetry:t})=>{const n=Zg(e),r=ex(e),{title:a,detail:o}=Jg(n,r),[i,c]=l.useState(!1),{Account:u}=rr();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(Rt,{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:()=>c(!0),"aria-label":"Dismiss message body error",className:"rounded-md p-1 text-fg-muted hover:bg-surface-raised hover:text-fg transition-colors",children:s.jsx(Be,{className:"size-4","aria-hidden":"true"})})]})]})},sx=()=>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"})]}),qa=()=>s.jsx("p",{className:"text-fg-muted text-sm italic",children:"This message has no body content."}),ul=({bodyParts:e,html:t,text:n,isTrusted:r=!1,messageId:a,fromAddressId:o,category:i,className:c})=>{const[u,d]=l.useState(!1),f=r||u,m=Gg(),{toggleTrusted:h,isPending:p}=kr({messageId:a??""}),b=!!e&&e.length>0,{picked:x,data:v,isLoading:g,isError:y,error:w,refetch:j}=Ei({messageId:a,bodyParts:e,enabled:b}),I=l.useMemo(()=>Ju(e??[]),[e]),N=b&&v?.kind==="html"?v.body:t,S=b&&v?.kind==="text"?v.body:n;if(b){if(g)return s.jsx("div",{className:ce("message-body",c),children:s.jsx(sx,{})});if(y)return s.jsx("div",{className:ce("message-body",c),children:s.jsx(tx,{error:w,onRetry:()=>j()})});if(!x)return s.jsx("div",{className:ce("message-body",c),children:s.jsx(qa,{})})}else if(!t&&!n)return s.jsx("div",{className:ce("message-body",c),children:s.jsx(qa,{})});const C=!!(o&&a),k=()=>{!o||p||(d(!0),h(o,!1))};return s.jsx(Zo,{className:c,html:N,text:S,isDark:m,category:i,allowImages:f,resolveCid:I,renderBlockedNotice:M=>s.jsx(Xg,{blockedImageCount:M,canAlwaysTrust:C,isTrustPending:p,onLoadOnce:()=>d(!0),onAlwaysTrust:k})})},nx=({messageId:e,threadId:t,mailboxId:n,accountId:r,isRead:a,isStarred:o,onToggleStar:i,fromAddressId:c,isTrusted:u,showRaw:d,onToggleRaw:f,onReply:m,onReplyAll:h,onForward:p})=>{const b=je(),{deleteMessages:x}=vs({mailboxId:n,threadId:t}),{moveMessages:v}=gt({mailboxId:n,threadId:t,accountId:r}),{toggleTrusted:g}=kr({messageId:e}),{mutate:y}=be({...ln(),onSettled:()=>{b.invalidateQueries({queryKey:Mt({path:{threadId:t}})}),b.invalidateQueries({queryKey:lt({path:{mailboxId:n}})}),b.invalidateQueries({queryKey:bt({path:{mailboxId:n}})})}}),w=l.useCallback(S=>{v([e],S)},[v,e]),j=l.useCallback(()=>{x([e])},[x,e]),I=l.useCallback(()=>{y({body:{messageIds:[e],isRead:!a}})},[y,e,a]),N=[];return c&&N.push({key:"trusted",label:u?"Trusted sender":"Mark sender trusted",icon:u?s.jsx(un,{className:"size-4 text-positive"}):s.jsx(Cs,{className:"size-4"}),onSelect:()=>g(c,u)}),f&&N.push({key:"raw",label:d?"Show formatted":"Show raw email",icon:s.jsx(Oo,{className:"size-4"}),onSelect:f}),s.jsx(Jo,{hasThread:!0,onReply:m,onReplyAll:h,onForward:p,isStarred:o,onToggleStar:i,onDelete:j,isRead:a,onToggleRead:I,overflowItems:N,moveSlot:r?s.jsx(Ts,{accountId:r,currentMailboxId:n,onMove:w,label:"Move this message"}):void 0})},rx=()=>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"})]}),ax=({messageId:e,enabled:t=!0})=>{const{data:n,isLoading:r,isError:a,error:o,refetch:i}=oe({...$c({path:{messageId:e}}),enabled:t});if(r)return s.jsx("div",{className:"message-body",children:s.jsx(rx,{})});if(a)return s.jsx("div",{className:"message-body",children:s.jsx(yt,{variant:"inline",title:"Couldn't load the raw email",error:o,onRetry:()=>i()})});const c=n?.raw??"";return c===""?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:c})})},ox=()=>s.jsx(un,{className:"inline-block size-4 ml-1 -mt-0.5 text-positive align-middle","aria-label":"Trusted sender","data-testid":"trusted-sender-badge"}),dl=(e,t)=>({id:e.messageId,fromName:e.fromName??e.fromEmail??"?",fromEmail:e.fromEmail??"",toLabel:"",dateLabel:t,snippet:e.snippet||"",bodyHtml:""}),fl=({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:ce("shrink-0 p-0.5 rounded transition-colors",e?"text-warning":ce("text-fg-subtle hover:text-warning",r&&"opacity-0 group-hover:opacity-100 focus:opacity-100"),n&&"opacity-50"),children:s.jsx(vt,{className:ce("size-3.5",e&&"fill-current")})}),ix=({threadMessage:e,isFocused:t,onToggle:n,onToggleStar:r,isStarPending:a})=>{const o=Ro(e.sentDate,"datetime"),i=dl(e,o);return s.jsx(ei,{message:i,onClick:n,isFocused:t,isUnread:!e.isRead,trailing:s.jsxs(s.Fragment,{children:[e.hasAttachment&&s.jsx(dn,{className:"size-3 shrink-0 text-fg-subtle"}),s.jsx(fl,{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})]})})},lx=({threadMessage:e,messageData:t,isLoading:n,isError:r,error:a,onRetry:o,isFocused:i,onToggle:c,onToggleStar:u,isStarPending:d,accountId:f,showRaw:m,onToggleRaw:h,mobile:p,onReply:b,onReplyAll:x,onForward:v})=>{const g=Ro(e.sentDate,"long"),y=!e.isRead,w=t?.envelope.from[0]?.flags?.trusted?.value===!0,j=t?.envelope.from[0]?.addressId,I=dl(e,g),N=e.autoMoved?s.jsx(zi,{accountId:f,messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,autoMoved:e.autoMoved,size:"md"}):null;return s.jsx(ti,{message:I,isFocused:i,onHeaderClick:c,senderBadge:w?s.jsx(ox,{}):void 0,trailing:s.jsx("span",{"data-testid":"message-date",className:"text-2xs text-fg-subtle",children:g}),to:t?s.jsx(Ou,{label:"To",addresses:t.envelope.to}):null,indicators:N||!p?s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mt-0.5",children:[N,!p&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex items-center justify-end gap-1",children:[s.jsx(fl,{isStarred:e.hasStars,onToggleStar:u,isStarPending:d}),e.hasAttachment&&s.jsx("span",{className:"text-fg-subtle p-0.5",children:s.jsx(dn,{className:"size-3.5"})})]}),y&&s.jsx("span",{className:"size-1.5 rounded-full bg-accent","aria-label":"Unread"})]})]}):void 0,actionMenu:p?void 0:s.jsx(Yg,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,isRead:e.isRead,accountId:f,fromAddressId:j,isTrusted:w,showRaw:m,onToggleRaw:h}),actionBar:p?s.jsx(nx,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,accountId:f,isRead:e.isRead,isStarred:e.hasStars,onToggleStar:u,fromAddressId:j,isTrusted:w,showRaw:m,onToggleRaw:h,onReply:b,onReplyAll:x,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&&Kc(a)?s.jsx("div",{className:"mt-3",children:s.jsx(Ai,{message:"This message has been deleted"})}):r?s.jsx("div",{className:"mt-3",children:s.jsx(yt,{variant:"inline",title:"Couldn't load this message",error:a,onRetry:o})}):m?s.jsx("div",{className:"mt-3",children:s.jsx(ax,{messageId:e.messageId})}):s.jsx("div",{className:"mt-3",children:s.jsx(ul,{bodyParts:t?.bodyParts,messageId:e.messageId,fromAddressId:t?.envelope.from[0]?.addressId,isTrusted:w,category:gn(e.category)})})})},cx=({threadMessage:e,isExpanded:t,isFocused:n,onToggle:r,onToggleStar:a,isStarPending:o,accountId:i,mobile:c,onReply:u,onReplyAll:d,onForward:f})=>{const[m,h]=l.useState(!1),{data:p,isLoading:b,isError:x,error:v,refetch:g}=oe({...ir({path:{messageId:e.messageId}}),enabled:t,meta:{softError:!0}});return t?s.jsx(lx,{threadMessage:e,messageData:p,isLoading:b,isError:x,error:v,onRetry:()=>g(),isFocused:n,onToggle:r,onToggleStar:a,isStarPending:o,accountId:i,showRaw:m,onToggleRaw:()=>h(y=>!y),mobile:c,onReply:u,onReplyAll:d,onForward:f}):s.jsx(ix,{threadMessage:e,isFocused:n,onToggle:r,onToggleStar:a,isStarPending:o})},ux=()=>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 Ua({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(Is,{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 os=({threadId:e,mailboxId:t,subject:n,selectedMessageId:r,authenticity:a,onOpenIntelligence:o,onBack:i,composeRequest:c,onComposeClose:u,onSwipeNext:d,onSwipePrevious:f,mobileIntelligenceOpen:m})=>{const h=Ot(),{handlers:p}=Gh({onSwipeLeft:d,onSwipeRight:f}),{accountId:b}=Oi(t),{data:x,isLoading:v,isError:g,error:y,refetch:w}=oe({...qc({path:{threadId:e},query:{order:"desc"}})}),j=l.useMemo(()=>x?.items??[],[x?.items]),I=l.useRef(new Map),[N,S]=l.useState(new Set),[C,k]=l.useState(null),[M,R]=l.useState(0);l.useEffect(()=>{if(j.length>0&&e!==C){k(e);const W=new Set([j[0].threadMessageId]);if(r){const Y=j.find(ne=>ne.messageId===r);Y&&W.add(Y.threadMessageId)}S(W),R(0)}},[e,j,C,r]);const D=l.useCallback(W=>{S(Y=>{const ne=new Set(Y);return ne.has(W)?ne.delete(W):ne.add(W),ne})},[]),E=l.useCallback(W=>{const Y=j[W];if(!Y)return;I.current.get(Y.threadMessageId)?.scrollIntoView({behavior:"smooth",block:"nearest"})},[j]),T=l.useCallback(()=>{if(j.length===0)return;const W=Math.min(M+1,j.length-1);R(W),E(W)},[j.length,M,E]),O=l.useCallback(()=>{if(j.length===0)return;const W=Math.max(M-1,0);R(W),E(W)},[j.length,M,E]),B=l.useCallback(()=>{const W=j[M];W&&D(W.threadMessageId)},[j,M,D]),{data:q}=oe({...it(),staleTime:1/0}),X=q?.accounts?.[0],z=!!X?.smtpHost;Qh({messages:j,expandedIds:N,threadId:e,mailboxId:t,accountId:X?.accountId});const{toggleStar:$,isPending:ee,pendingMessageId:te}=Wn({threadId:e,mailboxId:t,messages:j}),[A,P]=l.useState(null);l.useEffect(()=>{c&&c!=="new"&&(P(c),u?.())},[c,u]);const K=j[0],{data:ie}=oe({...ir({path:{messageId:K?.messageId??""}}),enabled:!!K&&A!==null}),me=l.useCallback(()=>{P("reply")},[]),he=l.useCallback(()=>{P("reply_all")},[]),ue=l.useCallback(()=>{P("forward")},[]),Ne=l.useCallback(()=>{P(null),u?.()},[u]);if(jr({enabled:!v&&j.length>0&&A===null,bindings:[{key:"j",handler:T,preventDefault:!0},{key:"ArrowDown",handler:T,preventDefault:!0},{key:"k",handler:O,preventDefault:!0},{key:"ArrowUp",handler:O,preventDefault:!0},{key:"Enter",handler:B,preventDefault:!0},{key:"o",handler:B,preventDefault:!0},...z?[{key:"r",handler:me,preventDefault:!0},{key:"R",handler:he,noModifiers:!1,preventDefault:!0},{key:"f",handler:ue,preventDefault:!0}]:[]]}),v)return s.jsx(ux,{});if(g)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsx(yt,{title:"Couldn't load this conversation",error:y,onRetry:()=>w()})});if(j.length===0)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsx(Ai,{message:"No messages in this thread"})});const V=n||j[0]?.subject||"(No subject)",Ce=j.length,Pe=W=>s.jsx("div",{children:j.map((Y,ne)=>s.jsx("div",{ref:ge=>{ge&&I.current.set(Y.threadMessageId,ge)},children:s.jsx(cx,{threadMessage:Y,isExpanded:N.has(Y.threadMessageId),isFocused:ne===M,onToggle:()=>D(Y.threadMessageId),onToggleStar:()=>$(Y.messageId,Y.hasStars),isStarPending:ee&&te===Y.messageId,accountId:b,mobile:W,onReply:W&&z?me:void 0,onReplyAll:W&&z?he:void 0,onForward:W&&z?ue:void 0})},Y.threadMessageId))}),H=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:V}),s.jsxs("p",{className:"mt-1 text-2xs text-fg-subtle",children:[Ce," ",Ce===1?"message":"messages"]})]});return h?s.jsxs("article",{className:"h-full flex flex-col",children:[H,a?.dkimMismatch&&s.jsx(Ua,{authenticity:a,onOpenIntelligence:o}),s.jsx("div",{className:"flex-1 overflow-auto",children:Pe(!1)}),A!==null&&s.jsx(Da,{mode:A,account:X,sourceMessage:ie,onClose:Ne})]}):s.jsxs(Sd,{thread:{subject:V,messages:[]},onBack:i??(()=>{}),intelligenceOpen:m,onToggleIntelligence:o,touchHandlers:p,children:[a?.dkimMismatch&&s.jsx(Ua,{authenticity:a,onOpenIntelligence:o}),Pe(!0),A!==null&&s.jsx(Da,{mode:A,account:X,sourceMessage:ie,onClose:Ne})]})},ml=e=>e.trim().toLocaleLowerCase(),dx=/^\d{4}-\d{2}-\d{2}$/;function Ha(e,t,n){if(!dx.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 fx(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 Ha("before",e,e.slice(7));if(n.startsWith("after:")&&e.length>6)return Ha("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 Ds(e,t={}){const n=e.split(/\s+/).filter(o=>o.length>0),r=[],a=[];for(const o of n){const i=fx(o,t);i?r.push(i):a.push(o)}return{freeText:a.join(" "),tokens:r}}function mx(e,t){return e.split(/\s+/).filter(n=>n.length>0&&n!==t.raw).join(" ")}function hx(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 gx=20,xx=new Set(Object.values(Ve)),px=e=>e!==void 0&&xx.has(e)?e:void 0;function hl({mailboxId:e,filterCategory:t}={}){const{searchQuery:n,mailboxNameIndex:r,accountNameIndex:a}=Me(),o=ml(n),{freeText:i,tokens:c}=Ds(o,{mailboxesByName:r,accountsByName:a}),u=o.length>0,d=px(t),f=c.some(y=>y.type==="hasAttachment")?!0:void 0,m=c.some(y=>y.type==="isUnread")?!1:void 0,h=c.find(y=>y.type==="after"),p=c.find(y=>y.type==="before"),x=c.find(y=>y.type==="in")?.mailboxId??e,{data:v,isLoading:g}=oe({...So({query:{query:i,mailboxId:x,limit:gx,...d!==void 0?{category:d}:{},...f!==void 0?{hasAttachment:f}:{},...m!==void 0?{isRead:m}:{},...h?{sentDateFrom:h.epochSeconds}:{},...p?{sentDateTo:p.epochSeconds}:{}}}),enabled:u,staleTime:6e4});return{hits:v?.items??[],isLoading:u&&g}}const bx=(e,t)=>e.createdAt!==t.createdAt?e.createdAt-t.createdAt:e.accountId.localeCompare(t.accountId),vx=e=>[...e].sort(bx);function gl(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:wt(e.sentDate),sentDate:e.sentDate,isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:gn(e.category),suspicious:t}}const Qa=[{id:"personal",label:"Personal",category:Ve.personal},{id:"transactional",label:"Transactional",category:Ve.transactional},{id:"newsletter",label:"Newsletter",category:Ve.newsletter},{id:"marketing",label:"Marketing",category:Ve.marketing},{id:"social",label:"Social",category:Ve.social},{id:"automated",label:"Automated",category:Ve.automated},{id:"uncategorized",label:"Unclassified",category:Ve.uncategorized}];function yx(e){const t=new Map(Qa.map(r=>[r.category,[]]));for(const r of e){const a=r.category??Ve.uncategorized;(t.get(a)??t.get(Ve.uncategorized))?.push(r)}const n=[];for(const r of Qa){const a=t.get(r.category);a&&a.length>0&&n.push({id:r.id,label:r.label,threads:a})}return n}function xl(e,t){return e.fromName.toLowerCase().includes(t)||e.fromEmail.toLowerCase().includes(t)||e.subject.toLowerCase().includes(t)||e.snippet.toLowerCase().includes(t)}function pl(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 wx={sender:"sender",recipient:"recipient",subject:"subject",attachment:"attachment",body:"body",entities:"entities"};function jx(e){return wx[e]??e}function Sx(e){return{id:e.messageId,sender:e.fromName??e.fromEmail??"Unknown",subject:e.subject??"(No subject)",snippet:e.snippet??"",date:wt(e.sentDate),unread:!e.isRead,flagged:e.hasStars===!0,threadId:e.threadId,mailboxId:e.mailboxId}}function bl(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 Nx(e){return{id:e.messageId,sender:e.fromName??"Unknown",subject:e.subject??"(No subject)",snippet:"",date:e.sentDate!=null?wt(e.sentDate*1e3):"",threadId:e.threadId,matchedChunkLabel:jx(e.matchedChunkType),score:e.score,...e.mailboxIds[0]!=null?{mailboxId:e.mailboxIds[0]}:{}}}function vl(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(Nx(a)));return r}const kx=768,Cx=1024,yl=e=>e!=="desktop",As=()=>{const e=Qn(`(min-width: ${kx}px)`);return Qn(`(min-width: ${Cx}px)`)?"desktop":e?"tablet":"phone"},wl="remit.recentSearches",Ex=5;function Gn(){try{const e=localStorage.getItem(wl);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(n=>typeof n=="string"):[]}catch{return[]}}function Wa(e){const t=e.trim();if(!t)return Gn();const n=[t,...Gn().filter(r=>r!==t)].slice(0,Ex);try{localStorage.setItem(wl,JSON.stringify(n))}catch{return n}return n}function jl({title:e,unreadCount:t,children:n,footer:r,searchFilter:a,searchResults:o,searchLoading:i,relatedResults:c,relatedLoading:u,onSelectSearchResult:d}){const{searchInput:f,onSearchChange:m,onSearchClear:h,mailboxNameIndex:p,accountNameIndex:b}=Me(),x=lr(),v=As(),[g,y]=l.useState(!1),[w,j]=l.useState(Gn),I=f.trim().length>0,N=Ds(f,{mailboxesByName:p,accountsByName:b}).tokens.map(B=>({label:hx(B),onRemove:()=>m(mx(f,B))})),S=o??[],C=c??[],k=I?[{id:"top",label:"Top matches",results:S},{id:"related",label:"Related",results:C}]:[],R=!(S.length+C.length>0)&&(i===!0||u===!0);if(v==="phone"&&g){const B=q=>{j(Wa(f)),y(!1),d?.(q)};return s.jsx(Zd,{value:f,onChange:m,onClear:h,onCancel:()=>{y(!1),h()},filter:a,recentSearches:w,onPickRecent:m,sections:k,loading:R,onSelectResult:B,tokens:N})}const D=v!=="phone"&&I,E=B=>{j(Wa(f)),d?.(B)},T=s.jsx(ri,{value:f,sections:k,loading:R,onSelectResult:E,tokens:N}),O=D?a?s.jsx(Zn,{...a,children:T}):s.jsx("div",{className:"h-full overflow-y-auto",children:T}):n;return s.jsxs("section",{className:"flex h-full w-full flex-col bg-surface",children:[s.jsx(Yd,{title:e,unreadCount:t,isDesktop:!1,showSearch:yl(v),onMenuClick:()=>x?.openNav(),searchValue:f,onSearchChange:m,onSearchClear:h,searchOpen:g,onSearchOpenChange:y}),s.jsx("div",{className:"min-h-0 flex-1",children:O}),r]})}const Ix={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()},Va=()=>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))}),Rx=({accountEmail:e})=>{const t=Re();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(Rt,{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:U("group w-full",ns({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(Ze,{name:e.fromName,email:e.fromEmail,size:"sm"}),s.jsx(rs,{thread:e})]})};function Sl({accounts:e,selectedMessageId:t,onSelectMessage:n,onSelectSearchResult:r}){const{searchQuery:a,mailboxNameIndex:o,accountNameIndex:i}=Me(),c=Ot(),u=l.useMemo(()=>vx(e.filter(A=>!A.muted?.value)),[e]),[d,f]=l.useState("all"),[m,h]=l.useState("all"),[p,b]=l.useState(new Set),[x,v]=l.useState(!1),g=l.useCallback(A=>{b(P=>{const K=new Set(P);return K.has(A)?K.delete(A):K.add(A),K})},[]),{data:y,isLoading:w,isError:j,refetch:I}=oe({...cr(),staleTime:6e4}),N=At({queries:u.map(A=>({...Je({path:{accountId:A.accountId}}),staleTime:1/0,meta:{softError:!0}}))}),S=l.useMemo(()=>{const A=new Map;for(let P=0;P<u.length;P++){const K=u[P].accountId,me=(N[P]?.data?.items??[]).reduce((he,ue)=>he+(ue.unseenCount??0),0);A.set(K,me)}return A},[u,N]),C=l.useMemo(()=>u.filter((A,P)=>{const K=N[P];return K?.isError?!_n(K.error):!1}),[u,N]),{freeText:k,tokens:M}=Ds(a.trim().toLowerCase(),{mailboxesByName:o,accountsByName:i}),R=l.useMemo(()=>(y?.items??[]).filter(P=>d==="all"||(P.accountId??P.accountConfigId)===d).map(gl).filter(P=>(!k||xl(P,k))&&pl(P,M)),[y,d,k,M]),D=l.useMemo(()=>yx(R),[R]),E=l.useMemo(()=>u.length<=1?[]:[{id:"all",label:"All",active:d==="all"},...u.map(A=>({id:A.accountId,label:A.email.split("@")[0]??A.email,count:S.get(A.accountId),active:d===A.accountId}))],[u,S,d]),T=l.useMemo(()=>e.filter(A=>A.muted?.value).length,[e]),O=l.useMemo(()=>Array.from(S.values()).reduce((A,P)=>A+P,0),[S]),B=l.useMemo(()=>{const A=Array.from(p).map(P=>Ix[P]).filter(P=>P!=null);return R.filter(P=>(m==="all"||P.category===m)&&A.every(K=>K(P))).map(bl)},[R,m,p]),{hits:q,isLoading:X}=hl(),z=l.useMemo(()=>{const A=new Map;for(const K of y?.items??[])A.set(K.messageId,K.threadId);const P=B.map(K=>A.get(K.id)).filter(K=>K!=null);return vl(q,P)},[q,B,y]),$=l.useMemo(()=>{const A=Nf(E.map(P=>({id:P.id,label:P.label,count:P.count,active:P.active})));return{categories:A.categories,filters:A.filters,sources:A.sources,sourcesNote:T>0?`+${T} muted`:void 0,selectedCategory:m,activeFilters:p,expanded:x,onExpandedChange:v,onSelectCategory:P=>h(P),onSelectSource:f,onToggleFilter:g,onClear:()=>{h("all"),f("all"),b(new Set)}}},[E,T,m,p,x,g]),ee=D.length===0&&d==="all"&&k.length===0,te=w?s.jsxs("div",{className:"h-full overflow-y-auto",children:[s.jsx(Va,{}),s.jsx(Va,{})]}):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(Rt,{className:"size-8 text-danger"}),s.jsx("p",{children:"Couldn't load your messages"}),s.jsxs("button",{type:"button",onClick:()=>I(),className:"flex items-center gap-1 text-accent underline text-xs",children:[s.jsx(Fo,{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(Xe,{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(oo,{sections:D,Row:Mx,briefCategory:m,onSelectBriefCategory:h,sources:E,sourcesNote:T>0?`+${T} muted`:void 0,onSelectSource:f,selectedThreadId:t,onSelectThread:n});return s.jsx(jl,{title:"Daily brief",unreadCount:O,footer:c?s.jsx(Uo,{}):void 0,searchFilter:$,searchResults:B,searchLoading:w,relatedResults:z,relatedLoading:X,onSelectSearchResult:r,children:s.jsxs("div",{className:"flex h-full flex-col",children:[C.map(A=>s.jsx(Rx,{accountEmail:A.email,accountId:A.accountId},A.accountId)),s.jsx("div",{className:"min-h-0 flex-1",children:te})]})})}const Nl=({isOpen:e,title:t,description:n,confirmLabel:r,cancelLabel:a="Cancel",destructive:o=!1,isBusy:i=!1,onConfirm:c,onCancel:u})=>{const d=l.useRef(null),f=l.useCallback(m=>{m.key==="Escape"&&(m.preventDefault(),m.stopPropagation(),m.stopImmediatePropagation(),u())},[u]);return l.useEffect(()=>{if(e)return window.addEventListener("keydown",f,!0),()=>window.removeEventListener("keydown",f,!0)},[e,f]),l.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:ce("relative z-10 w-full max-w-sm","bg-surface border border-line rounded-sm shadow-lg","p-6"),onClick:m=>m.stopPropagation(),onKeyDown:m=>m.stopPropagation(),children:[s.jsx("h2",{className:"text-lg font-semibold",children:t}),n&&s.jsx("p",{className:"mt-2 text-sm text-fg-muted",children:n}),s.jsxs("div",{className:"mt-6 flex items-center justify-end gap-2",children:[s.jsx("button",{ref:d,type:"button",onClick:u,className:ce("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:c,disabled:i,className:ce("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},Tx=10,kl=e=>({q:e?.toLowerCase()??"",limit:Tx}),Dx=(e,t)=>{if(!t)return;const n=t.toLowerCase();return e?.find(r=>r.normalizedEmail===n)};function Ax(e){const t=new Date(e),n=new Date;return t.toDateString()===n.toDateString()?"today":tn(t,{month:"short",year:"numeric"})}function Cl(e){if(!e)return!0;const[,t]=e.split("@");return t?!t.includes("."):!0}const Ox="We can't verify the sender of this email, which could mean it's from an insecure source.",Px="We couldn't read this sender's address, so we can't confirm who really sent this message.";function Lx(e,t){return{name:e.fromName??e.fromEmail??"Unknown",email:e.fromEmail??"",trust:e.senderTrust,firstSeenLabel:t?Ax(t.createdAt):"unknown",inboundCount:t?.inboundCount,replyCount:t?.replyCount,addressUnverified:Cl(e.fromEmail)}}function zx(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 _x(e,t){const n=t>0?t:void 0;if(Cl(e.fromEmail))return{verdict:"mismatch",fromDomain:"",addressUnreadable:!0,summary:Px,similarCount:n};const r=e.authenticity;if(!r)return{verdict:"caution",fromDomain:e.fromEmail?.split("@")[1]??"",summary:Ox};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,c=i?`The display name claims "${i}", but this message was actually sent from ${o??"another sender"} — not ${a}. Real senders use their own address.`:`This message claims to be from ${a}, but it was actually sent from ${o??"a different sender"}.`;return{verdict:"mismatch",fromDomain:a,dkimDomain:o,claimedBrand:i,summary:c,similarCount:n}}function El(e,t){const n=e?.fromEmail??null,r=e?.subject??"",{data:a,error:o}=oe({...vo({query:kl(n??void 0)}),enabled:!!n,staleTime:3e4}),i=Dx(a?.items,n??void 0),c=[r,n].filter(Boolean).join(" "),{data:u,isLoading:d,error:f}=oe({...So({query:{query:c,limit:5}}),enabled:!!(e&&c.length>3),staleTime:6e4,retry:1});return{data:l.useMemo(()=>{if(!e)return null;const h=(u?.items??[]).filter(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?wt(g.sentDate*1e3):"",matched:g.matchedChunkType})),p=Lx(e,i),b=_x(e,h.length),x={value:e.category??"personal",overridden:i?.flags?.category?.value!=null&&i.flags.category.value!==e.category},v=zx(i);return{sender:p,authenticity:b,category:x,flags:v,similar:h}},[e,i,u,t]),isSimilarLoading:d,similarError:f,similarErrorIsFatal:_n(f),addressErrorIsFatal:_n(o),addressId:i?.addressId,address:i}}function Fx(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 Il({addressId:e,senderEmail:t}){const n=je(),{pushError:r}=He(),a=Uc({query:kl(t)}),{mutate:o,isPending:i}=be({...jo(),onMutate:async u=>{const d=u.body.flags??{};await n.cancelQueries({queryKey:a});const f=n.getQueryData(a);return n.setQueryData(a,m=>m&&{...m,items:m.items.map(h=>h.addressId===u.path.addressId?{...h,flags:Fx(h.flags,d)}:h)}),{previous:f}},onError:(u,d,f)=>{f?.previous!==void 0&&n.setQueryData(a,f.previous),r({title:"Couldn't update sender preference",detail:Ye(u),error:u})},onSettled:()=>{n.invalidateQueries({queryKey:a})}});return{updateFlags:l.useCallback(u=>{if(!e){No(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 Bx=e=>e==="vip"?"A sender you know":e==="wellknown"?"You've emailed them before":"Passed authentication",Rl=e=>e.senderTrust!=="vip"&&e.senderTrust!=="wellknown"?!1:e.authenticity?.dkimMismatch!==!0;function $x(e,t){e.recordEvent("rescue.candidates_surfaced",{count:String(t)})}function Kx(e,t){e.recordEvent("rescue.flow_opened",{count:String(t)})}function qx(e,t){e.recordEvent("rescue.committed",{selected:String(t.selected),total:String(t.total),destination:t.toInbox?"inbox":"other"})}function Ml(e,t){e.recordEvent("rescue.sent_to_junk",{count:String(t.count),senderTrust:t.senderTrust,wasRescuable:String(t.wasRescuable)})}const Ux=["personal","newsletter","marketing","automated","transactional","social"],Hx=e=>{const{mailboxId:t,junkMailboxId:n,inboxMailboxId:r}=e;return t?n&&t===n?r?"notSpam":null:n?"markSpam":null:null},Qx=e=>{const{similarError:t,similarErrorIsFatal:n,isSimilarLoading:r}=e;return t&&!n?"error":r?"loading":"ready"};function Wx(){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(Xe,{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 Vx({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:Ux.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 Yx({thread:e,onClose:t,mailboxId:n,accountId:r,hideCloseButton:a}){const{data:o,addressId:i,isSimilarLoading:c,similarError:u,similarErrorIsFatal:d}=El(e,n),[f,m]=l.useState(!1),[h,p]=l.useState(!1),b=e.fromEmail??void 0,{updateFlags:x,isPending:v}=Il({addressId:i,senderEmail:b}),{junkMailboxId:g}=Nr(r),{inboxMailboxId:y}=Sr(r),{moveMessages:w}=gt({mailboxId:n??"",threadId:e.threadId,accountId:r}),j=Ss(),I=Hx({mailboxId:n,junkMailboxId:g,inboxMailboxId:y}),N=l.useCallback(()=>{y&&w([e.messageId],y)},[y,w,e.messageId]),S=l.useCallback(()=>{g&&(Ml(j,{count:1,senderTrust:e.senderTrust,wasRescuable:Rl(e)}),w([e.messageId],g))},[g,w,e,j]),C=l.useCallback(()=>{},[]),k=l.useCallback(()=>{const z=o?.flags?.vip!==!0;x({vip:{value:z}})},[o?.flags?.vip,x]),M=l.useCallback(()=>{const z=o?.flags?.muted!==!0;x({muted:{value:z}})},[o?.flags?.muted,x]),R=l.useCallback(()=>{o?.flags?.blocked===!0?x({blocked:{value:!1}}):m(!0)},[o?.flags?.blocked,x]),D=l.useCallback(()=>{m(!1),x({blocked:{value:!0}})},[x]),E=l.useCallback(()=>{const z=o?.flags?.unsubscribed!==!0;x({unsubscribed:{value:z}})},[o?.flags?.unsubscribed,x]),T=l.useCallback(z=>{p(!1),x({category:{value:z}})},[x]),O=i!==void 0,B={onToggleVip:O?k:void 0,onToggleMute:O?M:void 0,onToggleBlock:O?R:void 0,onToggleUnsubscribe:O?E:void 0,onReclassify:O?()=>p(!0):void 0,onNotSpam:I==="notSpam"?N:void 0,onMarkSpam:I==="markSpam"?S:void 0},q=({mailboxId:z,messageId:$,className:ee,ariaLabel:te,children:A})=>s.jsx(ot,{to:"/mail/$mailboxId",params:{mailboxId:z},search:P=>({...P,selectedMessageId:$}),className:ee,"aria-label":te,children:A});if(!o)return s.jsx(Wx,{});const X=Qx({similarError:u,similarErrorIsFatal:d,isSimilarLoading:c});return s.jsxs(s.Fragment,{children:[s.jsx(qo,{data:o,onClose:t,hideCloseButton:a,onShowSimilar:C,actions:B,similarState:X,similarLinkComponent:q,className:"border-l-0 h-full w-full"}),s.jsx(Nl,{isOpen:f,title:"Block this sender?",description:`Messages from ${b??"this sender"} will never load images and will be flagged. You can undo this in Settings → Senders.`,confirmLabel:"Block sender",destructive:!0,isBusy:v,onConfirm:D,onCancel:()=>m(!1)}),s.jsx(Vx,{isOpen:h,current:o.category.value,onSelect:T,onCancel:()=>p(!1)})]})}const bn=({onClose:e,thread:t,mailboxId:n,accountId:r,hideCloseButton:a})=>t?s.jsx(Yx,{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(Xe,{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(Xe,{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."})]})]}),On="Open a message first",Mr=({hasThread:e,intelligenceOpen:t,showIntelligenceToggle:n,onToggleIntelligence:r,onReply:a,onReplyAll:o,onForward:i,onDelete:c,canDelete:u,onToggleStar:d,isStarred:f,moveContext:m})=>{const[h,p]=l.useState(null),b=u??e,x=v=>()=>p(v);return s.jsx(Yu,{hasThread:e,isStarred:f,onUnavailable:v=>p(On),unavailableHint:h,replyTitle:`Reply ${Ht("reply")}`,replyAllTitle:`Reply all ${Ht("replyAll")}`,forwardTitle:`Forward ${Ht("forward")}`,deleteTitle:`Move to Trash ${Ht("delete")}`,flagTitle:`Star ${Ht("toggleStar")}`,onReply:a,onReplyAll:o,onForward:i,onDelete:b?c:x(On),onToggleStar:d,onMove:x(On),moveSlot:m?s.jsx(Ts,{accountId:m.accountId,currentMailboxId:m.currentMailboxId,onMove:m.onMove,label:"Move to mailbox"}):void 0,children:n&&s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(lo,{className:"size-4"}),title:"Intelligence","aria-label":t?"Hide intelligence sidebar":"Show intelligence sidebar","aria-pressed":t,onClick:r,className:t?"bg-accent-2-soft text-accent-2":void 0})})};function Gx(e){return{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,messageId:e.messageId,authenticity:e.authenticity}}function Tl(e,t){if(e)return Gx(e);if(t.messageId&&t.threadId&&t.mailboxId)return{threadId:t.threadId,mailboxId:t.mailboxId,messageId:t.messageId}}const Dl=l.createContext(null);function Tr(){const e=l.useContext(Dl);if(!e)throw new Error("BriefPane.* must be used inside <BriefPane>");return e}function Xx({selectedMessageId:e,children:t}){const n=Re(),{searchInput:r}=Me(),{selectedThreadId:a,selectedMailboxId:o}=Yt({strict:!1}),{data:i}=oe({...cr(),staleTime:6e4}),c=l.useMemo(()=>{if(e)return i?.items.find(p=>p.messageId===e)},[i,e]),u=l.useMemo(()=>Tl(c,{messageId:e,threadId:a,mailboxId:o}),[c,e,a,o]),d=l.useCallback(p=>{n({to:"/mail",search:b=>({...b,selectedMessageId:p,selectedThreadId:void 0,selectedMailboxId:void 0})})},[n]),f=l.useCallback(p=>{n({to:"/mail",search:b=>({...b,q:r||void 0,selectedMessageId:p.id,selectedThreadId:p.threadId,selectedMailboxId:p.mailboxId})})},[n,r]),m=l.useCallback(()=>{n({to:"/mail",search:p=>({...p,selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0})})},[n]),h={selectedMessageId:e,selectedThread:c,conversation:u,onSelectMessage:d,onSelectSearchResult:f,onCloseThread:m};return s.jsx(Dl.Provider,{value:h,children:t})}function Jx(){const{selectedMessageId:e,onSelectMessage:t,onSelectSearchResult:n}=Tr(),{accounts:r}=Me();return s.jsx(Sl,{accounts:r,selectedMessageId:e,onSelectMessage:t,onSelectSearchResult:n})}function Zx(){const{conversation:e}=Tr(),{onToggleIntelligence:t}=Me();return s.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[s.jsx(Mr,{hasThread:!!e,intelligenceOpen:!1,showIntelligenceToggle:!1,onToggleIntelligence:t}),s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?s.jsx(os,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,selectedMessageId:e.messageId,authenticity:e.authenticity}):s.jsx(as,{})})]})}function ep(){const{selectedThread:e,conversation:t,selectedMessageId:n,onSelectMessage:r,onSelectSearchResult:a,onCloseThread:o}=Tr(),{accounts:i,intelligenceOpen:c,onToggleIntelligence:u}=Me();return t?s.jsxs(s.Fragment,{children:[s.jsx(os,{threadId:t.threadId,mailboxId:t.mailboxId,subject:t.subject,selectedMessageId:t.messageId,authenticity:t.authenticity,onBack:o,onOpenIntelligence:u}),s.jsx(yr,{isOpen:c,onClose:u,ariaLabel:"Message details",side:"right",children:s.jsx(bn,{onClose:u,thread:e,hideCloseButton:!0})})]}):s.jsx("div",{className:"h-full",children:s.jsx(Sl,{accounts:i,selectedMessageId:n,onSelectMessage:r,onSelectSearchResult:a})})}const Ws=Object.assign(Xx,{List:Jx,Reading:Zx,Phone:ep}),tp=e=>{const t=new Set;return e.filter(n=>t.has(n.threadId)?!1:(t.add(n.threadId),!0))};function Al({title:e,unreadCount:t,preset:n,selectedCategory:r,activeFilters:a,onSelectCategory:o,onToggleFilter:i,onSelectSource:c,onClearFilters:u,children:d,footer:f,searchResults:m,searchLoading:h,relatedResults:p,relatedLoading:b,onSelectSearchResult:x}){const[v,g]=l.useState(!1),y={categories:n.categories,filters:n.filters,sources:n.sources,selectedCategory:r,activeFilters:a,expanded:v,onExpandedChange:g,onSelectCategory:o,onSelectSource:c,onToggleFilter:i,onClear:u};return s.jsx(jl,{title:e,unreadCount:t,footer:f,searchFilter:y,searchResults:m,searchLoading:h,relatedResults:p,relatedLoading:b,onSelectSearchResult:x,children:s.jsx(Zn,{...y,children:d})})}const sp={unread:e=>!e.isRead,attachment:e=>e.hasAttachment===!0};function np({selectedMessageId:e,onSelectMessage:t}){const{searchQuery:n,mailboxNameIndex:r,accountNameIndex:a}=Me(),o=Ot(),[i,c]=l.useState("all"),[u,d]=l.useState(new Set),f=l.useCallback(E=>{d(T=>{const O=new Set(T);return O.has(E)?O.delete(E):O.add(E),O})},[]),m=l.useCallback(()=>{c("all"),d(new Set)},[]),{data:h,isLoading:p,isError:b,error:x,refetch:v,fetchNextPage:g,hasNextPage:y,isFetchingNextPage:w}=wi({queryKey:wo({query:{starred:!0,order:"desc"}}),queryFn:async({pageParam:E})=>{const{data:T}=await Hc({query:{starred:!0,order:"desc",continuationToken:E},throwOnError:!0});return T},initialPageParam:void 0,getNextPageParam:E=>E.continuationToken,staleTime:6e4}),{freeText:j,tokens:I}=Ds(n.trim().toLowerCase(),{mailboxesByName:r,accountsByName:a}),N=l.useMemo(()=>{const E=Array.from(u).map(T=>sp[T]).filter(T=>T!=null);return tp((h?.pages??[]).flatMap(T=>T.items??[])).map(gl).filter(T=>(i==="all"||T.category===i)&&E.every(O=>O(T))&&(!j||xl(T,j))&&pl(T,I))},[h,i,u,j,I]),S=l.useMemo(()=>Cf(),[]),C=l.useMemo(()=>N.map(bl),[N]),k=l.useMemo(()=>N.filter(E=>!E.isRead).length,[N]),M=p?"loading":b?"error":N.length===0?"empty":"ready",R=l.useCallback(()=>{const E=or(ar());window.open(E,"_blank","noopener,noreferrer")},[]),D=s.jsxs("div",{className:"flex-1 overflow-y-auto",children:[s.jsx("div",{className:"divide-y divide-line",children:N.map(E=>s.jsx(Vo,{thread:E,active:E.id===e,onClick:()=>t?.(E.id)},E.id))}),y?s.jsx("button",{type:"button",className:"w-full py-3 text-sm text-muted hover:text-fg disabled:opacity-50",onClick:()=>g(),disabled:w,children:w?"Loading…":"Load more"}):null]});return s.jsx(Al,{title:"Starred",unreadCount:k,preset:S,selectedCategory:i,activeFilters:u,onSelectCategory:c,onToggleFilter:f,onClearFilters:m,searchResults:C,searchLoading:p,onSelectSearchResult:E=>t?.(E.id),children:s.jsx(Xo,{listTitle:"Starred",sections:[{id:"flagged",threads:N}],flatList:!0,hideHeader:!0,listState:M,searchQuery:j?n:void 0,errorMessage:b?Io(x):void 0,onRetry:()=>v(),onReportError:R,selectedThreadId:e,onSelectThread:t,onSelectBriefCategory:()=>{},isDesktop:o,listBody:M==="ready"?D:void 0})})}const Ol=l.createContext(null);function Dr(){const e=l.useContext(Ol);if(!e)throw new Error("FlaggedPane.* must be used inside <FlaggedPane>");return e}function rp({selectedMessageId:e,children:t}){const n=Re(),{data:r}=oe({...cr(),staleTime:6e4}),a=l.useMemo(()=>{if(e)return r?.items.find(u=>u.messageId===e)},[r,e]),o=l.useCallback(u=>{n({to:"/mail/flagged",search:d=>({...d,selectedMessageId:u})})},[n]),i=l.useCallback(()=>{n({to:"/mail/flagged",search:u=>({...u,selectedMessageId:void 0})})},[n]),c={selectedMessageId:e,selectedThread:a,onSelectMessage:o,onCloseThread:i};return s.jsx(Ol.Provider,{value:c,children:t})}function Pl(){const{selectedMessageId:e,onSelectMessage:t}=Dr();return s.jsx(np,{selectedMessageId:e,onSelectMessage:t})}function ap(){const{selectedThread:e}=Dr(),{onToggleIntelligence:t}=Me();return s.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[s.jsx(Mr,{hasThread:!!e,intelligenceOpen:!1,showIntelligenceToggle:!1,onToggleIntelligence:t}),s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?s.jsx(os,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,authenticity:e.authenticity}):s.jsx(as,{})})]})}function op(){const{selectedThread:e,onCloseThread:t}=Dr(),{intelligenceOpen:n,onToggleIntelligence:r}=Me();return e?s.jsxs(s.Fragment,{children:[s.jsx(os,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,authenticity:e.authenticity,onBack:t,onOpenIntelligence:r}),s.jsx(yr,{isOpen:n,onClose:r,ariaLabel:"Message details",side:"right",children:s.jsx(bn,{onClose:r,thread:e,hideCloseButton:!0})})]}):s.jsx("div",{className:"h-full",children:s.jsx(Pl,{})})}const Vs=Object.assign(rp,{List:Pl,Reading:ap,Phone:op}),ip={reply:"Reply",reply_all:"Reply All",forward:"Forward",new:"New Message"},lp=()=>{const e=l.useRef(!1);return l.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},[])},cp=()=>{const{state:e,closeCompose:t}=pt(),n=lp(),[r,a]=l.useState(!1),{isError:o,error:i,refetch:c}=oe({...it(),staleTime:1/0}),u=l.useCallback(h=>{h||(n()?a(!0):t())},[t,n]),d=l.useCallback(()=>{a(!1),t()},[t]),f=l.useCallback(()=>{a(!1)},[]);if(!e.isOpen)return null;const m=ip[e.mode]??"New Message";return s.jsxs(Fe.Root,{open:e.isOpen,onOpenChange:u,children:[s.jsxs(Fe.Portal,{children:[s.jsx(Fe.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),s.jsxs(Fe.Content,{className:"fixed inset-x-0 bottom-0 z-50 flex flex-col bg-canvas rounded-t-lg",style:{height:"95dvh"},children:[s.jsx(Fe.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-muted/30"}),s.jsx(Fe.Title,{className:"px-4 py-2 text-base font-semibold border-b border-line",children:m}),o?s.jsx("div",{className:"flex-1 flex items-center justify-center p-4",children:s.jsx(yt,{title:"Couldn't load compose",error:i,onRetry:()=>{c()}})}):s.jsx("div",{className:"flex-1 overflow-hidden",children:s.jsx(wr,{mode:e.mode,account:e.account,sourceMessage:e.sourceMessage,onClose:t})})]})]}),r&&s.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center bg-black/50",children:s.jsxs("div",{className:"mx-4 w-full max-w-sm rounded-xl bg-canvas p-6 shadow-xl",children:[s.jsx("h3",{className:"text-lg font-semibold",children:"Discard draft?"}),s.jsx("p",{className:"mt-2 text-sm text-fg-muted",children:"Your message has unsaved content. Are you sure you want to discard it?"}),s.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[s.jsx("button",{type:"button",onClick:f,className:"rounded-md px-4 py-2 text-sm font-medium hover:bg-surface-raised transition-colors",children:"Keep editing"}),s.jsx("button",{type:"button",onClick:d,className:"rounded-md bg-danger px-4 py-2 text-sm font-medium text-canvas hover:bg-danger/90 transition-colors",children:"Discard"})]})]})})]})},up={reply:"Reply",reply_all:"Reply All",forward:"Forward",new:"New Message"},Ll=()=>{const{state:e,closeCompose:t}=pt(),n=Ot(),{isError:r,error:a,refetch:o}=oe({...it(),staleTime:1/0});if(!n)return s.jsx(cp,{});if(!e.isOpen)return null;const i=up[e.mode]??"New Message",c=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(Be,{className:"size-5"})})]});return r?s.jsxs("div",{className:"h-full flex flex-col bg-canvas",children:[c,s.jsx("div",{className:"flex-1 flex items-center justify-center p-4",children:s.jsx(yt,{title:"Couldn't load compose",error:a,onRetry:()=>{o()}})})]}):s.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-canvas",children:[c,s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:s.jsx(wr,{mode:e.mode,account:e.account,sourceMessage:e.sourceMessage,onClose:t},e.outboxMessageId??"new")})]})};function dp(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:wt(e.updatedAt),isRead:!0}}function fp(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:wt(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0}}function mp({outboxMessages:e,accountId:t,imapThreads:n}){const r=e.filter(i=>i.status==="draft"&&i.accountId===t).map(dp),a=n.map(fp),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 Ar(){const e=lr();return!e||e.showNavPane?null:s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(fr,{className:"size-4"}),onClick:e.openNav,"aria-label":"Open folders",className:"-ml-1 shrink-0"})}const hp=({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})]}),gp=({row:e,isSelected:t,onOpen:n,onDelete:r,isDeleting:a})=>s.jsxs("button",{type:"button",onClick:()=>n(e.id),className:U("group",ns({active:t})),children:[s.jsx(Eo,{className:"size-7 shrink-0 text-fg-muted mt-0.5"}),s.jsx(rs,{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(et,{className:"size-3.5"})})})]}),xp=({row:e,isSelected:t,onOpen:n})=>{const r=!e.isRead;return s.jsxs("button",{type:"button",onClick:()=>n(e.id),className:U("group",ns({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(Ze,{name:e.fromName,email:e.fromEmail,size:"sm"}),s.jsx(rs,{thread:e})]})};function pp({mailboxId:e,accountId:t,selectedMessageId:n,imapThreads:r,title:a,unreadCount:o}){const{openCompose:i,state:c}=pt(),u=Re(),d=je(),{data:f}=oe(an()),m=l.useMemo(()=>mp({outboxMessages:f?.items??[],accountId:t,imapThreads:r}),[f?.items,t,r]),h=be({...on(),onSuccess:()=>{d.invalidateQueries({queryKey:ur()})}}),p=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})},x=g=>{u({to:"/mail/$mailboxId",params:{mailboxId:e},search:{selectedMessageId:g}})},v=m.length===0;return s.jsxs("section",{className:"flex h-full w-full flex-col bg-surface",children:[s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[s.jsx(Ar,{}),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(Jn,{className:"size-8 text-fg-subtle"}),s.jsx("p",{className:"text-sm font-medium text-fg",children:"No drafts"}),s.jsx("p",{className:"text-xs text-fg-subtle",children:"Messages you start composing will appear here."})]}):m.map(g=>s.jsxs("div",{children:[g.label&&s.jsx(hp,{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(gp,{row:y,isSelected:c.isOpen&&y.id===c.outboxMessageId,onOpen:b,onDelete:p,isDeleting:h.isPending},y.id):s.jsx(xp,{row:y,isSelected:y.id===n,onOpen:x},y.id))})]},g.id))})]})}function bp(e,t,n){const r=new Array(e);return new Proxy(r,{get(a,o,i){if(typeof o=="string"){const c=o.charCodeAt(0);if(c>=48&&c<=57){const u=+o;if(Number.isInteger(u)&&u>=0&&u<e){let d=a[u];if(!d){const f=t[u*2];d=a[u]={index:u,key:n(u),start:f,size:t[u*2+1],end:f+t[u*2+1],lane:0}}return d}}if(o==="length")return e}return Reflect.get(a,o,i)}})}function Ut(e,t,n){let r=n.initialDeps??[],a,o=!0;function i(){const c=e();return(c.length!==r.length||c.some((d,f)=>r[f]!==d))&&(r=c,a=t(...c),n?.onChange&&!(o&&n.skipInitialOnChange)&&n.onChange(a),o=!1),a}return i.updateDeps=c=>{r=c},i}function Ya(e,t){if(e===void 0)throw new Error("Unexpected undefined");return e}const vp=(e,t)=>Math.abs(e-t)<1.01,yp=(e,t,n)=>{let r;return function(...a){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,a),n)}};let gs;const Pn=()=>{if(gs!==void 0)return gs;if(typeof navigator>"u")return gs=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return gs=!0;const e=navigator.maxTouchPoints;return gs=navigator.platform==="MacIntel"&&e!==void 0&&e>0},Ga=e=>{const{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},wp=e=>e,jp=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},Sp=(e,t)=>{const n=e.scrollElement;if(!n)return;const r=e.targetWindow;if(!r)return;const a=i=>{const{width:c,height:u}=i;t({width:Math.round(c),height:Math.round(u)})};if(a(Ga(n)),!r.ResizeObserver)return()=>{};const o=new r.ResizeObserver(i=>{const c=()=>{const u=i[0];if(u?.borderBoxSize){const d=u.borderBoxSize[0];if(d){a({width:d.inlineSize,height:d.blockSize});return}}a(Ga(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(c):c()});return o.observe(n,{box:"border-box"}),()=>{o.unobserve(n)}},nn={passive:!0},Np=typeof window>"u"?!0:"onscrollend"in window,kp=(e,t,n)=>{const r=e.scrollElement;if(!r)return;const a=e.targetWindow;if(!a)return;const o=e.options.useScrollendEvent&&Np;let i=0;const c=o?null:yp(a,()=>t(i,!1),e.options.isScrollingResetDelay),u=m=>()=>{i=n(r),c?.(),t(i,m)},d=u(!0),f=u(!1);return r.addEventListener("scroll",d,nn),o&&r.addEventListener("scrollend",f,nn),()=>{r.removeEventListener("scroll",d),o&&r.removeEventListener("scrollend",f)}},Cp=(e,t)=>kp(e,t,n=>{const{horizontal:r,isRtl:a}=e.options;return r?n.scrollLeft*(a&&-1||1):n.scrollTop}),Ep=(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"]},Ip=(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})},Rp=Ip;class Mp{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 c=o.target,u=this.indexFromElement(c);if(!c.isConnected){this.observer.unobserve(c);for(const[d,f]of this.elementsCache)if(f===c){this.elementsCache.delete(d);break}return}this.shouldMeasureDuringScroll(u)&&this.resizeItem(u,this.options.measureElement(c,o,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(i):i()})}));return{disconnect:()=>{var a;(a=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:wp,rangeExtractor:jp,onChange:()=>{},measureElement:Ep,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 p=n[h];p!==void 0&&(o[h]=p)}const i=this.options;let c=null,u=null,d=!1;if(i!==void 0&&i.enabled&&o.enabled&&o.anchorTo==="end"&&this.scrollElement!==null){const h=i.count,p=o.count,b=this.getMeasurements(),x=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(p!==h||h>0&&p>0&&(o.getItemKey(0)!==x||o.getItemKey(p-1)!==v)){d=!0;const w=h>0?this.getVirtualItemForOffset(this.getScrollOffset())??b[0]:null;w&&(c=[w.key,this.getScrollOffset()-w.start]);const j=o.followOnAppend===!0?"auto":o.followOnAppend||null;j&&p>h&&this.isAtEnd(i.scrollEndThreshold)&&(h===0||o.getItemKey(p-1)!==v)&&(u=j)}}this.options=o,d&&(this.pendingMin=0,this.itemSizeCacheVersion++);let f=!1,m=0;if(c&&this.scrollOffset!==null){const[h,p]=c,b=this.getMeasurements(),{count:x,getItemKey:v}=this.options;let g=0;for(;g<x&&v(g)!==h;)g++;if(g<x){const y=b[g];if(y){const w=y.start+p;w!==this.scrollOffset&&(m=w-this.scrollOffset,this.scrollOffset=w,f=!0)}}}(f||u)&&(this.pendingScrollAnchor=[f?c[0]:null,f?c[1]:0,u,m])},this.notify=n=>{var r,a;(a=(r=this.options).onChange)==null||a.call(r,this,n)},this.maybeNotify=Ut(()=>(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 c=this.getScrollOffset();this.scrollDirection=i?c===o?this.scrollDirection:c<o?"forward":"backward":null,this.scrollOffset=o,this.isScrolling=i,this._flushIosDeferredIfReady(),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),"addEventListener"in this.scrollElement){const o=this.scrollElement,i=()=>{this._iosTouching=!0,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)},c=()=>{this._iosTouching=!1,!(!Pn()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};o.addEventListener("touchstart",i,nn),o.addEventListener("touchend",c,nn),this.unsubs.push(()=>{o.removeEventListener("touchstart",i),o.removeEventListener("touchend",c),this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)})}this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}const a=this.pendingScrollAnchor;if(this.pendingScrollAnchor=null,a&&this.scrollElement&&this.options.enabled){const[o,i,c,u]=a;o!==null&&!c&&(Pn()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?u!==0&&(this._iosDeferredAdjustment+=u):this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})),c&&this.scrollToEnd({behavior:c})}},this._flushIosDeferredIfReady=()=>{if(this._iosDeferredAdjustment===0||this.isScrolling||this._iosTouching||this._iosJustTouchEnded)return;const 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=Ut(()=>[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,c,u,d)=>(this.prevLanes!==void 0&&this.prevLanes!==c&&(this.lanesChangedFlag=!0),this.prevLanes=c,this.pendingMin=null,{count:n,paddingStart:r,scrollMargin:a,getItemKey:o,enabled:i,lanes:c,laneAssignmentMode:u,gap:d}),{key:!1}),this.getMeasurements=Ut(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:n,paddingStart:r,scrollMargin:a,getItemKey:o,enabled:i,lanes:c,laneAssignmentMode:u,gap:d},f)=>{const m=this.itemSizeCache;if(!i)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>n)for(const 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),c===1){const g=n*2;let y=this._flatMeasurements;if(!y||y.length<g){const I=new Float64Array(g);y&&h>0&&I.set(y.subarray(0,h*2)),y=I,this._flatMeasurements=y}let w;if(h===0)w=r+a;else{const I=h-1;w=y[I*2]+y[I*2+1]+d}for(let I=h;I<n;I++){const N=o(I),S=m.get(N),C=typeof S=="number"?S:this.options.estimateSize(I);y[I*2]=w,y[I*2+1]=C,w+=C+d}const j=bp(n,y,o);return this.measurementsCache=j,j}const p=this.measurementsCache.slice(0,h),b=new Array(c).fill(void 0),x=new Float64Array(c);let v=0;for(let g=0;g<h;g++){const y=p[g];y&&(b[y.lane]===void 0&&v++,b[y.lane]=g,x[y.lane]=y.end)}for(let g=h;g<n;g++){const y=o(g),w=this.laneAssignments.get(g);let j,I;const N=u==="estimate"||m.has(y);if(w!==void 0&&this.options.lanes>1){j=w;const M=b[j],R=M!==void 0?p[M]:void 0;I=R?R.end+d:r+a}else if(v===c){let M=0,R=x[0],D=b[0];for(let E=1;E<c;E++){const T=x[E];(T<R||T===R&&b[E]<D)&&(M=E,R=T,D=b[E])}j=M,I=R+d,N&&this.laneAssignments.set(g,j)}else j=g%this.options.lanes,I=r+a,N&&this.laneAssignments.set(g,j);const S=m.get(y),C=typeof S=="number"?S:this.options.estimateSize(g),k=I+C;p[g]={index:g,start:I,size:C,end:k,key:y,lane:j},b[j]===void 0&&v++,b[j]=g,x[j]=k}return this.measurementsCache=p,p},{key:!1,debug:()=>this.options.debug}),this.calculateRange=Ut(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(n,r,a,o)=>n.length===0||r===0?(this.range=null,null):(this.range=Dp(n,r,a,o,o===1&&this._flatMeasurements!=null?this._flatMeasurements:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=Ut(()=>{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),c=Math.min(this.options.count-1,a+o);return n>=i&&n<=c}return!0},this.measureElement=n=>{if(!n){this.elementsCache.forEach((i,c)=>{i.isConnected||(this.observer.unobserve(i),this.elementsCache.delete(c))});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,c,u;const d=this._flatMeasurements;if(this.options.lanes===1&&d!==null)u=this.options.getItemKey(n),c=d[n*2],i=d[n*2+1];else{const h=this.measurementsCache[n];if(!h)return;u=h.key,c=h.start,i=h.size}const f=this.itemSizeCache.get(u)??i,m=r-f;if(m!==0){const h=this.options.anchorTo==="end"&&((a=this.scrollState)==null?void 0:a.behavior)!=="smooth"&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,p=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:c,size:i,end:c+i,lane:0},m,this):c<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()-p):b&&this.applyScrollAdjustment(m),this.notify(!1)}},this.getVirtualItems=Ut(()=>[this.getVirtualIndexes(),this.getMeasurements()],(n,r)=>{const a=[];for(let o=0,i=n.length;o<i;o++){const c=n[o],u=r[c];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=zl(0,r.length-1,o?c=>a[c*2]:c=>Ya(r[c]).start,n);return Ya(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 c=this.getMaxScrollOffset();return Math.max(Math.min(c,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 c=r==="end"?i.end+this.options.scrollPaddingEnd:i.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(c,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,c]=o,u=this.now();this.scrollState={index:n,align:c,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(c=>c===null);){const c=r[i];o[c.lane]===null&&(o[c.lane]=c.end),i--}a=Math.max(...o.filter(c=>c!==null))}return Math.max(a-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{const 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&&(Pn()&&(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&&vp(a,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=o){this.getScrollOffset()!==a&&this._scrollToOffset(a,{adjustments:void 0,behavior:"auto"}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,i){const c=this.getSize()||600,u=Math.abs(a-this.getScrollOffset()),d=this.scrollState.behavior==="smooth"&&u>c;this.scrollState.lastTargetOffset=a,d||(this.scrollState.behavior="auto"),this._scrollToOffset(a,{adjustments:void 0,behavior:d?"smooth":"auto"})}this.scheduleScrollReconcile()}}const zl=(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 Tp(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 Dp(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=Tp(a,o,n);let f=d;const m=n+t;for(;f<o&&a[f*2]+a[f*2+1]<m;)f++;return{startIndex:d,endIndex:f}}let c=zl(0,o,d=>e[d].start,n),u=c;if(r===1)for(;u<o&&e[u].end<n+t;)u++;else if(r>1){const d=Array(r).fill(0);for(;u<o&&d.some(m=>m<n+t);){const m=e[u];d[m.lane]=m.end,u++}const f=Array(r).fill(n+t);for(;c>=0&&f.some(m=>m>=n);){const m=e[c];f[m.lane]=m.start,c--}c=Math.max(0,c-c%r),u=Math.min(o,u+(r-1-u%r))}return{startIndex:c,endIndex:u}}const Ln=typeof document<"u"?l.useLayoutEffect:l.useEffect;function Ap({useFlushSync:e=!0,directDomUpdates:t=!1,directDomUpdatesMode:n="transform",...r}){const a=l.useReducer(d=>d+1,0)[1],o=l.useRef({enabled:t,mode:n,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});o.current.enabled=t,o.current.mode=n;const i=d=>{const f=o.current;if(!f.enabled||!f.container)return;const m=d.getTotalSize();if(m!==f.lastSize){f.lastSize=m;const g=d.options.horizontal?"width":"height";f.container.style[g]=`${m}px`}const h=!!d.options.horizontal,p=f.mode==="transform",b=h?"left":"top",x=d.options.scrollMargin,v=d.getVirtualItems();for(const g of v){const y=g.start-x,w=d.elementsCache.get(g.key);w&&f.lastPositions.get(w)!==y&&(f.lastPositions.set(w,y),p?w.style.transform=h?`translate3d(${y}px, 0, 0)`:`translate3d(0, ${y}px, 0)`:w.style[b]=`${y}px`)}},c={...r,onChange:(d,f)=>{var m;const h=o.current;let p=!0;if(h.enabled){i(d);const b=d.range,x=h.prevRange;p=!x||x.isScrolling!==d.isScrolling||x.startIndex!==b?.startIndex||x.endIndex!==b?.endIndex,p&&(h.prevRange=b?{startIndex:b.startIndex,endIndex:b.endIndex,isScrolling:d.isScrolling}:null)}p&&(e&&f?sr.flushSync(a):a()),(m=r.onChange)==null||m.call(r,d,f)}},[u]=l.useState(()=>{const d=new Mp(c);return Object.assign(d,{containerRef:f=>{const m=o.current;if(m.container=f,m.lastSize=null,f&&m.enabled){const h=d.getTotalSize();m.lastSize=h;const p=d.options.horizontal?"width":"height";f.style[p]=`${h}px`}}})});return u.setOptions(c),Ln(()=>u._didMount(),[]),Ln(()=>u._willUpdate()),Ln(()=>{i(u)}),u}function Op(e){return Ap({observeElementRect:Sp,observeElementOffset:Cp,scrollToFn:Rp,...e})}const Pp=(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)},Lp=(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]},zp=e=>{const[t,n]=l.useState(new Set),[r,a]=l.useState(void 0),o=l.useCallback(b=>t.has(b),[t]),i=l.useCallback(b=>{a(b),n(x=>{const v=new Set(x);return v.has(b)?v.delete(b):v.add(b),v})},[]),c=l.useCallback(b=>{a(b),n(x=>{if(x.has(b))return x;const v=new Set(x);return v.add(b),v})},[]),u=l.useCallback(b=>{n(x=>{if(!x.has(b))return x;const v=new Set(x);return v.delete(b),v})},[]),d=l.useCallback(b=>{n(new Set(b))},[]),f=l.useCallback(()=>{a(void 0),n(new Set)},[]),m=l.useCallback(b=>{n(x=>b.every(g=>x.has(g))?new Set:new Set(b))},[]),h=l.useCallback(b=>{a(b)},[]),p=l.useCallback((b,x)=>{n(v=>{const g=Pp(b,r,x);if(g.length===0)return v;const y=new Set(v);for(const w of g)y.add(w);return y}),a(v=>v??x)},[r]);return{selectedIds:t,selectedCount:t.size,hasSelection:t.size>0,isSelected:o,toggle:i,select:c,deselect:u,selectAll:d,clearSelection:f,toggleAll:m,selectRange:p,setAnchor:h,anchorId:r}};function _p(e,t){if(e.length!==0)return t!==void 0&&e.includes(t)?t:e[0]}const Fp=e=>{const t=be(Qc()),{mutate:n}=t;return{preview:l.useCallback(a=>{e&&n({path:{accountId:e},body:Mo(a)})},[e,n]),reset:t.reset,matchedCount:t.data?.matchedCount,messageIds:t.data?.messageIds,isPending:t.isPending,isError:t.isError,error:t.error}},Bp=new Set(["Complete","Failed"]),Xa=e=>e!==void 0&&Bp.has(e),$p=1e3,Kp=15e3,qp=e=>{const t=Math.max(0,e),n=$p*2**t;return Math.min(n,Kp)},Up=e=>{const[t,n]=l.useState(),r=be({...Wc(),onSuccess:m=>n(m.organizeJobId)}),{mutate:a}=r,o=oe({...Vc({path:{accountId:e??"",organizeJobId:t??""}}),enabled:!!e&&!!t,refetchInterval:m=>{const h=m.state.data?.state;return Xa(h)?!1:qp(m.state.dataUpdateCount)}}),i=l.useCallback(m=>{e&&(n(void 0),a({path:{accountId:e},body:Mo(m)}))},[e,a]),c=o.data,u=c?.state??r.data?.state,d=Xa(c?.state),f={state:u,matchedCount:c?.matchedCount??0,appliedCount:c?.appliedCount??0,failedCount:c?.failedCount??0,errorMessage:c?.errorMessage??""};return{start:i,progress:f,isStarting:r.isPending,isRunning:!!t&&!d,isDone:d,isError:r.isError||o.isError,error:r.error??o.error}},Hp=({draft:e,scope:t,name:n,pickedDate:r})=>{if(!pu(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."},Qp=(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"}},Wp=(e,t,n)=>e==="just-these"?t:n,Vp=[{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 Yp({accountId:e,mailboxId:t,selectedMessageIds:n,anchorMessageId:r,matchedCount:a,onClose:o}){const[i,c]=l.useState("all-like-these"),[u,d]=l.useState(""),[f,m]=l.useState(""),[h,p]=l.useState(""),{data:b}=oe({...Je({path:{accountId:e}}),staleTime:1/0}),x=l.useMemo(()=>Rr(b?.items??[]).map(M=>({id:M.mailboxId,label:en(M.fullPath)})),[b?.items]),v=l.useMemo(()=>({anchorMessageId:r,matchOperator:"And",literalClauses:[],moveMailboxId:u||void 0,expiresAt:i==="temporary"?bu(h):void 0}),[r,u,i,h]),{moveMessages:g}=gt({mailboxId:t,accountId:e}),y=Up(e),w=vu(e),j=n.length,I=Wp(i,j,a),N=Hp({draft:v,scope:i,name:f,pickedDate:h}),S=()=>{if(!N)switch(i){case"just-these":u&&g(n,u),o();return;case"all-like-these":y.start(v);return;case"standing":w.createFilter(v,"standing",f.trim());return;case"temporary":w.createFilter(v,"temporary",f.trim());return}};if(y.isRunning||y.isDone)return s.jsx(Gp,{progress:y.progress,isDone:y.isDone,onClose:o});if(w.isSuccess)return s.jsxs("div",{className:"flex flex-col items-center gap-3 px-5 py-8 text-center",children:[s.jsx(mr,{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 C=i==="standing"||i==="temporary";return s.jsxs("div",{className:"flex min-h-0 flex-col",children:[s.jsxs("div",{className:"border-b border-line px-5 py-3",children:[s.jsx("h2",{className:"text-sm font-semibold text-fg",children:"Organize"}),s.jsxs("p",{className:"mt-0.5 text-xs text-fg-muted",children:[a," similar message",a===1?"":"s"," found",j>0?` from ${j} 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(xu,{"aria-label":"Destination folder",value:u,onChange:k=>d(k.target.value),children:[s.jsx("option",{value:"",children:"Choose a folder…"}),x.map(k=>s.jsx("option",{value:k.id,children:k.label},k.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:Vp.map(k=>{const M=i===k.id;return s.jsxs("button",{type:"button",onClick:()=>c(k.id),className:`flex w-full items-start gap-3 rounded-lg border px-3 py-2.5 text-left transition-colors ${M?"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 ${M?"border-accent-2 bg-accent-2":"border-line bg-surface"}`,children:M&&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 ${M?"text-accent-2":"text-fg"}`,children:k.label}),s.jsx("span",{className:"block text-xs text-fg-subtle",children:k.caption})]})]},k.id)})}),C&&s.jsxs("section",{className:"space-y-2",children:[s.jsx(uo,{value:f,onChange:k=>m(k.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:k=>p(k.target.value),"aria-label":"Expiry date",className:"rounded-md border border-line bg-surface-sunken px-2 py-1 text-sm text-fg"})]})]})]}),s.jsxs("div",{className:"space-y-2 border-t border-line px-5 py-3",children:[N&&s.jsx("p",{className:"text-xs text-fg-subtle",role:"status",children:N}),w.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:!!N||w.isPending||y.isStarting,className:"w-full",children:w.isPending?"Saving…":Qp(i,I)}),s.jsx(G,{variant:"ghost",onClick:o,className:"w-full",children:"Not now"})]})]})}function Gp({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(mr,{className:"size-8 text-positive"}):s.jsx(Tt,{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 Xp({open:e,accountId:t,mailboxId:n,selectedMessageIds:r,onClose:a}){const o=r[0],{preview:i,reset:c,matchedCount:u,isPending:d,isError:f,error:m}=Fp(t);l.useEffect(()=>{!e||!o||i({anchorMessageId:o,matchOperator:"And",literalClauses:[]})},[e,o,i]);const h=()=>{c(),a()};return e?s.jsx(co,{open:e,onClose:h,title:"Organize similar mail",children:d||u===void 0?f?s.jsxs("div",{className:"flex flex-col items-center gap-3 px-5 py-8 text-center",children:[s.jsx("p",{className:"text-sm font-medium text-danger",children:"Couldn't find similar messages"}),s.jsx("p",{className:"max-w-xs text-xs text-fg-muted",children:m instanceof Error?m.message:"Please try again."}),s.jsx(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(Tt,{className:"size-8 animate-spin text-accent-2"}),s.jsx("p",{className:"text-sm font-medium text-fg",children:"Finding similar messages…"})]}):s.jsx(Yp,{accountId:t,mailboxId:n,selectedMessageIds:r,anchorMessageId:o,matchedCount:u,onClose:h})}):null}const Jp=({selectedCount:e,onDelete:t,onClearSelection:n,onMarkAsRead:r,onMove:a,onOrganize:o,isDeleting:i=!1,isMoving:c=!1,accountId:u,currentMailboxId:d,moveDisabledHint:f})=>{const m=i||c;if(e===0)return null;const h=!!a&&!!u&&!!d,p=!!o&&!!u&&!!d&&!f;return s.jsxs("div",{className:"sticky top-0 z-10 flex items-center justify-between px-3 py-2 bg-surface-sunken border-b border-line",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("button",{type:"button",onClick:n,className:"min-h-11 min-w-11 inline-flex items-center justify-center rounded hover:bg-surface-raised transition-colors","aria-label":"Clear selection",children:s.jsx(Be,{className:"size-4 text-fg-muted"})}),s.jsxs("span",{className:"text-sm font-medium",children:[e," ",e===1?"message":"messages"," ","selected"]}),f&&s.jsx("span",{className:"text-xs text-fg-muted",role:"status","aria-live":"polite",children:f})]}),s.jsxs("div",{className:"flex items-center gap-1",children:[p&&o&&s.jsxs("button",{type:"button",onClick:m?void 0:o,className:"min-h-11 inline-flex items-center justify-center gap-1.5 px-3 rounded text-sm font-medium transition-colors hover:bg-surface-raised","aria-label":"Organize similar messages",children:[s.jsx(Xe,{className:"size-4"}),s.jsx("span",{className:"hidden sm:inline",children:"Organize"})]}),r&&s.jsx("button",{type:"button",onClick:m?void 0:r,className:"min-h-11 min-w-11 inline-flex items-center justify-center rounded text-sm font-medium transition-colors hover:bg-surface-raised","aria-label":"Mark as read","aria-busy":m,children:s.jsx(Es,{className:"size-4"})}),h&&a&&u&&d&&s.jsx(Ts,{accountId:u,currentMailboxId:d,onMove:m?()=>{}:a,disabledHint:f,variant:"icon-only",label:"Move selected messages"}),s.jsxs("button",{type:"button",onClick:m?void 0:t,className:ce("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(Tt,{className:"size-4 animate-spin"}):s.jsx(et,{className:"size-4"}),s.jsx("span",{className:"hidden sm:inline",children:i?"Deleting...":"Delete"})]})]})]})},Zp=8,eb=({onLongPress:e,delayMs:t=500})=>{const n=l.useRef(null),r=l.useRef(null),a=l.useCallback(()=>{n.current&&(clearTimeout(n.current),n.current=null),r.current=null},[]),o=l.useCallback(d=>{a(),r.current={x:d.clientX,y:d.clientY},n.current=setTimeout(()=>{e(),a()},t)},[e,t,a]),i=l.useCallback(d=>{if(!r.current)return;const f=d.clientX-r.current.x,m=d.clientY-r.current.y;Math.sqrt(f*f+m*m)>Zp&&a()},[a]),c=l.useCallback(()=>{a()},[a]),u=l.useCallback(()=>{a()},[a]);return{handlers:{onPointerDown:o,onPointerMove:i,onPointerUp:c,onPointerCancel:u}}},tb=(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:wt(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:gn(e.category),messageCount:t,suspicious:n}},sb=({thread:e,mailboxId:t,accountId:n,isSelected:r,isFocused:a=!1,isTabStop:o=!1,onFocusRow:i,isChecked:c,onToggleCheck:u,onRowSelect:d,messageCount:f,isMultiSelectMode:m=!1,onLongPress:h,isDesktop:p=!0,density:b="comfortable"})=>{const x=je(),v=e.messageId,g=tb(e,f),y=R=>{R.preventDefault(),R.stopPropagation(),u(e.messageId)},w=l.useCallback(R=>{if(!p)return;const D={shiftKey:R.shiftKey,metaKey:R.metaKey,ctrlKey:R.ctrlKey};d(v,D)&&(R.preventDefault(),R.stopPropagation(),D.shiftKey&&window.getSelection()?.removeAllRanges())},[p,d,v]),j=l.useCallback(R=>{p&&R.shiftKey&&R.preventDefault()},[p]),I=l.useCallback(()=>{h?.(v)},[h,v]),N=eb({onLongPress:I,delayMs:500}),S=l.useCallback(()=>{x.prefetchQuery(ir({path:{messageId:e.messageId}}))},[x,e.messageId]),C=l.useCallback(()=>{S(),i?.(v)},[S,i,v]),k={"data-message-row":!0,"data-message-id":v,role:"option","aria-selected":c,tabIndex:o?0:-1,onClick:w,onMouseDown:j,onMouseEnter:S,onFocus:C},M=!e.isRead;return b==="compact"?s.jsx(ot,{to:"/mail/$mailboxId",params:{mailboxId:t},search:R=>({...R,selectedMessageId:e.messageId}),...k,...!p&&N.handlers,className:ce(Ho({active:r,focused:a}),"outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-inset",c&&"bg-accent-soft",!p&&"min-h-11"),children:s.jsx(Qo,{thread:g})}):s.jsxs(ot,{to:"/mail/$mailboxId",params:{mailboxId:t},search:R=>({...R,selectedMessageId:e.messageId}),...k,...!p&&N.handlers,className:ce("group",ns({active:r,focused:a}),"outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-inset",c&&"bg-accent-soft",!p&&"min-h-11"),children:[M&&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(Ze,{name:e.fromName??e.fromEmail??"?",email:e.fromEmail??void 0,size:"sm",className:ce("absolute inset-0","sm:group-hover:opacity-0 transition-opacity",(c||m)&&"opacity-0")}),s.jsx("button",{type:"button",tabIndex:-1,onClick:y,className:ce("absolute inset-0 size-7 rounded-full border items-center justify-center transition-opacity",m?"flex":"hidden sm:flex",c?"bg-accent border-accent text-accent-fg opacity-100":m?"border-fg-subtle/40 opacity-100 bg-canvas":"border-fg-subtle/40 opacity-0 group-hover:opacity-100 bg-canvas"),"aria-label":c?"Deselect message":"Select message",children:c&&s.jsx(Cs,{className:"size-3"})})]}),s.jsx(rs,{thread:g,badge:e.autoMoved&&s.jsx(zi,{accountId:n,messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,autoMoved:e.autoMoved,size:"sm"})})]})},nb=l.memo(sb),rb=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:wt(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:gn(e.category),suspicious:t}},ab=({thread:e,mailboxId:t,accountId:n,isSelected:r,isFocused:a,isTabStop:o,onFocusRow:i,isChecked:c,onToggleCheck:u,onRowSelect:d,isMultiSelectMode:f,onLongPress:m,isDesktop:h,onDelete:p,onToggleRead:b,density:x})=>{const[v,g]=l.useState("none"),y=l.useCallback(I=>{navigator.vibrate?.(10),I==="trailing"?p(e.messageId):b(e.messageId,e.isRead),g("none")},[p,b,e.messageId,e.isRead]),w=l.useCallback(()=>{m(e.messageId)},[m,e.messageId]),j=l.useCallback(()=>{u(e.messageId)},[u,e.messageId]);return h||f?s.jsx(nb,{thread:e,mailboxId:t,accountId:n,isSelected:r,isFocused:a,isTabStop:o,onFocusRow:i,isChecked:c,onToggleCheck:u,onRowSelect:d,isMultiSelectMode:f,onLongPress:m,isDesktop:h,density:x}):s.jsx(Go,{thread:rb(e),selectionMode:!1,checked:!1,active:r,peek:v,onPeek:g,onToggleCheck:j,onLongPress:w,onOpen:()=>{},onAct:y,linkComponent:({onOpenClick:I,children:N,...S})=>s.jsx(ot,{...S,to:"/mail/$mailboxId",params:{mailboxId:t},search:C=>({...C,selectedMessageId:e.messageId}),"data-message-row":!0,onClick:I,children:N})})},ob=72,ib=32,lb=5,_l="remit:list-density",cb=()=>{try{const e=localStorage.getItem(_l);if(e==="compact"||e==="comfortable")return e}catch{}return"comfortable"},ub=({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(Ns,{className:"size-4 text-fg-muted"}),s.jsxs("span",{className:"text-sm text-fg-muted",children:[t," ",t===1?"result":"results"," for “",e,"”"]})]}),db=({mailboxId:e,threads:t,selectedMessageId:n,isLoading:r,isError:a=!1,error:o,onRetry:i,searchQuery:c,onDeleteMessages:u,onMarkAsRead:d,onMoveMessages:f,isDeleting:m=!1,isMoving:h=!1,onLoadMore:p,hasMore:b=!1,isLoadingMore:x=!1,accountId:v,listTitle:g,listMeta:y,onTriageContextChange:w,commandsRef:j,hideHeader:I=!1})=>{const N=l.useRef(null),S=Re(),C=Ot(),[k,M]=l.useState(!1),[R,D]=l.useState(!1),[E,T]=l.useState(n),[O,B]=l.useState(cb),q=l.useCallback(()=>{B(_=>{const Z=_==="comfortable"?"compact":"comfortable";try{localStorage.setItem(_l,Z)}catch{}return Z})},[]),{toggleReadFor:X}=Pi({mailboxId:e}),{selectedIds:z,selectedCount:$,hasSelection:ee,isSelected:te,toggle:A,select:P,clearSelection:K,selectRange:ie,setAnchor:me,selectAll:he}=zp(),[ue,Ne]=l.useState(null),V=l.useRef(null),Ce=!r&&t.length>0,Pe=ue!==null;l.useEffect(()=>{k&&$===0&&M(!1)},[k,$]);const H=Op({count:t.length,getScrollElement:()=>N.current,estimateSize:()=>O==="compact"?ib:ob,overscan:lb}),W=n?t.findIndex(_=>_.messageId===n):-1,Y=E?t.findIndex(_=>_.messageId===E):-1,ne=l.useCallback(_=>{if(_<0||_>=t.length)return;const Z=t[_];if(k){A(Z.messageId);return}V.current=Z.messageId,T(Z.messageId)},[t,k,A]),ge=l.useCallback(()=>{if(t.length===0)return;const _=Y<0?0:Math.min(Y+1,t.length-1);ne(_)},[t.length,Y,ne]),$e=l.useCallback(()=>{if(t.length===0)return;const _=Y<=0?0:Y-1;ne(_)},[t.length,Y,ne]),Ae=l.useCallback(()=>ne(0),[ne]),We=l.useCallback(()=>ne(t.length-1),[ne,t.length]),Ee=l.useCallback(()=>{E&&A(E)},[E,A]),ke=l.useMemo(()=>t.map(_=>_.messageId),[t]),xe=l.useCallback((_,Z)=>Z.shiftKey?(ie(ke,_),!0):Z.metaKey||Z.ctrlKey?(A(_),!0):(K(),me(_),!1),[ke,ie,A,K,me]),Ke=l.useCallback(_=>{!u||_.length===0||Ne(_)},[u]),tt=l.useCallback(_=>{const Z=Lp(ke,E,_);Z!==void 0&&(ie(ke,Z),V.current=Z,T(Z))},[ke,E,ie]),is=l.useCallback(()=>tt(-1),[tt]),st=l.useCallback(()=>tt(1),[tt]),nt=l.useCallback(()=>{ke.length>0&&he(ke)},[ke,he]),jt=l.useCallback(()=>ue!==null?!0:u?$>0?(Ke(Array.from(z)),!0):E?(Ke([E]),!0):!1:!1,[ue,u,$,z,E,Ke]),St=l.useCallback(()=>{E&&S({to:"/mail/$mailboxId",params:{mailboxId:e},search:_=>({..._,selectedMessageId:E})})},[E,S,e]),qe=l.useCallback(()=>{$>0&&Ke(Array.from(z))},[Ke,$,z]),Nt=l.useCallback(()=>{if(!ue||ue.length===0){Ne(null);return}const _=new Set(ue),Z=t.findIndex(de=>_.has(de.messageId));let De;for(let de=Z+1;de<t.length;de++)if(!_.has(t[de].messageId)){De=t[de].messageId;break}if(De===void 0){for(let de=Z-1;de>=0;de--)if(!_.has(t[de].messageId)){De=t[de].messageId;break}}u?.(ue),K(),Ne(null),De!==void 0&&S({to:"/mail/$mailboxId",params:{mailboxId:e},search:de=>({...de,selectedMessageId:De}),replace:!0})},[ue,t,u,K,S,e]),kt=l.useCallback(()=>{Ne(null)},[]),Pt=l.useCallback(()=>{d&&$>0&&d(Array.from(z))},[d,$,z]),Ue=l.useCallback(_=>{!f||$===0||(f(Array.from(z),_),K())},[f,$,z,K]),ut=l.useMemo(()=>{if($===0)return;const _=new Set;for(const Z of t)z.has(Z.messageId)&&_.add(Z.accountConfigId);if(_.size>1)return"Move only works within one account — clear selection or pick messages from a single account"},[$,z,t]),ls=l.useCallback(_=>{u?.([_])},[u]),Q=l.useCallback((_,Z)=>{X([_],!Z)},[X]),re=l.useCallback(_=>{C||(M(!0),P(_))},[C,P]),ae=l.useCallback(()=>{M(!1),K()},[K]);l.useEffect(()=>{if(!C&&n)return;const _=Y>=0?Y:W;_>=0&&H.scrollToIndex(_,{align:"auto"})},[Y,W,H,C,n]),l.useEffect(()=>{n&&T(n)},[n]),l.useEffect(()=>{E&&(t.some(_=>_.messageId===E)||T(t[0]?.messageId))},[t,E]),l.useEffect(()=>{w?.({focusedMessageId:E,selectedIds:Array.from(z),hasList:Ce,blocksKeyboard:Pe})},[E,z,Ce,Pe,w]);const J=l.useRef(w);J.current=w,l.useEffect(()=>()=>J.current?.({focusedMessageId:void 0,selectedIds:[],hasList:!1,blocksKeyboard:!1}),[]),l.useEffect(()=>{const _=new Set(t.map(De=>De.messageId));Array.from(z).some(De=>!_.has(De))&&K()},[t,z,K]),l.useEffect(()=>{const _=N.current;if(!_||!b||!p)return;const Z=()=>{if(x)return;const{scrollTop:De,scrollHeight:de,clientHeight:Ps}=_;De+Ps>=de-200&&p()};return _.addEventListener("scroll",Z,{passive:!0}),Z(),()=>_.removeEventListener("scroll",Z)},[b,x,p]),l.useEffect(()=>{const _=V.current;if(!_)return;const Z=N.current?.querySelector(`[data-message-id="${_}"]`);Z&&(V.current=null,Z.focus({preventScroll:!0}))}),l.useEffect(()=>{if(j){if(!Ce){j.current=null;return}return j.current={focusNext:ge,focusPrevious:$e,focusFirst:Ae,focusLast:We,openFocused:St,toggleSelect:Ee,extendSelectDown:st,extendSelectUp:is,selectAll:nt,clearSelection:()=>ee?(K(),!0):!1,requestDelete:jt,toggleDensity:q},()=>{j.current=null}}},[j,Ce,ge,$e,Ae,We,St,Ee,st,is,nt,ee,K,jt,q]);const le=r?"loading":a?"error":t.length===0?"empty":"ready",Se=a?Io(o):void 0,ye=l.useCallback(()=>{const _=or(ar());window.open(_,"_blank","noopener,noreferrer")},[]),Le=[{id:"inbox",threads:[]}],pe=ee&&C?s.jsx(Jp,{selectedCount:$,onDelete:qe,onClearSelection:K,onMarkAsRead:d?Pt:void 0,onMove:f?Ue:void 0,onOrganize:()=>D(!0),isDeleting:m,isMoving:h,accountId:v,currentMailboxId:e,moveDisabledHint:ut}):void 0,ze=k&&!C?s.jsx(Yo,{count:$,onCancel:ae,onDelete:qe,onMarkRead:d?Pt:void 0,isBusy:m||h,moveDisabledHint:ut,moveSlot:f&&v&&e?s.jsxs(s.Fragment,{children:[!ut&&s.jsx("button",{type:"button",onClick:()=>D(!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(Xe,{className:"size-4"})}),s.jsx(Ts,{accountId:v,currentMailboxId:e,onMove:m||h?()=>{}:Ue,disabledHint:ut,label:"Move selected messages"})]}):void 0}):void 0,Ie=pe??ze,Te=_p(ke,E),rt=l.useCallback(_=>{T(_)},[]),Ct=!!c?.trim(),Os=s.jsxs(s.Fragment,{children:[Ct&&c&&s.jsx(ub,{query:c,count:t.length}),s.jsxs("div",{ref:N,role:"listbox","aria-multiselectable":!0,"aria-label":g,className:"flex-1 overflow-y-auto",children:[s.jsx("div",{role:"presentation",className:"relative w-full",style:{height:`${H.getTotalSize()}px`},children:H.getVirtualItems().map(_=>{const Z=t[_.index];return s.jsx("div",{role:"presentation","data-index":_.index,ref:H.measureElement,className:"absolute left-0 top-0 w-full border-b border-line",style:{transform:`translateY(${_.start}px)`},children:s.jsx(ab,{thread:Z,mailboxId:e,accountId:v,isSelected:n===Z.messageId,isFocused:E===Z.messageId,isTabStop:Te===Z.messageId,onFocusRow:rt,isChecked:te(Z.messageId),onToggleCheck:A,onRowSelect:xe,isMultiSelectMode:k,onLongPress:re,isDesktop:C,onDelete:ls,onToggleRead:Q,density:O})},_.key)})}),x&&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"})})]})]});return s.jsxs(s.Fragment,{children:[s.jsx(Xo,{listTitle:g,listMeta:y,sections:Le,flatList:!0,listState:le,searchQuery:Ct?c:void 0,errorMessage:Se,onRetry:i,onReportError:ye,density:O,selectedThreadId:n,onSelectThread:_=>S({to:"/mail/$mailboxId",params:{mailboxId:e},search:Z=>({...Z,selectedMessageId:_})}),onSelectBriefCategory:()=>{},isDesktop:C,hideHeader:I,selectionBar:Ie,listBody:le==="ready"?Os:void 0}),s.jsx(Nl,{isOpen:ue!==null,title:hu(ue?.length??0),description:"You can restore them from Trash later.",confirmLabel:"Move to Trash",destructive:!0,isBusy:m,onConfirm:Nt,onCancel:kt}),R&&v&&s.jsx(Xp,{open:R,accountId:v,mailboxId:e,selectedMessageIds:Array.from(z),onClose:()=>D(!1)})]})},fb=e=>ts({path:{accountId:e}}),mb=e=>{const t=je(),n=Ss(),r=be({...Yc(),onSuccess:()=>{n.recordEvent("sync.triggered"),t.invalidateQueries({queryKey:fb(e)})}});return{trigger:()=>{r.mutate({path:{accountId:e}})},triggerAsync:()=>r.mutateAsync({path:{accountId:e}}),isPending:r.isPending,error:r.error,reset:r.reset}},hb=({accountId:e,children:t})=>{const{triggerAsync:n,isPending:r}=mb(e);return s.jsx(lf,{onRefresh:n,isRefreshing:r,children:t})};function gb({accountId:e,currentMailboxId:t,candidates:n,onMove:r,children:a}){const[o,i]=l.useState(!1),c=Ss(),{t:u}=cn("mail",{useSuspense:!1}),d=l.useCallback((y,w)=>u(y,{defaultValue:w}),[u]),{inboxMailboxId:f}=Sr(e),m=Li(e),{data:h}=oe({...Je({path:{accountId:e}}),staleTime:1/0}),p=l.useMemo(()=>{const y=Rr(h?.items??[],m),w=ss(m);return y.map(j=>({id:j.mailboxId,label:Gt(j,w.get(j.mailboxId),d),searchValue:j.fullPath,isCurrent:j.mailboxId===t}))},[h?.items,m,t,d]),b=l.useMemo(()=>f||(p.find(w=>w.label.toLowerCase()==="inbox")?.id??p.find(w=>!w.isCurrent)?.id??""),[f,p]),x=l.useRef(!1);l.useEffect(()=>{x.current||(x.current=!0,$x(c,n.length))},[c,n.length]);const v=l.useCallback(()=>{Kx(c,n.length),i(!0)},[c,n.length]),g=l.useCallback((y,w)=>{qx(c,{selected:y.length,total:n.length,toInbox:w===f}),r(y,w)},[c,n.length,f,r]);return s.jsxs("div",{className:"relative flex h-full min-h-0 flex-col",children:[s.jsx("div",{className:"shrink-0 px-row-inset pt-2",children:s.jsx(df,{count:n.length,onReview:v})}),s.jsx("div",{className:"min-h-0 flex-1",children:a}),s.jsx(wf,{open:o,candidates:n,defaultDestinationId:b,availableFolders:p,onConfirmMove:g,onCancel:()=>i(!1)})]})}const xb=({accounts:e})=>{const t=dr({strict:!1}),n=hn(),r=t.mailboxId,{t:a}=cn("mail",{useSuspense:!1}),o=l.useCallback((c,u)=>a(c,{defaultValue:u}),[a]),i=At({queries:e.map(c=>({...Je({path:{accountId:c.accountId}}),staleTime:1/0}))});if(n.pathname.startsWith("/mail/outbox"))return"Outbox";if(!r)return null;for(let c=0;c<e.length;c++){const u=i[c]?.data?.items;if(!u)continue;const d=u.find(m=>m.mailboxId===r);if(!d)continue;const f=ss(e[c].folderAppointments);return Gt(d,f.get(r),o)}return null},pb=({accounts:e})=>{const n=dr({strict:!1}).mailboxId,r=At({queries:e.map(a=>({...Je({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(c=>c.mailboxId===n);if(i)return i.unseenCount}return null},bb="We can verify this sender";function vb(e){const{data:t}=oe({...Gc({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:bb,trustSubReason:Bx(r.senderTrust),senderTrust:r.senderTrust}))}}const xs={action:null,nextPrefix:null,preventDefault:!1},yb={b:"goBrief",i:"goInbox",s:"goSent",f:"goFlagged",",":"goSettings"},wb={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 jb(e,t){const n=e.key.toLowerCase(),r=e.metaKey||e.ctrlKey;if(e.inEditable)return{...xs,nextPrefix:t==="g"?null:t};if(e.onControl&&(n==="enter"||n===" "))return{...xs,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{...xs,nextPrefix:t==="g"?null:t};if(n==="escape")return{action:"back",nextPrefix:null,preventDefault:!1};if(t==="g"){const i=yb[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=wb[n];if(a){const o=a.requireShift===!0,i=n.length===1&&!/[a-z0-9]/.test(n);return!o&&e.shiftKey&&!i?xs:{action:a.action,nextPrefix:null,preventDefault:!0}}return xs}function Sb(e){if(!(e instanceof HTMLElement))return!1;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"||e.isContentEditable}const Nb="data-message-row",kb='button, a[href], summary, [role="button"], [role="menuitem"], [role="tab"], [role="switch"], [role="checkbox"]';function Cb(e){if(!(e instanceof HTMLElement))return!1;const t=e.closest(kb);return t?!t.hasAttribute(Nb):!1}function Eb({handlers:e,enabled:t=!0,sequenceTimeoutMs:n=1e3}){const r=l.useRef(e);r.current=e;const a=l.useRef(null),o=l.useRef(null);l.useEffect(()=>{if(!t)return;const i=()=>{o.current!==null&&(clearTimeout(o.current),o.current=null)},c=u=>{const d=jb({key:u.key,shiftKey:u.shiftKey,metaKey:u.metaKey,ctrlKey:u.ctrlKey,altKey:u.altKey,inEditable:Sb(u.target),onControl:Cb(u.target)},a.current);if(i(),a.current=d.nextPrefix,d.nextPrefix!==null&&(o.current=setTimeout(()=>{a.current=null,o.current=null},n)),d.action===null)return;const f=r.current[d.action];f&&(d.preventDefault&&u.preventDefault(),f())};return window.addEventListener("keydown",c),()=>{window.removeEventListener("keydown",c),i(),a.current=null}},[t,n])}const Ja=(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]},Fl="remit:intelligence-open";function Ib(){try{return localStorage.getItem(Fl)!=="closed"}catch{return!0}}function Za(e){try{localStorage.setItem(Fl,e?"open":"closed")}catch{}}const Rb=(e,t)=>e!==t,Mb=(e,t,n)=>{if(!(n||!t))return e.find(r=>r.messageId===t)},Tb={unread:e=>!e.isRead,flagged:e=>e.hasStars===!0,attachment:e=>!!e.hasAttachment};function Db(e,t,n){const r=Array.from(n).map(a=>Tb[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 Bl=l.createContext(null);function vn(){const e=l.useContext(Bl);if(!e)throw new Error("MailboxPane.* must be used inside <MailboxPane>");return e}function Ab({mailboxId:e,selectedMessageId:t,children:n}){const r=Re(),o=As()==="desktop",i=Ss(),{accounts:c,mailboxNameIndex:u,accountNameIndex:d,searchQuery:f,searchInput:m,intelligenceOpen:h,onToggleIntelligence:p,onSetIntelligenceOpen:b}=Me(),x=ml(f),v=x.length>0,{freeText:g,tokens:y}=Ds(x,{mailboxesByName:u,accountsByName:d}),w=y.find(L=>L.type==="from"),j={order:"desc",...g?{query:g}:{},...w?{from:w.value}:{},...y.some(L=>L.type==="hasAttachment")?{attachments:!0}:{},...y.some(L=>L.type==="isUnread")?{unread:!0}:{}},I=v?bt({path:{mailboxId:e},query:j}):lt({path:{mailboxId:e},query:{order:"desc"}}),{data:N,isLoading:S,isError:C,error:k,refetch:M,fetchNextPage:R,hasNextPage:D,isFetchingNextPage:E}=wi({queryKey:I,queryFn:async({pageParam:L})=>{if(v){const{data:_e}=await Jc({path:{mailboxId:e},query:{...j,continuationToken:L},throwOnError:!0});return _e}const{data:Oe}=await Zc({path:{mailboxId:e},query:{order:"desc",continuationToken:L},throwOnError:!0});return Oe},initialPageParam:void 0,getNextPageParam:L=>L.continuationToken,enabled:v?x.length>0:!0,placeholderData:Xc}),T=l.useCallback(L=>{t&&L.includes(t)&&r({to:"/mail/$mailboxId",params:{mailboxId:e},search:Oe=>({...Oe,selectedMessageId:void 0,selectedThreadId:void 0})})},[t,e,r]),{deleteMessages:O,isPending:B}=vs({mailboxId:e,onAfterOptimisticRemove:T}),{accountId:q}=Oi(e),X=xb({accounts:c}),{moveMessages:z,isPending:$}=gt({mailboxId:e,accountId:q,onAfterOptimisticRemove:T}),ee=og(N?.pages.flatMap(L=>L.items??[])??[]),[te,A]=l.useState("all"),[P,K]=l.useState(new Set),ie=l.useMemo(()=>Db(ee,te,P),[ee,te,P]),me=l.useCallback(L=>{A(L)},[]),he=l.useCallback(L=>{K(Oe=>{const _e=new Set(Oe);return _e.has(L)?_e.delete(L):_e.add(L),_e})},[]),ue=l.useCallback(()=>{A("all"),K(new Set)},[]),Ne=Rb(m,f),V=Mb(ee,t,Ne),{selectedThreadId:Ce}=Yt({strict:!1}),Pe=l.useMemo(()=>Tl(V,{messageId:t,threadId:Ne?void 0:Ce,mailboxId:e}),[V,t,Ce,Ne,e]),[H,W]=l.useState(void 0),[Y,ne]=l.useState([]),ge=l.useRef(null),[$e,Ae]=l.useState(!1),[We,Ee]=l.useState(!1),ke=l.useCallback(L=>{W(L.focusedMessageId),ne(L.selectedIds),Ae(L.hasList),Ee(L.blocksKeyboard)},[]),xe=ie.find(L=>L.messageId===H)??V,Ke=l.useRef(null);l.useEffect(()=>{const L=V?.messageId??null;L&&Ke.current!==L&&V?.authenticity?.dkimMismatch&&(Ke.current=L,h||p())},[V?.messageId,V?.authenticity?.dkimMismatch,h,p]);const tt=l.useRef(!1);l.useEffect(()=>{tt.current||o&&V?.messageId&&(tt.current=!0,Ib()&&!h&&b(!0))},[o,V?.messageId,h,b]);const st=pb({accounts:c})??ee.filter(L=>!L.isRead).length,nt=je(),{pushError:jt}=He(),{deleteMessages:St}=vs({mailboxId:e,threadId:V?.threadId,onAfterOptimisticRemove:T}),{moveMessages:qe}=gt({mailboxId:e,threadId:V?.threadId,accountId:q,onAfterOptimisticRemove:T}),{draftsMailboxId:Nt}=rg(q),kt=Nt!==void 0&&Nt===e,{archiveMailboxId:Pt}=ng(q),Ue=l.useCallback(L=>{const Oe=Mt({path:{threadId:L.threadId}}),Kr=nt.getQueriesData({queryKey:Oe}).flatMap(([,uc])=>uc?.items.map(dc=>dc.messageId)??[]);return Kr.length>0?Kr:[L.messageId]},[nt]),ut=l.useCallback(()=>{if(!V)return;const L=Ue(V);St(L)},[V,Ue,St]),ls=l.useCallback(L=>{if(!V)return;const Oe=Ue(V);qe(Oe,L)},[V,Ue,qe]),{toggleStar:Q}=Wn({threadId:V?.threadId??"",mailboxId:e}),re=l.useCallback(()=>{V&&Q(V.messageId,V.hasStars)},[V,Q]),[ae,J]=l.useState(null),le=l.useCallback(()=>{J("reply")},[]),Se=l.useCallback(()=>{J("reply_all")},[]),ye=l.useCallback(()=>{J("forward")},[]),Le=l.useCallback(()=>{J(null)},[]),{state:pe,openCompose:ze,closeCompose:Ie}=pt(),Te=l.useCallback(()=>{ze({mode:"new"})},[ze]),rt=be({...on(),onError:L=>{jt(ys("Couldn't discard draft","The draft wasn't deleted.",L))}}),Ct=l.useCallback(()=>{const L=pe.outboxMessageId;L&&(rt.mutate({path:{outboxMessageId:L}}),nt.invalidateQueries({queryKey:ur()}),Ie())},[pe.outboxMessageId,rt,nt,Ie]),Os=l.useCallback(()=>{ge.current?.clearSelection()||t&&r({to:"/mail/$mailboxId",params:{mailboxId:e},search:L=>({...L,selectedMessageId:void 0,selectedThreadId:void 0})})},[t,e,r]),_=l.useCallback(L=>L?Ue(L):[],[Ue]),{toggleStar:Z}=Wn({threadId:xe?.threadId??"",mailboxId:e}),{toggleReadFor:De}=Pi({mailboxId:e,accountId:q}),{junkMailboxId:de}=Nr(q),Ps=de!=null&&de===e,{candidates:Lr}=vb(Ps?de:void 0),{moveMessages:zr}=gt({mailboxId:e,threadId:xe?.threadId,accountId:q,onAfterOptimisticRemove:T}),{deleteMessages:_r}=vs({mailboxId:e,threadId:xe?.threadId,onAfterOptimisticRemove:T}),{addressId:cs,address:Ls}=El(xe),{updateFlags:zs}=Il({addressId:cs,senderEmail:xe?.fromEmail??void 0}),Lt=l.useCallback(()=>t||!H?!1:(r({to:"/mail/$mailboxId",params:{mailboxId:e},search:L=>({...L,selectedMessageId:H})}),!0),[t,H,e,r]),Vl=l.useCallback(()=>{Lt()||V&&J("reply")},[Lt,V]),Yl=l.useCallback(()=>{Lt()||V&&J("reply_all")},[Lt,V]),Gl=l.useCallback(()=>{Lt()||V&&J("forward")},[Lt,V]),zt=l.useCallback(()=>Y.length>0?Y:_(xe),[Y,_,xe]),Xl=l.useCallback(()=>{if(ge.current?.requestDelete())return;const L=zt();L.length>0&&_r(L)},[zt,_r]),Jl=l.useCallback(()=>{if(!de)return;const L=zt();L.length!==0&&(Ml(i,{count:L.length,senderTrust:xe?.senderTrust??"unknown",wasRescuable:xe?Rl(xe):!1}),zr(L,de))},[de,zt,zr,i,xe]),Zl=l.useCallback(()=>{if(Y.length>0){const L=!(xe?.hasStars??!1),Oe=new Set(Y);for(const _e of ie)Oe.has(_e.messageId)&&_e.hasStars!==L&&Z(_e.messageId,_e.hasStars);return}xe&&Z(xe.messageId,xe.hasStars)},[Y,ie,xe,Z]),ec=l.useCallback(()=>{const L=zt();if(L.length===0)return;const Oe=!(xe?.isRead??!1);De(L,Oe)},[zt,xe,De]),tc=l.useCallback(()=>{if(!cs)return;const L=Ls?.flags?.muted?.value!==!0;zs({muted:{value:L}})},[cs,Ls,zs]),sc=l.useCallback(()=>{if(!cs)return;const L=Ls?.flags?.vip?.value!==!0;zs({vip:{value:L}})},[cs,Ls,zs]),nc=l.useCallback(()=>{h||p()},[h,p]),us=l.useCallback(L=>{r({to:L})},[r]),Fr=kt?"drafts":Pt===e?"archive":de===e?"junk":"inbox",Br=l.useRef("");l.useEffect(()=>{const L=Br.current;Br.current=x,x.length>0&&L.length===0&&i.recordEvent("search.submitted",{mailboxType:Fr})},[x,Fr,i]);const rc=!!V,ac=kt&&pe.isOpen&&!!pe.outboxMessageId&&!V,oc=o&&h&&rc;Eb({enabled:!pe.isOpen&&!We,handlers:{...$e?{focusNext:()=>ge.current?.focusNext(),focusPrevious:()=>ge.current?.focusPrevious(),focusFirst:()=>ge.current?.focusFirst(),focusLast:()=>ge.current?.focusLast(),openFocused:()=>ge.current?.openFocused(),toggleSelect:()=>ge.current?.toggleSelect(),extendSelectDown:()=>ge.current?.extendSelectDown(),extendSelectUp:()=>ge.current?.extendSelectUp(),selectAll:()=>ge.current?.selectAll(),toggleDensity:()=>ge.current?.toggleDensity()}:{},back:Os,reply:Vl,replyAll:Yl,forward:Gl,delete:Xl,toggleStar:Zl,toggleRead:ec,muteSender:tc,blockSender:nc,vipSender:sc,markJunk:Jl,toggleIntelligence:V?p:void 0,compose:Te,goBrief:()=>us("/mail"),goInbox:()=>us("/mail"),goSent:()=>us("/mail"),goFlagged:()=>us("/mail/flagged"),goSettings:()=>us("/settings")}}),jr({enabled:pe.isOpen,bindings:[{key:"Escape",handler:Ie,preventDefault:!0}]});const $r=ie.map(L=>L.messageId),ic=Ja($r,t,"next")??void 0,lc=Ja($r,t,"previous")??void 0,cc={mailboxId:e,selectedMessageId:t,selectedThread:V,conversation:Pe,threads:ie,isLoading:S,isError:C,error:k,mailboxAccountId:q,mailboxName:X,unreadCount:st,isDraftsMailbox:kt,isSpamFolder:Ps,rescueCandidates:Lr,filterCategory:te,filterAttributes:P,onSelectFilterCategory:me,onToggleFilterAttribute:he,onClearFilters:ue,showIntelligence:oc,intelligenceOpen:h,onToggleIntelligence:p,onDeleteMessages:O,onMoveMessages:z,isDeleting:B,isMoving:$,onLoadMore:R,hasMore:D,isLoadingMore:E,onTriageContextChange:ke,listCommandsRef:ge,onRetry:()=>M(),toolbarComposeRequest:ae,onToolbarReply:le,onToolbarReplyAll:Se,onToolbarForward:ye,onClearComposeRequest:Le,onToolbarDelete:ut,onToolbarStar:re,onToolbarDiscardDraft:Ct,onToolbarMove:ls,composeState:pe,closeCompose:Ie,hasRemitDraftOpen:ac,onBack:Os,nextMessageId:ic,previousMessageId:lc};return s.jsx(Bl.Provider,{value:cc,children:n})}function $l(){const{mailboxId:e,selectedMessageId:t,threads:n,isLoading:r,isError:a,error:o,onDeleteMessages:i,onMoveMessages:c,isDeleting:u,isMoving:d,onLoadMore:f,hasMore:m,isLoadingMore:h,mailboxAccountId:p,mailboxName:b,unreadCount:x,isDraftsMailbox:v,isSpamFolder:g,rescueCandidates:y,onTriageContextChange:w,listCommandsRef:j,onRetry:I,filterCategory:N,filterAttributes:S,onSelectFilterCategory:C,onToggleFilterAttribute:k,onClearFilters:M}=vn(),{searchQuery:R,searchInput:D,accounts:E}=Me(),T=As(),O=Re(),B=b??"Inbox",q=l.useMemo(()=>kf(),[]),X=l.useMemo(()=>n.map(Sx),[n]),{hits:z,isLoading:$}=hl({mailboxId:e,filterCategory:N}),ee=l.useMemo(()=>vl(z,n.map(me=>me.threadId)),[z,n]),te=l.useCallback(me=>O({to:"/mail/$mailboxId",params:{mailboxId:e},search:he=>({...he,q:D||void 0,selectedMessageId:me.id,selectedThreadId:me.threadId})}),[e,O,D]);if(v&&p)return s.jsx(pp,{mailboxId:e,accountId:p,selectedMessageId:t,imapThreads:n,title:b??"Drafts",unreadCount:x??void 0});const A=s.jsx(db,{mailboxId:e,threads:n,selectedMessageId:t,isLoading:r,isError:a,error:o,onRetry:I,searchQuery:R,onDeleteMessages:i,onMoveMessages:c,isDeleting:u,isMoving:d,onLoadMore:f,hasMore:m,isLoadingMore:h,accountId:p,listTitle:B,hideHeader:!0,onTriageContextChange:w,commandsRef:j}),P=E[0]?.accountId,K=T==="phone"&&P?s.jsx(hb,{accountId:P,children:A}):A,ie=g&&y.length>0&&p?s.jsx(gb,{accountId:p,currentMailboxId:e,candidates:y,onMove:c,children:K}):K;return s.jsx(Al,{title:B,unreadCount:x,preset:q,selectedCategory:N,activeFilters:S,onSelectCategory:C,onToggleFilter:k,onClearFilters:M,searchResults:X,searchLoading:r,relatedResults:ee,relatedLoading:$,onSelectSearchResult:te,children:ie})}function Ob(){const{mailboxId:e,mailboxAccountId:t,selectedThread:n,conversation:r,hasRemitDraftOpen:a,showIntelligence:o,onToggleIntelligence:i,toolbarComposeRequest:c,onToolbarReply:u,onToolbarReplyAll:d,onToolbarForward:f,onClearComposeRequest:m,onToolbarDelete:h,onToolbarStar:p,onToolbarDiscardDraft:b,onToolbarMove:x,composeState:v}=vn(),y=As()==="desktop",w=!!r,j=v.isOpen&&!r?s.jsx(Ll,{}):r?s.jsx(os,{threadId:r.threadId,mailboxId:r.mailboxId,subject:r.subject,selectedMessageId:r.messageId,authenticity:r.authenticity,onOpenIntelligence:r.authenticity?.dkimMismatch?i:void 0,composeRequest:c,onComposeClose:m}):s.jsx(as,{});return s.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[s.jsx(Mr,{hasThread:w,intelligenceOpen:o,showIntelligenceToggle:y&&w,onToggleIntelligence:i,onReply:w?u:void 0,onReplyAll:w?d:void 0,onForward:w?f:void 0,canDelete:w||a,onDelete:w?h:a?b:void 0,onToggleStar:w?p:void 0,isStarred:n?.hasStars,moveContext:w&&t?{accountId:t,currentMailboxId:e,onMove:x}:void 0}),s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:j})]})}function Pb(){const{mailboxId:e,mailboxAccountId:t,selectedThread:n,onToggleIntelligence:r}=vn();return s.jsx(bn,{onClose:r,thread:n,mailboxId:e,accountId:t})}function Lb(){const{mailboxId:e,selectedThread:t,conversation:n,intelligenceOpen:r,onToggleIntelligence:a,onBack:o,nextMessageId:i,previousMessageId:c,composeState:u}=vn(),d=Re();if(n){const f=m=>d({to:"/mail/$mailboxId",params:{mailboxId:e},search:h=>({...h,selectedMessageId:m,selectedThreadId:void 0})});return s.jsxs(s.Fragment,{children:[s.jsx(os,{threadId:n.threadId,mailboxId:n.mailboxId,subject:n.subject,selectedMessageId:n.messageId,authenticity:n.authenticity,onBack:o,onOpenIntelligence:a,onSwipeNext:i?()=>f(i):void 0,onSwipePrevious:c?()=>f(c):void 0,mobileIntelligenceOpen:r}),s.jsx(yr,{isOpen:r,onClose:a,ariaLabel:"Message details",side:"right",children:s.jsx(bn,{onClose:a,thread:t,hideCloseButton:!0})})]})}return u.isOpen?s.jsx("div",{className:"h-full",children:s.jsx(Ll,{})}):s.jsx($l,{})}const ps=Object.assign(Ab,{List:$l,Reading:Ob,Intelligence:Pb,Phone:Lb}),Kl=e=>e==="failed"||e==="blocked",ql=e=>e!=="draft"&&e!=="sent",Or="remit.savedSearches",zb=25;function rn(){try{const e=localStorage.getItem(Or);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(n=>typeof n=="string"):[]}catch{return[]}}function _b(e){const t=e.trim();if(!t)return rn();const n=[t,...rn().filter(r=>r!==t)].slice(0,zb);try{localStorage.setItem(Or,JSON.stringify(n))}catch{return n}return n}function Fb(e){const t=rn().filter(n=>n!==e);try{localStorage.setItem(Or,JSON.stringify(t))}catch{return t}return t}const eo=e=>/^\d/.test(e),Bb=(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 $b(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)=>Bb(Gt(o,void 0,n),Gt(i,void 0,n))),{system:r,labels:a}}function Kb(e,t,n){const r=ou(t)&&e.unseenCount>0;return{id:e.mailboxId,name:Gt(e,t,n),unseen:r?e.unseenCount:void 0,role:t,fullPath:e.fullPath}}function qb(){const e=hn(),t=dr({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 to({accounts:e,onMailboxSelect:t,variant:n="desktop"}){const r=je(),a=Re(),o=qb(),{searchInput:i,onSearchChange:c}=Me(),[u,d]=l.useState(rn),{t:f}=cn("mail",{useSuspense:!1}),m=l.useCallback((C,k)=>f(C,{defaultValue:k}),[f]),h=At({queries:e.map(C=>({...Je({path:{accountId:C.accountId}}),staleTime:1/0}))}),{data:p}=oe(an()),b=l.useMemo(()=>(p?.items??[]).filter(C=>ql(C.status)).length,[p?.items]),x=l.useMemo(()=>e.map((C,k)=>{const M=h[k],R=M?.data?.items??[],D=ss(C.folderAppointments),{system:E,labels:T}=$b(R,D,m),O=M?.isError?"error":M?.isLoading?"loading":"ready";return{id:C.accountId,label:C.email,email:C.email,muted:!!C.muted,outboxPending:b,status:O,onRetry:()=>M?.refetch(),mailboxes:[...E,...T].map(B=>Kb(B,D.get(B.mailboxId),m))}}),[e,h,b,m]),v=C=>{r.invalidateQueries({queryKey:lt({path:{mailboxId:C},query:{order:"desc"}})})},g=({navId:C,className:k,ariaLabel:M,title:R,children:D,onClick:E})=>C==="brief"?s.jsx(ot,{to:"/mail",search:{q:void 0,selectedMessageId:void 0},onClick:()=>E?.(),className:k,"aria-label":M,title:R,children:D}):C==="outbox"?s.jsx(ot,{to:"/mail/outbox",search:{q:void 0,selectedOutboxMessageId:void 0},onClick:()=>E?.(),className:k,"aria-label":M,title:R,children:D}):C==="flagged"?s.jsx(ot,{to:"/mail/flagged",search:{q:void 0,selectedMessageId:void 0},onClick:()=>E?.(),className:k,"aria-label":M,title:R,children:D}):s.jsx(ot,{to:"/mail/$mailboxId",params:{mailboxId:C},search:{q:void 0,selectedMessageId:void 0},onClick:()=>{v(C),E?.()},className:k,"aria-label":M,title:R,children:D}),y=()=>{t?.()},w=i.trim(),j=w.length>0&&!u.includes(w)?w:void 0,I=l.useCallback(()=>{j&&d(_b(j))},[j]),N=l.useCallback(C=>{d(Fb(C))},[]),S=l.useCallback(C=>{c(C),a({to:"/mail",search:{q:C,selectedMessageId:void 0}}),t?.()},[c,a,t]);return s.jsx(Md,{accounts:x,selectedNavId:o,onSelectNav:y,linkComponent:g,variant:n,savedSearches:u,saveableQuery:j,onSaveCurrentSearch:I,onSelectSavedSearch:S,onRemoveSavedSearch:N})}function Ub({accounts:e,onMailboxSelect:t}){return lr()?.showNavPane??!0?s.jsx(to,{accounts:e}):s.jsxs("div",{className:"flex h-full flex-col",children:[s.jsx("div",{className:"flex-1 overflow-y-auto",children:s.jsx(to,{accounts:e,onMailboxSelect:t,variant:"drawer"})}),s.jsxs("div",{className:"border-t border-line px-2 py-2",children:[s.jsxs(ot,{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(Ko,{className:"size-4 shrink-0"}),s.jsx("span",{className:"flex-1 truncate text-left",children:"Settings"})]}),s.jsx(ki,{variant:"drawer"}),s.jsx(Ni,{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(_o,{className:"size-4 shrink-0"}),s.jsx("span",{className:"flex-1 truncate text-left",children:"Sign out"})]})})]})]})}const Ul={queued:{icon:hr,label:"Queued",className:"text-warning"},sending:{icon:Tt,label:"Sending…",className:"text-accent-2"},sent:{icon:Ao,label:"Sent",className:"text-positive"},failed:{icon:Rt,label:"Failed",className:"text-danger"},blocked:{icon:er,label:"Blocked",className:"text-warning"}},Hb=e=>gu(e).toDateString()===new Date().toDateString()?tn(e,{hour:"numeric",minute:"2-digit"}):tn(e,{month:"short",day:"numeric"}),so=e=>tn(e,{dateStyle:"medium",timeStyle:"short"}),Qb=e=>{const t=e.toAddresses??[];return t.length===0?"No recipients":t.length===1?t[0]:`${t[0]} +${t.length-1}`},Hl=l.createContext(null);function Pr(){const e=l.useContext(Hl);if(!e)throw new Error("OutboxPane.* must be used inside <OutboxPane>");return e}function Wb({children:e}){const t=Re(),{selectedOutboxMessageId:n}=Yt({strict:!1}),{data:r,isLoading:a}=oe(an()),o=l.useMemo(()=>(r?.items??[]).filter(d=>ql(d.status)),[r]),i=l.useMemo(()=>o.find(d=>d.outboxMessageId===n),[o,n]),c=l.useCallback(d=>{t({to:"/mail/outbox",search:f=>({...f,selectedOutboxMessageId:d})})},[t]),u={messages:o,isLoading:a,selectedMessageId:n,selectedMessage:i,onSelectMessage:c};return s.jsx(Hl.Provider,{value:u,children:e})}function Ql({message:e,isSelected:t,onSelect:n}){const r=je(),{openCompose:a}=pt(),{pushError:o}=He(),i=l.useCallback(()=>{r.invalidateQueries({queryKey:ur()})},[r]),c=be({...yo(),onSuccess:i,onError:m=>{o(ys("Couldn't resend message","The message wasn't sent.",m))}}),u=be({...on(),onSuccess:i,onError:m=>{o(ys("Couldn't delete message","The message wasn't deleted.",m))}}),d=e.status;if(!Ul[d])return null;const f=Kl(e.status);return s.jsx(af,{recipients:Qb(e),subject:e.subject||"",time:Hb(e.sentAt??e.updatedAt),status:d,error:f?e.lastError??void 0:void 0,selected:t,onSelect:n,onRetry:d==="failed"?()=>c.mutate({path:{outboxMessageId:e.outboxMessageId}}):void 0,retrying:c.isPending,onEdit:()=>a({mode:"new",outboxMessageId:e.outboxMessageId}),onDelete:()=>u.mutate({path:{outboxMessageId:e.outboxMessageId}}),deleting:u.isPending})}function Wl({message:e,onBack:t}){const n=e.status,r=Ul[n],a=r?.icon??ks,o=e.sentAt?so(e.sentAt):so(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(To,{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:ce("size-4",r.className,n==="sending"&&"animate-spin")}),s.jsx("span",{className:ce("text-xs font-medium",r.className),children:r.label}),Kl(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(ul,{html:e.htmlBody,text:e.textBody})})]})}function Vb(){const{messages:e,isLoading:t,selectedMessageId:n,onSelectMessage:r}=Pr();return t?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(as,{message:"No outbox messages",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(Ar,{}),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(a=>s.jsx(Ql,{message:a,isSelected:n===a.outboxMessageId,onSelect:()=>r(a.outboxMessageId)},a.outboxMessageId))})]})}function Yb(){const{selectedMessage:e}=Pr();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(Wl,{message:e}):s.jsx(as,{message:"Select a message to read",showHints:!1})})]})}function Gb(){const{messages:e,isLoading:t,selectedMessageId:n,selectedMessage:r,onSelectMessage:a}=Pr();return t?s.jsx("div",{className:"flex h-full items-center justify-center bg-canvas",children:s.jsx("span",{className:"text-fg-muted",children:"Loading..."})}):r?s.jsx(Wl,{message:r,onBack:()=>a(void 0)}):e.length===0?s.jsx("div",{className:"flex h-full bg-surface",children:s.jsx(as,{message:"No outbox messages",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(Ar,{}),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(o=>s.jsx(Ql,{message:o,isSelected:n===o.outboxMessageId,onSelect:()=>a(o.outboxMessageId)},o.outboxMessageId))})]})}const Ys=Object.assign(Wb,{List:Vb,Reading:Yb,Phone:Gb}),Xb=({isOpen:e,onClose:t})=>{const n=l.useCallback(r=>{r.key==="Escape"&&(r.preventDefault(),t())},[t]);return l.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:ce("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(Be,{className:"size-5"})})]}),s.jsx("div",{className:"grid gap-x-8 gap-y-6 sm:grid-cols-2",children:Ci.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(l.Fragment,{children:[i>0&&a.keys[0]==="g"&&s.jsx("span",{className:"text-2xs text-fg-subtle",children:"then"}),s.jsx(Wt,{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(Wt,{children:"Esc"})," to close"]})})]})]}):null};function Jb(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 Zb(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 ev(e){const t=At({queries:e.map(n=>({...Je({path:{accountId:n.accountId}}),staleTime:1/0}))});return l.useMemo(()=>Zb(t.map(n=>n.data?.items??[])),[t])}var Gs={exports:{}},no;function tv(){if(no)return Gs.exports;no=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 c=[],u=t[Symbol.iterator]();let d=!1,f=!1,m=0,h=0;const p=()=>{if(d)return;const b=u.next(),x=h;if(h++,b.done){f=!0,m===0&&a(c);return}m++,Promise.resolve(b.value).then(v=>n(v,x)).then(v=>{c[x]=v,m--,p()},v=>{d=!0,o(v)})};for(let b=0;b<i&&(p(),!f);b++);});return Gs.exports=e,Gs.exports.default=e,Gs.exports}var sv=tv();const nv=eu(sv),rv=900*1e3,av=300,ov=(e,t)=>{if(!e)return t;const n=Number.parseInt(e,10);return Number.isFinite(n)&&n>0?n:t},iv=60*1e3,lv=e=>Math.max(ov(e,av)*1e3,iv),Zs=lv(nu().mailboxPollIntervalSeconds),cv=5,Xn=new Set,uv=(e,t,n=rv)=>e.filter(r=>{const a=r.lastSyncAt;return a==null?!0:t-a>n}).map(r=>r.accountId),dv=(e,t,n=Zs)=>e-t>=n,fv=(e,t)=>e.filter(n=>!t.has(n)),ro=(e,t)=>{if(Xn.delete(e),su(t,{softError:!0})){No(t);return}console.warn("[remit] background mailbox sync failed",{accountId:e,error:t})},ao=(e,t)=>tu({path:{accountId:e},throwOnError:!0}).then(()=>{t.invalidateQueries({queryKey:ts({path:{accountId:e}})})}),mv=e=>{const t=je(),n=l.useRef(e);n.current=e;const r=e.map(a=>a.accountId).join(",");l.useEffect(()=>{const a=Date.now(),i=uv(n.current,a).filter(c=>!Xn.has(c));if(i.length!==0)for(const c of i)Xn.add(c),ao(c,t).catch(u=>{ro(c,u)})},[r,t]),l.useEffect(()=>{let a=Date.now(),o;const i=new Set,c=()=>{a=Date.now();const f=fv(n.current.map(m=>m.accountId),i);for(const m of f)i.add(m);nv(f,m=>ao(m,t).catch(h=>{ro(m,h)}).finally(()=>{i.delete(m)}),{concurrency:cv})},u=()=>{if(document.visibilityState==="visible"){c(),o=setTimeout(u,Zs);return}},d=()=>{document.visibilityState==="visible"&&dv(Date.now(),a)&&(o!==void 0&&clearTimeout(o),c(),o=setTimeout(u,Zs))};return o=setTimeout(u,Zs),document.addEventListener("visibilitychange",d),()=>{o!==void 0&&clearTimeout(o),document.removeEventListener("visibilitychange",d)}},[r,t])},hv="/mail/",gv="/mail/outbox",xv="/mail/flagged";function pv(e){return e.some(t=>t.routeId===hv)}function bv(e){return e.some(t=>t.routeId===xv)}function vv(e){return e.some(t=>t.routeId===gv)}function yv(){const{q:e=""}=Yt({from:"/mail"}),t=Re(),n=As(),r=yl(n),[a,o]=l.useState(!1),[i,c]=l.useState(!1),[u,d]=l.useState(!1),f=l.useCallback(A=>{d(A),Za(A)},[]),[m,h]=l.useState(e),p=ko(m,200),b=l.useRef(e);b.current=e,l.useEffect(()=>{p!==b.current&&t({to:".",search:A=>{const P=A.q===p;return{...A,q:p||void 0,...p&&!P?{selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0}:{}}},replace:!0})},[p,t]);const{data:x,isLoading:v,isError:g,error:y,refetch:w}=oe({...it(),staleTime:1/0}),j=!!(x&&(x.accounts?.length??0)===0);l.useEffect(()=>{j&&t({to:"/onboarding",replace:!0})},[j,t]),jr({enabled:!a,bindings:[{key:"?",handler:()=>o(!0),noModifiers:!1,preventDefault:!0}]});const I=l.useCallback(A=>{h(A)},[]),N=l.useCallback(()=>{h("")},[]),S=l.useCallback(()=>{h("")},[]),C=l.useCallback(()=>{d(A=>{const P=!A;return Za(P),P})},[]),k=x?.accounts??[],M=ev(k),R=l.useMemo(()=>Jb(k),[k]),D=Us({select:A=>A.matches.find(K=>"mailboxId"in K.params)?.params.mailboxId}),{selectedMessageId:E}=Yt({strict:!1}),T=Us({select:A=>pv(A.matches)}),O=Us({select:A=>bv(A.matches)}),B=Us({select:A=>vv(A.matches)});mv(k);const q=l.useCallback(()=>{c(!1)},[]),X={accounts:k,mailboxNameIndex:M,accountNameIndex:R,searchQuery:p,searchInput:m,onSearchChange:I,onSearchClear:N,onSearchClearQuery:S,intelligenceOpen:u,onToggleIntelligence:C,onSetIntelligenceOpen:f},z=s.jsx(Ub,{accounts:k,onMailboxSelect:q}),$=r?s.jsx(ih,{accounts:k}):void 0,ee=r?void 0:s.jsx(dh,{accounts:k}),te={navOpen:i,onOpenNav:()=>c(!0),onCloseNav:()=>c(!1)};return s.jsxs(ru.Provider,{value:X,children:[g?s.jsx("div",{className:"flex h-full items-center justify-center bg-canvas p-4",children:s.jsx(yt,{title:"Couldn't load your account",error:y,onRetry:()=>{w()}})}):T?s.jsx(Ws,{selectedMessageId:E,children:r?s.jsx(dt,{nav:z,list:s.jsx(Ws.Phone,{}),intelligenceOpen:u,overlay:$,skeleton:s.jsx(at,{}),isLoading:v||j,...te}):s.jsx(dt,{nav:z,topBar:ee,list:s.jsx(Ws.List,{}),reading:s.jsx(Ws.Reading,{}),intelligenceOpen:u,overlay:$,skeleton:s.jsx(at,{}),isLoading:v||j,...te})}):O?s.jsx(Vs,{selectedMessageId:E,children:r?s.jsx(dt,{nav:z,list:s.jsx(Vs.Phone,{}),intelligenceOpen:u,overlay:$,skeleton:s.jsx(at,{}),isLoading:v||j,...te}):s.jsx(dt,{nav:z,topBar:ee,list:s.jsx(Vs.List,{}),reading:s.jsx(Vs.Reading,{}),intelligenceOpen:u,overlay:$,skeleton:s.jsx(at,{}),isLoading:v||j,...te})}):D?s.jsx(ps,{mailboxId:D,selectedMessageId:E,children:r?s.jsx(dt,{nav:z,list:s.jsx(ps.Phone,{}),intelligenceOpen:u,overlay:$,skeleton:s.jsx(at,{}),isLoading:v||j,...te}):s.jsx(dt,{nav:z,topBar:ee,list:s.jsx(ps.List,{}),reading:s.jsx(ps.Reading,{}),intelligence:s.jsx(ps.Intelligence,{}),intelligenceOpen:u,overlay:$,skeleton:s.jsx(at,{}),isLoading:v||j,...te})}):B?s.jsx(Ys,{children:r?s.jsx(dt,{nav:z,list:s.jsx(Ys.Phone,{}),intelligenceOpen:!1,overlay:$,skeleton:s.jsx(at,{}),isLoading:v||j,...te}):s.jsx(dt,{nav:z,topBar:ee,list:s.jsx(Ys.List,{}),reading:s.jsx(Ys.Reading,{}),intelligenceOpen:!1,overlay:$,skeleton:s.jsx(at,{}),isLoading:v||j,...te})}):s.jsx(at,{}),s.jsx(Xb,{isOpen:a,onClose:()=>o(!1)}),s.jsx(au,{})]})}const zv=Object.freeze(Object.defineProperty({__proto__:null,component:yv,useMailContext:Me},Symbol.toStringTag,{value:"Module"}));export{Lv as S,Du as U,zv as m};
|