@remit/web-client-dist 0.0.16 → 0.0.17

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.
Files changed (34) hide show
  1. package/assets/{ComposeBody-Dxf7Xcn6.js → ComposeBody-Omy6Iikn.js} +1 -1
  2. package/assets/{ErrorState-DTbu9FBO.js → ErrorState-CMJQu24g.js} +1 -1
  3. package/assets/{OnboardingWizard-z9T48972.js → OnboardingWizard-DyTSf32t.js} +1 -1
  4. package/assets/{account-form-helpers-CBNs1CuK.js → account-form-helpers-IIJQ_zIy.js} +1 -1
  5. package/assets/{accounts-C3fO3ByV.js → accounts-zD2fMm5w.js} +1 -1
  6. package/assets/{advanced-BOw3cO4L.js → advanced-bZLZJckI.js} +1 -1
  7. package/assets/{appearance-BDf8BjWx.js → appearance-BEOe1utH.js} +1 -1
  8. package/assets/{avatar-CmNpdeZG.js → avatar-CrYixtkF.js} +1 -1
  9. package/assets/{browser-ponyfill-RFt62ULJ.js → browser-ponyfill-HaH_d-s2.js} +1 -1
  10. package/assets/{filter-status-4UYnt5_2.js → filter-status-Delv1mjf.js} +1 -1
  11. package/assets/{filters-BT9p3-lN.js → filters-DD7Bx5kU.js} +1 -1
  12. package/assets/{flagged-Q2Lwoy7o.js → flagged-CjMllyK4.js} +1 -1
  13. package/assets/{folders-D8JMfNoj.js → folders-CALGdFf9.js} +1 -1
  14. package/assets/{index-UBVwsOGx.js → index-BXWD3e_s.js} +1 -1
  15. package/assets/{index-BJoSTpkV.js → index-DYDvqoFE.js} +4 -4
  16. package/assets/index-DbdEbY-o.js +1 -0
  17. package/assets/{kbd-Cqt9oWri.js → kbd-Dl3RbT9N.js} +1 -1
  18. package/assets/{mail-DhKGYHPd.js → mail-sFAc3P11.js} +3 -3
  19. package/assets/{onboarding-BQuo7fLE.js → onboarding-CyZOq7bs.js} +1 -1
  20. package/assets/{select-DM0DMg2t.js → select-BNte2MZ2.js} +1 -1
  21. package/assets/{send-D3NtGfTI.js → send-BkiFD3dw.js} +1 -1
  22. package/assets/{senders-B1hXmpDl.js → senders-s1umG2u7.js} +1 -1
  23. package/assets/settings-B2WnGIUh.js +1 -0
  24. package/assets/{settings-screen-DhBh2Lb0.js → settings-screen-dnSJWdYX.js} +1 -1
  25. package/assets/{star-XmNKmgmr.js → star-1_IepXnJ.js} +1 -1
  26. package/assets/{suggested-vips-0jjDeWy0.js → suggested-vips-DN49oABN.js} +1 -1
  27. package/assets/{trash-2-DfcQ4G5V.js → trash-2-dB1s9hPl.js} +1 -1
  28. package/assets/{useDebouncedValue-CzuKj07y.js → useDebouncedValue-BD7yKD1h.js} +1 -1
  29. package/assets/{useMutation-CztUJa3L.js → useMutation-TJNHFMis.js} +1 -1
  30. package/assets/{useSignature-CaL30Llq.js → useSignature-DClGSIOU.js} +1 -1
  31. package/index.html +1 -1
  32. package/package.json +1 -1
  33. package/assets/index-Dc5rQJ-_.js +0 -1
  34. package/assets/settings-DhsvFL1a.js +0 -1
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ComposeBody-Dxf7Xcn6.js","assets/index-BJoSTpkV.js","assets/index-9Uw_PSW4.css","assets/kbd-Cqt9oWri.js","assets/avatar-CmNpdeZG.js","assets/star-XmNKmgmr.js","assets/trash-2-DfcQ4G5V.js","assets/account-form-helpers-CBNs1CuK.js","assets/send-D3NtGfTI.js","assets/useMutation-CztUJa3L.js","assets/useSignature-CaL30Llq.js","assets/useDebouncedValue-CzuKj07y.js","assets/ErrorState-DTbu9FBO.js","assets/format-BGdB831k.js","assets/folder-roles-XnseeyyD.js","assets/select-DM0DMg2t.js","assets/filter-status-4UYnt5_2.js"])))=>i.map(i=>d[i]);
2
- import{c as se,r as l,j as s,C as vt,X as Pe,a as q,B as X,b as Je,d as yt,e as Zl,f as Xa,p as Ja,I as Qn,i as ec,g as Za,D as eo,O as tc,S as sc,h as nc,F as Hn,k as to,T as Wn,P as rc,l as so,m as ac,R as Vn,n as Yn,_ as it,o as no,q as oc,Q as Gn,s as ic,t as lc,u as cc,v as Mn,w as uc,x as dc,y as je,z as fc,A as mc,E as hc,G as gc,H as pc,J as xc,K as Lr,L as bc,M as vc,N as yc,U as ro,V as ao,W as oo,Y as wt,Z as Ce,$ as fe,a0 as xs,a1 as Xn,a2 as ie,a3 as io,a4 as lo,a5 as wc,a6 as Js,a7 as co,a8 as Ze,a9 as ze,aa as jc,ab as $e,ac as uo,ad as fs,ae as Zs,af as Sc,ag as et,ah as tt,ai as ut,aj as Vt,ak as en,al as jt,am as fo,an as Nc,ao as kc,ap as Cc,aq as mo,ar as _,as as tn,at as Ut,au as Ec,av as Jn,aw as Ic,ax as Rc,ay as Ee,az as ho,aA as Zn,aB as er,aC as Tn,aD as Mc,aE as go,aF as Xe,aG as tr,aH as sr,aI as Tc,aJ as nr,aK as Dc,aL as Ac,aM as Oc,aN as Pc,aO as rr,aP as Lc,aQ as zc,aR as _c,aS as Fc,aT as Bc,aU as $c,aV as Kc,aW as qc,aX as Uc,aY as at,aZ as Ye,a_ as Qc}from"./index-BJoSTpkV.js";import{K as Kt}from"./kbd-Cqt9oWri.js";import{A as st,M as ar,C as Hc}from"./avatar-CmNpdeZG.js";import{S as dt}from"./star-XmNKmgmr.js";import{T as qe}from"./trash-2-DfcQ4G5V.js";import{L as St,M as po,a as Wc}from"./account-form-helpers-CBNs1CuK.js";import{S as bs,F as Vc,M as Yc,A as Gc,a as xo}from"./send-D3NtGfTI.js";import{u as xe}from"./useMutation-CztUJa3L.js";import{R as Xc,u as Jc}from"./useSignature-CaL30Llq.js";import{S as vs,u as bo}from"./useDebouncedValue-CzuKj07y.js";import{E as ft,f as vo}from"./ErrorState-DTbu9FBO.js";import{f as yo,a as mt,b as Ws,c as Zc,t as eu}from"./format-BGdB831k.js";import{b as ys,R as Dn,g as Vs,l as Qt,s as tu}from"./folder-roles-XnseeyyD.js";import{C as ws,S as su}from"./select-DM0DMg2t.js";import{b as wo,h as nu,p as ru,u as au}from"./filter-status-4UYnt5_2.js";const jo=se("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);const ou=se("ArrowRight",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]);const sn=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 iu=se("Ban",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m4.9 4.9 14.2 14.2",key:"1m5liu"}]]);const So=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 lu=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 zr=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 ms=se("ChevronRight",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]);const No=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 or=se("CircleCheck",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const ir=se("Clock",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]]);const ko=se("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]);const Co=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 cu=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 Eo=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 Io=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 Ro=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 uu=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 js=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 du=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 fu=se("Minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);const nn=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 mu=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 Mo=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 To=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 Do=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 hu=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 Ao=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 Ss=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 rn=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 gu=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 pu=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 Ke=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 xu=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 bu=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"}]]),vu=({address:e,showTrustedBadge:t=!1})=>{const n=t?s.jsx(sn,{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]})},yu=({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(vu,{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(vt,{className:"h-4 w-4"}):s.jsx(ms,{className:"h-4 w-4"})})]})},wu=({email:e,displayName:t,onRemove:n,className:r})=>s.jsxs("span",{className:q("inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-accent-2-soft text-sm max-w-[200px]",r),children:[s.jsx("span",{className:"truncate",children:t||e}),s.jsx("button",{type:"button",onClick:n,className:"shrink-0 p-0.5 rounded-full hover:bg-fg-muted/20 transition-colors","aria-label":`Remove ${e}`,children:s.jsx(Pe,{className:"size-3"})})]}),ju={unknown:{label:"Unknown sender",tone:"neutral"},wellknown:{label:"Known sender",tone:"positive"},vip:{label:"VIP",tone:"accent"}};function At({label:e,children:t,className:n}){return s.jsxs("section",{className:q("border-b border-line px-row-inset py-3",n),children:[s.jsx("h3",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e}),s.jsx("div",{className:"mt-2",children:t})]})}function Su({sender:e}){const t=ju[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(st,{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(Je,{tone:"danger",dot:!0,children:"Address couldn't be verified"}):s.jsx(Je,{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 Nu({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(rn,{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(gu,{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(Ss,{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(X,{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 Ot({icon:e,label:t,active:n,danger:r,onClick:a}){return s.jsxs("button",{type:"button",onClick:a,className:q("flex items-center gap-2 rounded-md border px-2 py-1 text-xs transition-colors",n?"border-accent-2 bg-accent-2-soft text-accent-2":"border-line text-fg-muted hover:border-line-strong hover:text-fg",r&&!n&&"text-danger hover:bg-danger-soft"),children:[e,t]})}const ku={sender:"matched: sender",recipient:"matched: recipient",subject:"matched: subject",attachment:"matched: attachment",body:"matched: body",entities:"matched: entities"};function Oo({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,x=d.verdict==="mismatch";return s.jsxs("aside",{className:q("flex w-76 shrink-0 flex-col overflow-y-auto border-l border-line bg-surface",i),children:[s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center justify-between border-b border-line px-row-inset",children:[s.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"}),!c&&s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(Pe,{className:"size-3.5"}),onClick:t,"aria-label":"Collapse intelligence sidebar"})]}),s.jsx(At,{label:"Sender",children:s.jsx(Su,{sender:u})}),s.jsx(At,{label:"Authenticity",children:s.jsx(Nu,{auth:d,onShowSimilar:n})}),s.jsx(At,{label:"Category",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Je,{tone:x?"danger":"neutral",children:f.value}),f.overridden&&s.jsx("span",{className:"text-2xs text-fg-subtle",children:"your override"}),s.jsx("button",{type:"button",className:"ml-auto text-2xs text-accent hover:underline",onClick:r?.onReclassify,children:"reclassify"})]})}),s.jsx(At,{label:"Quick actions",children:s.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[s.jsx(Ot,{icon:s.jsx(dt,{className:"size-3.5"}),label:"VIP",active:m.vip,onClick:r?.onToggleVip}),s.jsx(Ot,{icon:s.jsx(So,{className:"size-3.5"}),label:"Mute",active:m.muted,onClick:r?.onToggleMute}),s.jsx(Ot,{icon:s.jsx(iu,{className:"size-3.5"}),label:"Block",active:m.blocked,danger:!0,onClick:r?.onToggleBlock}),s.jsx(Ot,{icon:s.jsx(du,{className:"size-3.5"}),label:"Unsubscribe",active:m.unsubscribed,onClick:r?.onToggleUnsubscribe}),r?.onNotSpam&&s.jsx(Ot,{icon:s.jsx(uu,{className:"size-3.5"}),label:"Not spam",onClick:r.onNotSpam}),r?.onMarkSpam&&s.jsx(Ot,{icon:s.jsx(pu,{className:"size-3.5"}),label:"Mark spam",danger:!0,onClick:r.onMarkSpam})]})}),(a!=="ready"||h.length>0)&&s.jsx(At,{label:"Similar messages",children:a==="loading"?s.jsx("div",{className:"animate-pulse space-y-2",children:Array.from({length:3}).map((b,p)=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"h-3 w-3/4 rounded bg-surface-sunken"}),s.jsx("div",{className:"h-2.5 w-1/2 rounded bg-surface-sunken"})]},p))}):a==="error"?s.jsx("p",{className:"text-xs text-fg-subtle",children:"Similarity search unavailable"}):s.jsx("ul",{className:"-mx-1 space-y-1",children:h.map(b=>{const p="block w-full rounded-md px-1 py-1 text-left hover:bg-surface-sunken",y=`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:ku[b.matched]})]});return s.jsx("li",{children:o?o({mailboxId:b.mailboxId,messageId:b.id,className:p,ariaLabel:y,children:g}):s.jsx("div",{className:p,children:g})},b.id)})})}),s.jsx(At,{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(Ke,{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(Ke,{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 Cu=[{keys:["j","k"],label:"navigate"},{keys:["m"],label:"mute"},{keys:["?"],label:"all shortcuts"}];function Po({hints:e=Cu,className:t}){return s.jsx("footer",{className:q("flex items-center gap-2 border-t border-line px-row-inset py-1 text-2xs text-fg-subtle",t),children:e.map(n=>s.jsx(Eu,{hint:n},n.label))})}function Eu({hint:e}){return s.jsxs("span",{className:"flex items-center gap-1",children:[e.keys.map(t=>s.jsx(Kt,{children:t},t)),s.jsx("span",{children:e.label})]})}function Iu(){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 Ru({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 Mu({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(yt,{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(X,{variant:"secondary",size:"sm",onClick:t,children:"Retry"}),n&&s.jsx(X,{variant:"ghost",size:"sm",onClick:n,children:"Report a problem"})]})]})})}const Lo=({active:e,focused:t})=>q("relative flex h-8 w-full items-center gap-2 px-row-inset text-left",e?"bg-accent-2-soft":t?"bg-surface-sunken":"hover:bg-surface-sunken",t&&!e&&"before:absolute before:inset-y-0 before:left-0 before:w-0.5 before:bg-accent-2"),Yt=({active:e,focused:t})=>q("relative flex w-full items-start gap-3 py-2 pl-5 pr-row-inset text-left transition-colors",e?"bg-accent-2-soft":t?"bg-surface-sunken":"hover:bg-surface-sunken",t&&!e&&"before:absolute before:inset-y-0 before:left-0 before:w-0.5 before:bg-accent-2");function zo({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(Ss,{className:"size-3.5 text-danger"}):e.starred?s.jsx(dt,{className:"size-3 fill-warning text-warning"}):t?s.jsx("span",{className:"size-1.5 rounded-full bg-accent"}):null}),s.jsx("span",{className:q("w-36 shrink-0 truncate text-xs",t?"font-semibold text-fg":"text-fg-muted"),children:e.fromName}),s.jsxs("span",{className:"min-w-0 flex-1 truncate text-xs",children:[s.jsx("span",{className:q(t?"font-medium text-fg":"text-fg-muted"),children:e.subject}),s.jsxs("span",{className:"text-fg-subtle",children:[" — ",e.snippet]})]}),e.hasAttachment&&s.jsx(nn,{className:"size-3 shrink-0 text-fg-subtle"}),s.jsx("span",{className:"w-11 shrink-0 text-right text-2xs text-fg-subtle tabular-nums",children:e.timeLabel})]})}function Gt({thread:e,badge:t}){const n=!e.isRead;return s.jsxs("span",{className:"min-w-0 flex-1",children:[s.jsxs("span",{className:"flex items-baseline justify-between gap-2",children:[s.jsxs("span",{className:q("flex min-w-0 items-center gap-1.5 truncate text-sm",n?"font-semibold text-fg":"font-medium text-fg-muted"),children:[e.trust==="vip"&&s.jsx("span",{className:"size-1.5 shrink-0 rounded-full bg-accent-2"}),s.jsx("span",{className:"truncate",children:e.fromName}),e.messageCount!=null&&e.messageCount>1&&s.jsx("span",{className:"shrink-0 text-2xs font-normal text-fg-subtle",children:e.messageCount})]}),s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.timeLabel})]}),s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:q("truncate text-sm",n?"text-fg":"text-fg-muted"),children:e.subject}),e.suspicious&&s.jsx(Ss,{className:"size-3.5 shrink-0 text-danger"}),e.starred&&s.jsx(dt,{className:"size-3 shrink-0 fill-warning text-warning"}),e.hasAttachment&&s.jsx(nn,{className:"size-3 shrink-0 text-fg-subtle"})]}),s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"line-clamp-1 min-w-0 flex-1 text-xs text-fg-subtle",children:e.snippet}),e.category&&e.category!=="personal"&&s.jsx(Je,{tone:Zl[e.category],className:"shrink-0",children:e.category}),t]})]})}function _o({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(st,{name:e.fromName,email:e.fromEmail,size:"sm"}),s.jsx(Gt,{thread:e})]})}function Tu({thread:e,active:t,onClick:n}){return s.jsx("button",{type:"button",onClick:n,className:Lo({active:t}),children:s.jsx(zo,{thread:e})})}function Fo({thread:e,active:t,onClick:n}){return s.jsx("button",{type:"button",onClick:n,className:Yt({active:t}),children:s.jsx(_o,{thread:e})})}function Bo({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(X,{variant:"ghost",size:"sm",icon:s.jsx(Pe,{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(X,{variant:"ghost",size:"sm",icon:s.jsx(js,{className:"size-4"}),onClick:i?void 0:n,"aria-label":"Mark as read","aria-busy":i||void 0,className:"shrink-0"}),a,s.jsx(X,{variant:"ghost",size:"sm",icon:i?s.jsx(St,{className:"size-4 animate-spin"}):s.jsx(qe,{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 Ht=72,_r=10;function Fr(e){return e==="leading"?Ht:e==="trailing"?-Ht:0}function Du(e){return e>=Ht/2?"leading":e<=-Ht/2?"trailing":"none"}function $o({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),[x,b]=l.useState(null),p=()=>clearTimeout(m.current),y=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 T=k.clientX-M.startX,D=k.clientY-M.startY;if(M.axis==="none"){if(Math.abs(D)>_r&&Math.abs(D)>Math.abs(T)){M.axis="vertical",p(),h.current=null;return}Math.abs(T)>_r&&(M.axis="horizontal",M.moved=!0,p(),k.currentTarget.setPointerCapture(k.pointerId))}if(M.axis!=="horizontal")return;const I=Fr(a),R=Math.max(-Ht,Math.min(Ht,I+T));b(R)},v=()=>{p();const k=h.current;h.current=null;const M=x;if(b(null),!!k){if(k.axis==="horizontal"&&M!==null){o(Du(M));return}if(t){i();return}if(a!=="none"){o("none");return}f||u()}},j=k=>{a!=="none"&&k.preventDefault()},w=x??Fr(a),N=w>0?"leading":w<0?"trailing":"none",E=q("relative touch-pan-y bg-surface",Yt({active:n||r})),S={transform:w!==0?`translateX(${w}px)`:void 0,transition:x===null?"transform 150ms ease":"none",minHeight:44},C=t?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:q("inline-flex size-7 shrink-0 items-center justify-center rounded-full border",n?"border-accent bg-accent text-accent-fg":"border-line-strong bg-canvas"),children:n&&s.jsx(ws,{className:"size-3.5"})}),s.jsx(Gt,{thread:e})]}):s.jsx(_o,{thread:e});return s.jsxs("div",{className:"relative overflow-hidden",children:[N==="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(po,{className:"size-6"}):s.jsx(js,{className:"size-6"})}),N==="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(qe,{className:"size-6"})}),f&&!t?f({className:E,style:S,onPointerDown:y,onPointerMove:g,onPointerUp:v,onPointerCancel:v,onOpenClick:j,children:C}):s.jsx("button",{type:"button",onPointerDown:y,onPointerMove:g,onPointerUp:v,onPointerCancel:v,className:E,style:S,children:C})]})}function Au({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(p=>p.threads)),[h,x]=l.useState(a&&a!=="none"&&f[1]?{id:f[1].id,side:a}:null),b=(p,y)=>{m(y==="trailing"?g=>g.filter(v=>v.id!==p):g=>g.map(v=>v.id===p?{...v,isRead:!v.isRead}:v)),x(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(Mo,{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(p=>s.jsx($o,{thread:p,selectionMode:n,checked:r.has(p.id),active:p.id===t,peek:h?.id===p.id?h.side:"none",onPeek:y=>x(y==="none"?null:{id:p.id,side:y}),onToggleCheck:()=>o(p.id),onLongPress:()=>i(p.id),onOpen:()=>c(p.id),onAct:y=>b(p.id,y)},p.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 Ko({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:x,onSelectBriefCategory:b,onOpenNav:p,isDesktop:y,initialTouchState:g,selectionBar:v,listBody:j,hideHeader:w=!1}){const N=h==="compact"?Tu:Fo,E=!y&&!r&&o==="ready",S=n.flatMap(U=>U.threads),[C,k]=l.useState(g==="selection"),[M,T]=l.useState(()=>g==="selection"?new Set(S.slice(0,2).map(U=>U.id)):new Set),[D,I]=l.useState(!1),R=g==="peek-trailing"?"trailing":g==="peek-leading"?"leading":void 0,O=U=>{T(te=>{const Q=new Set(te);return Q.has(U)?Q.delete(U):Q.add(U),Q.size===0&&k(!1),Q})},B=U=>{k(!0),T(new Set([U]))},K=()=>{k(!1),T(new Set)},F=()=>{I(!0),setTimeout(()=>I(!1),1400)},$=!v&&E&&C&&M.size>0;return s.jsxs("section",{className:"flex h-full w-full flex-col bg-surface",children:[v??($?s.jsx(Bo,{count:M.size,onCancel:K,onMarkRead:K,onDelete:K}):w?null:s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[p&&s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(ar,{className:"size-4"}),onClick:p,"aria-label":"Open folders",className:"-ml-1 shrink-0"}),s.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e}),t&&s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle",children:t})]})),o==="loading"?s.jsx("div",{className:"flex-1 overflow-y-auto",children:s.jsx(Iu,{})}):o==="empty"?s.jsx(Ru,{searchQuery:i}):o==="error"?s.jsx(Mu,{message:c,onRetry:u,onReport:d}):r?s.jsx(Xa,{sections:n,briefCategory:f,selectedThreadId:m,Row:N,onSelectThread:x,onSelectBriefCategory:b}):j??(E?s.jsx(Au,{sections:n,selectedThreadId:m,selectionMode:C,checkedIds:M,initialPeek:R,onToggleCheck:O,onEnterSelection:B,onOpenThread:U=>x?.(U),onRefresh:F,refreshing:D}):s.jsx("div",{className:"flex-1 overflow-y-auto",children:n.map(U=>s.jsxs("div",{children:[!a&&U.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:U.label}),s.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:U.threads.length})]}),s.jsx("div",{className:"divide-y divide-line",children:U.threads.map(te=>s.jsx(N,{thread:te,active:te.id===m,onClick:()=>x?.(te.id)},te.id))})]},U.id))})),y&&s.jsx(Po,{})]})}function Ou({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:q("relative",o),children:[s.jsx(X,{variant:"ghost",size:"sm",icon:t??s.jsx(Co,{className:"size-5"}),onClick:()=>c(d=>!d),"aria-label":e,"aria-haspopup":"menu","aria-expanded":i,className:q(a&&"min-h-11 min-w-11 px-0")}),i&&s.jsx("div",{role:"menu",className:q("absolute top-full z-50 mt-1 flex min-w-44 flex-col rounded-md border border-line bg-surface py-1 shadow-lg",r==="end"?"right-0":"left-0"),children:n.map(d=>s.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{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 rs="min-h-11 min-w-11 px-0";function qo({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:x}){const b=(y,g)=>()=>{if(!e){m?.(y);return}g?.()},p=u?[{key:"toggle-read",label:c?"Mark as unread":"Mark as read",icon:c?s.jsx(po,{className:"size-4"}):s.jsx(js,{className:"size-4"}),onSelect:b("toggleRead",u)}]:[];return s.jsxs("div",{className:q("relative",x),children:[s.jsxs("div",{className:"flex h-12 shrink-0 items-center gap-0.5 border-y border-line bg-canvas px-1",children:[s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(Do,{className:"size-5"}),onClick:b("reply",t),"aria-label":"Reply",title:"Reply",className:rs}),s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(To,{className:"size-5"}),onClick:b("replyAll",n),"aria-label":"Reply all",title:"Reply all",className:rs}),s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(Io,{className:"size-5"}),onClick:b("forward",r),"aria-label":"Forward",title:"Forward",className:rs}),s.jsx("div",{className:"flex-1"}),s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(dt,{className:q("size-5",a&&"fill-warning text-warning")}),onClick:b("star",o),"aria-label":a?"Unstar":"Star","aria-pressed":a,title:a?"Unstar":"Star",className:rs}),d,s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(qe,{className:"size-5"}),onClick:b("delete",i),"aria-label":"Move to Trash",title:"Move to Trash",className:rs}),s.jsx(Ou,{triggerLabel:"More actions",items:[...p,...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 Pu({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:x="Reply all (a)",forwardTitle:b="Forward (f)",deleteTitle:p="Move to Trash (#)",flagTitle:y="Star (s)",children:g,className:v}){const j=(w,N)=>()=>{if(!e){t?.(w);return}N?.()};return s.jsxs("div",{className:"relative",children:[s.jsxs("header",{className:q("flex h-pane-header shrink-0 items-center gap-1 border-b border-line bg-surface px-3",v),children:[s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(Do,{className:"size-4"}),title:h,"aria-label":"Reply",onClick:j("reply",o)}),s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(To,{className:"size-4"}),title:x,"aria-label":"Reply all",onClick:j("replyAll",i)}),s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(Io,{className:"size-4"}),title:b,"aria-label":"Forward",onClick:j("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(X,{variant:"ghost",size:"sm",icon:s.jsx(qe,{className:"size-4"}),title:p,"aria-label":"Move to Trash",onClick:j("delete",u)}),f??s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(Eo,{className:"size-4"}),title:"Move to mailbox","aria-label":"Move to mailbox",onClick:j("move",m)}),s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(dt,{className:q("size-4",r&&"fill-warning text-warning")}),title:y,"aria-label":"Star",onClick:j("flag",d)})]}),s.jsx("div",{className:"flex-1"}),g]}),!e&&n&&s.jsx("p",{role:"status",className:"border-b border-line bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:n})]})}const Lu=(e,t)=>{const r=e==="newsletter"||e==="marketing"||t;return{framed:r,isPlain:!r}},zu=()=>`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ComposeBody-Omy6Iikn.js","assets/index-DYDvqoFE.js","assets/index-9Uw_PSW4.css","assets/kbd-Dl3RbT9N.js","assets/avatar-CrYixtkF.js","assets/star-1_IepXnJ.js","assets/trash-2-dB1s9hPl.js","assets/account-form-helpers-IIJQ_zIy.js","assets/send-BkiFD3dw.js","assets/useMutation-TJNHFMis.js","assets/useSignature-DClGSIOU.js","assets/useDebouncedValue-BD7yKD1h.js","assets/ErrorState-CMJQu24g.js","assets/format-BGdB831k.js","assets/folder-roles-XnseeyyD.js","assets/select-BNte2MZ2.js","assets/filter-status-Delv1mjf.js"])))=>i.map(i=>d[i]);
2
+ import{c as se,r as l,j as s,C as vt,X as Pe,a as q,B as X,b as Je,d as yt,e as Zl,f as Xa,p as Ja,I as Qn,i as ec,g as Za,D as eo,O as tc,S as sc,h as nc,F as Hn,k as to,T as Wn,P as rc,l as so,m as ac,R as Vn,n as Yn,_ as it,o as no,q as oc,Q as Gn,s as ic,t as lc,u as cc,v as Mn,w as uc,x as dc,y as je,z as fc,A as mc,E as hc,G as gc,H as pc,J as xc,K as Lr,L as bc,M as vc,N as yc,U as ro,V as ao,W as oo,Y as wt,Z as Ce,$ as fe,a0 as xs,a1 as Xn,a2 as ie,a3 as io,a4 as lo,a5 as wc,a6 as Js,a7 as co,a8 as Ze,a9 as ze,aa as jc,ab as $e,ac as uo,ad as fs,ae as Zs,af as Sc,ag as et,ah as tt,ai as ut,aj as Vt,ak as en,al as jt,am as fo,an as Nc,ao as kc,ap as Cc,aq as mo,ar as _,as as tn,at as Ut,au as Ec,av as Jn,aw as Ic,ax as Rc,ay as Ee,az as ho,aA as Zn,aB as er,aC as Tn,aD as Mc,aE as go,aF as Xe,aG as tr,aH as sr,aI as Tc,aJ as nr,aK as Dc,aL as Ac,aM as Oc,aN as Pc,aO as rr,aP as Lc,aQ as zc,aR as _c,aS as Fc,aT as Bc,aU as $c,aV as Kc,aW as qc,aX as Uc,aY as at,aZ as Ye,a_ as Qc}from"./index-DYDvqoFE.js";import{K as Kt}from"./kbd-Dl3RbT9N.js";import{A as st,M as ar,C as Hc}from"./avatar-CrYixtkF.js";import{S as dt}from"./star-1_IepXnJ.js";import{T as qe}from"./trash-2-dB1s9hPl.js";import{L as St,M as po,a as Wc}from"./account-form-helpers-IIJQ_zIy.js";import{S as bs,F as Vc,M as Yc,A as Gc,a as xo}from"./send-BkiFD3dw.js";import{u as xe}from"./useMutation-TJNHFMis.js";import{R as Xc,u as Jc}from"./useSignature-DClGSIOU.js";import{S as vs,u as bo}from"./useDebouncedValue-BD7yKD1h.js";import{E as ft,f as vo}from"./ErrorState-CMJQu24g.js";import{f as yo,a as mt,b as Ws,c as Zc,t as eu}from"./format-BGdB831k.js";import{b as ys,R as Dn,g as Vs,l as Qt,s as tu}from"./folder-roles-XnseeyyD.js";import{C as ws,S as su}from"./select-BNte2MZ2.js";import{b as wo,h as nu,p as ru,u as au}from"./filter-status-Delv1mjf.js";const jo=se("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);const ou=se("ArrowRight",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]);const sn=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 iu=se("Ban",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m4.9 4.9 14.2 14.2",key:"1m5liu"}]]);const So=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 lu=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 zr=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 ms=se("ChevronRight",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]);const No=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 or=se("CircleCheck",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const ir=se("Clock",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]]);const ko=se("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]);const Co=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 cu=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 Eo=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 Io=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 Ro=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 uu=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 js=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 du=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 fu=se("Minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);const nn=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 mu=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 Mo=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 To=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 Do=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 hu=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 Ao=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 Ss=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 rn=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 gu=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 pu=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 Ke=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 xu=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 bu=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"}]]),vu=({address:e,showTrustedBadge:t=!1})=>{const n=t?s.jsx(sn,{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]})},yu=({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(vu,{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(vt,{className:"h-4 w-4"}):s.jsx(ms,{className:"h-4 w-4"})})]})},wu=({email:e,displayName:t,onRemove:n,className:r})=>s.jsxs("span",{className:q("inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-accent-2-soft text-sm max-w-[200px]",r),children:[s.jsx("span",{className:"truncate",children:t||e}),s.jsx("button",{type:"button",onClick:n,className:"shrink-0 p-0.5 rounded-full hover:bg-fg-muted/20 transition-colors","aria-label":`Remove ${e}`,children:s.jsx(Pe,{className:"size-3"})})]}),ju={unknown:{label:"Unknown sender",tone:"neutral"},wellknown:{label:"Known sender",tone:"positive"},vip:{label:"VIP",tone:"accent"}};function At({label:e,children:t,className:n}){return s.jsxs("section",{className:q("border-b border-line px-row-inset py-3",n),children:[s.jsx("h3",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e}),s.jsx("div",{className:"mt-2",children:t})]})}function Su({sender:e}){const t=ju[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(st,{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(Je,{tone:"danger",dot:!0,children:"Address couldn't be verified"}):s.jsx(Je,{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 Nu({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(rn,{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(gu,{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(Ss,{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(X,{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 Ot({icon:e,label:t,active:n,danger:r,onClick:a}){return s.jsxs("button",{type:"button",onClick:a,className:q("flex items-center gap-2 rounded-md border px-2 py-1 text-xs transition-colors",n?"border-accent-2 bg-accent-2-soft text-accent-2":"border-line text-fg-muted hover:border-line-strong hover:text-fg",r&&!n&&"text-danger hover:bg-danger-soft"),children:[e,t]})}const ku={sender:"matched: sender",recipient:"matched: recipient",subject:"matched: subject",attachment:"matched: attachment",body:"matched: body",entities:"matched: entities"};function Oo({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,x=d.verdict==="mismatch";return s.jsxs("aside",{className:q("flex w-76 shrink-0 flex-col overflow-y-auto border-l border-line bg-surface",i),children:[s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center justify-between border-b border-line px-row-inset",children:[s.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"}),!c&&s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(Pe,{className:"size-3.5"}),onClick:t,"aria-label":"Collapse intelligence sidebar"})]}),s.jsx(At,{label:"Sender",children:s.jsx(Su,{sender:u})}),s.jsx(At,{label:"Authenticity",children:s.jsx(Nu,{auth:d,onShowSimilar:n})}),s.jsx(At,{label:"Category",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Je,{tone:x?"danger":"neutral",children:f.value}),f.overridden&&s.jsx("span",{className:"text-2xs text-fg-subtle",children:"your override"}),s.jsx("button",{type:"button",className:"ml-auto text-2xs text-accent hover:underline",onClick:r?.onReclassify,children:"reclassify"})]})}),s.jsx(At,{label:"Quick actions",children:s.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[s.jsx(Ot,{icon:s.jsx(dt,{className:"size-3.5"}),label:"VIP",active:m.vip,onClick:r?.onToggleVip}),s.jsx(Ot,{icon:s.jsx(So,{className:"size-3.5"}),label:"Mute",active:m.muted,onClick:r?.onToggleMute}),s.jsx(Ot,{icon:s.jsx(iu,{className:"size-3.5"}),label:"Block",active:m.blocked,danger:!0,onClick:r?.onToggleBlock}),s.jsx(Ot,{icon:s.jsx(du,{className:"size-3.5"}),label:"Unsubscribe",active:m.unsubscribed,onClick:r?.onToggleUnsubscribe}),r?.onNotSpam&&s.jsx(Ot,{icon:s.jsx(uu,{className:"size-3.5"}),label:"Not spam",onClick:r.onNotSpam}),r?.onMarkSpam&&s.jsx(Ot,{icon:s.jsx(pu,{className:"size-3.5"}),label:"Mark spam",danger:!0,onClick:r.onMarkSpam})]})}),(a!=="ready"||h.length>0)&&s.jsx(At,{label:"Similar messages",children:a==="loading"?s.jsx("div",{className:"animate-pulse space-y-2",children:Array.from({length:3}).map((b,p)=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"h-3 w-3/4 rounded bg-surface-sunken"}),s.jsx("div",{className:"h-2.5 w-1/2 rounded bg-surface-sunken"})]},p))}):a==="error"?s.jsx("p",{className:"text-xs text-fg-subtle",children:"Similarity search unavailable"}):s.jsx("ul",{className:"-mx-1 space-y-1",children:h.map(b=>{const p="block w-full rounded-md px-1 py-1 text-left hover:bg-surface-sunken",y=`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:ku[b.matched]})]});return s.jsx("li",{children:o?o({mailboxId:b.mailboxId,messageId:b.id,className:p,ariaLabel:y,children:g}):s.jsx("div",{className:p,children:g})},b.id)})})}),s.jsx(At,{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(Ke,{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(Ke,{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 Cu=[{keys:["j","k"],label:"navigate"},{keys:["m"],label:"mute"},{keys:["?"],label:"all shortcuts"}];function Po({hints:e=Cu,className:t}){return s.jsx("footer",{className:q("flex items-center gap-2 border-t border-line px-row-inset py-1 text-2xs text-fg-subtle",t),children:e.map(n=>s.jsx(Eu,{hint:n},n.label))})}function Eu({hint:e}){return s.jsxs("span",{className:"flex items-center gap-1",children:[e.keys.map(t=>s.jsx(Kt,{children:t},t)),s.jsx("span",{children:e.label})]})}function Iu(){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 Ru({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 Mu({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(yt,{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(X,{variant:"secondary",size:"sm",onClick:t,children:"Retry"}),n&&s.jsx(X,{variant:"ghost",size:"sm",onClick:n,children:"Report a problem"})]})]})})}const Lo=({active:e,focused:t})=>q("relative flex h-8 w-full items-center gap-2 px-row-inset text-left",e?"bg-accent-2-soft":t?"bg-surface-sunken":"hover:bg-surface-sunken",t&&!e&&"before:absolute before:inset-y-0 before:left-0 before:w-0.5 before:bg-accent-2"),Yt=({active:e,focused:t})=>q("relative flex w-full items-start gap-3 py-2 pl-5 pr-row-inset text-left transition-colors",e?"bg-accent-2-soft":t?"bg-surface-sunken":"hover:bg-surface-sunken",t&&!e&&"before:absolute before:inset-y-0 before:left-0 before:w-0.5 before:bg-accent-2");function zo({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(Ss,{className:"size-3.5 text-danger"}):e.starred?s.jsx(dt,{className:"size-3 fill-warning text-warning"}):t?s.jsx("span",{className:"size-1.5 rounded-full bg-accent"}):null}),s.jsx("span",{className:q("w-36 shrink-0 truncate text-xs",t?"font-semibold text-fg":"text-fg-muted"),children:e.fromName}),s.jsxs("span",{className:"min-w-0 flex-1 truncate text-xs",children:[s.jsx("span",{className:q(t?"font-medium text-fg":"text-fg-muted"),children:e.subject}),s.jsxs("span",{className:"text-fg-subtle",children:[" — ",e.snippet]})]}),e.hasAttachment&&s.jsx(nn,{className:"size-3 shrink-0 text-fg-subtle"}),s.jsx("span",{className:"w-11 shrink-0 text-right text-2xs text-fg-subtle tabular-nums",children:e.timeLabel})]})}function Gt({thread:e,badge:t}){const n=!e.isRead;return s.jsxs("span",{className:"min-w-0 flex-1",children:[s.jsxs("span",{className:"flex items-baseline justify-between gap-2",children:[s.jsxs("span",{className:q("flex min-w-0 items-center gap-1.5 truncate text-sm",n?"font-semibold text-fg":"font-medium text-fg-muted"),children:[e.trust==="vip"&&s.jsx("span",{className:"size-1.5 shrink-0 rounded-full bg-accent-2"}),s.jsx("span",{className:"truncate",children:e.fromName}),e.messageCount!=null&&e.messageCount>1&&s.jsx("span",{className:"shrink-0 text-2xs font-normal text-fg-subtle",children:e.messageCount})]}),s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.timeLabel})]}),s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:q("truncate text-sm",n?"text-fg":"text-fg-muted"),children:e.subject}),e.suspicious&&s.jsx(Ss,{className:"size-3.5 shrink-0 text-danger"}),e.starred&&s.jsx(dt,{className:"size-3 shrink-0 fill-warning text-warning"}),e.hasAttachment&&s.jsx(nn,{className:"size-3 shrink-0 text-fg-subtle"})]}),s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"line-clamp-1 min-w-0 flex-1 text-xs text-fg-subtle",children:e.snippet}),e.category&&e.category!=="personal"&&s.jsx(Je,{tone:Zl[e.category],className:"shrink-0",children:e.category}),t]})]})}function _o({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(st,{name:e.fromName,email:e.fromEmail,size:"sm"}),s.jsx(Gt,{thread:e})]})}function Tu({thread:e,active:t,onClick:n}){return s.jsx("button",{type:"button",onClick:n,className:Lo({active:t}),children:s.jsx(zo,{thread:e})})}function Fo({thread:e,active:t,onClick:n}){return s.jsx("button",{type:"button",onClick:n,className:Yt({active:t}),children:s.jsx(_o,{thread:e})})}function Bo({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(X,{variant:"ghost",size:"sm",icon:s.jsx(Pe,{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(X,{variant:"ghost",size:"sm",icon:s.jsx(js,{className:"size-4"}),onClick:i?void 0:n,"aria-label":"Mark as read","aria-busy":i||void 0,className:"shrink-0"}),a,s.jsx(X,{variant:"ghost",size:"sm",icon:i?s.jsx(St,{className:"size-4 animate-spin"}):s.jsx(qe,{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 Ht=72,_r=10;function Fr(e){return e==="leading"?Ht:e==="trailing"?-Ht:0}function Du(e){return e>=Ht/2?"leading":e<=-Ht/2?"trailing":"none"}function $o({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),[x,b]=l.useState(null),p=()=>clearTimeout(m.current),y=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 T=k.clientX-M.startX,D=k.clientY-M.startY;if(M.axis==="none"){if(Math.abs(D)>_r&&Math.abs(D)>Math.abs(T)){M.axis="vertical",p(),h.current=null;return}Math.abs(T)>_r&&(M.axis="horizontal",M.moved=!0,p(),k.currentTarget.setPointerCapture(k.pointerId))}if(M.axis!=="horizontal")return;const I=Fr(a),R=Math.max(-Ht,Math.min(Ht,I+T));b(R)},v=()=>{p();const k=h.current;h.current=null;const M=x;if(b(null),!!k){if(k.axis==="horizontal"&&M!==null){o(Du(M));return}if(t){i();return}if(a!=="none"){o("none");return}f||u()}},j=k=>{a!=="none"&&k.preventDefault()},w=x??Fr(a),N=w>0?"leading":w<0?"trailing":"none",E=q("relative touch-pan-y bg-surface",Yt({active:n||r})),S={transform:w!==0?`translateX(${w}px)`:void 0,transition:x===null?"transform 150ms ease":"none",minHeight:44},C=t?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:q("inline-flex size-7 shrink-0 items-center justify-center rounded-full border",n?"border-accent bg-accent text-accent-fg":"border-line-strong bg-canvas"),children:n&&s.jsx(ws,{className:"size-3.5"})}),s.jsx(Gt,{thread:e})]}):s.jsx(_o,{thread:e});return s.jsxs("div",{className:"relative overflow-hidden",children:[N==="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(po,{className:"size-6"}):s.jsx(js,{className:"size-6"})}),N==="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(qe,{className:"size-6"})}),f&&!t?f({className:E,style:S,onPointerDown:y,onPointerMove:g,onPointerUp:v,onPointerCancel:v,onOpenClick:j,children:C}):s.jsx("button",{type:"button",onPointerDown:y,onPointerMove:g,onPointerUp:v,onPointerCancel:v,className:E,style:S,children:C})]})}function Au({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(p=>p.threads)),[h,x]=l.useState(a&&a!=="none"&&f[1]?{id:f[1].id,side:a}:null),b=(p,y)=>{m(y==="trailing"?g=>g.filter(v=>v.id!==p):g=>g.map(v=>v.id===p?{...v,isRead:!v.isRead}:v)),x(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(Mo,{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(p=>s.jsx($o,{thread:p,selectionMode:n,checked:r.has(p.id),active:p.id===t,peek:h?.id===p.id?h.side:"none",onPeek:y=>x(y==="none"?null:{id:p.id,side:y}),onToggleCheck:()=>o(p.id),onLongPress:()=>i(p.id),onOpen:()=>c(p.id),onAct:y=>b(p.id,y)},p.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 Ko({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:x,onSelectBriefCategory:b,onOpenNav:p,isDesktop:y,initialTouchState:g,selectionBar:v,listBody:j,hideHeader:w=!1}){const N=h==="compact"?Tu:Fo,E=!y&&!r&&o==="ready",S=n.flatMap(U=>U.threads),[C,k]=l.useState(g==="selection"),[M,T]=l.useState(()=>g==="selection"?new Set(S.slice(0,2).map(U=>U.id)):new Set),[D,I]=l.useState(!1),R=g==="peek-trailing"?"trailing":g==="peek-leading"?"leading":void 0,O=U=>{T(te=>{const Q=new Set(te);return Q.has(U)?Q.delete(U):Q.add(U),Q.size===0&&k(!1),Q})},B=U=>{k(!0),T(new Set([U]))},K=()=>{k(!1),T(new Set)},F=()=>{I(!0),setTimeout(()=>I(!1),1400)},$=!v&&E&&C&&M.size>0;return s.jsxs("section",{className:"flex h-full w-full flex-col bg-surface",children:[v??($?s.jsx(Bo,{count:M.size,onCancel:K,onMarkRead:K,onDelete:K}):w?null:s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[p&&s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(ar,{className:"size-4"}),onClick:p,"aria-label":"Open folders",className:"-ml-1 shrink-0"}),s.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e}),t&&s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle",children:t})]})),o==="loading"?s.jsx("div",{className:"flex-1 overflow-y-auto",children:s.jsx(Iu,{})}):o==="empty"?s.jsx(Ru,{searchQuery:i}):o==="error"?s.jsx(Mu,{message:c,onRetry:u,onReport:d}):r?s.jsx(Xa,{sections:n,briefCategory:f,selectedThreadId:m,Row:N,onSelectThread:x,onSelectBriefCategory:b}):j??(E?s.jsx(Au,{sections:n,selectedThreadId:m,selectionMode:C,checkedIds:M,initialPeek:R,onToggleCheck:O,onEnterSelection:B,onOpenThread:U=>x?.(U),onRefresh:F,refreshing:D}):s.jsx("div",{className:"flex-1 overflow-y-auto",children:n.map(U=>s.jsxs("div",{children:[!a&&U.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:U.label}),s.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:U.threads.length})]}),s.jsx("div",{className:"divide-y divide-line",children:U.threads.map(te=>s.jsx(N,{thread:te,active:te.id===m,onClick:()=>x?.(te.id)},te.id))})]},U.id))})),y&&s.jsx(Po,{})]})}function Ou({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:q("relative",o),children:[s.jsx(X,{variant:"ghost",size:"sm",icon:t??s.jsx(Co,{className:"size-5"}),onClick:()=>c(d=>!d),"aria-label":e,"aria-haspopup":"menu","aria-expanded":i,className:q(a&&"min-h-11 min-w-11 px-0")}),i&&s.jsx("div",{role:"menu",className:q("absolute top-full z-50 mt-1 flex min-w-44 flex-col rounded-md border border-line bg-surface py-1 shadow-lg",r==="end"?"right-0":"left-0"),children:n.map(d=>s.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{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 rs="min-h-11 min-w-11 px-0";function qo({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:x}){const b=(y,g)=>()=>{if(!e){m?.(y);return}g?.()},p=u?[{key:"toggle-read",label:c?"Mark as unread":"Mark as read",icon:c?s.jsx(po,{className:"size-4"}):s.jsx(js,{className:"size-4"}),onSelect:b("toggleRead",u)}]:[];return s.jsxs("div",{className:q("relative",x),children:[s.jsxs("div",{className:"flex h-12 shrink-0 items-center gap-0.5 border-y border-line bg-canvas px-1",children:[s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(Do,{className:"size-5"}),onClick:b("reply",t),"aria-label":"Reply",title:"Reply",className:rs}),s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(To,{className:"size-5"}),onClick:b("replyAll",n),"aria-label":"Reply all",title:"Reply all",className:rs}),s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(Io,{className:"size-5"}),onClick:b("forward",r),"aria-label":"Forward",title:"Forward",className:rs}),s.jsx("div",{className:"flex-1"}),s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(dt,{className:q("size-5",a&&"fill-warning text-warning")}),onClick:b("star",o),"aria-label":a?"Unstar":"Star","aria-pressed":a,title:a?"Unstar":"Star",className:rs}),d,s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(qe,{className:"size-5"}),onClick:b("delete",i),"aria-label":"Move to Trash",title:"Move to Trash",className:rs}),s.jsx(Ou,{triggerLabel:"More actions",items:[...p,...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 Pu({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:x="Reply all (a)",forwardTitle:b="Forward (f)",deleteTitle:p="Move to Trash (#)",flagTitle:y="Star (s)",children:g,className:v}){const j=(w,N)=>()=>{if(!e){t?.(w);return}N?.()};return s.jsxs("div",{className:"relative",children:[s.jsxs("header",{className:q("flex h-pane-header shrink-0 items-center gap-1 border-b border-line bg-surface px-3",v),children:[s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(Do,{className:"size-4"}),title:h,"aria-label":"Reply",onClick:j("reply",o)}),s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(To,{className:"size-4"}),title:x,"aria-label":"Reply all",onClick:j("replyAll",i)}),s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(Io,{className:"size-4"}),title:b,"aria-label":"Forward",onClick:j("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(X,{variant:"ghost",size:"sm",icon:s.jsx(qe,{className:"size-4"}),title:p,"aria-label":"Move to Trash",onClick:j("delete",u)}),f??s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(Eo,{className:"size-4"}),title:"Move to mailbox","aria-label":"Move to mailbox",onClick:j("move",m)}),s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(dt,{className:q("size-4",r&&"fill-warning text-warning")}),title:y,"aria-label":"Star",onClick:j("flag",d)})]}),s.jsx("div",{className:"flex-1"}),g]}),!e&&n&&s.jsx("p",{role:"status",className:"border-b border-line bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:n})]})}const Lu=(e,t)=>{const r=e==="newsletter"||e==="marketing"||t;return{framed:r,isPlain:!r}},zu=()=>`
3
3
  /* Zero the UA default body margin and clamp the document to the iframe width so
4
4
  wide author markup can't push the body (and the page) past the viewport. */
5
5
  html, body {
@@ -107,6 +107,6 @@ a, a:visited {
107
107
  .block-interactivity-`.concat(e,` {pointer-events: none;}
108
108
  .allow-interactivity-`).concat(e,` {pointer-events: all;}
109
109
  `)},Dm=0,_t=[];function Am(e){var t=l.useRef([]),n=l.useRef([0,0]),r=l.useRef(),a=l.useState(Dm++)[0],o=l.useState(ai)[0],i=l.useRef(e);l.useEffect(function(){i.current=e},[e]),l.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(a));var p=oc([e.lockRef.current],(e.shards||[]).map(xa),!0).filter(Boolean);return p.forEach(function(y){return y.classList.add("allow-interactivity-".concat(a))}),function(){document.body.classList.remove("block-interactivity-".concat(a)),p.forEach(function(y){return y.classList.remove("allow-interactivity-".concat(a))})}}},[e.inert,e.lockRef.current,e.shards]);var c=l.useCallback(function(p,y){if("touches"in p&&p.touches.length===2||p.type==="wheel"&&p.ctrlKey)return!i.current.allowPinchZoom;var g=Ps(p),v=n.current,j="deltaX"in p?p.deltaX:v[0]-g[0],w="deltaY"in p?p.deltaY:v[1]-g[1],N,E=p.target,S=Math.abs(j)>Math.abs(w)?"h":"v";if("touches"in p&&S==="h"&&E.type==="range")return!1;var C=window.getSelection(),k=C&&C.anchorNode,M=k?k===E||k.contains(E):!1;if(M)return!1;var T=ga(S,E);if(!T)return!0;if(T?N=S:(N=S==="v"?"h":"v",T=ga(S,E)),!T)return!1;if(!r.current&&"changedTouches"in p&&(j||w)&&(r.current=N),!N)return!0;var D=r.current||N;return Rm(D,y,p,D==="h"?j:w)},[]),u=l.useCallback(function(p){var y=p;if(!(!_t.length||_t[_t.length-1]!==o)){var g="deltaY"in y?pa(y):Ps(y),v=t.current.filter(function(N){return N.name===y.type&&(N.target===y.target||y.target===N.shadowParent)&&Mm(N.delta,g)})[0];if(v&&v.should){y.cancelable&&y.preventDefault();return}if(!v){var j=(i.current.shards||[]).map(xa).filter(Boolean).filter(function(N){return N.contains(y.target)}),w=j.length>0?c(y,j[0]):!i.current.noIsolation;w&&y.cancelable&&y.preventDefault()}}},[]),d=l.useCallback(function(p,y,g,v){var j={name:p,delta:y,target:g,should:v,shadowParent:Om(g)};t.current.push(j),setTimeout(function(){t.current=t.current.filter(function(w){return w!==j})},1)},[]),f=l.useCallback(function(p){n.current=Ps(p),r.current=void 0},[]),m=l.useCallback(function(p){d(p.type,pa(p),p.target,c(p,e.lockRef.current))},[]),h=l.useCallback(function(p){d(p.type,Ps(p),p.target,c(p,e.lockRef.current))},[]);l.useEffect(function(){return _t.push(o),e.setCallbacks({onScrollCapture:m,onWheelCapture:m,onTouchMoveCapture:h}),document.addEventListener("wheel",u,zt),document.addEventListener("touchmove",u,zt),document.addEventListener("touchstart",f,zt),function(){_t=_t.filter(function(p){return p!==o}),document.removeEventListener("wheel",u,zt),document.removeEventListener("touchmove",u,zt),document.removeEventListener("touchstart",f,zt)}},[]);var x=e.removeScrollBar,b=e.inert;return l.createElement(l.Fragment,null,b?l.createElement(o,{styles:Tm(a)}):null,x?l.createElement(jm,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Om(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const Pm=cm(ri,Am);var ci=l.forwardRef(function(e,t){return l.createElement(on,it({},e,{ref:t,sideCar:Pm}))});ci.classNames=on.classNames;var Lm=class extends Gn{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:lc(t,n.data),hasPreviousPage:ic(t,n.data),isFetchNextPageError:d,isFetchingNextPage:f,isFetchPreviousPageError:m,isFetchingPreviousPage:h,isRefetchError:c&&!d&&!m,isRefetching:o&&!f&&!h}}};function ba(e,t){const n=new Set(t);return e.filter(r=>!n.has(r))}function zm(e,t,n){const r=e.slice(0);return r[t]=n,r}var _m=class extends cc{#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,Mn.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||!uc(f,h)});!u&&!d||(u&&(this.#c=r,this.#t=a),this.#e=o,this.hasListeners()&&(u&&(ba(n,a).forEach(f=>{f.destroy()}),ba(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=dc(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 Gn(this.#r,a);n.push({defaultedQueryOptions:a,observer:i})}),n}#m(e,t){const n=this.#t.indexOf(e);n!==-1&&(this.#e=zm(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)&&Mn.batch(()=>{this.listeners.forEach(a=>{a(this.#e)})})}}};function Jt({queries:e,...t},n){const r=je(),a=fc(),o=mc(),i=l.useMemo(()=>e.map(p=>{const y=r.defaultQueryOptions(p);return y._optimisticResults=a?"isRestoring":"optimistic",y}),[e,r,a]);i.forEach(p=>{hc(p);const y=r.getQueryCache().get(p.queryHash);gc(p,o,y)}),pc(o);const[c]=l.useState(()=>new _m(r,i,t)),[u,d,f]=c.getOptimisticResult(i,t.combine),m=!a&&t.subscribed!==!1;l.useSyncExternalStore(l.useCallback(p=>m?c.subscribe(Mn.batchCalls(p)):xc,[c,m]),()=>c.getCurrentResult(),()=>c.getCurrentResult()),l.useEffect(()=>{c.setQueries(i,t)},[i,t,c]);const x=u.some((p,y)=>Lr(i[y],p))?u.flatMap((p,y)=>{const g=i[y];if(g&&Lr(g,p)){const v=new Gn(r,g);return bc(g,v,o)}return[]}):[];if(x.length>0)throw Promise.all(x);const b=u.find((p,y)=>{const g=i[y];return g&&vc({result:p,errorResetBoundary:o,throwOnError:g.throwOnError,query:r.getQueryCache().get(g.queryHash),suspense:g.suspense})});if(b?.error)throw b.error;return d(f())}function ui(e,t){return yc(e,Lm)}function Ls(e){const t=ro({warn:e?.router===void 0}),n=e?.router||t;return ao(n.stores.__store,oo(e,n))}function mr(e){const t=ro();return ao(t.stores.location,oo(e,t))}const Fm=e=>/^\/mail\/(?!outbox)[^/?]+/.test(e),Bm=e=>e.startsWith("/mail")||e.startsWith("/settings"),$m=()=>{const{state:e,openCompose:t}=wt(),n=mr(),r=Ce(),a=n.search,o=typeof a?.selectedMessageId=="string"&&a.selectedMessageId.length>0;if(!Bm(n.pathname)||e.isOpen||o)return null;const i=()=>{l.startTransition(()=>{t({mode:"new"})}),!Fm(n.pathname)&&r({to:"/mail"})};return s.jsx("button",{type:"button",onClick:i,"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(mu,{className:"size-6"})})},hr=({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:fe("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(Pe,{className:"size-5"})})}),s.jsx("div",{className:"flex-1 overflow-y-auto",children:n})]})]})},Km=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},Ln={all:["messages"],detail:e=>[...Ln.all,"detail",e],body:e=>[...Ln.detail(e),"body"]};class bt 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 qm=e=>{const t=Number.parseInt(e??"",10);return!Number.isFinite(t)||t<=0?1:Math.min(t,30)},Um=8,Qm="x-remit-403-reason",Hm=(e,t)=>{const n=t?.trim()??"";return e===401?"auth":e===403?n.length>0?"auth":"body-missing":e===404?"body-missing":"generic"},Wm=(e,t)=>(t??"").toLowerCase().startsWith("text/html")?/<div\s+id=["']root["']/i.test(e):!1,Vm=(e,t)=>{const n=(t??"").toLowerCase();return!!(e==="text"&&n.startsWith("text/html"))},Ym=async(e,t,n=async()=>null)=>{const r={},a=await n();a&&(r.Authorization=`Bearer ${a}`);const o=await fetch(e,{headers:r});if(o.status===202)throw new bt("not-ready","Message body is still syncing",202,qm(o.headers.get("Retry-After")));if(!o.ok){const u=o.headers.get(Qm),d=Hm(o.status,u);throw new bt(d,`Failed to load message body (${o.status} ${o.statusText})`,o.status)}const i=o.headers.get("content-type");if(Vm(t,i))throw new bt("content-type-mismatch",`Refusing to render message body — expected ${t}, got Content-Type ${i}`);const c=await o.text();if(Wm(c,i))throw new bt("spa-shell-leak","Refusing to render message body — response looks like the SPA shell (CloudFront 403/404 fallback leaked through to /content/*)");return c},Gm=async(e,t)=>(t.isRetryAfterNotReady&&await e.refetchDescribeMessage(),e.fetchContent(t.contentUrl,t.kind)),di=({messageId:e,bodyParts:t,enabled:n=!0})=>{const r=t?Km(t):null,a=xs(),{getToken:o}=Xn(),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=ie({queryKey:e?[...Ln.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,Gm({fetchContent:(p,y)=>Ym(p,y,o),refetchDescribeMessage:()=>c.refetchQueries({queryKey:io({path:{messageId:e}})})},{contentUrl:r.contentUrl,kind:r.kind,isRetryAfterNotReady:b})},enabled:n&&!!e&&!!r,staleTime:300*1e3,gcTime:1800*1e3,retry:(b,p)=>p instanceof bt&&p.reason==="not-ready"?b<Um:b<1,retryDelay:(b,p)=>p instanceof bt&&p.reason==="not-ready"?(u.current=!0,(p.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 x=m.data&&r?{kind:r.kind,body:m.data}:void 0;return{picked:r,data:x,isLoading:h,isError:m.isError,error:m.error,refetch:m.refetch}},Xm=({outboxMessageId:e,onDraftCreated:t})=>{const[n,r]=l.useState("idle"),[a,o]=l.useState(null),i=l.useRef(void 0),c=je(),u=xe(lo()),d=xe(wc()),f=l.useCallback(async b=>{if(r("saving"),o(null),e){const y=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"),y}const p=await u.mutateAsync({body:{...b,sendImmediately:!1}});return t(p.outboxMessageId),r("saved"),c.invalidateQueries({queryKey:Js().queryKey}),p},[e,u,d,t,c]),m=l.useCallback(b=>{i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{f(b).catch(p=>{o(p),r("error")})},2e3)},[f]),h=l.useCallback(b=>(i.current&&clearTimeout(i.current),f(b)),[f]),x=l.useCallback(()=>{i.current&&clearTimeout(i.current)},[]);return{saveStatus:n,saveError:a,saveDraft:m,saveImmediately:h,cancelAutoSave:x}},fi=e=>"text"in e&&!("children"in e),mi=e=>e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),Jm=e=>{let t=mi(e.text);return e.bold&&(t=`<strong>${t}</strong>`),e.italic&&(t=`<em>${t}</em>`),t},hi=e=>{const t=e.children.map(n=>fi(n)?Jm(n):hi(n)).join("");switch(e.type){case"blockquote":return`<blockquote>${t}</blockquote>`;case"a":{const n=e.url??"";return`<a href="${mi(n)}">${t}</a>`}default:return`<p>${t}</p>`}},va=e=>e.map(hi).join(""),gi=e=>fi(e)?e.text:e.children.map(gi).join(""),zn=e=>e.map(gi).join(`
110
- `),Zm=e=>e.displayName?`${e.displayName} <${e.normalizedEmail}>`:e.normalizedEmail,ya=e=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.trim()),eh=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(ya(a))return{email:a,displayName:r}}if(ya(t))return{email:t}},jn=({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=bo(a,200),{data:x}=ie({...co({query:{q:h,limit:8}}),enabled:h.length>=2}),b=x?.items??[],p=new Set(t.map(S=>S.email.toLowerCase())),y=b.filter(S=>!p.has(S.normalizedEmail.toLowerCase()));l.useEffect(()=>{c(-1),d(y.length>0&&a.length>=2)},[y.length,a.length]);const g=l.useCallback(S=>{p.has(S.email.toLowerCase())||(n([...t,S]),o(""),d(!1))},[t,p,n]),v=l.useCallback(S=>{n(t.filter((C,k)=>k!==S))},[t,n]),j=l.useCallback(S=>{g({email:S.normalizedEmail,displayName:S.displayName}),f.current?.focus()},[g]),w=l.useCallback(()=>{const S=eh(a);S&&g(S)},[a,g]),N=l.useCallback(S=>{if(S.key==="Backspace"&&a===""&&t.length>0){v(t.length-1);return}if(S.key==="Enter"||S.key==="Tab"||S.key===","){if(i>=0&&y[i]){S.preventDefault(),j(y[i]);return}a.trim()&&(S.preventDefault(),w());return}if(S.key==="ArrowDown"&&u){S.preventDefault(),c(C=>C<y.length-1?C+1:0);return}if(S.key==="ArrowUp"&&u){S.preventDefault(),c(C=>C>0?C-1:y.length-1);return}S.key==="Escape"&&(d(!1),c(-1))},[a,t.length,i,y,u,v,j,w]),E=l.useCallback(()=>{setTimeout(()=>{w(),d(!1)},150)},[w]);return s.jsxs("div",{className:"relative",children:[s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("label",{htmlFor:`address-field-${e}`,className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:[e,":"]}),s.jsxs("div",{className:"flex-1 flex flex-wrap items-center gap-1 min-h-[36px] px-2 py-1 border rounded-md bg-canvas cursor-text",onClick:()=>f.current?.focus(),onKeyDown:S=>{(S.key==="Enter"||S.key===" ")&&f.current?.focus()},children:[t.map((S,C)=>s.jsx(wu,{email:S.email,displayName:S.displayName,onRemove:()=>v(C)},S.email)),s.jsx("input",{ref:f,id:`address-field-${e}`,type:"text",value:a,onChange:S=>o(S.target.value),onKeyDown:N,onBlur:E,placeholder:t.length===0?r:"",className:"flex-1 min-w-[120px] bg-transparent outline-none text-sm py-0.5"})]})]}),u&&y.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:y.map((S,C)=>s.jsx("li",{className:fe("px-3 py-2 text-sm cursor-pointer transition-colors",C===i&&"bg-accent-2-soft"),onMouseDown:k=>{k.preventDefault(),j(S)},onMouseEnter:()=>c(C),children:Zm(S)},S.addressId))})]})},th=({accountId:e})=>{const t=Ce();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(Wn,{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(ou,{className:"size-3","aria-hidden":"true"})]})]})]})},_n=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},kt=()=>_n("(min-width: 1024px)"),wa=150,sh=()=>{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>wa}});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>wa})};return r(),n.addEventListener("resize",r),()=>n.removeEventListener("resize",r)},[]),e},nh=({selectedAccountId:e,onSelect:t})=>{const{data:n}=ie({...Ze(),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))})]})},rh=({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})]}),ah=["p","br","strong","b","em","i","a","blockquote","ul","ol","li"],oh=["href"],ih=e=>Ja.sanitize(e,{ALLOWED_TAGS:ah,ALLOWED_ATTR:oh}),lh=l.lazy(()=>Sc(()=>import("./ComposeBody-Dxf7Xcn6.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}))),ch=()=>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"})]}),pi=[{type:"p",children:[{text:""}]}],uh=[{type:"p",children:[{text:""}]},{type:"p",children:[{text:"-- "}]}],dh=e=>e?[...uh,{type:"p",children:[{text:e}]}]:pi,fh=e=>e?/^re:\s/i.test(e)?e:`Re: ${e}`:"Re: ",mh=e=>e?/^fwd?:\s/i.test(e)?e:`Fwd: ${e}`:"Fwd: ",hh=(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}},gh=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}},ph=(e,t,n,r,a)=>e.length===0&&t.length===0&&n.length===0&&r.trim()===""&&zn(a).trim()==="",xh=({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:x})=>{const b=kt(),{isKeyboardOpen:p}=sh();if(!b&&p){const g=[];return n.length>0&&g.push(`To: ${n.map(v=>v.displayName??v.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(nh,{selectedAccountId:e,onSelect:t}),s.jsx(jn,{label:"To",addresses:n,onChange:r,placeholder:"Recipients"}),u?s.jsx(jn,{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(jn,{label:"Bcc",addresses:i,onChange:c}),s.jsx(rh,{value:h,onChange:x})]})},gr=({mode:e,account:t,sourceMessage:n,onClose:r,onAccountChange:a})=>{const{state:o,setOutboxMessageId:i,startSendPolling:c}=wt(),{pushError:u}=ze(),{outboxMessageId:d}=o,[f,m]=l.useState([]),[h,x]=l.useState([]),[b,p]=l.useState([]),[y,g]=l.useState(""),[v,j]=l.useState(!1),[w,N]=l.useState(!1),[E,S]=l.useState(t?.accountId),[C,k]=l.useState(!1),M=l.useRef(d);l.useEffect(()=>{M.current!==d&&(M.current=d,d&&(m([]),x([]),p([]),g(""),j(!1),N(!1),I(pi),k(!1)))},[d]);const{signature:T}=Jc(E),[D,I]=l.useState(()=>dh(T.plainText)),{data:R}=ie({...jc({path:{outboxMessageId:d??""}}),enabled:!!d&&!C});l.useEffect(()=>{!R||C||(m(R.toAddresses.map(W=>({email:W,displayName:void 0}))),R.ccAddresses&&R.ccAddresses.length>0&&(x(R.ccAddresses.map(W=>({email:W,displayName:void 0}))),j(!0)),R.bccAddresses&&R.bccAddresses.length>0&&(p(R.bccAddresses.map(W=>({email:W,displayName:void 0}))),N(!0)),R.subject&&g(R.subject),R.textBody&&I([{type:"p",children:[{text:R.textBody}]}]),S(R.accountId),k(!0))},[R,C]),l.useEffect(()=>{if(n){if(e==="reply"||e==="reply_all"){const{to:W,cc:ee}=hh(n,e,t?.email);m(W),x(ee),ee.length>0&&j(!0),g(fh(n.envelope.subject))}e==="forward"&&g(mh(n.envelope.subject))}},[e,n,t?.email]);const O=e==="reply"||e==="reply_all"||e==="forward",{data:B}=di({messageId:n?.message.messageId,bodyParts:n?.bodyParts,enabled:O&&!!n}),K=B?.kind==="text"?B.body:"",F=B?.kind==="html"?ih(B.body):void 0,$=n?.envelope.from[0]?.displayName??n?.envelope.from[0]?.normalizedEmail,{saveStatus:U,saveError:te,saveDraft:Q,cancelAutoSave:L}=Xm({outboxMessageId:d,onDraftCreated:i});l.useEffect(()=>{te&&u({title:"Couldn't save draft",detail:$e(te)??"Saving the draft failed."})},[te,u]);const A=xe(lo()),Y=xe(uo()),le=xe({...Zs(),onError:W=>{u(fs("Couldn't discard draft","The draft wasn't discarded.",W))}}),{data:ve}=ie({...Ze(),staleTime:1/0}),ce=ve?.accounts.find(W=>W.accountId===E),ye=ce?Wc(ce):!1,Se=A.isPending||Y.isPending,G=f.length>0&&!!E&&!ye;l.useEffect(()=>{if(!E||d&&!C||ph(f,h,b,y,D))return;const W=zn(D),ee=va(D);Q({accountId:E,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:y||void 0,textBody:W||void 0,htmlBody:ee||void 0})},[E,d,C,f,h,b,y,D,Q]);const ge=l.useCallback(async()=>{if(!E||f.length===0)return;L();const W=n&&(e==="reply"||e==="reply_all")?gh(n):{};let ee=d,ne=!1;if(!ee){const ae=zn(D),Ne=va(D),Fe=await A.mutateAsync({body:{accountId:E,toAddresses:f.map(De=>De.email),ccAddresses:h.length>0?h.map(De=>De.email):void 0,bccAddresses:b.length>0?b.map(De=>De.email):void 0,subject:y||void 0,textBody:ae||void 0,htmlBody:Ne||void 0,sendImmediately:!0,...W}}).catch(De=>(u({title:"Couldn't send message",detail:$e(De)??"Saving the draft failed."}),null));if(Fe===null)return;ee=Fe.outboxMessageId,ne=!0,i(ee)}await Y.mutateAsync({path:{outboxMessageId:ee}}).catch(ae=>(u({title:"Couldn't send message",detail:$e(ae)??(ne?"The draft was saved but the send request failed. Try again from the Outbox.":"The send request failed. Try again.")}),null))!==null&&(c(ee),r())},[E,f,h,b,y,D,e,n,d,A,Y,L,c,i,u,r]),Ie=l.useCallback(()=>{L(),d&&le.mutate({path:{outboxMessageId:d}}),r()},[L,d,le,r]),H=l.useCallback(W=>{S(W.accountId),a?.(W)},[a]);return s.jsx(Ed,{banner:ce&&ye?s.jsx(th,{accountId:ce.accountId}):void 0,header:s.jsx(xh,{selectedAccountId:E,onAccountChange:H,toAddresses:f,setToAddresses:m,ccAddresses:h,setCcAddresses:x,bccAddresses:b,setBccAddresses:p,showCc:v,setShowCc:j,showBcc:w,setShowBcc:N,subject:y,setSubject:g}),quoted:K||F?s.jsx(Wd,{text:K,html:F,senderName:$}):void 0,actionBar:s.jsx(Cd,{onSend:ge,onDiscard:Ie,sending:Se,canSend:G,saveStatus:U,unavailableReason:ye?"SMTP not configured":void 0,onUnavailable:W=>u({title:"Can't send yet",detail:W})}),children:s.jsx(l.Suspense,{fallback:s.jsx(ch,{}),children:s.jsx(lh,{value:D,onChange:I,onSubmit:ge,autoFocus:e==="new"})})})},ja=({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(gr,{mode:e,account:t,sourceMessage:n,onClose:r})}),xi=({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})]}),ps=({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])},bi=e=>{const{data:t,isLoading:n}=ie({...Ze(),staleTime:1/0}),r=l.useMemo(()=>(t?.accounts??[]).map(c=>c.accountId),[t?.accounts]),a=Jt({queries:r.map(c=>({...et({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}},Sa=(e,t,n)=>e.map(r=>t.has(r.messageId)?{...r,isRead:n}:r),bh=(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),vh=({messages:e,expandedIds:t,threadId:n,mailboxId:r,accountId:a})=>{const o=je(),{pushError:i}=ze(),c=l.useRef(new Set),u=l.useRef(new Set),{mutate:d}=xe({...en(),onMutate:async h=>{const x=new Set(h.body.messageIds??[]),b=h.body.isRead??!0,p=jt({path:{threadId:n}}),y=tt({path:{mailboxId:r}}),g=ut({path:{mailboxId:r}});await Promise.all([o.cancelQueries({queryKey:p}),o.cancelQueries({queryKey:y}),o.cancelQueries({queryKey:g})]);const v=o.getQueriesData({queryKey:p}).filter(N=>N[1]!==void 0).map(([N,E])=>({queryKey:N,data:E})),j=o.getQueriesData({queryKey:y}).concat(o.getQueriesData({queryKey:g})).filter(N=>N[1]!==void 0).map(([N,E])=>({queryKey:N,data:E}));o.setQueriesData({queryKey:p},N=>N&&{...N,items:Sa(N.items,x,b)});const w=N=>N&&{...N,pages:N.pages.map(E=>({...E,items:Sa(E.items,x,b)}))};return o.setQueriesData({queryKey:y},w),o.setQueriesData({queryKey:g},w),{threadMessagesPrefix:p,threadsListPrefix:y,threadsSearchPrefix:g,previousThreadMessages:v,previousThreadsList:j}},onSuccess:(h,x)=>{const b=x.body.messageIds??[];for(const p of b)c.current.add(p),u.current.delete(p)},onError:(h,x,b)=>{const p=x.body.messageIds??[];for(const g of p)u.current.delete(g);if(b){for(const g of b.previousThreadMessages)o.setQueryData(g.queryKey,g.data);for(const g of b.previousThreadsList)o.setQueryData(g.queryKey,g.data)}const y=x.body.isRead??!0;i({title:y?"Couldn't mark as read":"Couldn't mark as unread",detail:$e(h)})},onSettled:(h,x,b,p)=>{p&&(o.invalidateQueries({queryKey:p.threadMessagesPrefix}),o.invalidateQueries({queryKey:p.threadsListPrefix}),o.invalidateQueries({queryKey:p.threadsSearchPrefix}),a&&o.invalidateQueries({queryKey:Vt({path:{accountId:a}})}))}}),f=l.useCallback(h=>{const x=h.filter(b=>!c.current.has(b)&&!u.current.has(b));if(x.length!==0){for(const b of x)u.current.add(b);d({body:{messageIds:x,isRead:!0}})}},[d]),m=l.useMemo(()=>bh(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])},vi=e=>{const{mailboxId:t,accountId:n}=e,r=je(),{pushError:a}=ze(),{mutate:o,isPending:i}=xe({...en(),onError:(u,d)=>{const f=d.body.isRead??!0;a({title:f?"Couldn't mark as read":"Couldn't mark as unread",detail:$e(u)})},onSettled:()=>{r.invalidateQueries({queryKey:tt({path:{mailboxId:t}})}),r.invalidateQueries({queryKey:ut({path:{mailboxId:t}})}),n&&r.invalidateQueries({queryKey:Vt({path:{accountId:n}})})}});return{toggleReadFor:l.useCallback((u,d)=>{u.length!==0&&o({body:{messageIds:u,isRead:d}})},[o]),isPending:i}},yh=60,wh=1.5,jh=(e,t,n)=>{const r=Math.abs(e),a=Math.abs(t);return r<n?{direction:null}:r<a*wh?{direction:null}:{direction:e<0?"left":"right"}},Sh=({onSwipeLeft:e,onSwipeRight:t,thresholdPx:n=yh})=>{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}=jh(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}}},Na=(e,t,n)=>e.map(r=>r.messageId===t?{...r,hasStars:n}:r),Fn=({threadId:e,mailboxId:t})=>{const n=je(),{pushError:r}=ze(),{mutate:a,isPending:o,variables:i}=xe({...Nc(),onMutate:async u=>{const d=u.path.messageId,f=u.body.isStarred??!1,m=jt({path:{threadId:e}}),h=tt({path:{mailboxId:t}}),x=ut({path:{mailboxId:t}}),b=fo();await Promise.all([n.cancelQueries({queryKey:m}),n.cancelQueries({queryKey:h}),n.cancelQueries({queryKey:x}),n.cancelQueries({queryKey:b})]);const p=n.getQueriesData({queryKey:m}).filter(w=>w[1]!==void 0).map(([w,N])=>({queryKey:w,data:N})),y=n.getQueriesData({queryKey:h}).concat(n.getQueriesData({queryKey:x})).filter(w=>w[1]!==void 0).map(([w,N])=>({queryKey:w,data:N})),g=n.getQueriesData({queryKey:b}).filter(w=>w[1]!==void 0).map(([w,N])=>({queryKey:w,data:N})),v=w=>w&&{...w,items:Na(w.items,d,f)};n.setQueriesData({queryKey:m},v),n.setQueriesData({queryKey:b},v);const j=w=>w&&{...w,pages:w.pages.map(N=>({...N,items:Na(N.items,d,f)}))};return n.setQueriesData({queryKey:h},j),n.setQueriesData({queryKey:x},j),{threadMessagesPrefix:m,threadsListPrefix:h,threadsSearchPrefix:x,unifiedThreadsPrefix:b,previousThreadMessages:p,previousThreadsList:y,previousUnifiedThreads:g}},onError:(u,d,f)=>{if(f){for(const h of f.previousThreadMessages)n.setQueryData(h.queryKey,h.data);for(const h of f.previousThreadsList)n.setQueryData(h.queryKey,h.data);for(const h of f.previousUnifiedThreads)n.setQueryData(h.queryKey,h.data)}const m=d.body.isStarred??!1;r({title:m?"Couldn't star message":"Couldn't unstar message",detail:$e(u)})},onSettled:(u,d,f,m)=>{m&&(n.invalidateQueries({queryKey:m.threadMessagesPrefix}),n.invalidateQueries({queryKey:m.threadsListPrefix}),n.invalidateQueries({queryKey:m.threadsSearchPrefix}),n.invalidateQueries({queryKey:m.unifiedThreadsPrefix}))}});return{toggleStar:(u,d)=>{a({path:{messageId:u},body:{isStarred:!d}})},isPending:o,pendingMessageId:o?i?.path.messageId:void 0}};function ln(e){return e===void 0||e==="uncategorized"?"personal":e}const Ge={uncategorized:"uncategorized",personal:"personal",newsletter:"newsletter",marketing:"marketing",automated:"automated",transactional:"transactional",social:"social"},ka={MoveToInbox:"MoveToInbox",MoveToJunk:"MoveToJunk"},Nh={inbox:"Inbox",junk:"Junk"},kh=e=>`Moved from ${Nh[e]??"another folder"} by Remit`,Ch=(e,t)=>{if(e===ka.MoveToInbox)return t.inboxMailboxId;if(e===ka.MoveToJunk)return t.junkMailboxId},Eh=(e,t,n)=>{if(!e||!t)return!1;const r=Ch(e.action,n);return r!==void 0&&r===t},Ih=(e,t)=>{if(e==="inbox")return t.inboxMailboxId;if(e==="junk")return t.junkMailboxId},cn=(e,t)=>{const{data:n,isLoading:r}=ie({...Ze(),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}},Rh=e=>{const{mailboxId:t,isLoading:n}=cn(e,"Archive");return{archiveMailboxId:t,isLoading:n}},Mh=e=>{const{mailboxId:t,isLoading:n}=cn(e,"Drafts");return{draftsMailboxId:t,isLoading:n}},pr=e=>{const{mailboxId:t,isLoading:n}=cn(e,"Inbox");return{inboxMailboxId:t,isLoading:n}},xr=e=>{const{mailboxId:t,isLoading:n}=cn(e,"Junk");return{junkMailboxId:t,isLoading:n}},yi=e=>{const{data:t}=ie({...Ze(),staleTime:1/0,enabled:!!e});return l.useMemo(()=>t?.accounts.find(n=>n.accountId===e)?.folderAppointments??[],[t,e])},Ca=(e,t)=>e.filter(n=>!t.has(n.messageId)),ct=({mailboxId:e,threadId:t,accountId:n,onAfterOptimisticRemove:r})=>{const a=je(),{pushError:o}=ze(),{mutate:i,isPending:c}=xe({...kc(),onMutate:async d=>{const f=new Set(d.body.messageIds??[]),m=t?jt({path:{threadId:t}}):[],h=tt({path:{mailboxId:e}}),x=ut({path:{mailboxId:e}});await Promise.all([...t?[a.cancelQueries({queryKey:m})]:[],a.cancelQueries({queryKey:h}),a.cancelQueries({queryKey:x})]);const b=t?a.getQueriesData({queryKey:m}).filter(g=>g[1]!==void 0).map(([g,v])=>({queryKey:g,data:v})):[],p=a.getQueriesData({queryKey:h}).concat(a.getQueriesData({queryKey:x})).filter(g=>g[1]!==void 0).map(([g,v])=>({queryKey:g,data:v}));t&&a.setQueriesData({queryKey:m},g=>g&&{...g,items:Ca(g.items,f)});const y=g=>g&&{...g,pages:g.pages.map(v=>({...v,items:Ca(v.items,f)}))};return a.setQueriesData({queryKey:h},y),a.setQueriesData({queryKey:x},y),r?.(Array.from(f)),{threadMessagesPrefix:m,threadsListPrefix:h,threadsSearchPrefix:x,previousThreadMessages:b,previousThreadsList:p}},onError:(d,f,m)=>{if(m){for(const x of m.previousThreadMessages)a.setQueryData(x.queryKey,x.data);for(const x of m.previousThreadsList)a.setQueryData(x.queryKey,x.data)}const h=f.body.messageIds?.length??0;o({title:h>1?`Couldn't move ${h} messages`:"Couldn't move this message",detail:$e(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:Vt({path:{accountId:n}})}))}});return{moveMessages:l.useCallback((d,f)=>{d.length!==0&&i({body:{messageIds:d,destinationMailboxId:f}})},[i]),isPending:c}},Th=({accountId:e,messageId:t,threadId:n,mailboxId:r,autoMoved:a})=>{const{inboxMailboxId:o}=pr(e),{junkMailboxId:i}=xr(e),{moveMessages:c,isPending:u}=ct({mailboxId:r,threadId:n,accountId:e}),d={inboxMailboxId:o,junkMailboxId:i},f=Eh(a,r,d),m=a?Ih(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:kh(a.fromPlacement),onUndo:m?h:void 0,isUndoing:u}};function wi({accountId:e,messageId:t,threadId:n,mailboxId:r,autoMoved:a,size:o="sm"}){const i=Th({accountId:e,messageId:t,threadId:n,mailboxId:r,autoMoved:a});return i.show?s.jsx(gd,{label:i.label,size:o,onUndo:i.onUndo,undoLabel:i.isUndoing?"Undoing…":"Undo"}):null}const ji=({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:fe("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:fe("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})]})},$t=({onClick:e,disabled:t,destructive:n,children:r})=>s.jsx("button",{type:"button",onClick:a=>{a.stopPropagation(),t||e()},disabled:t,className:fe("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}),Bn=()=>s.jsx("div",{className:"my-1 h-px bg-line"}),Ea=(e,t)=>e.filter(n=>!t.has(n.messageId)),Dh=e=>e.filter(t=>t.isDeleted!==!0),ds=({mailboxId:e,threadId:t,accountId:n,onAfterOptimisticRemove:r})=>{const a=je(),{pushError:o}=ze(),{mutate:i,isPending:c}=xe({...Cc(),onMutate:async d=>{const f=new Set(d.body.messageIds??[]),m=t?jt({path:{threadId:t}}):[],h=tt({path:{mailboxId:e}}),x=ut({path:{mailboxId:e}});await Promise.all([a.cancelQueries({queryKey:m}),a.cancelQueries({queryKey:h}),a.cancelQueries({queryKey:x})]);const b=t?a.getQueriesData({queryKey:m}).filter(g=>g[1]!==void 0).map(([g,v])=>({queryKey:g,data:v})):[],p=a.getQueriesData({queryKey:h}).concat(a.getQueriesData({queryKey:x})).filter(g=>g[1]!==void 0).map(([g,v])=>({queryKey:g,data:v}));t&&a.setQueriesData({queryKey:m},g=>g&&{...g,items:Ea(g.items,f)});const y=g=>g&&{...g,pages:g.pages.map(v=>({...v,items:Ea(v.items,f)}))};return a.setQueriesData({queryKey:h},y),a.setQueriesData({queryKey:x},y),r?.(Array.from(f)),{threadMessagesPrefix:m,threadsListPrefix:h,threadsSearchPrefix:x,previousThreadMessages:b,previousThreadsList:p}},onError:(d,f,m)=>{if(m){for(const x of m.previousThreadMessages)a.setQueryData(x.queryKey,x.data);for(const x of m.previousThreadsList)a.setQueryData(x.queryKey,x.data)}const h=f.body.messageIds?.length??0;o({title:h>1?`Couldn't delete ${h} messages`:"Couldn't delete this message",detail:$e(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:Vt({path:{accountId:n}})}))}});return{deleteMessages:l.useCallback(d=>{d.length!==0&&i({body:{messageIds:d}})},[i]),isPending:c}},Si=(e,t=Date.now())=>({value:e,setAt:t}),Ah=(e,t,n,r)=>{if(e.addressId!==t)return e;const a={...e.flags??{}};return n?a.trusted=Si(!0,r):delete a.trusted,{...e,flags:a}},Oh=(e,t,n,r)=>{const a=o=>o.map(i=>Ah(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)}}},br=({messageId:e})=>{const t=je(),{pushError:n}=ze(),{mutate:r,isPending:a,error:o,reset:i}=xe({...mo(),onMutate:async u=>{const d=u.path.addressId,m=u.body.flags?.trusted?.value===!0,h=io({path:{messageId:e}});await t.cancelQueries({queryKey:h});const x=t.getQueriesData({queryKey:h}).filter(b=>b[1]!==void 0).map(([b,p])=>({queryKey:b,data:p}));return t.setQueriesData({queryKey:h},b=>b&&Oh(b,d,m)),{describePrefix:h,previous:x}},onError:(u,d,f)=>{if(f)for(const m of f.previous)t.setQueryData(m.queryKey,m.data);n(fs("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:Si(!d)}}})},isPending:a,error:o,reset:i}};var un="Dialog",[Ni]=uf(un),[Ph,_e]=Ni(un),ki=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]=mf({prop:r,defaultProp:a??!1,onChange:o,caller:un});return s.jsx(Ph,{scope:t,triggerRef:c,contentRef:u,contentId:xn(),titleId:xn(),descriptionId:xn(),open:d,onOpenChange:f,onOpenToggle:l.useCallback(()=>f(m=>!m),[f]),modal:i,children:n})};ki.displayName=un;var Ci="DialogTrigger",Lh=l.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,a=_e(Ci,n),o=Nt(t,a.triggerRef);return s.jsx(nt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":yr(a.open),...r,ref:o,onClick:lt(e.onClick,a.onOpenToggle)})});Lh.displayName=Ci;var vr="DialogPortal",[zh,Ei]=Ni(vr,{forceMount:void 0}),Ii=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:a}=e,o=_e(vr,t);return s.jsx(zh,{scope:t,forceMount:n,children:l.Children.map(r,i=>s.jsx(an,{present:n||o.open,children:s.jsx(ti,{asChild:!0,container:a,children:i})}))})};Ii.displayName=vr;var Ys="DialogOverlay",Ri=l.forwardRef((e,t)=>{const n=Ei(Ys,e.__scopeDialog),{forceMount:r=n.forceMount,...a}=e,o=_e(Ys,e.__scopeDialog);return o.modal?s.jsx(an,{present:r||o.open,children:s.jsx(Fh,{...a,ref:t})}):null});Ri.displayName=Ys;var _h=dr("DialogOverlay.RemoveScroll"),Fh=l.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,a=_e(Ys,n),o=Df(),i=Nt(t,o);return s.jsx(ci,{as:_h,allowPinchZoom:!0,shards:[a.contentRef],children:s.jsx(nt.div,{"data-state":yr(a.open),...r,ref:i,style:{pointerEvents:"auto",...r.style}})})}),Wt="DialogContent",Mi=l.forwardRef((e,t)=>{const n=Ei(Wt,e.__scopeDialog),{forceMount:r=n.forceMount,...a}=e,o=_e(Wt,e.__scopeDialog);return s.jsx(an,{present:r||o.open,children:o.modal?s.jsx(Bh,{...a,ref:t}):s.jsx($h,{...a,ref:t})})});Mi.displayName=Wt;var Bh=l.forwardRef((e,t)=>{const n=_e(Wt,e.__scopeDialog),r=l.useRef(null),a=Nt(t,n.contentRef,r);return l.useEffect(()=>{const o=r.current;if(o)return em(o)},[]),s.jsx(Ti,{...e,ref:a,trapFocus:n.open,disableOutsidePointerEvents:n.open,onCloseAutoFocus:lt(e.onCloseAutoFocus,o=>{o.preventDefault(),n.triggerRef.current?.focus()}),onPointerDownOutside:lt(e.onPointerDownOutside,o=>{const i=o.detail.originalEvent,c=i.button===0&&i.ctrlKey===!0;(i.button===2||c)&&o.preventDefault()}),onFocusOutside:lt(e.onFocusOutside,o=>o.preventDefault())})}),$h=l.forwardRef((e,t)=>{const n=_e(Wt,e.__scopeDialog),r=l.useRef(!1),a=l.useRef(!1);return s.jsx(Ti,{...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()}})}),Ti=l.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:a,onCloseAutoFocus:o,...i}=e,c=_e(Wt,n);return Lf(),s.jsx(s.Fragment,{children:s.jsx(Zo,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:a,onUnmountAutoFocus:o,children:s.jsx(Xo,{role:"dialog",id:c.contentId,"aria-describedby":c.descriptionId,"aria-labelledby":c.titleId,"data-state":yr(c.open),...i,ref:t,deferPointerDownOutside:!0,onDismiss:()=>c.onOpenChange(!1)})})})}),Di="DialogTitle",Ai=l.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,a=_e(Di,n);return s.jsx(nt.h2,{id:a.titleId,...r,ref:t})});Ai.displayName=Di;var Oi="DialogDescription",Kh=l.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,a=_e(Oi,n);return s.jsx(nt.p,{id:a.descriptionId,...r,ref:t})});Kh.displayName=Oi;var Pi="DialogClose",qh=l.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,a=_e(Pi,n);return s.jsx(nt.button,{type:"button",...r,ref:t,onClick:lt(e.onClick,()=>a.onOpenChange(!1))})});qh.displayName=Pi;function yr(e){return e?"open":"closed"}function Uh(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 Li=_.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}),Ns=()=>{const e=_.useContext(Li);if(!e)throw new Error("useDrawerContext must be used within a Drawer.Root");return e};Uh(`[data-vaul-drawer]{touch-action:none;will-change:transform;transition:transform .5s cubic-bezier(.32, .72, 0, 1);animation-duration:.5s;animation-timing-function:cubic-bezier(0.32,0.72,0,1)}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=bottom][data-state=open]{animation-name:slideFromBottom}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=bottom][data-state=closed]{animation-name:slideToBottom}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=top][data-state=open]{animation-name:slideFromTop}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=top][data-state=closed]{animation-name:slideToTop}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=left][data-state=open]{animation-name:slideFromLeft}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=left][data-state=closed]{animation-name:slideToLeft}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=right][data-state=open]{animation-name:slideFromRight}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=right][data-state=closed]{animation-name:slideToRight}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=bottom]{transform:translate3d(0,var(--initial-transform,100%),0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=top]{transform:translate3d(0,calc(var(--initial-transform,100%) * -1),0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=left]{transform:translate3d(calc(var(--initial-transform,100%) * -1),0,0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=right]{transform:translate3d(var(--initial-transform,100%),0,0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=top]{transform:translate3d(0,var(--snap-point-height,0),0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=bottom]{transform:translate3d(0,var(--snap-point-height,0),0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=left]{transform:translate3d(var(--snap-point-height,0),0,0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=right]{transform:translate3d(var(--snap-point-height,0),0,0)}[data-vaul-overlay][data-vaul-snap-points=false]{animation-duration:.5s;animation-timing-function:cubic-bezier(0.32,0.72,0,1)}[data-vaul-overlay][data-vaul-snap-points=false][data-state=open]{animation-name:fadeIn}[data-vaul-overlay][data-state=closed]{animation-name:fadeOut}[data-vaul-animate=false]{animation:none!important}[data-vaul-overlay][data-vaul-snap-points=true]{opacity:0;transition:opacity .5s cubic-bezier(.32, .72, 0, 1)}[data-vaul-overlay][data-vaul-snap-points=true]{opacity:1}[data-vaul-drawer]:not([data-vaul-custom-container=true])::after{content:'';position:absolute;background:inherit;background-color:inherit}[data-vaul-drawer][data-vaul-drawer-direction=top]::after{top:initial;bottom:100%;left:0;right:0;height:200%}[data-vaul-drawer][data-vaul-drawer-direction=bottom]::after{top:100%;bottom:initial;left:0;right:0;height:200%}[data-vaul-drawer][data-vaul-drawer-direction=left]::after{left:initial;right:100%;top:0;bottom:0;width:200%}[data-vaul-drawer][data-vaul-drawer-direction=right]::after{left:100%;right:initial;top:0;bottom:0;width:200%}[data-vaul-overlay][data-vaul-snap-points=true]:not([data-vaul-snap-points-overlay=true]):not(
110
+ `),Zm=e=>e.displayName?`${e.displayName} <${e.normalizedEmail}>`:e.normalizedEmail,ya=e=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.trim()),eh=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(ya(a))return{email:a,displayName:r}}if(ya(t))return{email:t}},jn=({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=bo(a,200),{data:x}=ie({...co({query:{q:h,limit:8}}),enabled:h.length>=2}),b=x?.items??[],p=new Set(t.map(S=>S.email.toLowerCase())),y=b.filter(S=>!p.has(S.normalizedEmail.toLowerCase()));l.useEffect(()=>{c(-1),d(y.length>0&&a.length>=2)},[y.length,a.length]);const g=l.useCallback(S=>{p.has(S.email.toLowerCase())||(n([...t,S]),o(""),d(!1))},[t,p,n]),v=l.useCallback(S=>{n(t.filter((C,k)=>k!==S))},[t,n]),j=l.useCallback(S=>{g({email:S.normalizedEmail,displayName:S.displayName}),f.current?.focus()},[g]),w=l.useCallback(()=>{const S=eh(a);S&&g(S)},[a,g]),N=l.useCallback(S=>{if(S.key==="Backspace"&&a===""&&t.length>0){v(t.length-1);return}if(S.key==="Enter"||S.key==="Tab"||S.key===","){if(i>=0&&y[i]){S.preventDefault(),j(y[i]);return}a.trim()&&(S.preventDefault(),w());return}if(S.key==="ArrowDown"&&u){S.preventDefault(),c(C=>C<y.length-1?C+1:0);return}if(S.key==="ArrowUp"&&u){S.preventDefault(),c(C=>C>0?C-1:y.length-1);return}S.key==="Escape"&&(d(!1),c(-1))},[a,t.length,i,y,u,v,j,w]),E=l.useCallback(()=>{setTimeout(()=>{w(),d(!1)},150)},[w]);return s.jsxs("div",{className:"relative",children:[s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("label",{htmlFor:`address-field-${e}`,className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:[e,":"]}),s.jsxs("div",{className:"flex-1 flex flex-wrap items-center gap-1 min-h-[36px] px-2 py-1 border rounded-md bg-canvas cursor-text",onClick:()=>f.current?.focus(),onKeyDown:S=>{(S.key==="Enter"||S.key===" ")&&f.current?.focus()},children:[t.map((S,C)=>s.jsx(wu,{email:S.email,displayName:S.displayName,onRemove:()=>v(C)},S.email)),s.jsx("input",{ref:f,id:`address-field-${e}`,type:"text",value:a,onChange:S=>o(S.target.value),onKeyDown:N,onBlur:E,placeholder:t.length===0?r:"",className:"flex-1 min-w-[120px] bg-transparent outline-none text-sm py-0.5"})]})]}),u&&y.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:y.map((S,C)=>s.jsx("li",{className:fe("px-3 py-2 text-sm cursor-pointer transition-colors",C===i&&"bg-accent-2-soft"),onMouseDown:k=>{k.preventDefault(),j(S)},onMouseEnter:()=>c(C),children:Zm(S)},S.addressId))})]})},th=({accountId:e})=>{const t=Ce();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(Wn,{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(ou,{className:"size-3","aria-hidden":"true"})]})]})]})},_n=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},kt=()=>_n("(min-width: 1024px)"),wa=150,sh=()=>{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>wa}});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>wa})};return r(),n.addEventListener("resize",r),()=>n.removeEventListener("resize",r)},[]),e},nh=({selectedAccountId:e,onSelect:t})=>{const{data:n}=ie({...Ze(),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))})]})},rh=({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})]}),ah=["p","br","strong","b","em","i","a","blockquote","ul","ol","li"],oh=["href"],ih=e=>Ja.sanitize(e,{ALLOWED_TAGS:ah,ALLOWED_ATTR:oh}),lh=l.lazy(()=>Sc(()=>import("./ComposeBody-Omy6Iikn.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}))),ch=()=>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"})]}),pi=[{type:"p",children:[{text:""}]}],uh=[{type:"p",children:[{text:""}]},{type:"p",children:[{text:"-- "}]}],dh=e=>e?[...uh,{type:"p",children:[{text:e}]}]:pi,fh=e=>e?/^re:\s/i.test(e)?e:`Re: ${e}`:"Re: ",mh=e=>e?/^fwd?:\s/i.test(e)?e:`Fwd: ${e}`:"Fwd: ",hh=(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}},gh=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}},ph=(e,t,n,r,a)=>e.length===0&&t.length===0&&n.length===0&&r.trim()===""&&zn(a).trim()==="",xh=({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:x})=>{const b=kt(),{isKeyboardOpen:p}=sh();if(!b&&p){const g=[];return n.length>0&&g.push(`To: ${n.map(v=>v.displayName??v.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(nh,{selectedAccountId:e,onSelect:t}),s.jsx(jn,{label:"To",addresses:n,onChange:r,placeholder:"Recipients"}),u?s.jsx(jn,{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(jn,{label:"Bcc",addresses:i,onChange:c}),s.jsx(rh,{value:h,onChange:x})]})},gr=({mode:e,account:t,sourceMessage:n,onClose:r,onAccountChange:a})=>{const{state:o,setOutboxMessageId:i,startSendPolling:c}=wt(),{pushError:u}=ze(),{outboxMessageId:d}=o,[f,m]=l.useState([]),[h,x]=l.useState([]),[b,p]=l.useState([]),[y,g]=l.useState(""),[v,j]=l.useState(!1),[w,N]=l.useState(!1),[E,S]=l.useState(t?.accountId),[C,k]=l.useState(!1),M=l.useRef(d);l.useEffect(()=>{M.current!==d&&(M.current=d,d&&(m([]),x([]),p([]),g(""),j(!1),N(!1),I(pi),k(!1)))},[d]);const{signature:T}=Jc(E),[D,I]=l.useState(()=>dh(T.plainText)),{data:R}=ie({...jc({path:{outboxMessageId:d??""}}),enabled:!!d&&!C});l.useEffect(()=>{!R||C||(m(R.toAddresses.map(W=>({email:W,displayName:void 0}))),R.ccAddresses&&R.ccAddresses.length>0&&(x(R.ccAddresses.map(W=>({email:W,displayName:void 0}))),j(!0)),R.bccAddresses&&R.bccAddresses.length>0&&(p(R.bccAddresses.map(W=>({email:W,displayName:void 0}))),N(!0)),R.subject&&g(R.subject),R.textBody&&I([{type:"p",children:[{text:R.textBody}]}]),S(R.accountId),k(!0))},[R,C]),l.useEffect(()=>{if(n){if(e==="reply"||e==="reply_all"){const{to:W,cc:ee}=hh(n,e,t?.email);m(W),x(ee),ee.length>0&&j(!0),g(fh(n.envelope.subject))}e==="forward"&&g(mh(n.envelope.subject))}},[e,n,t?.email]);const O=e==="reply"||e==="reply_all"||e==="forward",{data:B}=di({messageId:n?.message.messageId,bodyParts:n?.bodyParts,enabled:O&&!!n}),K=B?.kind==="text"?B.body:"",F=B?.kind==="html"?ih(B.body):void 0,$=n?.envelope.from[0]?.displayName??n?.envelope.from[0]?.normalizedEmail,{saveStatus:U,saveError:te,saveDraft:Q,cancelAutoSave:L}=Xm({outboxMessageId:d,onDraftCreated:i});l.useEffect(()=>{te&&u({title:"Couldn't save draft",detail:$e(te)??"Saving the draft failed."})},[te,u]);const A=xe(lo()),Y=xe(uo()),le=xe({...Zs(),onError:W=>{u(fs("Couldn't discard draft","The draft wasn't discarded.",W))}}),{data:ve}=ie({...Ze(),staleTime:1/0}),ce=ve?.accounts.find(W=>W.accountId===E),ye=ce?Wc(ce):!1,Se=A.isPending||Y.isPending,G=f.length>0&&!!E&&!ye;l.useEffect(()=>{if(!E||d&&!C||ph(f,h,b,y,D))return;const W=zn(D),ee=va(D);Q({accountId:E,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:y||void 0,textBody:W||void 0,htmlBody:ee||void 0})},[E,d,C,f,h,b,y,D,Q]);const ge=l.useCallback(async()=>{if(!E||f.length===0)return;L();const W=n&&(e==="reply"||e==="reply_all")?gh(n):{};let ee=d,ne=!1;if(!ee){const ae=zn(D),Ne=va(D),Fe=await A.mutateAsync({body:{accountId:E,toAddresses:f.map(De=>De.email),ccAddresses:h.length>0?h.map(De=>De.email):void 0,bccAddresses:b.length>0?b.map(De=>De.email):void 0,subject:y||void 0,textBody:ae||void 0,htmlBody:Ne||void 0,sendImmediately:!0,...W}}).catch(De=>(u({title:"Couldn't send message",detail:$e(De)??"Saving the draft failed."}),null));if(Fe===null)return;ee=Fe.outboxMessageId,ne=!0,i(ee)}await Y.mutateAsync({path:{outboxMessageId:ee}}).catch(ae=>(u({title:"Couldn't send message",detail:$e(ae)??(ne?"The draft was saved but the send request failed. Try again from the Outbox.":"The send request failed. Try again.")}),null))!==null&&(c(ee),r())},[E,f,h,b,y,D,e,n,d,A,Y,L,c,i,u,r]),Ie=l.useCallback(()=>{L(),d&&le.mutate({path:{outboxMessageId:d}}),r()},[L,d,le,r]),H=l.useCallback(W=>{S(W.accountId),a?.(W)},[a]);return s.jsx(Ed,{banner:ce&&ye?s.jsx(th,{accountId:ce.accountId}):void 0,header:s.jsx(xh,{selectedAccountId:E,onAccountChange:H,toAddresses:f,setToAddresses:m,ccAddresses:h,setCcAddresses:x,bccAddresses:b,setBccAddresses:p,showCc:v,setShowCc:j,showBcc:w,setShowBcc:N,subject:y,setSubject:g}),quoted:K||F?s.jsx(Wd,{text:K,html:F,senderName:$}):void 0,actionBar:s.jsx(Cd,{onSend:ge,onDiscard:Ie,sending:Se,canSend:G,saveStatus:U,unavailableReason:ye?"SMTP not configured":void 0,onUnavailable:W=>u({title:"Can't send yet",detail:W})}),children:s.jsx(l.Suspense,{fallback:s.jsx(ch,{}),children:s.jsx(lh,{value:D,onChange:I,onSubmit:ge,autoFocus:e==="new"})})})},ja=({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(gr,{mode:e,account:t,sourceMessage:n,onClose:r})}),xi=({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})]}),ps=({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])},bi=e=>{const{data:t,isLoading:n}=ie({...Ze(),staleTime:1/0}),r=l.useMemo(()=>(t?.accounts??[]).map(c=>c.accountId),[t?.accounts]),a=Jt({queries:r.map(c=>({...et({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}},Sa=(e,t,n)=>e.map(r=>t.has(r.messageId)?{...r,isRead:n}:r),bh=(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),vh=({messages:e,expandedIds:t,threadId:n,mailboxId:r,accountId:a})=>{const o=je(),{pushError:i}=ze(),c=l.useRef(new Set),u=l.useRef(new Set),{mutate:d}=xe({...en(),onMutate:async h=>{const x=new Set(h.body.messageIds??[]),b=h.body.isRead??!0,p=jt({path:{threadId:n}}),y=tt({path:{mailboxId:r}}),g=ut({path:{mailboxId:r}});await Promise.all([o.cancelQueries({queryKey:p}),o.cancelQueries({queryKey:y}),o.cancelQueries({queryKey:g})]);const v=o.getQueriesData({queryKey:p}).filter(N=>N[1]!==void 0).map(([N,E])=>({queryKey:N,data:E})),j=o.getQueriesData({queryKey:y}).concat(o.getQueriesData({queryKey:g})).filter(N=>N[1]!==void 0).map(([N,E])=>({queryKey:N,data:E}));o.setQueriesData({queryKey:p},N=>N&&{...N,items:Sa(N.items,x,b)});const w=N=>N&&{...N,pages:N.pages.map(E=>({...E,items:Sa(E.items,x,b)}))};return o.setQueriesData({queryKey:y},w),o.setQueriesData({queryKey:g},w),{threadMessagesPrefix:p,threadsListPrefix:y,threadsSearchPrefix:g,previousThreadMessages:v,previousThreadsList:j}},onSuccess:(h,x)=>{const b=x.body.messageIds??[];for(const p of b)c.current.add(p),u.current.delete(p)},onError:(h,x,b)=>{const p=x.body.messageIds??[];for(const g of p)u.current.delete(g);if(b){for(const g of b.previousThreadMessages)o.setQueryData(g.queryKey,g.data);for(const g of b.previousThreadsList)o.setQueryData(g.queryKey,g.data)}const y=x.body.isRead??!0;i({title:y?"Couldn't mark as read":"Couldn't mark as unread",detail:$e(h)})},onSettled:(h,x,b,p)=>{p&&(o.invalidateQueries({queryKey:p.threadMessagesPrefix}),o.invalidateQueries({queryKey:p.threadsListPrefix}),o.invalidateQueries({queryKey:p.threadsSearchPrefix}),a&&o.invalidateQueries({queryKey:Vt({path:{accountId:a}})}))}}),f=l.useCallback(h=>{const x=h.filter(b=>!c.current.has(b)&&!u.current.has(b));if(x.length!==0){for(const b of x)u.current.add(b);d({body:{messageIds:x,isRead:!0}})}},[d]),m=l.useMemo(()=>bh(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])},vi=e=>{const{mailboxId:t,accountId:n}=e,r=je(),{pushError:a}=ze(),{mutate:o,isPending:i}=xe({...en(),onError:(u,d)=>{const f=d.body.isRead??!0;a({title:f?"Couldn't mark as read":"Couldn't mark as unread",detail:$e(u)})},onSettled:()=>{r.invalidateQueries({queryKey:tt({path:{mailboxId:t}})}),r.invalidateQueries({queryKey:ut({path:{mailboxId:t}})}),n&&r.invalidateQueries({queryKey:Vt({path:{accountId:n}})})}});return{toggleReadFor:l.useCallback((u,d)=>{u.length!==0&&o({body:{messageIds:u,isRead:d}})},[o]),isPending:i}},yh=60,wh=1.5,jh=(e,t,n)=>{const r=Math.abs(e),a=Math.abs(t);return r<n?{direction:null}:r<a*wh?{direction:null}:{direction:e<0?"left":"right"}},Sh=({onSwipeLeft:e,onSwipeRight:t,thresholdPx:n=yh})=>{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}=jh(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}}},Na=(e,t,n)=>e.map(r=>r.messageId===t?{...r,hasStars:n}:r),Fn=({threadId:e,mailboxId:t})=>{const n=je(),{pushError:r}=ze(),{mutate:a,isPending:o,variables:i}=xe({...Nc(),onMutate:async u=>{const d=u.path.messageId,f=u.body.isStarred??!1,m=jt({path:{threadId:e}}),h=tt({path:{mailboxId:t}}),x=ut({path:{mailboxId:t}}),b=fo();await Promise.all([n.cancelQueries({queryKey:m}),n.cancelQueries({queryKey:h}),n.cancelQueries({queryKey:x}),n.cancelQueries({queryKey:b})]);const p=n.getQueriesData({queryKey:m}).filter(w=>w[1]!==void 0).map(([w,N])=>({queryKey:w,data:N})),y=n.getQueriesData({queryKey:h}).concat(n.getQueriesData({queryKey:x})).filter(w=>w[1]!==void 0).map(([w,N])=>({queryKey:w,data:N})),g=n.getQueriesData({queryKey:b}).filter(w=>w[1]!==void 0).map(([w,N])=>({queryKey:w,data:N})),v=w=>w&&{...w,items:Na(w.items,d,f)};n.setQueriesData({queryKey:m},v),n.setQueriesData({queryKey:b},v);const j=w=>w&&{...w,pages:w.pages.map(N=>({...N,items:Na(N.items,d,f)}))};return n.setQueriesData({queryKey:h},j),n.setQueriesData({queryKey:x},j),{threadMessagesPrefix:m,threadsListPrefix:h,threadsSearchPrefix:x,unifiedThreadsPrefix:b,previousThreadMessages:p,previousThreadsList:y,previousUnifiedThreads:g}},onError:(u,d,f)=>{if(f){for(const h of f.previousThreadMessages)n.setQueryData(h.queryKey,h.data);for(const h of f.previousThreadsList)n.setQueryData(h.queryKey,h.data);for(const h of f.previousUnifiedThreads)n.setQueryData(h.queryKey,h.data)}const m=d.body.isStarred??!1;r({title:m?"Couldn't star message":"Couldn't unstar message",detail:$e(u)})},onSettled:(u,d,f,m)=>{m&&(n.invalidateQueries({queryKey:m.threadMessagesPrefix}),n.invalidateQueries({queryKey:m.threadsListPrefix}),n.invalidateQueries({queryKey:m.threadsSearchPrefix}),n.invalidateQueries({queryKey:m.unifiedThreadsPrefix}))}});return{toggleStar:(u,d)=>{a({path:{messageId:u},body:{isStarred:!d}})},isPending:o,pendingMessageId:o?i?.path.messageId:void 0}};function ln(e){return e===void 0||e==="uncategorized"?"personal":e}const Ge={uncategorized:"uncategorized",personal:"personal",newsletter:"newsletter",marketing:"marketing",automated:"automated",transactional:"transactional",social:"social"},ka={MoveToInbox:"MoveToInbox",MoveToJunk:"MoveToJunk"},Nh={inbox:"Inbox",junk:"Junk"},kh=e=>`Moved from ${Nh[e]??"another folder"} by Remit`,Ch=(e,t)=>{if(e===ka.MoveToInbox)return t.inboxMailboxId;if(e===ka.MoveToJunk)return t.junkMailboxId},Eh=(e,t,n)=>{if(!e||!t)return!1;const r=Ch(e.action,n);return r!==void 0&&r===t},Ih=(e,t)=>{if(e==="inbox")return t.inboxMailboxId;if(e==="junk")return t.junkMailboxId},cn=(e,t)=>{const{data:n,isLoading:r}=ie({...Ze(),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}},Rh=e=>{const{mailboxId:t,isLoading:n}=cn(e,"Archive");return{archiveMailboxId:t,isLoading:n}},Mh=e=>{const{mailboxId:t,isLoading:n}=cn(e,"Drafts");return{draftsMailboxId:t,isLoading:n}},pr=e=>{const{mailboxId:t,isLoading:n}=cn(e,"Inbox");return{inboxMailboxId:t,isLoading:n}},xr=e=>{const{mailboxId:t,isLoading:n}=cn(e,"Junk");return{junkMailboxId:t,isLoading:n}},yi=e=>{const{data:t}=ie({...Ze(),staleTime:1/0,enabled:!!e});return l.useMemo(()=>t?.accounts.find(n=>n.accountId===e)?.folderAppointments??[],[t,e])},Ca=(e,t)=>e.filter(n=>!t.has(n.messageId)),ct=({mailboxId:e,threadId:t,accountId:n,onAfterOptimisticRemove:r})=>{const a=je(),{pushError:o}=ze(),{mutate:i,isPending:c}=xe({...kc(),onMutate:async d=>{const f=new Set(d.body.messageIds??[]),m=t?jt({path:{threadId:t}}):[],h=tt({path:{mailboxId:e}}),x=ut({path:{mailboxId:e}});await Promise.all([...t?[a.cancelQueries({queryKey:m})]:[],a.cancelQueries({queryKey:h}),a.cancelQueries({queryKey:x})]);const b=t?a.getQueriesData({queryKey:m}).filter(g=>g[1]!==void 0).map(([g,v])=>({queryKey:g,data:v})):[],p=a.getQueriesData({queryKey:h}).concat(a.getQueriesData({queryKey:x})).filter(g=>g[1]!==void 0).map(([g,v])=>({queryKey:g,data:v}));t&&a.setQueriesData({queryKey:m},g=>g&&{...g,items:Ca(g.items,f)});const y=g=>g&&{...g,pages:g.pages.map(v=>({...v,items:Ca(v.items,f)}))};return a.setQueriesData({queryKey:h},y),a.setQueriesData({queryKey:x},y),r?.(Array.from(f)),{threadMessagesPrefix:m,threadsListPrefix:h,threadsSearchPrefix:x,previousThreadMessages:b,previousThreadsList:p}},onError:(d,f,m)=>{if(m){for(const x of m.previousThreadMessages)a.setQueryData(x.queryKey,x.data);for(const x of m.previousThreadsList)a.setQueryData(x.queryKey,x.data)}const h=f.body.messageIds?.length??0;o({title:h>1?`Couldn't move ${h} messages`:"Couldn't move this message",detail:$e(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:Vt({path:{accountId:n}})}))}});return{moveMessages:l.useCallback((d,f)=>{d.length!==0&&i({body:{messageIds:d,destinationMailboxId:f}})},[i]),isPending:c}},Th=({accountId:e,messageId:t,threadId:n,mailboxId:r,autoMoved:a})=>{const{inboxMailboxId:o}=pr(e),{junkMailboxId:i}=xr(e),{moveMessages:c,isPending:u}=ct({mailboxId:r,threadId:n,accountId:e}),d={inboxMailboxId:o,junkMailboxId:i},f=Eh(a,r,d),m=a?Ih(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:kh(a.fromPlacement),onUndo:m?h:void 0,isUndoing:u}};function wi({accountId:e,messageId:t,threadId:n,mailboxId:r,autoMoved:a,size:o="sm"}){const i=Th({accountId:e,messageId:t,threadId:n,mailboxId:r,autoMoved:a});return i.show?s.jsx(gd,{label:i.label,size:o,onUndo:i.onUndo,undoLabel:i.isUndoing?"Undoing…":"Undo"}):null}const ji=({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:fe("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:fe("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})]})},$t=({onClick:e,disabled:t,destructive:n,children:r})=>s.jsx("button",{type:"button",onClick:a=>{a.stopPropagation(),t||e()},disabled:t,className:fe("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}),Bn=()=>s.jsx("div",{className:"my-1 h-px bg-line"}),Ea=(e,t)=>e.filter(n=>!t.has(n.messageId)),Dh=e=>e.filter(t=>t.isDeleted!==!0),ds=({mailboxId:e,threadId:t,accountId:n,onAfterOptimisticRemove:r})=>{const a=je(),{pushError:o}=ze(),{mutate:i,isPending:c}=xe({...Cc(),onMutate:async d=>{const f=new Set(d.body.messageIds??[]),m=t?jt({path:{threadId:t}}):[],h=tt({path:{mailboxId:e}}),x=ut({path:{mailboxId:e}});await Promise.all([a.cancelQueries({queryKey:m}),a.cancelQueries({queryKey:h}),a.cancelQueries({queryKey:x})]);const b=t?a.getQueriesData({queryKey:m}).filter(g=>g[1]!==void 0).map(([g,v])=>({queryKey:g,data:v})):[],p=a.getQueriesData({queryKey:h}).concat(a.getQueriesData({queryKey:x})).filter(g=>g[1]!==void 0).map(([g,v])=>({queryKey:g,data:v}));t&&a.setQueriesData({queryKey:m},g=>g&&{...g,items:Ea(g.items,f)});const y=g=>g&&{...g,pages:g.pages.map(v=>({...v,items:Ea(v.items,f)}))};return a.setQueriesData({queryKey:h},y),a.setQueriesData({queryKey:x},y),r?.(Array.from(f)),{threadMessagesPrefix:m,threadsListPrefix:h,threadsSearchPrefix:x,previousThreadMessages:b,previousThreadsList:p}},onError:(d,f,m)=>{if(m){for(const x of m.previousThreadMessages)a.setQueryData(x.queryKey,x.data);for(const x of m.previousThreadsList)a.setQueryData(x.queryKey,x.data)}const h=f.body.messageIds?.length??0;o({title:h>1?`Couldn't delete ${h} messages`:"Couldn't delete this message",detail:$e(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:Vt({path:{accountId:n}})}))}});return{deleteMessages:l.useCallback(d=>{d.length!==0&&i({body:{messageIds:d}})},[i]),isPending:c}},Si=(e,t=Date.now())=>({value:e,setAt:t}),Ah=(e,t,n,r)=>{if(e.addressId!==t)return e;const a={...e.flags??{}};return n?a.trusted=Si(!0,r):delete a.trusted,{...e,flags:a}},Oh=(e,t,n,r)=>{const a=o=>o.map(i=>Ah(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)}}},br=({messageId:e})=>{const t=je(),{pushError:n}=ze(),{mutate:r,isPending:a,error:o,reset:i}=xe({...mo(),onMutate:async u=>{const d=u.path.addressId,m=u.body.flags?.trusted?.value===!0,h=io({path:{messageId:e}});await t.cancelQueries({queryKey:h});const x=t.getQueriesData({queryKey:h}).filter(b=>b[1]!==void 0).map(([b,p])=>({queryKey:b,data:p}));return t.setQueriesData({queryKey:h},b=>b&&Oh(b,d,m)),{describePrefix:h,previous:x}},onError:(u,d,f)=>{if(f)for(const m of f.previous)t.setQueryData(m.queryKey,m.data);n(fs("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:Si(!d)}}})},isPending:a,error:o,reset:i}};var un="Dialog",[Ni]=uf(un),[Ph,_e]=Ni(un),ki=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]=mf({prop:r,defaultProp:a??!1,onChange:o,caller:un});return s.jsx(Ph,{scope:t,triggerRef:c,contentRef:u,contentId:xn(),titleId:xn(),descriptionId:xn(),open:d,onOpenChange:f,onOpenToggle:l.useCallback(()=>f(m=>!m),[f]),modal:i,children:n})};ki.displayName=un;var Ci="DialogTrigger",Lh=l.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,a=_e(Ci,n),o=Nt(t,a.triggerRef);return s.jsx(nt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":yr(a.open),...r,ref:o,onClick:lt(e.onClick,a.onOpenToggle)})});Lh.displayName=Ci;var vr="DialogPortal",[zh,Ei]=Ni(vr,{forceMount:void 0}),Ii=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:a}=e,o=_e(vr,t);return s.jsx(zh,{scope:t,forceMount:n,children:l.Children.map(r,i=>s.jsx(an,{present:n||o.open,children:s.jsx(ti,{asChild:!0,container:a,children:i})}))})};Ii.displayName=vr;var Ys="DialogOverlay",Ri=l.forwardRef((e,t)=>{const n=Ei(Ys,e.__scopeDialog),{forceMount:r=n.forceMount,...a}=e,o=_e(Ys,e.__scopeDialog);return o.modal?s.jsx(an,{present:r||o.open,children:s.jsx(Fh,{...a,ref:t})}):null});Ri.displayName=Ys;var _h=dr("DialogOverlay.RemoveScroll"),Fh=l.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,a=_e(Ys,n),o=Df(),i=Nt(t,o);return s.jsx(ci,{as:_h,allowPinchZoom:!0,shards:[a.contentRef],children:s.jsx(nt.div,{"data-state":yr(a.open),...r,ref:i,style:{pointerEvents:"auto",...r.style}})})}),Wt="DialogContent",Mi=l.forwardRef((e,t)=>{const n=Ei(Wt,e.__scopeDialog),{forceMount:r=n.forceMount,...a}=e,o=_e(Wt,e.__scopeDialog);return s.jsx(an,{present:r||o.open,children:o.modal?s.jsx(Bh,{...a,ref:t}):s.jsx($h,{...a,ref:t})})});Mi.displayName=Wt;var Bh=l.forwardRef((e,t)=>{const n=_e(Wt,e.__scopeDialog),r=l.useRef(null),a=Nt(t,n.contentRef,r);return l.useEffect(()=>{const o=r.current;if(o)return em(o)},[]),s.jsx(Ti,{...e,ref:a,trapFocus:n.open,disableOutsidePointerEvents:n.open,onCloseAutoFocus:lt(e.onCloseAutoFocus,o=>{o.preventDefault(),n.triggerRef.current?.focus()}),onPointerDownOutside:lt(e.onPointerDownOutside,o=>{const i=o.detail.originalEvent,c=i.button===0&&i.ctrlKey===!0;(i.button===2||c)&&o.preventDefault()}),onFocusOutside:lt(e.onFocusOutside,o=>o.preventDefault())})}),$h=l.forwardRef((e,t)=>{const n=_e(Wt,e.__scopeDialog),r=l.useRef(!1),a=l.useRef(!1);return s.jsx(Ti,{...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()}})}),Ti=l.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:a,onCloseAutoFocus:o,...i}=e,c=_e(Wt,n);return Lf(),s.jsx(s.Fragment,{children:s.jsx(Zo,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:a,onUnmountAutoFocus:o,children:s.jsx(Xo,{role:"dialog",id:c.contentId,"aria-describedby":c.descriptionId,"aria-labelledby":c.titleId,"data-state":yr(c.open),...i,ref:t,deferPointerDownOutside:!0,onDismiss:()=>c.onOpenChange(!1)})})})}),Di="DialogTitle",Ai=l.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,a=_e(Di,n);return s.jsx(nt.h2,{id:a.titleId,...r,ref:t})});Ai.displayName=Di;var Oi="DialogDescription",Kh=l.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,a=_e(Oi,n);return s.jsx(nt.p,{id:a.descriptionId,...r,ref:t})});Kh.displayName=Oi;var Pi="DialogClose",qh=l.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,a=_e(Pi,n);return s.jsx(nt.button,{type:"button",...r,ref:t,onClick:lt(e.onClick,()=>a.onOpenChange(!1))})});qh.displayName=Pi;function yr(e){return e?"open":"closed"}function Uh(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 Li=_.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}),Ns=()=>{const e=_.useContext(Li);if(!e)throw new Error("useDrawerContext must be used within a Drawer.Root");return e};Uh(`[data-vaul-drawer]{touch-action:none;will-change:transform;transition:transform .5s cubic-bezier(.32, .72, 0, 1);animation-duration:.5s;animation-timing-function:cubic-bezier(0.32,0.72,0,1)}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=bottom][data-state=open]{animation-name:slideFromBottom}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=bottom][data-state=closed]{animation-name:slideToBottom}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=top][data-state=open]{animation-name:slideFromTop}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=top][data-state=closed]{animation-name:slideToTop}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=left][data-state=open]{animation-name:slideFromLeft}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=left][data-state=closed]{animation-name:slideToLeft}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=right][data-state=open]{animation-name:slideFromRight}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=right][data-state=closed]{animation-name:slideToRight}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=bottom]{transform:translate3d(0,var(--initial-transform,100%),0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=top]{transform:translate3d(0,calc(var(--initial-transform,100%) * -1),0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=left]{transform:translate3d(calc(var(--initial-transform,100%) * -1),0,0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=right]{transform:translate3d(var(--initial-transform,100%),0,0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=top]{transform:translate3d(0,var(--snap-point-height,0),0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=bottom]{transform:translate3d(0,var(--snap-point-height,0),0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=left]{transform:translate3d(var(--snap-point-height,0),0,0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=right]{transform:translate3d(var(--snap-point-height,0),0,0)}[data-vaul-overlay][data-vaul-snap-points=false]{animation-duration:.5s;animation-timing-function:cubic-bezier(0.32,0.72,0,1)}[data-vaul-overlay][data-vaul-snap-points=false][data-state=open]{animation-name:fadeIn}[data-vaul-overlay][data-state=closed]{animation-name:fadeOut}[data-vaul-animate=false]{animation:none!important}[data-vaul-overlay][data-vaul-snap-points=true]{opacity:0;transition:opacity .5s cubic-bezier(.32, .72, 0, 1)}[data-vaul-overlay][data-vaul-snap-points=true]{opacity:1}[data-vaul-drawer]:not([data-vaul-custom-container=true])::after{content:'';position:absolute;background:inherit;background-color:inherit}[data-vaul-drawer][data-vaul-drawer-direction=top]::after{top:initial;bottom:100%;left:0;right:0;height:200%}[data-vaul-drawer][data-vaul-drawer-direction=bottom]::after{top:100%;bottom:initial;left:0;right:0;height:200%}[data-vaul-drawer][data-vaul-drawer-direction=left]::after{left:initial;right:100%;top:0;bottom:0;width:200%}[data-vaul-drawer][data-vaul-drawer-direction=right]::after{left:100%;right:initial;top:0;bottom:0;width:200%}[data-vaul-overlay][data-vaul-snap-points=true]:not([data-vaul-snap-points-overlay=true]):not(
111
111
  [data-state=closed]
112
112
  ){opacity:0}[data-vaul-overlay][data-vaul-snap-points-overlay=true]{opacity:1}[data-vaul-handle]{display:block;position:relative;opacity:.7;background:#e2e2e4;margin-left:auto;margin-right:auto;height:5px;width:32px;border-radius:1rem;touch-action:pan-y}[data-vaul-handle]:active,[data-vaul-handle]:hover{opacity:1}[data-vaul-handle-hitarea]{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);width:max(100%,2.75rem);height:max(100%,2.75rem);touch-action:inherit}@media (hover:hover) and (pointer:fine){[data-vaul-drawer]{user-select:none}}@media (pointer:fine){[data-vaul-handle-hitarea]:{width:100%;height:100%}}@keyframes fadeIn{from{opacity:0}to{opacity:1}}@keyframes fadeOut{to{opacity:0}}@keyframes slideFromBottom{from{transform:translate3d(0,var(--initial-transform,100%),0)}to{transform:translate3d(0,0,0)}}@keyframes slideToBottom{to{transform:translate3d(0,var(--initial-transform,100%),0)}}@keyframes slideFromTop{from{transform:translate3d(0,calc(var(--initial-transform,100%) * -1),0)}to{transform:translate3d(0,0,0)}}@keyframes slideToTop{to{transform:translate3d(0,calc(var(--initial-transform,100%) * -1),0)}}@keyframes slideFromLeft{from{transform:translate3d(calc(var(--initial-transform,100%) * -1),0,0)}to{transform:translate3d(0,0,0)}}@keyframes slideToLeft{to{transform:translate3d(calc(var(--initial-transform,100%) * -1),0,0)}}@keyframes slideFromRight{from{transform:translate3d(var(--initial-transform,100%),0,0)}to{transform:translate3d(0,0,0)}}@keyframes slideToRight{to{transform:translate3d(var(--initial-transform,100%),0,0)}}`);function Qh(){const e=navigator.userAgent;return typeof window<"u"&&(/Firefox/.test(e)&&/Mobile/.test(e)||/FxiOS/.test(e))}function Hh(){return wr(/^Mac/)}function Wh(){return wr(/^iPhone/)}function Ia(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function Vh(){return wr(/^iPad/)||Hh()&&navigator.maxTouchPoints>1}function zi(){return Wh()||Vh()}function wr(e){return typeof window<"u"&&window.navigator!=null?e.test(window.navigator.platform):void 0}const Yh=24,Gh=typeof window<"u"?l.useLayoutEffect:l.useEffect;function Ra(...e){return(...t)=>{for(let n of e)typeof n=="function"&&n(...t)}}const Sn=typeof document<"u"&&window.visualViewport;function Ma(e){let t=window.getComputedStyle(e);return/(auto|scroll)/.test(t.overflow+t.overflowX+t.overflowY)}function _i(e){for(Ma(e)&&(e=e.parentElement);e&&!Ma(e);)e=e.parentElement;return e||document.scrollingElement||document.documentElement}const Xh=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);let zs=0,Nn;function Jh(e={}){let{isDisabled:t}=e;Gh(()=>{if(!t)return zs++,zs===1&&zi()&&(Nn=Zh()),()=>{zs--,zs===0&&Nn?.()}},[t])}function Zh(){let e,t=0,n=m=>{e=_i(m.target),!(e===document.documentElement&&e===document.body)&&(t=m.changedTouches[0].pageY)},r=m=>{if(!e||e===document.documentElement||e===document.body){m.preventDefault();return}let h=m.changedTouches[0].pageY,x=e.scrollTop,b=e.scrollHeight-e.clientHeight;b!==0&&((x<=0&&h>t||x>=b&&h<t)&&m.preventDefault(),t=h)},a=m=>{let h=m.target;$n(h)&&h!==document.activeElement&&(m.preventDefault(),h.style.transform="translateY(-2000px)",h.focus(),requestAnimationFrame(()=>{h.style.transform=""}))},o=m=>{let h=m.target;$n(h)&&(h.style.transform="translateY(-2000px)",requestAnimationFrame(()=>{h.style.transform="",Sn&&(Sn.height<window.innerHeight?requestAnimationFrame(()=>{Ta(h)}):Sn.addEventListener("resize",()=>Ta(h),{once:!0}))}))},i=()=>{window.scrollTo(0,0)},c=window.pageXOffset,u=window.pageYOffset,d=Ra(eg(document.documentElement,"paddingRight",`${window.innerWidth-document.documentElement.clientWidth}px`));window.scrollTo(0,0);let f=Ra(os(document,"touchstart",n,{passive:!1,capture:!0}),os(document,"touchmove",r,{passive:!1,capture:!0}),os(document,"touchend",a,{passive:!1,capture:!0}),os(document,"focus",o,!0),os(window,"scroll",i));return()=>{d(),f(),window.scrollTo(c,u)}}function eg(e,t,n){let r=e.style[t];return e.style[t]=n,()=>{e.style[t]=r}}function os(e,t,n,r){return e.addEventListener(t,n,r),()=>{e.removeEventListener(t,n,r)}}function Ta(e){let t=document.scrollingElement||document.documentElement;for(;e&&e!==t;){let n=_i(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+Yh;o>i&&(n.scrollTop+=a-r)}e=n.parentElement}}function $n(e){return e instanceof HTMLInputElement&&!Xh.has(e.type)||e instanceof HTMLTextAreaElement||e instanceof HTMLElement&&e.isContentEditable}function tg(e,t){typeof e=="function"?e(t):e!=null&&(e.current=t)}function sg(...e){return t=>e.forEach(n=>tg(n,t))}function Fi(...e){return l.useCallback(sg(...e),e)}const Bi=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&&Bi.set(e,r)}function ng(e,t){if(!e||!(e instanceof HTMLElement))return;let n=Bi.get(e);n&&(e.style[t]=n[t])}const be=e=>{switch(e){case"top":case"bottom":return!0;case"left":case"right":return!1;default:return e}};function _s(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(", ")[be(t)?13:12]):(a=r.match(/^matrix\((.+)\)$/),a?parseFloat(a[1].split(", ")[be(t)?5:4]):null)}function rg(e){return 8*(Math.log(e+1)-2)}function kn(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 he={DURATION:.5,EASE:[.32,.72,0,1]},$i=.4,og=.25,ig=100,Ki=8,xt=16,Kn=26,Cn="vaul-dragging";function qi(e){const t=_.useRef(e);return _.useEffect(()=>{t.current=e}),_.useMemo(()=>(...n)=>t.current==null?void 0:t.current.call(t,...n),[])}function lg({defaultProp:e,onChange:t}){const n=_.useState(e),[r]=n,a=_.useRef(r),o=qi(t);return _.useEffect(()=>{a.current!==r&&(o(r),a.current=r)},[r,a,o]),n}function Ui({prop:e,defaultProp:t,onChange:n=()=>{}}){const[r,a]=lg({defaultProp:t,onChange:n}),o=e!==void 0,i=o?e:r,c=qi(n),u=_.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 cg({activeSnapPointProp:e,setActiveSnapPointProp:t,snapPoints:n,drawerRef:r,overlayRef:a,fadeFromIndex:o,onSnapPointChange:i,direction:c="bottom",container:u,snapToSequentialPoint:d}){const[f,m]=Ui({prop:e,defaultProp:n?.[0],onChange:t}),[h,x]=_.useState(typeof window<"u"?{innerWidth:window.innerWidth,innerHeight:window.innerHeight}:void 0);_.useEffect(()=>{function S(){x({innerWidth:window.innerWidth,innerHeight:window.innerHeight})}return window.addEventListener("resize",S),()=>window.removeEventListener("resize",S)},[]);const b=_.useMemo(()=>f===n?.[n.length-1]||null,[n,f]),p=_.useMemo(()=>{var S;return(S=n?.findIndex(C=>C===f))!=null?S:null},[n,f]),y=n&&n.length>0&&(o||o===0)&&!Number.isNaN(o)&&n[o]===f||!n,g=_.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 T=0;if(M&&(T=parseInt(k,10)),be(c)){const I=M?T:h?k*S.height:0;return h?c==="bottom"?S.height-I:-S.height+I:I}const D=M?T:h?k*S.width:0;return h?c==="right"?S.width-D:-S.width+D:D}))!=null?C:[]},[n,h,u]),v=_.useMemo(()=>p!==null?g?.[p]:null,[g,p]),j=_.useCallback(S=>{var C;const k=(C=g?.findIndex(M=>M===S))!=null?C:null;i(k),we(r.current,{transition:`transform ${he.DURATION}s cubic-bezier(${he.EASE.join(",")})`,transform:be(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 ${he.DURATION}s cubic-bezier(${he.EASE.join(",")})`,opacity:"0"}):we(a.current,{transition:`opacity ${he.DURATION}s cubic-bezier(${he.EASE.join(",")})`,opacity:"1"}),m(n?.[Math.max(k,0)])},[r.current,n,g,o,a,m]);_.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"&&j(g[C])}},[f,e,n,g,j]);function w({draggedDistance:S,closeDrawer:C,velocity:k,dismissible:M}){if(o===void 0)return;const T=c==="bottom"||c==="right"?(v??0)-S:(v??0)+S,D=p===o-1,I=p===0,R=S>0;if(D&&we(a.current,{transition:`opacity ${he.DURATION}s cubic-bezier(${he.EASE.join(",")})`}),!d&&k>2&&!R){M?C():j(g[0]);return}if(!d&&k>2&&R&&g&&n){j(g[n.length-1]);return}const O=g?.reduce((K,F)=>typeof K!="number"||typeof F!="number"?K:Math.abs(F-T)<Math.abs(K-T)?F:K),B=be(c)?window.innerHeight:window.innerWidth;if(k>$i&&Math.abs(S)<B*.4){const K=R?1:-1;if(K>0&&b&&n){j(g[n.length-1]);return}if(I&&K<0&&M&&C(),p===null)return;j(g[p+K]);return}j(O)}function N({draggedDistance:S}){if(v===null)return;const C=c==="bottom"||c==="right"?v-S:v+S;(c==="bottom"||c==="right")&&C<g[g.length-1]||(c==="top"||c==="left")&&C>g[g.length-1]||we(r.current,{transform:be(c)?`translate3d(0, ${C}px, 0)`:`translate3d(${C}px, 0, 0)`})}function E(S,C){if(!n||typeof p!="number"||!g||o===void 0)return null;const k=p===o-1;if(p>=o&&C)return 0;if(k&&!C)return 1;if(!y&&!k)return null;const T=k?p+1:p-1,D=k?g[T]-g[T-1]:g[T+1]-g[T],I=S/Math.abs(D);return k?1-I:I}return{isLastSnapPoint:b,activeSnapPoint:f,shouldFade:y,getPercentageDragged:E,setActiveSnapPoint:m,activeSnapPointIndex:p,onRelease:w,onDrag:N,snapPointsOffset:g}}const ug=()=>()=>{};function dg(){const{direction:e,isOpen:t,shouldScaleBackground:n,setBackgroundColorOnScale:r,noBodyStyles:a}=Ns(),o=_.useRef(null),i=l.useMemo(()=>document.body.style.backgroundColor,[]);function c(){return(window.innerWidth-Kn)/window.innerWidth}_.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?kn(document.body,{background:"black"}):ug,kn(u,{transformOrigin:be(e)?"top":"left",transitionProperty:"transform, border-radius",transitionDuration:`${he.DURATION}s`,transitionTimingFunction:`cubic-bezier(${he.EASE.join(",")})`}));const d=kn(u,{borderRadius:`${Ki}px`,overflow:"hidden",...be(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")},he.DURATION*1e3)}}},[t,n,i])}let is=null;function fg({isOpen:e,modal:t,nested:n,hasBeenOpened:r,preventScrollRestoration:a,noBodyStyles:o}){const[i,c]=_.useState(()=>typeof window<"u"?window.location.href:""),u=_.useRef(0),d=_.useCallback(()=>{if(Ia()&&is===null&&e&&!o){is={position:document.body.style.position,top:document.body.style.top,left:document.body.style.left,height:document.body.style.height,right:"unset"};const{scrollX:m,innerHeight:h}=window;document.body.style.setProperty("position","fixed","important"),Object.assign(document.body.style,{top:`${-u.current}px`,left:`${-m}px`,right:"0px",height:"auto"}),window.setTimeout(()=>window.requestAnimationFrame(()=>{const x=h-window.innerHeight;x&&u.current>=h&&(document.body.style.top=`${-(u.current+x)}px`)}),300)}},[e]),f=_.useCallback(()=>{if(Ia()&&is!==null&&!o){const m=-parseInt(document.body.style.top,10),h=-parseInt(document.body.style.left,10);Object.assign(document.body.style,is),window.requestAnimationFrame(()=>{if(a&&i!==window.location.href){c(window.location.href);return}window.scrollTo(h,m)}),is=null}},[i]);return _.useEffect(()=>{function m(){u.current=window.scrollY}return m(),window.addEventListener("scroll",m),()=>{window.removeEventListener("scroll",m)}},[]),_.useEffect(()=>{if(t)return()=>{typeof document>"u"||document.querySelector("[data-vaul-drawer]")||f()}},[t,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 mg({open:e,onOpenChange:t,children:n,onDrag:r,onRelease:a,snapPoints:o,shouldScaleBackground:i=!1,setBackgroundColorOnScale:c=!0,closeThreshold:u=og,scrollLockTimeout:d=ig,dismissible:f=!0,handleOnly:m=!1,fadeFromIndex:h=o&&o.length-1,activeSnapPoint:x,setActiveSnapPoint:b,fixed:p,modal:y=!0,onClose:g,nested:v,noBodyStyles:j=!1,direction:w="bottom",defaultOpen:N=!1,disablePreventScroll:E=!0,snapToSequentialPoint:S=!1,preventScrollRestoration:C=!1,repositionInputs:k=!0,onAnimationEnd:M,container:T,autoFocus:D=!1}){var I,R;const[O=!1,B]=Ui({defaultProp:N,prop:e,onChange:V=>{t?.(V),!V&&!v&&Et(),setTimeout(()=>{M?.(V)},he.DURATION*1e3),V&&!y&&typeof window<"u"&&window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"}),V||(document.body.style.pointerEvents="auto")}}),[K,F]=_.useState(!1),[$,U]=_.useState(!1),[te,Q]=_.useState(!1),L=_.useRef(null),A=_.useRef(null),Y=_.useRef(null),le=_.useRef(null),ve=_.useRef(null),ce=_.useRef(!1),ye=_.useRef(null),Se=_.useRef(0),G=_.useRef(!1),ge=_.useRef(!N),Ie=_.useRef(0),H=_.useRef(null),W=_.useRef(((I=H.current)==null?void 0:I.getBoundingClientRect().height)||0),ee=_.useRef(((R=H.current)==null?void 0:R.getBoundingClientRect().width)||0),ne=_.useRef(0),Ue=_.useCallback(V=>{o&&V===Qe.length-1&&(A.current=new Date)},[]),{activeSnapPoint:ae,activeSnapPointIndex:Ne,setActiveSnapPoint:Fe,onRelease:De,snapPointsOffset:Qe,onDrag:He,shouldFade:Ct,getPercentageDragged:ht}=cg({snapPoints:o,activeSnapPointProp:x,setActiveSnapPointProp:b,drawerRef:H,fadeFromIndex:h,overlayRef:L,onSnapPointChange:Ue,direction:w,container:T,snapToSequentialPoint:S});Jh({isDisabled:!O||$||!y||te||!K||!k||!E});const{restorePositionSetting:Et}=fg({isOpen:O,modal:y,nested:v??!1,hasBeenOpened:K,preventScrollRestoration:C,noBodyStyles:j});function We(){return(window.innerWidth-Kn)/window.innerWidth}function rt(V){var re,oe;!f&&!o||H.current&&!H.current.contains(V.target)||(W.current=((re=H.current)==null?void 0:re.getBoundingClientRect().height)||0,ee.current=((oe=H.current)==null?void 0:oe.getBoundingClientRect().width)||0,U(!0),Y.current=new Date,zi()&&window.addEventListener("touchend",()=>ce.current=!1,{once:!0}),V.target.setPointerCapture(V.pointerId),Se.current=be(w)?V.pageY:V.pageX)}function gt(V,re){var oe;let Z=V;const ue=(oe=window.getSelection())==null?void 0:oe.toString(),pe=H.current?_s(H.current,w):null,P=new Date;if(Z.tagName==="SELECT"||Z.hasAttribute("data-vaul-no-drag")||Z.closest("[data-vaul-no-drag]"))return!1;if(w==="right"||w==="left")return!0;if(A.current&&P.getTime()-A.current.getTime()<500)return!1;if(pe!==null&&(w==="bottom"?pe>0:pe<0))return!0;if(ue&&ue.length>0)return!1;if(ve.current&&P.getTime()-ve.current.getTime()<d&&pe===0||re)return ve.current=P,!1;for(;Z;){if(Z.scrollHeight>Z.clientHeight){if(Z.scrollTop!==0)return ve.current=new Date,!1;if(Z.getAttribute("role")==="dialog")return!0}Z=Z.parentNode}return!0}function Re(V){if(H.current&&$){const re=w==="bottom"||w==="right"?1:-1,oe=(Se.current-(be(w)?V.pageY:V.pageX))*re,Z=oe>0,ue=o&&!f&&!Z;if(ue&&Ne===0)return;const pe=Math.abs(oe),P=document.querySelector("[data-vaul-drawer-wrapper]"),J=w==="bottom"||w==="top"?W.current:ee.current;let me=pe/J;const de=ht(pe,Z);if(de!==null&&(me=de),ue&&me>=1||!ce.current&&!gt(V.target,Z))return;if(H.current.classList.add(Cn),ce.current=!0,we(H.current,{transition:"none"}),we(L.current,{transition:"none"}),o&&He({draggedDistance:oe}),Z&&!o){const ke=rg(oe),pt=Math.min(ke*-1,0)*re;we(H.current,{transform:be(w)?`translate3d(0, ${pt}px, 0)`:`translate3d(${pt}px, 0, 0)`});return}const Me=1-me;if((Ct||h&&Ne===h-1)&&(r?.(V,me),we(L.current,{opacity:`${Me}`,transition:"none"},!0)),P&&L.current&&i){const ke=Math.min(We()+me*(1-We()),1),pt=8-me*8,Be=Math.max(0,14-me*14);we(P,{borderRadius:`${pt}px`,transform:be(w)?`scale(${ke}) translate3d(0, ${Be}px, 0)`:`scale(${ke}) translate3d(${Be}px, 0, 0)`,transition:"none"},!0)}if(!o){const ke=pe*re;we(H.current,{transform:be(w)?`translate3d(0, ${ke}px, 0)`:`translate3d(${ke}px, 0, 0)`})}}}_.useEffect(()=>{window.requestAnimationFrame(()=>{ge.current=!0})},[]),_.useEffect(()=>{var V;function re(){if(!H.current||!k)return;const oe=document.activeElement;if($n(oe)||G.current){var Z;const ue=((Z=window.visualViewport)==null?void 0:Z.height)||0,pe=window.innerHeight;let P=pe-ue;const J=H.current.getBoundingClientRect().height||0,me=J>pe*.8;ne.current||(ne.current=J);const de=H.current.getBoundingClientRect().top;if(Math.abs(Ie.current-P)>60&&(G.current=!G.current),o&&o.length>0&&Qe&&Ne){const Me=Qe[Ne]||0;P+=Me}if(Ie.current=P,J>ue||G.current){const Me=H.current.getBoundingClientRect().height;let ke=Me;Me>ue&&(ke=ue-(me?de:Kn)),p?H.current.style.height=`${Me-Math.max(P,0)}px`:H.current.style.height=`${Math.max(ke,ue-de)}px`}else Qh()||(H.current.style.height=`${ne.current}px`);o&&o.length>0&&!G.current?H.current.style.bottom="0px":H.current.style.bottom=`${Math.max(P,0)}px`}}return(V=window.visualViewport)==null||V.addEventListener("resize",re),()=>{var oe;return(oe=window.visualViewport)==null?void 0:oe.removeEventListener("resize",re)}},[Ne,o,Qe]);function Ve(V){Rt(),g?.(),V||B(!1),setTimeout(()=>{o&&Fe(o[0])},he.DURATION*1e3)}function It(){if(!H.current)return;const V=document.querySelector("[data-vaul-drawer-wrapper]"),re=_s(H.current,w);we(H.current,{transform:"translate3d(0, 0, 0)",transition:`transform ${he.DURATION}s cubic-bezier(${he.EASE.join(",")})`}),we(L.current,{transition:`opacity ${he.DURATION}s cubic-bezier(${he.EASE.join(",")})`,opacity:"1"}),i&&re&&re>0&&O&&we(V,{borderRadius:`${Ki}px`,overflow:"hidden",...be(w)?{transform:`scale(${We()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`,transformOrigin:"top"}:{transform:`scale(${We()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)`,transformOrigin:"left"},transitionProperty:"transform, border-radius",transitionDuration:`${he.DURATION}s`,transitionTimingFunction:`cubic-bezier(${he.EASE.join(",")})`},!0)}function Rt(){!$||!H.current||(H.current.classList.remove(Cn),ce.current=!1,U(!1),le.current=new Date)}function es(V){if(!$||!H.current)return;H.current.classList.remove(Cn),ce.current=!1,U(!1),le.current=new Date;const re=_s(H.current,w);if(!V||!gt(V.target,!1)||!re||Number.isNaN(re)||Y.current===null)return;const oe=le.current.getTime()-Y.current.getTime(),Z=Se.current-(be(w)?V.pageY:V.pageX),ue=Math.abs(Z)/oe;if(ue>.05&&(Q(!0),setTimeout(()=>{Q(!1)},200)),o){De({draggedDistance:Z*(w==="bottom"||w==="right"?1:-1),closeDrawer:Ve,velocity:ue,dismissible:f}),a?.(V,!0);return}if(w==="bottom"||w==="right"?Z>0:Z<0){It(),a?.(V,!0);return}if(ue>$i){Ve(),a?.(V,!1);return}var pe;const P=Math.min((pe=H.current.getBoundingClientRect().height)!=null?pe:0,window.innerHeight);var J;const me=Math.min((J=H.current.getBoundingClientRect().width)!=null?J:0,window.innerWidth),de=w==="left"||w==="right";if(Math.abs(re)>=(de?me:P)*u){Ve(),a?.(V,!1);return}a?.(V,!0),It()}_.useEffect(()=>(O&&(we(document.documentElement,{scrollBehavior:"auto"}),A.current=new Date),()=>{ng(document.documentElement,"scrollBehavior")}),[O]);function Mt(V){const re=V?(window.innerWidth-xt)/window.innerWidth:1,oe=V?-xt:0;ye.current&&window.clearTimeout(ye.current),we(H.current,{transition:`transform ${he.DURATION}s cubic-bezier(${he.EASE.join(",")})`,transform:be(w)?`scale(${re}) translate3d(0, ${oe}px, 0)`:`scale(${re}) translate3d(${oe}px, 0, 0)`}),!V&&H.current&&(ye.current=setTimeout(()=>{const Z=_s(H.current,w);we(H.current,{transition:"none",transform:be(w)?`translate3d(0, ${Z}px, 0)`:`translate3d(${Z}px, 0, 0)`})},500))}function Le(V,re){if(re<0)return;const oe=(window.innerWidth-xt)/window.innerWidth,Z=oe+re*(1-oe),ue=-xt+re*xt;we(H.current,{transform:be(w)?`scale(${Z}) translate3d(0, ${ue}px, 0)`:`scale(${Z}) translate3d(${ue}px, 0, 0)`,transition:"none"})}function ts(V,re){const oe=be(w)?window.innerHeight:window.innerWidth,Z=re?(oe-xt)/oe:1,ue=re?-xt:0;re&&we(H.current,{transition:`transform ${he.DURATION}s cubic-bezier(${he.EASE.join(",")})`,transform:be(w)?`scale(${Z}) translate3d(0, ${ue}px, 0)`:`scale(${Z}) translate3d(${ue}px, 0, 0)`})}return _.useEffect(()=>{y||window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"})},[y]),_.createElement(ki,{defaultOpen:N,onOpenChange:V=>{!f&&!V||(V?F(!0):Ve(!0),B(V))},open:O},_.createElement(Li.Provider,{value:{activeSnapPoint:ae,snapPoints:o,setActiveSnapPoint:Fe,drawerRef:H,overlayRef:L,onOpenChange:t,onPress:rt,onRelease:es,onDrag:Re,dismissible:f,shouldAnimate:ge,handleOnly:m,isOpen:O,isDragging:$,shouldFade:Ct,closeDrawer:Ve,onNestedDrag:Le,onNestedOpenChange:Mt,onNestedRelease:ts,keyboardIsOpen:G,modal:y,snapPointsOffset:Qe,activeSnapPointIndex:Ne,direction:w,shouldScaleBackground:i,setBackgroundColorOnScale:c,noBodyStyles:j,container:T,autoFocus:D}},n))}const Qi=_.forwardRef(function({...e},t){const{overlayRef:n,snapPoints:r,onRelease:a,shouldFade:o,isOpen:i,modal:c,shouldAnimate:u}=Ns(),d=Fi(t,n),f=r&&r.length>0;if(!c)return null;const m=_.useCallback(h=>a(h),[a]);return _.createElement(Ri,{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})});Qi.displayName="Drawer.Overlay";const Hi=_.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:x,direction:b,snapPoints:p,container:y,handleOnly:g,shouldAnimate:v,autoFocus:j}=Ns(),[w,N]=_.useState(!1),E=Fi(a,o),S=_.useRef(null),C=_.useRef(null),k=_.useRef(!1),M=p&&p.length>0;dg();const T=(I,R,O=0)=>{if(k.current)return!0;const B=Math.abs(I.y),K=Math.abs(I.x),F=K>B,$=["bottom","right"].includes(R)?1:-1;if(R==="left"||R==="right"){if(!(I.x*$<0)&&K>=0&&K<=O)return F}else if(!(I.y*$<0)&&B>=0&&B<=O)return!F;return k.current=!0,!0};_.useEffect(()=>{M&&window.requestAnimationFrame(()=>{N(!0)})},[]);function D(I){S.current=null,k.current=!1,c(I)}return _.createElement(Mi,{"data-vaul-drawer-direction":b,"data-vaul-drawer":"","data-vaul-delayed-snap-points":w?"true":"false","data-vaul-snap-points":x&&M?"true":"false","data-vaul-custom-container":y?"true":"false","data-vaul-animate":v?.current?"true":"false",...r,ref:E,style:f&&f.length>0?{"--snap-point-height":`${f[m??0]}px`,...t}:t,onPointerDown:I=>{g||(r.onPointerDown==null||r.onPointerDown.call(r,I),S.current={x:I.pageX,y:I.pageY},i(I))},onOpenAutoFocus:I=>{n?.(I),j||I.preventDefault()},onPointerDownOutside:I=>{if(e?.(I),!h||I.defaultPrevented){I.preventDefault();return}d.current&&(d.current=!1)},onFocusOutside:I=>{if(!h){I.preventDefault();return}},onPointerMove:I=>{if(C.current=I,g||(r.onPointerMove==null||r.onPointerMove.call(r,I),!S.current))return;const R=I.pageY-S.current.y,O=I.pageX-S.current.x,B=I.pointerType==="touch"?10:2;T({x:O,y:R},b,B)?u(I):(Math.abs(O)>B||Math.abs(R)>B)&&(S.current=null)},onPointerUp:I=>{r.onPointerUp==null||r.onPointerUp.call(r,I),S.current=null,k.current=!1,c(I)},onPointerOut:I=>{r.onPointerOut==null||r.onPointerOut.call(r,I),D(C.current)},onContextMenu:I=>{r.onContextMenu==null||r.onContextMenu.call(r,I),C.current&&D(C.current)}})});Hi.displayName="Drawer.Content";const hg=250,gg=120,Wi=_.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:x}=Ns(),b=_.useRef(null),p=_.useRef(!1);function y(){if(p.current){j();return}window.setTimeout(()=>{g()},gg)}function g(){if(o||e||p.current){j();return}if(j(),!i||i.length===0){d||a();return}if(c===i[i.length-1]&&d){a();return}const N=i.findIndex(S=>S===c);if(N===-1)return;const E=i[N+1];u(E)}function v(){b.current=window.setTimeout(()=>{p.current=!0},hg)}function j(){b.current&&window.clearTimeout(b.current),p.current=!1}return _.createElement("div",{onClick:y,onPointerCancel:j,onPointerDown:w=>{f&&h(w),v()},onPointerMove:w=>{f&&x(w)},ref:r,"data-vaul-drawer-visible":m?"true":"false","data-vaul-handle":"","aria-hidden":"true",...n},_.createElement("span",{"data-vaul-handle-hitarea":"","aria-hidden":"true"},t))});Wi.displayName="Drawer.Handle";function pg(e){const t=Ns(),{container:n=t.container,...r}=e;return _.createElement(Ii,{container:n,...r})}const Oe={Root:mg,Content:Hi,Overlay:Qi,Portal:pg,Handle:Wi,Title:Ai},xg=new Set(["outbox","postvak uit","boîte d'envoi","postausgang","buzón de salida","posta in uscita","送信トレイ","送件匣","发件箱","skrzynka nadawcza"]),bg=e=>{const t=Vs(e.fullPath).trim().toLowerCase();return xg.has(t)},Da=Dn.length,jr=(e,t=[])=>{const n=ys(t);return[...e.filter(a=>{const o=n.get(a.mailboxId);return o==="drafts"||o==="sent"?!1:!bg(a)})].sort((a,o)=>{const i=n.has(a.mailboxId)?Dn.indexOf(n.get(a.mailboxId)??"inbox"):Da,c=n.has(o.mailboxId)?Dn.indexOf(n.get(o.mailboxId)??"inbox"):Da;return i!==c?i-c:Vs(a.fullPath).localeCompare(Vs(o.fullPath),void 0,{sensitivity:"base",numeric:!0})})},Vi="inline-flex items-center justify-center transition-colors",vg=fe(Vi,"min-h-11 min-w-11 rounded hover:bg-surface-raised"),yg=fe(Vi,"min-h-11 gap-1.5 px-3 rounded text-sm font-medium hover:bg-surface-raised"),ks=({accountId:e,currentMailboxId:t,onMove:n,disabled:r=!1,disabledHint:a,variant:o="icon-only",label:i})=>{const[c,u]=l.useState(!1),d=kt(),f=l.useRef(null),m=i??"Move to folder",h=l.useId(),{t:x}=tn("mail",{useSuspense:!1}),b=l.useCallback((M,T)=>x(M,{defaultValue:T}),[x]),{data:p,isLoading:y,isError:g,error:v,refetch:j}=ie({...et({path:{accountId:e}}),staleTime:1/0,enabled:c}),w=yi(e),N=l.useMemo(()=>{const M=jr(p?.items??[],w),T=ys(w);return M.map(D=>({id:D.mailboxId,label:Qt(D,T.get(D.mailboxId),b),searchValue:D.fullPath,isCurrent:D.mailboxId===t}))},[p?.items,w,t,b]),E=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)},T=D=>{D.key==="Escape"&&u(!1)};return document.addEventListener("mousedown",M),document.addEventListener("keydown",T),()=>{document.removeEventListener("mousedown",M),document.removeEventListener("keydown",T)}},[c,d]);const S=r||!!a,C=s.jsxs("button",{type:"button",onClick:M=>{M.stopPropagation(),!S&&u(T=>!T)},"aria-label":m,"aria-haspopup":d?"listbox":"dialog","aria-expanded":c,"aria-controls":c?h:void 0,title:a,className:o==="icon-only"?vg:yg,children:[s.jsx(Eo,{className:"size-4"}),o==="compact"&&s.jsx("span",{className:"hidden sm:inline",children:"Move"})]}),k=y?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(ft,{variant:"inline",title:"Couldn't load folders",error:v,onRetry:()=>j()})}):s.jsx(Vo,{mailboxes:N,onSelect:E,onCancel:()=>u(!1),autoFocus:!d,labels:{searchPlaceholder:x("move_picker_placeholder",{defaultValue:"Move to…"}),searchAriaLabel:x("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:fe("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(Oe.Root,{open:c,onOpenChange:u,children:s.jsxs(Oe.Portal,{children:[s.jsx(Oe.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),s.jsxs(Oe.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(Oe.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-subtle/30"}),s.jsx(Oe.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})]})]})})]})},wg=({messageId:e,threadId:t,mailboxId:n,isRead:r,accountId:a,fromAddressId:o,isTrusted:i=!1,showRaw:c=!1,onToggleRaw:u})=>{const d=je(),f=Ce(),{pushError:m}=ze(),{selectedMessageId:h}=Ut({strict:!1}),{mutate:x,isPending:b}=xe({...en(),onMutate:async O=>{const B=O.body.isRead??!0,K=new Set(O.body.messageIds??[]),F=jt({path:{threadId:t}}),$=tt({path:{mailboxId:n}}),U=ut({path:{mailboxId:n}});await Promise.all([d.cancelQueries({queryKey:F}),d.cancelQueries({queryKey:$}),d.cancelQueries({queryKey:U})]);const te=d.getQueriesData({queryKey:F}).filter(A=>A[1]!==void 0).map(([A,Y])=>({queryKey:A,data:Y})),Q=d.getQueriesData({queryKey:$}).concat(d.getQueriesData({queryKey:U})).filter(A=>A[1]!==void 0).map(([A,Y])=>({queryKey:A,data:Y}));d.setQueriesData({queryKey:F},A=>A&&{...A,items:A.items.map(Y=>K.has(Y.messageId)?{...Y,isRead:B}:Y)});const L=A=>A&&{...A,pages:A.pages.map(Y=>({...Y,items:Y.items.map(le=>K.has(le.messageId)?{...le,isRead:B}:le)}))};return d.setQueriesData({queryKey:$},L),d.setQueriesData({queryKey:U},L),{threadMessagesPrefix:F,threadsListPrefix:$,threadsSearchPrefix:U,previousThreadMessages:te,previousThreadsList:Q}},onError:(O,B,K)=>{if(K){for(const $ of K.previousThreadMessages)d.setQueryData($.queryKey,$.data);for(const $ of K.previousThreadsList)d.setQueryData($.queryKey,$.data)}const F=B.body.isRead??!0;m({title:F?"Couldn't mark as read":"Couldn't mark as unread",detail:$e(O)})},onSettled:(O,B,K,F)=>{F&&(d.invalidateQueries({queryKey:F.threadMessagesPrefix}),d.invalidateQueries({queryKey:F.threadsListPrefix}),d.invalidateQueries({queryKey:F.threadsSearchPrefix}))}}),p=l.useCallback(O=>{h&&O.includes(h)&&f({to:"/mail/$mailboxId",params:{mailboxId:n},search:B=>({...B,selectedMessageId:void 0})})},[h,n,f]),{deleteMessages:y,isPending:g}=ds({mailboxId:n,threadId:t,onAfterOptimisticRemove:p}),{moveMessages:v,isPending:j}=ct({mailboxId:n,threadId:t,accountId:a,onAfterOptimisticRemove:p}),{toggleTrusted:w,isPending:N,error:E,reset:S}=br({messageId:e}),C=()=>{x({body:{messageIds:[e],isRead:!1}})},k=()=>{y([e])},M=()=>{o&&w(o,i)},T=b||g||j||N,D=T||!o,I=l.useCallback(O=>{v([e],O)},[v,e]),R=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(ks,{accountId:a,currentMailboxId:n,onMove:I,disabled:T,label:"Move this message"}),s.jsxs(ji,{trigger:s.jsx(Co,{className:"size-4"}),children:[s.jsxs($t,{onClick:M,disabled:D,children:[i?s.jsx(sn,{className:"size-4 text-positive"}):s.jsx(ws,{className:"size-4 opacity-0"}),s.jsx("span",{title:R,children:"Trusted sender"})]}),r&&s.jsxs($t,{onClick:C,disabled:T,children:[s.jsx(js,{className:"size-4"}),"Mark as unread"]}),u&&s.jsxs($t,{onClick:u,children:[s.jsx(ko,{className:"size-4"}),c?"Show formatted":"Show raw email"]}),s.jsx(Bn,{}),s.jsxs($t,{onClick:k,disabled:T,destructive:!0,children:[s.jsx(qe,{className:"size-4"}),"Delete"]})]})]}),E&&s.jsx("div",{className:"w-64",children:s.jsx(ft,{variant:"inline",title:"Couldn't update trust",error:E,onRetry:()=>{S(),M()}})})]})},jg=()=>{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},Sg=({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"})]})]}),Ng=(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}}},kg=e=>e instanceof bt?e.reason:"generic",Cg=e=>e instanceof Error?e.message:typeof e=="string"?e:"An unexpected error occurred while loading the message body.",Eg=({error:e,onRetry:t})=>{const n=kg(e),r=Cg(e),{title:a,detail:o}=Ng(n,r),[i,c]=l.useState(!1),{Account:u}=Xn();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(yt,{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(Pe,{className:"size-4","aria-hidden":"true"})})]})]})},Ig=()=>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"})]}),Aa=()=>s.jsx("p",{className:"text-fg-muted text-sm italic",children:"This message has no body content."}),Yi=({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=jg(),{toggleTrusted:h,isPending:x}=br({messageId:a??""}),b=!!e&&e.length>0,{picked:p,data:y,isLoading:g,isError:v,error:j,refetch:w}=di({messageId:a,bodyParts:e,enabled:b}),N=l.useMemo(()=>_u(e??[]),[e]),E=b&&y?.kind==="html"?y.body:t,S=b&&y?.kind==="text"?y.body:n;if(b){if(g)return s.jsx("div",{className:fe("message-body",c),children:s.jsx(Ig,{})});if(v)return s.jsx("div",{className:fe("message-body",c),children:s.jsx(Eg,{error:j,onRetry:()=>w()})});if(!p)return s.jsx("div",{className:fe("message-body",c),children:s.jsx(Aa,{})})}else if(!t&&!n)return s.jsx("div",{className:fe("message-body",c),children:s.jsx(Aa,{})});const C=!!(o&&a),k=()=>{!o||x||(d(!0),h(o,!1))};return s.jsx(Uo,{className:c,html:E,text:S,isDark:m,category:i,allowImages:f,resolveCid:N,renderBlockedNotice:M=>s.jsx(Sg,{blockedImageCount:M,canAlwaysTrust:C,isTrustPending:x,onLoadOnce:()=>d(!0),onAlwaysTrust:k})})},Rg=({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:x})=>{const b=je(),{deleteMessages:p}=ds({mailboxId:n,threadId:t}),{moveMessages:y}=ct({mailboxId:n,threadId:t,accountId:r}),{toggleTrusted:g}=br({messageId:e}),{mutate:v}=xe({...en(),onSettled:()=>{b.invalidateQueries({queryKey:jt({path:{threadId:t}})}),b.invalidateQueries({queryKey:tt({path:{mailboxId:n}})}),b.invalidateQueries({queryKey:ut({path:{mailboxId:n}})})}}),j=l.useCallback(S=>{y([e],S)},[y,e]),w=l.useCallback(()=>{p([e])},[p,e]),N=l.useCallback(()=>{v({body:{messageIds:[e],isRead:!a}})},[v,e,a]),E=[];return c&&E.push({key:"trusted",label:u?"Trusted sender":"Mark sender trusted",icon:u?s.jsx(sn,{className:"size-4 text-positive"}):s.jsx(ws,{className:"size-4"}),onSelect:()=>g(c,u)}),f&&E.push({key:"raw",label:d?"Show formatted":"Show raw email",icon:s.jsx(ko,{className:"size-4"}),onSelect:f}),s.jsx(qo,{hasThread:!0,onReply:m,onReplyAll:h,onForward:x,isStarred:o,onToggleStar:i,onDelete:w,isRead:a,onToggleRead:N,overflowItems:E,moveSlot:r?s.jsx(ks,{accountId:r,currentMailboxId:n,onMove:j,label:"Move this message"}):void 0})},Mg=()=>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"})]}),Tg=({messageId:e,enabled:t=!0})=>{const{data:n,isLoading:r,isError:a,error:o,refetch:i}=ie({...Ec({path:{messageId:e}}),enabled:t});if(r)return s.jsx("div",{className:"message-body",children:s.jsx(Mg,{})});if(a)return s.jsx("div",{className:"message-body",children:s.jsx(ft,{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})})},Dg=()=>s.jsx(sn,{className:"inline-block size-4 ml-1 -mt-0.5 text-positive align-middle","aria-label":"Trusted sender","data-testid":"trusted-sender-badge"}),Gi=(e,t)=>({id:e.messageId,fromName:e.fromName??e.fromEmail??"?",fromEmail:e.fromEmail??"",toLabel:"",dateLabel:t,snippet:e.snippet||"",bodyHtml:""}),Xi=({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:fe("shrink-0 p-0.5 rounded transition-colors",e?"text-warning":fe("text-fg-subtle hover:text-warning",r&&"opacity-0 group-hover:opacity-100 focus:opacity-100"),n&&"opacity-50"),children:s.jsx(dt,{className:fe("size-3.5",e&&"fill-current")})}),Ag=({threadMessage:e,isFocused:t,onToggle:n,onToggleStar:r,isStarPending:a})=>{const o=yo(e.sentDate,"datetime"),i=Gi(e,o);return s.jsx(Qo,{message:i,onClick:n,isFocused:t,isUnread:!e.isRead,trailing:s.jsxs(s.Fragment,{children:[e.hasAttachment&&s.jsx(nn,{className:"size-3 shrink-0 text-fg-subtle"}),s.jsx(Xi,{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})]})})},Og=({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:x,onReply:b,onReplyAll:p,onForward:y})=>{const g=yo(e.sentDate,"long"),v=!e.isRead,j=t?.envelope.from[0]?.flags?.trusted?.value===!0,w=t?.envelope.from[0]?.addressId,N=Gi(e,g),E=e.autoMoved?s.jsx(wi,{accountId:f,messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,autoMoved:e.autoMoved,size:"md"}):null;return s.jsx(Ho,{message:N,isFocused:i,onHeaderClick:c,senderBadge:j?s.jsx(Dg,{}):void 0,trailing:s.jsx("span",{"data-testid":"message-date",className:"text-2xs text-fg-subtle",children:g}),to:t?s.jsx(yu,{label:"To",addresses:t.envelope.to}):null,indicators:E||!x?s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mt-0.5",children:[E,!x&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex items-center justify-end gap-1",children:[s.jsx(Xi,{isStarred:e.hasStars,onToggleStar:u,isStarPending:d}),e.hasAttachment&&s.jsx("span",{className:"text-fg-subtle p-0.5",children:s.jsx(nn,{className:"size-3.5"})})]}),v&&s.jsx("span",{className:"size-1.5 rounded-full bg-accent","aria-label":"Unread"})]})]}):void 0,actionMenu:x?void 0:s.jsx(wg,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,isRead:e.isRead,accountId:f,fromAddressId:w,isTrusted:j,showRaw:m,onToggleRaw:h}),actionBar:x?s.jsx(Rg,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,accountId:f,isRead:e.isRead,isStarred:e.hasStars,onToggleStar:u,fromAddressId:w,isTrusted:j,showRaw:m,onToggleRaw:h,onReply:b,onReplyAll:p,onForward:y}):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&&Ic(a)?s.jsx("div",{className:"mt-3",children:s.jsx(xi,{message:"This message has been deleted"})}):r?s.jsx("div",{className:"mt-3",children:s.jsx(ft,{variant:"inline",title:"Couldn't load this message",error:a,onRetry:o})}):m?s.jsx("div",{className:"mt-3",children:s.jsx(Tg,{messageId:e.messageId})}):s.jsx("div",{className:"mt-3",children:s.jsx(Yi,{bodyParts:t?.bodyParts,messageId:e.messageId,fromAddressId:t?.envelope.from[0]?.addressId,isTrusted:j,category:ln(e.category)})})})},Pg=({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:x,isLoading:b,isError:p,error:y,refetch:g}=ie({...Jn({path:{messageId:e.messageId}}),enabled:t,meta:{softError:!0}});return t?s.jsx(Og,{threadMessage:e,messageData:x,isLoading:b,isError:p,error:y,onRetry:()=>g(),isFocused:n,onToggle:r,onToggleStar:a,isStarPending:o,accountId:i,showRaw:m,onToggleRaw:()=>h(v=>!v),mobile:c,onReply:u,onReplyAll:d,onForward:f}):s.jsx(Ag,{threadMessage:e,isFocused:n,onToggle:r,onToggleStar:a,isStarPending:o})},Lg=()=>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 Oa({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(Ss,{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 Zt=({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=kt(),{handlers:x}=Sh({onSwipeLeft:d,onSwipeRight:f}),{accountId:b}=bi(t),{data:p,isLoading:y,isError:g,error:v,refetch:j}=ie({...Rc({path:{threadId:e},query:{order:"desc",mailboxId:t}})}),w=l.useMemo(()=>p?.items??[],[p?.items]),N=l.useRef(new Map),[E,S]=l.useState(new Set),[C,k]=l.useState(null),[M,T]=l.useState(0);l.useEffect(()=>{if(w.length>0&&e!==C){k(e);const W=new Set([w[0].threadMessageId]);if(r){const ee=w.find(ne=>ne.messageId===r);ee&&W.add(ee.threadMessageId)}S(W),T(0)}},[e,w,C,r]);const D=l.useCallback(W=>{S(ee=>{const ne=new Set(ee);return ne.has(W)?ne.delete(W):ne.add(W),ne})},[]),I=l.useCallback(W=>{const ee=w[W];if(!ee)return;N.current.get(ee.threadMessageId)?.scrollIntoView({behavior:"smooth",block:"nearest"})},[w]),R=l.useCallback(()=>{if(w.length===0)return;const W=Math.min(M+1,w.length-1);T(W),I(W)},[w.length,M,I]),O=l.useCallback(()=>{if(w.length===0)return;const W=Math.max(M-1,0);T(W),I(W)},[w.length,M,I]),B=l.useCallback(()=>{const W=w[M];W&&D(W.threadMessageId)},[w,M,D]),{data:K}=ie({...Ze(),staleTime:1/0}),F=K?.accounts?.[0],$=!!F?.smtpHost;vh({messages:w,expandedIds:E,threadId:e,mailboxId:t,accountId:F?.accountId});const{toggleStar:U,isPending:te,pendingMessageId:Q}=Fn({threadId:e,mailboxId:t}),[L,A]=l.useState(null);l.useEffect(()=>{c&&c!=="new"&&(A(c),u?.())},[c,u]);const Y=w[0],{data:le}=ie({...Jn({path:{messageId:Y?.messageId??""}}),enabled:!!Y&&L!==null}),ve=l.useCallback(()=>{A("reply")},[]),ce=l.useCallback(()=>{A("reply_all")},[]),ye=l.useCallback(()=>{A("forward")},[]),Se=l.useCallback(()=>{A(null),u?.()},[u]);if(ps({enabled:!y&&w.length>0&&L===null,bindings:[{key:"j",handler:R,preventDefault:!0},{key:"ArrowDown",handler:R,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},...$?[{key:"r",handler:ve,preventDefault:!0},{key:"R",handler:ce,noModifiers:!1,preventDefault:!0},{key:"f",handler:ye,preventDefault:!0}]:[]]}),y)return s.jsx(Lg,{});if(g)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsx(ft,{title:"Couldn't load this conversation",error:v,onRetry:()=>j()})});if(w.length===0)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsx(xi,{message:"No messages in this thread"})});const G=n||w[0]?.subject||"(No subject)",ge=w.length,Ie=W=>s.jsx("div",{children:w.map((ee,ne)=>s.jsx("div",{ref:Ue=>{Ue&&N.current.set(ee.threadMessageId,Ue)},children:s.jsx(Pg,{threadMessage:ee,isExpanded:E.has(ee.threadMessageId),isFocused:ne===M,onToggle:()=>D(ee.threadMessageId),onToggleStar:()=>U(ee.messageId,ee.hasStars),isStarPending:te&&Q===ee.messageId,accountId:b,mobile:W,onReply:W&&$?ve:void 0,onReplyAll:W&&$?ce:void 0,onForward:W&&$?ye:void 0})},ee.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:G}),s.jsxs("p",{className:"mt-1 text-2xs text-fg-subtle",children:[ge," ",ge===1?"message":"messages"]})]});return h?s.jsxs("article",{className:"h-full flex flex-col",children:[H,a?.dkimMismatch&&s.jsx(Oa,{authenticity:a,onOpenIntelligence:o}),s.jsx("div",{className:"flex-1 overflow-auto",children:Ie(!1)}),L!==null&&s.jsx(ja,{mode:L,account:F,sourceMessage:le,onClose:Se})]}):s.jsxs(id,{thread:{subject:G,messages:[]},onBack:i??(()=>{}),intelligenceOpen:m,onToggleIntelligence:o,touchHandlers:x,children:[a?.dkimMismatch&&s.jsx(Oa,{authenticity:a,onOpenIntelligence:o}),Ie(!0),L!==null&&s.jsx(ja,{mode:L,account:F,sourceMessage:le,onClose:Se})]})},Ji=e=>e.trim().toLocaleLowerCase(),zg=/^\d{4}-\d{2}-\d{2}$/;function Pa(e,t,n){if(!zg.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 _g(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 Pa("before",e,e.slice(7));if(n.startsWith("after:")&&e.length>6)return Pa("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 Cs(e,t={}){const n=e.split(/\s+/).filter(o=>o.length>0),r=[],a=[];for(const o of n){const i=_g(o,t);i?r.push(i):a.push(o)}return{freeText:a.join(" "),tokens:r}}function Fg(e,t){return e.split(/\s+/).filter(n=>n.length>0&&n!==t.raw).join(" ")}function Bg(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 $g=20,Kg=new Set(Object.values(Ge)),qg=e=>e!==void 0&&Kg.has(e)?e:void 0;function Zi({mailboxId:e,filterCategory:t}={}){const{searchQuery:n,mailboxNameIndex:r,accountNameIndex:a}=Ee(),o=Ji(n),{freeText:i,tokens:c}=Cs(o,{mailboxesByName:r,accountsByName:a}),u=o.length>0,d=qg(t),f=c.some(v=>v.type==="hasAttachment")?!0:void 0,m=c.some(v=>v.type==="isUnread")?!1:void 0,h=c.find(v=>v.type==="after"),x=c.find(v=>v.type==="before"),p=c.find(v=>v.type==="in")?.mailboxId??e,{data:y,isLoading:g}=ie({...ho({query:{query:i,mailboxId:p,limit:$g,...d!==void 0?{category:d}:{},...f!==void 0?{hasAttachment:f}:{},...m!==void 0?{isRead:m}:{},...h?{sentDateFrom:h.epochSeconds}:{},...x?{sentDateTo:x.epochSeconds}:{}}}),enabled:u,staleTime:6e4});return{hits:y?.items??[],isLoading:u&&g}}const Ug=(e,t)=>e.createdAt!==t.createdAt?e.createdAt-t.createdAt:e.accountId.localeCompare(t.accountId),Qg=e=>[...e].sort(Ug);function el(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:mt(e.sentDate),sentDate:e.sentDate,isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:ln(e.category),suspicious:t}}const La=[{id:"personal",label:"Personal",category:Ge.personal},{id:"transactional",label:"Transactional",category:Ge.transactional},{id:"newsletter",label:"Newsletter",category:Ge.newsletter},{id:"marketing",label:"Marketing",category:Ge.marketing},{id:"social",label:"Social",category:Ge.social},{id:"automated",label:"Automated",category:Ge.automated}];function Hg(e){const t=new Map(La.map(r=>[r.category,[]]));for(const r of e){const a=r.category??Ge.personal;(t.get(a)??t.get(Ge.personal))?.push(r)}const n=[];for(const r of La){const a=t.get(r.category);a&&a.length>0&&n.push({id:r.id,label:r.label,threads:a})}return n}function tl(e,t){return e.fromName.toLowerCase().includes(t)||e.fromEmail.toLowerCase().includes(t)||e.subject.toLowerCase().includes(t)||e.snippet.toLowerCase().includes(t)}function sl(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 Wg={sender:"sender",recipient:"recipient",subject:"subject",attachment:"attachment",body:"body",entities:"entities"};function Vg(e){return Wg[e]??e}function Yg(e){return{id:e.messageId,sender:e.fromName??e.fromEmail??"Unknown",subject:e.subject??"(No subject)",snippet:e.snippet??"",date:mt(e.sentDate),unread:!e.isRead,flagged:e.hasStars===!0,threadId:e.threadId,mailboxId:e.mailboxId}}function nl(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 Gg(e){return{id:e.messageId,sender:e.fromName??"Unknown",subject:e.subject??"(No subject)",snippet:"",date:e.sentDate!=null?mt(e.sentDate*1e3):"",threadId:e.threadId,matchedChunkLabel:Vg(e.matchedChunkType),score:e.score,...e.mailboxIds[0]!=null?{mailboxId:e.mailboxIds[0]}:{}}}function rl(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(Gg(a)));return r}const Xg=768,Jg=1024,Zg=e=>e!=="desktop",Es=()=>{const e=_n(`(min-width: ${Xg}px)`);return _n(`(min-width: ${Jg}px)`)?"desktop":e?"tablet":"phone"},al="remit.recentSearches",ep=5;function qn(){try{const e=localStorage.getItem(al);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(n=>typeof n=="string"):[]}catch{return[]}}function za(e){const t=e.trim();if(!t)return qn();const n=[t,...qn().filter(r=>r!==t)].slice(0,ep);try{localStorage.setItem(al,JSON.stringify(n))}catch{return n}return n}function ol({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:x,accountNameIndex:b}=Ee(),p=Zn(),y=Es(),[g,v]=l.useState(!1),[j,w]=l.useState(qn),N=f.trim().length>0,E=Cs(f,{mailboxesByName:x,accountsByName:b}).tokens.map(B=>({label:Bg(B),onRemove:()=>m(Fg(f,B))})),S=o??[],C=c??[],k=N?[{id:"top",label:"Top matches",results:S},{id:"related",label:"Related",results:C}]:[],T=!(S.length+C.length>0)&&(i===!0||u===!0);if(y==="phone"&&g){const B=K=>{w(za(f)),v(!1),d?.(K)};return s.jsx(_d,{value:f,onChange:m,onClear:h,onCancel:()=>{v(!1),h()},filter:a,recentSearches:j,onPickRecent:m,sections:k,loading:T,onSelectResult:B,tokens:E})}const D=y!=="phone"&&N,I=B=>{w(za(f)),d?.(B)},R=s.jsx(Wo,{value:f,sections:k,loading:T,onSelectResult:I,tokens:E}),O=D?a?s.jsx(Hn,{...a,children:R}):s.jsx("div",{className:"h-full overflow-y-auto",children:R}):n;return s.jsxs("section",{className:"flex h-full w-full flex-col bg-surface",children:[s.jsx(Ad,{title:e,unreadCount:t,isDesktop:!1,onMenuClick:()=>p?.openNav(),searchValue:f,onSearchChange:m,onSearchClear:h,searchOpen:g,onSearchOpenChange:v}),s.jsx("div",{className:"min-h-0 flex-1",children:O}),r]})}const tp={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()},_a=()=>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))}),sp=({accountEmail:e})=>{const t=Ce();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(yt,{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"})]})},np=({thread:e,active:t,onClick:n})=>{const r=!e.isRead;return s.jsxs("button",{type:"button",onClick:n,className:q("group w-full",Yt({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(st,{name:e.fromName,email:e.fromEmail,size:"sm"}),s.jsx(Gt,{thread:e})]})};function il({accounts:e,selectedMessageId:t,onSelectMessage:n,onSelectSearchResult:r}){const{searchQuery:a,mailboxNameIndex:o,accountNameIndex:i}=Ee(),c=kt(),u=l.useMemo(()=>Qg(e.filter(L=>!L.muted?.value)),[e]),[d,f]=l.useState("all"),[m,h]=l.useState("all"),[x,b]=l.useState(new Set),[p,y]=l.useState(!1),g=l.useCallback(L=>{b(A=>{const Y=new Set(A);return Y.has(L)?Y.delete(L):Y.add(L),Y})},[]),{data:v,isLoading:j,isError:w,refetch:N}=ie({...er(),staleTime:6e4}),E=Jt({queries:u.map(L=>({...et({path:{accountId:L.accountId}}),staleTime:1/0,meta:{softError:!0}}))}),S=l.useMemo(()=>{const L=new Map;for(let A=0;A<u.length;A++){const Y=u[A].accountId,ve=(E[A]?.data?.items??[]).reduce((ce,ye)=>ce+(ye.unseenCount??0),0);L.set(Y,ve)}return L},[u,E]),C=l.useMemo(()=>u.filter((L,A)=>{const Y=E[A];return Y?.isError?!Tn(Y.error):!1}),[u,E]),{freeText:k,tokens:M}=Cs(a.trim().toLowerCase(),{mailboxesByName:o,accountsByName:i}),T=l.useMemo(()=>(v?.items??[]).filter(A=>d==="all"||(A.accountId??A.accountConfigId)===d).map(el).filter(A=>(!k||tl(A,k))&&sl(A,M)),[v,d,k,M]),D=l.useMemo(()=>Hg(T),[T]),I=l.useMemo(()=>u.length<=1?[]:[{id:"all",label:"All",active:d==="all"},...u.map(L=>({id:L.accountId,label:L.email.split("@")[0]??L.email,count:S.get(L.accountId),active:d===L.accountId}))],[u,S,d]),R=l.useMemo(()=>e.filter(L=>L.muted?.value).length,[e]),O=l.useMemo(()=>Array.from(S.values()).reduce((L,A)=>L+A,0),[S]),B=l.useMemo(()=>{const L=Array.from(x).map(A=>tp[A]).filter(A=>A!=null);return T.filter(A=>(m==="all"||A.category===m)&&L.every(Y=>Y(A))).map(nl)},[T,m,x]),{hits:K,isLoading:F}=Zi(),$=l.useMemo(()=>{const L=new Map;for(const Y of v?.items??[])L.set(Y.messageId,Y.threadId);const A=B.map(Y=>L.get(Y.id)).filter(Y=>Y!=null);return rl(K,A)},[K,B,v]),U=l.useMemo(()=>{const L=af(I.map(A=>({id:A.id,label:A.label,count:A.count,active:A.active})));return{categories:L.categories,filters:L.filters,sources:L.sources,sourcesNote:R>0?`+${R} muted`:void 0,selectedCategory:m,activeFilters:x,expanded:p,onExpandedChange:y,onSelectCategory:A=>h(A),onSelectSource:f,onToggleFilter:g,onClear:()=>{h("all"),f("all"),b(new Set)}}},[I,R,m,x,p,g]),te=D.length===0&&d==="all"&&k.length===0,Q=j?s.jsxs("div",{className:"h-full overflow-y-auto",children:[s.jsx(_a,{}),s.jsx(_a,{})]}):w?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(yt,{className:"size-8 text-danger"}),s.jsx("p",{children:"Couldn't load your messages"}),s.jsxs("button",{type:"button",onClick:()=>N(),className:"flex items-center gap-1 text-accent underline text-xs",children:[s.jsx(Mo,{className:"size-3.5"}),"Try again"]})]}):te?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 py-12 text-center px-4",children:[s.jsx(Ke,{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(Xa,{sections:D,Row:np,briefCategory:m,onSelectBriefCategory:h,sources:I,sourcesNote:R>0?`+${R} muted`:void 0,onSelectSource:f,selectedThreadId:t,onSelectThread:n});return s.jsx(ol,{title:"Daily brief",unreadCount:O,footer:c?s.jsx(Po,{}):void 0,searchFilter:U,searchResults:B,searchLoading:j,relatedResults:$,relatedLoading:F,onSelectSearchResult:r,children:s.jsxs("div",{className:"flex h-full flex-col",children:[C.map(L=>s.jsx(sp,{accountEmail:L.email,accountId:L.accountId},L.accountId)),s.jsx("div",{className:"min-h-0 flex-1",children:Q})]})})}const ll=({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","aria-hidden":"true",onClick:u,children:[s.jsx("div",{className:"absolute inset-0 bg-canvas/80 backdrop-blur-sm"}),s.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":t,className:fe("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:fe("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:fe("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};function rp(e){const t=new Date(e),n=new Date;return t.toDateString()===n.toDateString()?"today":Ws(t,{month:"short",year:"numeric"})}function cl(e){if(!e)return!0;const[,t]=e.split("@");return t?!t.includes("."):!0}const ap="We can't verify the sender of this email, which could mean it's from an insecure source.",op="We couldn't read this sender's address, so we can't confirm who really sent this message.";function ip(e,t){return{name:e.fromName??e.fromEmail??"Unknown",email:e.fromEmail??"",trust:e.senderTrust,firstSeenLabel:t?rp(t.createdAt):"unknown",inboundCount:t?.inboundCount,replyCount:t?.replyCount,addressUnverified:cl(e.fromEmail)}}function lp(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 cp(e,t){const n=t>0?t:void 0;if(cl(e.fromEmail))return{verdict:"mismatch",fromDomain:"",addressUnreadable:!0,summary:op,similarCount:n};const r=e.authenticity;if(!r)return{verdict:"caution",fromDomain:e.fromEmail?.split("@")[1]??"",summary:ap};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 ul(e,t){const n=e?.fromEmail??null,r=e?.subject??"",{data:a,error:o}=ie({...co({query:{q:n??"",limit:1}}),enabled:!!n,staleTime:3e4}),i=a?.items?.[0],c=[r,n].filter(Boolean).join(" "),{data:u,isLoading:d,error:f}=ie({...ho({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?mt(g.sentDate*1e3):"",matched:g.matchedChunkType})),x=ip(e,i),b=cp(e,h.length),p={value:e.category??"personal",overridden:i?.flags?.category?.value!=null&&i.flags.category.value!==e.category},y=lp(i);return{sender:x,authenticity:b,category:p,flags:y,similar:h}},[e,i,u,t]),isSimilarLoading:d,similarError:f,similarErrorIsFatal:Tn(f),addressErrorIsFatal:Tn(o),addressId:i?.addressId,address:i}}function up(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 dl({addressId:e,senderEmail:t}){const n=je(),{pushError:r}=ze(),a=Mc({query:{q:t??"",limit:1}}),{mutate:o,isPending:i}=xe({...mo(),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:up(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:$e(u)})},onSettled:()=>{n.invalidateQueries({queryKey:a})}});return{updateFlags:l.useCallback(u=>{if(!e){go(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 dp=e=>e==="vip"?"A sender you know":e==="wellknown"?"You've emailed them before":"Passed authentication",fl=e=>e.senderTrust!=="vip"&&e.senderTrust!=="wellknown"?!1:e.authenticity?.dkimMismatch!==!0;function fp(e,t){e.recordEvent("rescue.candidates_surfaced",{count:String(t)})}function mp(e,t){e.recordEvent("rescue.flow_opened",{count:String(t)})}function hp(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 gp=["personal","newsletter","marketing","automated","transactional","social"],pp=e=>{const{mailboxId:t,junkMailboxId:n,inboxMailboxId:r}=e;return t?n&&t===n?r?"notSpam":null:n?"markSpam":null:null},xp=e=>{const{similarError:t,similarErrorIsFatal:n,isSimilarLoading:r}=e;return t&&!n?"error":r?"loading":"ready"};function bp(){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(Ke,{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 vp({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:gp.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 yp({thread:e,onClose:t,mailboxId:n,accountId:r,hideCloseButton:a}){const{data:o,addressId:i,isSimilarLoading:c,similarError:u,similarErrorIsFatal:d}=ul(e,n),[f,m]=l.useState(!1),[h,x]=l.useState(!1),b=e.fromEmail??void 0,{updateFlags:p,isPending:y}=dl({addressId:i,senderEmail:b}),{junkMailboxId:g}=xr(r),{inboxMailboxId:v}=pr(r),{moveMessages:j}=ct({mailboxId:n??"",threadId:e.threadId,accountId:r}),w=xs(),N=pp({mailboxId:n,junkMailboxId:g,inboxMailboxId:v}),E=l.useCallback(()=>{v&&j([e.messageId],v)},[v,j,e.messageId]),S=l.useCallback(()=>{g&&(ml(w,{count:1,senderTrust:e.senderTrust,wasRescuable:fl(e)}),j([e.messageId],g))},[g,j,e,w]),C=l.useCallback(()=>{},[]),k=l.useCallback(()=>{const F=o?.flags?.vip!==!0;p({vip:{value:F}})},[o?.flags?.vip,p]),M=l.useCallback(()=>{const F=o?.flags?.muted!==!0;p({muted:{value:F}})},[o?.flags?.muted,p]),T=l.useCallback(()=>{o?.flags?.blocked===!0?p({blocked:{value:!1}}):m(!0)},[o?.flags?.blocked,p]),D=l.useCallback(()=>{m(!1),p({blocked:{value:!0}})},[p]),I=l.useCallback(()=>{const F=o?.flags?.unsubscribed!==!0;p({unsubscribed:{value:F}})},[o?.flags?.unsubscribed,p]),R=l.useCallback(F=>{x(!1),p({category:{value:F}})},[p]),O={onToggleVip:k,onToggleMute:M,onToggleBlock:T,onToggleUnsubscribe:I,onReclassify:()=>x(!0),onNotSpam:N==="notSpam"?E:void 0,onMarkSpam:N==="markSpam"?S:void 0},B=({mailboxId:F,messageId:$,className:U,ariaLabel:te,children:Q})=>s.jsx(Xe,{to:"/mail/$mailboxId",params:{mailboxId:F},search:L=>({...L,selectedMessageId:$}),className:U,"aria-label":te,children:Q});if(!o)return s.jsx(bp,{});const K=xp({similarError:u,similarErrorIsFatal:d,isSimilarLoading:c});return s.jsxs(s.Fragment,{children:[s.jsx(Oo,{data:o,onClose:t,hideCloseButton:a,onShowSimilar:C,actions:O,similarState:K,similarLinkComponent:B,className:"border-l-0 h-full w-full"}),s.jsx(ll,{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:y,onConfirm:D,onCancel:()=>m(!1)}),s.jsx(vp,{isOpen:h,current:o.category.value,onSelect:R,onCancel:()=>x(!1)})]})}const dn=({onClose:e,thread:t,mailboxId:n,accountId:r,hideCloseButton:a})=>t?s.jsx(yp,{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(Ke,{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(Ke,{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."})]})]}),hl=({children:e})=>{const{Account:t}=Xn();return s.jsx(t,{children:e})},wp=({email:e,onSignOut:t})=>{const n=Ce(),r=e??"Account";return s.jsxs(ji,{trigger:s.jsx(st,{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(Bn,{})]}),s.jsxs($t,{onClick:()=>n({to:"/settings/accounts"}),children:[s.jsx(Ao,{className:"size-4"}),"Settings"]}),s.jsx(Bn,{}),s.jsxs($t,{onClick:t,children:[s.jsx(Ro,{className:"size-4"}),"Sign out"]})]})},jp=()=>s.jsx(hl,{children:({email:e,signOut:t})=>s.jsx(wp,{email:e,onSignOut:t})}),Fa=()=>{const e=tr(),t=sr(e);window.open(t,"_blank","noopener,noreferrer")};function gl({variant:e="icon"}){return e==="drawer"?s.jsxs("button",{type:"button",onClick:Fa,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(zr,{className:"size-4 shrink-0"}),s.jsx("span",{className:"flex-1 truncate text-left",children:"Report a bug"})]}):s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(zr,{className:"size-4"}),title:"Report a bug","aria-label":"Report a bug",onClick:Fa})}const pl=[{title:"Navigation",hints:[{action:"focusNext",keys:["j"],description:"Focus next message"},{action:"focusPrevious",keys:["k"],description:"Focus previous message"},{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:"extendSelectDown",keys:["Shift","j"],description:"Extend selection down"},{action:"extendSelectUp",keys:["Shift","k"],description:"Extend selection up"}]},{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 Sp(e){for(const t of pl){const n=t.hints.find(r=>r.action===e);if(n)return n.keys}}function Ft(e){const t=Sp(e);return!t||t.length===0?"":t.length===1?`(${t[0]})`:t[0]==="g"?`(${t.join(" then ")})`:`(${t.join("")})`}const En="Open a message first",Sr=({hasThread:e,onCompose:t,intelligenceOpen:n,showIntelligenceToggle:r,onToggleIntelligence:a,searchValue:o,onSearchChange:i,onSearchClear:c,onSearchClearQuery:u,onReply:d,onReplyAll:f,onForward:m,onDelete:h,canDelete:x,onToggleStar:b,isStarred:p,moveContext:y})=>{const[g,v]=l.useState(null),j=x??e,w=N=>()=>v(N);return s.jsxs(Pu,{hasThread:e,isStarred:p,onUnavailable:N=>v(En),unavailableHint:g,replyTitle:`Reply ${Ft("reply")}`,replyAllTitle:`Reply all ${Ft("replyAll")}`,forwardTitle:`Forward ${Ft("forward")}`,deleteTitle:`Move to Trash ${Ft("delete")}`,flagTitle:`Star ${Ft("toggleStar")}`,onReply:d,onReplyAll:f,onForward:m,onDelete:j?h:w(En),onToggleStar:b,onMove:w(En),moveSlot:y?s.jsx(ks,{accountId:y.accountId,currentMailboxId:y.currentMailboxId,onMove:y.onMove,label:"Move to mailbox"}):void 0,children:[s.jsx("div",{className:"w-64 min-w-40 shrink",children:s.jsx(lr,{value:o,onChange:i,onClear:c,onClearQuery:u,placeholder:"Search mail"})}),s.jsx("span",{className:"mx-1 h-4 w-px bg-line","aria-hidden":!0}),s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(xu,{className:"size-4"}),title:`Compose ${Ft("compose")}`,"aria-label":"Compose",onClick:t}),r&&s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(Za,{className:"size-4"}),title:"Intelligence","aria-label":n?"Hide intelligence sidebar":"Show intelligence sidebar","aria-pressed":n,onClick:a,className:n?"bg-accent-2-soft text-accent-2":void 0}),s.jsx(gl,{}),s.jsx(jp,{})]})};function Np(e){return{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,messageId:e.messageId,authenticity:e.authenticity}}function xl(e,t){if(e)return Np(e);if(t.messageId&&t.threadId&&t.mailboxId)return{threadId:t.threadId,mailboxId:t.mailboxId,messageId:t.messageId}}const bl=l.createContext(null);function Nr(){const e=l.useContext(bl);if(!e)throw new Error("BriefPane.* must be used inside <BriefPane>");return e}function kp({selectedMessageId:e,children:t}){const n=Ce(),{searchInput:r}=Ee(),{selectedThreadId:a,selectedMailboxId:o}=Ut({strict:!1}),{data:i}=ie({...er(),staleTime:6e4}),c=l.useMemo(()=>{if(e)return i?.items.find(x=>x.messageId===e)},[i,e]),u=l.useMemo(()=>xl(c,{messageId:e,threadId:a,mailboxId:o}),[c,e,a,o]),d=l.useCallback(x=>{n({to:"/mail",search:b=>({...b,selectedMessageId:x,selectedThreadId:void 0,selectedMailboxId:void 0})})},[n]),f=l.useCallback(x=>{n({to:"/mail",search:b=>({...b,q:r||void 0,selectedMessageId:x.id,selectedThreadId:x.threadId,selectedMailboxId:x.mailboxId})})},[n,r]),m=l.useCallback(()=>{n({to:"/mail",search:x=>({...x,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(bl.Provider,{value:h,children:t})}function Cp(){const{selectedMessageId:e,onSelectMessage:t,onSelectSearchResult:n}=Nr(),{accounts:r}=Ee();return s.jsx(il,{accounts:r,selectedMessageId:e,onSelectMessage:t,onSelectSearchResult:n})}function Ep(){const{conversation:e}=Nr(),{onToggleIntelligence:t,searchInput:n,onSearchChange:r,onSearchClear:a,onSearchClearQuery:o}=Ee();return s.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[s.jsx(Sr,{hasThread:!!e,onCompose:()=>{},intelligenceOpen:!1,showIntelligenceToggle:!1,onToggleIntelligence:t,searchValue:n,onSearchChange:r,onSearchClear:a,onSearchClearQuery:o}),s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?s.jsx(Zt,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,selectedMessageId:e.messageId,authenticity:e.authenticity}):s.jsx(Xt,{})})]})}function Ip(){const{selectedThread:e,conversation:t,selectedMessageId:n,onSelectMessage:r,onSelectSearchResult:a,onCloseThread:o}=Nr(),{accounts:i,intelligenceOpen:c,onToggleIntelligence:u}=Ee();return t?s.jsxs(s.Fragment,{children:[s.jsx(Zt,{threadId:t.threadId,mailboxId:t.mailboxId,subject:t.subject,selectedMessageId:t.messageId,authenticity:t.authenticity,onBack:o,onOpenIntelligence:u}),s.jsx(hr,{isOpen:c,onClose:u,ariaLabel:"Message details",side:"right",children:s.jsx(dn,{onClose:u,thread:e,hideCloseButton:!0})})]}):s.jsx("div",{className:"h-full",children:s.jsx(il,{accounts:i,selectedMessageId:n,onSelectMessage:r,onSelectSearchResult:a})})}const Fs=Object.assign(kp,{List:Cp,Reading:Ep,Phone:Ip}),Rp=e=>{const t=new Set;return e.filter(n=>t.has(n.threadId)?!1:(t.add(n.threadId),!0))};function vl({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:x,relatedLoading:b,onSelectSearchResult:p}){const[y,g]=l.useState(!1),v={categories:n.categories,filters:n.filters,sources:n.sources,selectedCategory:r,activeFilters:a,expanded:y,onExpandedChange:g,onSelectCategory:o,onSelectSource:c,onToggleFilter:i,onClear:u};return s.jsx(ol,{title:e,unreadCount:t,footer:f,searchFilter:v,searchResults:m,searchLoading:h,relatedResults:x,relatedLoading:b,onSelectSearchResult:p,children:s.jsx(Hn,{...v,children:d})})}const Mp={unread:e=>!e.isRead,attachment:e=>e.hasAttachment===!0};function Tp({selectedMessageId:e,onSelectMessage:t}){const{searchQuery:n,mailboxNameIndex:r,accountNameIndex:a}=Ee(),o=kt(),[i,c]=l.useState("all"),[u,d]=l.useState(new Set),f=l.useCallback(I=>{d(R=>{const O=new Set(R);return O.has(I)?O.delete(I):O.add(I),O})},[]),m=l.useCallback(()=>{c("all"),d(new Set)},[]),{data:h,isLoading:x,isError:b,error:p,refetch:y,fetchNextPage:g,hasNextPage:v,isFetchingNextPage:j}=ui({queryKey:fo({query:{starred:!0,order:"desc"}}),queryFn:async({pageParam:I})=>{const{data:R}=await Tc({query:{starred:!0,order:"desc",continuationToken:I},throwOnError:!0});return R},initialPageParam:void 0,getNextPageParam:I=>I.continuationToken,staleTime:6e4}),{freeText:w,tokens:N}=Cs(n.trim().toLowerCase(),{mailboxesByName:r,accountsByName:a}),E=l.useMemo(()=>{const I=Array.from(u).map(R=>Mp[R]).filter(R=>R!=null);return Rp((h?.pages??[]).flatMap(R=>R.items??[])).map(el).filter(R=>(i==="all"||R.category===i)&&I.every(O=>O(R))&&(!w||tl(R,w))&&sl(R,N))},[h,i,u,w,N]),S=l.useMemo(()=>lf(),[]),C=l.useMemo(()=>E.map(nl),[E]),k=l.useMemo(()=>E.filter(I=>!I.isRead).length,[E]),M=x?"loading":b?"error":E.length===0?"empty":"ready",T=l.useCallback(()=>{const I=sr(tr());window.open(I,"_blank","noopener,noreferrer")},[]),D=s.jsxs("div",{className:"flex-1 overflow-y-auto",children:[s.jsx("div",{className:"divide-y divide-line",children:E.map(I=>s.jsx(Fo,{thread:I,active:I.id===e,onClick:()=>t?.(I.id)},I.id))}),v?s.jsx("button",{type:"button",className:"w-full py-3 text-sm text-muted hover:text-fg disabled:opacity-50",onClick:()=>g(),disabled:j,children:j?"Loading…":"Load more"}):null]});return s.jsx(vl,{title:"Starred",unreadCount:k,preset:S,selectedCategory:i,activeFilters:u,onSelectCategory:c,onToggleFilter:f,onClearFilters:m,searchResults:C,searchLoading:x,onSelectSearchResult:I=>t?.(I.id),children:s.jsx(Ko,{listTitle:"Starred",sections:[{id:"flagged",threads:E}],flatList:!0,hideHeader:!0,listState:M,searchQuery:w?n:void 0,errorMessage:b?vo(p):void 0,onRetry:()=>y(),onReportError:T,selectedThreadId:e,onSelectThread:t,onSelectBriefCategory:()=>{},isDesktop:o,listBody:M==="ready"?D:void 0})})}const yl=l.createContext(null);function kr(){const e=l.useContext(yl);if(!e)throw new Error("FlaggedPane.* must be used inside <FlaggedPane>");return e}function Dp({selectedMessageId:e,children:t}){const n=Ce(),{data:r}=ie({...er(),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(yl.Provider,{value:c,children:t})}function wl(){const{selectedMessageId:e,onSelectMessage:t}=kr();return s.jsx(Tp,{selectedMessageId:e,onSelectMessage:t})}function Ap(){const{selectedThread:e}=kr(),{onToggleIntelligence:t,searchInput:n,onSearchChange:r,onSearchClear:a,onSearchClearQuery:o}=Ee();return s.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[s.jsx(Sr,{hasThread:!!e,onCompose:()=>{},intelligenceOpen:!1,showIntelligenceToggle:!1,onToggleIntelligence:t,searchValue:n,onSearchChange:r,onSearchClear:a,onSearchClearQuery:o}),s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?s.jsx(Zt,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,authenticity:e.authenticity}):s.jsx(Xt,{})})]})}function Op(){const{selectedThread:e,onCloseThread:t}=kr(),{intelligenceOpen:n,onToggleIntelligence:r}=Ee();return e?s.jsxs(s.Fragment,{children:[s.jsx(Zt,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,authenticity:e.authenticity,onBack:t,onOpenIntelligence:r}),s.jsx(hr,{isOpen:n,onClose:r,ariaLabel:"Message details",side:"right",children:s.jsx(dn,{onClose:r,thread:e,hideCloseButton:!0})})]}):s.jsx("div",{className:"h-full",children:s.jsx(wl,{})})}const Bs=Object.assign(Dp,{List:wl,Reading:Ap,Phone:Op}),Pp={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},[])},zp=()=>{const{state:e,closeCompose:t}=wt(),n=Lp(),[r,a]=l.useState(!1),{isError:o,error:i,refetch:c}=ie({...Ze(),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=Pp[e.mode]??"New Message";return s.jsxs(Oe.Root,{open:e.isOpen,onOpenChange:u,children:[s.jsxs(Oe.Portal,{children:[s.jsx(Oe.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),s.jsxs(Oe.Content,{className:"fixed inset-x-0 bottom-0 z-50 flex flex-col bg-canvas rounded-t-lg",style:{height:"95dvh"},children:[s.jsx(Oe.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-muted/30"}),s.jsx(Oe.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(ft,{title:"Couldn't load compose",error:i,onRetry:()=>{c()}})}):s.jsx("div",{className:"flex-1 overflow-hidden",children:s.jsx(gr,{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"})]})]})})]})},_p={reply:"Reply",reply_all:"Reply All",forward:"Forward",new:"New Message"},jl=()=>{const{state:e,closeCompose:t}=wt(),n=kt(),{isError:r,error:a,refetch:o}=ie({...Ze(),staleTime:1/0});if(!n)return s.jsx(zp,{});if(!e.isOpen)return null;const i=_p[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(Pe,{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(ft,{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(gr,{mode:e.mode,account:e.account,sourceMessage:e.sourceMessage,onClose:t},e.outboxMessageId??"new")})]})};function Fp(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:mt(e.updatedAt),isRead:!0}}function Bp(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:mt(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0}}function $p({outboxMessages:e,accountId:t,imapThreads:n}){const r=e.filter(i=>i.status==="draft"&&i.accountId===t).map(Fp),a=n.map(Bp),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 Cr(){const e=Zn();return!e||e.showNavPane?null:s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(ar,{className:"size-4"}),onClick:e.openNav,"aria-label":"Open folders",className:"-ml-1 shrink-0"})}const Kp=({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})]}),qp=({row:e,isSelected:t,onOpen:n,onDelete:r,isDeleting:a})=>s.jsxs("button",{type:"button",onClick:()=>n(e.id),className:q("group",Yt({active:t})),children:[s.jsx(xo,{className:"size-7 shrink-0 text-fg-muted mt-0.5"}),s.jsx(Gt,{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(qe,{className:"size-3.5"})})})]}),Up=({row:e,isSelected:t,onOpen:n})=>{const r=!e.isRead;return s.jsxs("button",{type:"button",onClick:()=>n(e.id),className:q("group",Yt({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(st,{name:e.fromName,email:e.fromEmail,size:"sm"}),s.jsx(Gt,{thread:e})]})};function Qp({mailboxId:e,accountId:t,selectedMessageId:n,imapThreads:r,title:a,unreadCount:o}){const{openCompose:i,state:c}=wt(),u=Ce(),d=je(),{data:f}=ie(Js()),m=l.useMemo(()=>$p({outboxMessages:f?.items??[],accountId:t,imapThreads:r}),[f?.items,t,r]),h=xe({...Zs(),onSuccess:()=>{d.invalidateQueries({queryKey:nr()})}}),x=g=>{h.mutate({path:{outboxMessageId:g}})},b=g=>{n&&u({to:"/mail/$mailboxId",params:{mailboxId:e},search:{selectedMessageId:void 0}}),i({mode:"new",outboxMessageId:g})},p=g=>{u({to:"/mail/$mailboxId",params:{mailboxId:e},search:{selectedMessageId:g}})},y=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(Cr,{}),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:y?s.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-2 text-center px-4",children:[s.jsx(Qn,{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(Kp,{label:g.label,count:g.threads.length}),s.jsx("div",{className:"divide-y divide-line",children:g.threads.map(v=>g.id==="remit-drafts"?s.jsx(qp,{row:v,isSelected:c.isOpen&&v.id===c.outboxMessageId,onOpen:b,onDelete:x,isDeleting:h.isPending},v.id):s.jsx(Up,{row:v,isSelected:v.id===n,onOpen:p},v.id))})]},g.id))})]})}function Hp(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 Bt(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 Ba(e,t){if(e===void 0)throw new Error("Unexpected undefined");return e}const Wp=(e,t)=>Math.abs(e-t)<1.01,Vp=(e,t,n)=>{let r;return function(...a){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,a),n)}};let ls;const In=()=>{if(ls!==void 0)return ls;if(typeof navigator>"u")return ls=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return ls=!0;const e=navigator.maxTouchPoints;return ls=navigator.platform==="MacIntel"&&e!==void 0&&e>0},$a=e=>{const{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},Yp=e=>e,Gp=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},Xp=(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($a(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($a(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(c):c()});return o.observe(n,{box:"border-box"}),()=>{o.unobserve(n)}},Gs={passive:!0},Jp=typeof window>"u"?!0:"onscrollend"in window,Zp=(e,t,n)=>{const r=e.scrollElement;if(!r)return;const a=e.targetWindow;if(!a)return;const o=e.options.useScrollendEvent&&Jp;let i=0;const c=o?null:Vp(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,Gs),o&&r.addEventListener("scrollend",f,Gs),()=>{r.removeEventListener("scroll",d),o&&r.removeEventListener("scrollend",f)}},ex=(e,t)=>Zp(e,t,n=>{const{horizontal:r,isRtl:a}=e.options;return r?n.scrollLeft*(a&&-1||1):n.scrollTop}),tx=(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"]},sx=(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})},nx=sx;class rx{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:Yp,rangeExtractor:Gp,onChange:()=>{},measureElement:tx,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,anchorTo:"start",followOnAppend:!1,scrollEndThreshold:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:"estimate",useCachedMeasurements:!1};for(const h in n){const x=n[h];x!==void 0&&(o[h]=x)}const i=this.options;let c=null,u=null,d=!1;if(i!==void 0&&i.enabled&&o.enabled&&o.anchorTo==="end"&&this.scrollElement!==null){const h=i.count,x=o.count,b=this.getMeasurements(),p=h>0?((r=b[0])==null?void 0:r.key)??i.getItemKey(0):null,y=h>0?((a=b[h-1])==null?void 0:a.key)??i.getItemKey(h-1):null;if(x!==h||h>0&&x>0&&(o.getItemKey(0)!==p||o.getItemKey(x-1)!==y)){d=!0;const j=h>0?this.getVirtualItemForOffset(this.getScrollOffset())??b[0]:null;j&&(c=[j.key,this.getScrollOffset()-j.start]);const w=o.followOnAppend===!0?"auto":o.followOnAppend||null;w&&x>h&&this.isAtEnd(i.scrollEndThreshold)&&(h===0||o.getItemKey(x-1)!==y)&&(u=w)}}this.options=o,d&&(this.pendingMin=0,this.itemSizeCacheVersion++);let f=!1,m=0;if(c&&this.scrollOffset!==null){const[h,x]=c,b=this.getMeasurements(),{count:p,getItemKey:y}=this.options;let g=0;for(;g<p&&y(g)!==h;)g++;if(g<p){const v=b[g];if(v){const j=v.start+x;j!==this.scrollOffset&&(m=j-this.scrollOffset,this.scrollOffset=j,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=Bt(()=>(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,!(!In()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};o.addEventListener("touchstart",i,Gs),o.addEventListener("touchend",c,Gs),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&&(In()&&(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=Bt(()=>[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=Bt(()=>[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 v=this._flatMeasurements;if(!v||v.length<g){const N=new Float64Array(g);v&&h>0&&N.set(v.subarray(0,h*2)),v=N,this._flatMeasurements=v}let j;if(h===0)j=r+a;else{const N=h-1;j=v[N*2]+v[N*2+1]+d}for(let N=h;N<n;N++){const E=o(N),S=m.get(E),C=typeof S=="number"?S:this.options.estimateSize(N);v[N*2]=j,v[N*2+1]=C,j+=C+d}const w=Hp(n,v,o);return this.measurementsCache=w,w}const x=this.measurementsCache.slice(0,h),b=new Array(c).fill(void 0),p=new Float64Array(c);let y=0;for(let g=0;g<h;g++){const v=x[g];v&&(b[v.lane]===void 0&&y++,b[v.lane]=g,p[v.lane]=v.end)}for(let g=h;g<n;g++){const v=o(g),j=this.laneAssignments.get(g);let w,N;const E=u==="estimate"||m.has(v);if(j!==void 0&&this.options.lanes>1){w=j;const M=b[w],T=M!==void 0?x[M]:void 0;N=T?T.end+d:r+a}else if(y===c){let M=0,T=p[0],D=b[0];for(let I=1;I<c;I++){const R=p[I];(R<T||R===T&&b[I]<D)&&(M=I,T=R,D=b[I])}w=M,N=T+d,E&&this.laneAssignments.set(g,w)}else w=g%this.options.lanes,N=r+a,E&&this.laneAssignments.set(g,w);const S=m.get(v),C=typeof S=="number"?S:this.options.estimateSize(g),k=N+C;x[g]={index:g,start:N,size:C,end:k,key:v,lane:w},b[w]===void 0&&y++,b[w]=g,p[w]=k}return this.measurementsCache=x,x},{key:!1,debug:()=>this.options.debug}),this.calculateRange=Bt(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(n,r,a,o)=>n.length===0||r===0?(this.range=null,null):(this.range=ox(n,r,a,o,o===1&&this._flatMeasurements!=null?this._flatMeasurements:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=Bt(()=>{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,x=h?this.getTotalSize():0,b=((o=this.scrollState)==null?void 0:o.behavior)!=="smooth"&&(this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[n]??{index:n,key:u,start: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()-x):b&&this.applyScrollAdjustment(m),this.notify(!1)}},this.getVirtualItems=Bt(()=>[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=Sl(0,r.length-1,o?c=>a[c*2]:c=>Ba(r[c]).start,n);return Ba(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&&(In()&&(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&&Wp(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 Sl=(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 ax(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 ox(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=ax(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=Sl(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 Rn=typeof document<"u"?l.useLayoutEffect:l.useEffect;function ix({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,x=f.mode==="transform",b=h?"left":"top",p=d.options.scrollMargin,y=d.getVirtualItems();for(const g of y){const v=g.start-p,j=d.elementsCache.get(g.key);j&&f.lastPositions.get(j)!==v&&(f.lastPositions.set(j,v),x?j.style.transform=h?`translate3d(${v}px, 0, 0)`:`translate3d(0, ${v}px, 0)`:j.style[b]=`${v}px`)}},c={...r,onChange:(d,f)=>{var m;const h=o.current;let x=!0;if(h.enabled){i(d);const b=d.range,p=h.prevRange;x=!p||p.isScrolling!==d.isScrolling||p.startIndex!==b?.startIndex||p.endIndex!==b?.endIndex,x&&(h.prevRange=b?{startIndex:b.startIndex,endIndex:b.endIndex,isScrolling:d.isScrolling}:null)}x&&(e&&f?Yn.flushSync(a):a()),(m=r.onChange)==null||m.call(r,d,f)}},[u]=l.useState(()=>{const d=new rx(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 x=d.options.horizontal?"width":"height";f.style[x]=`${h}px`}}})});return u.setOptions(c),Rn(()=>u._didMount(),[]),Rn(()=>u._willUpdate()),Rn(()=>{i(u)}),u}function lx(e){return ix({observeElementRect:Xp,observeElementOffset:ex,scrollToFn:nx,...e})}const cx=(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)},ux=(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]},dx=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(p=>{const y=new Set(p);return y.has(b)?y.delete(b):y.add(b),y})},[]),c=l.useCallback(b=>{a(b),n(p=>{if(p.has(b))return p;const y=new Set(p);return y.add(b),y})},[]),u=l.useCallback(b=>{n(p=>{if(!p.has(b))return p;const y=new Set(p);return y.delete(b),y})},[]),d=l.useCallback(b=>{n(new Set(b))},[]),f=l.useCallback(()=>{a(void 0),n(new Set)},[]),m=l.useCallback(b=>{n(p=>b.every(g=>p.has(g))?new Set:new Set(b))},[]),h=l.useCallback(b=>{a(b)},[]),x=l.useCallback((b,p)=>{n(y=>{const g=cx(b,r,p);if(g.length===0)return y;const v=new Set(y);for(const j of g)v.add(j);return v}),a(y=>y??p)},[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:x,setAnchor:h,anchorId:r}},fx=e=>{const t=xe(Dc()),{mutate:n}=t;return{preview:l.useCallback(a=>{e&&n({path:{accountId:e},body:wo(a)})},[e,n]),reset:t.reset,matchedCount:t.data?.matchedCount,messageIds:t.data?.messageIds,isPending:t.isPending,isError:t.isError,error:t.error}},mx=new Set(["Complete","Failed"]),Ka=e=>e!==void 0&&mx.has(e),hx=1e3,gx=15e3,px=e=>{const t=Math.max(0,e),n=hx*2**t;return Math.min(n,gx)},xx=e=>{const[t,n]=l.useState(),r=xe({...Ac(),onSuccess:m=>n(m.organizeJobId)}),{mutate:a}=r,o=ie({...Oc({path:{accountId:e??"",organizeJobId:t??""}}),enabled:!!e&&!!t,refetchInterval:m=>{const h=m.state.data?.state;return Ka(h)?!1:px(m.state.dataUpdateCount)}}),i=l.useCallback(m=>{e&&(n(void 0),a({path:{accountId:e},body:wo(m)}))},[e,a]),c=o.data,u=c?.state??r.data?.state,d=Ka(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}},bx=({draft:e,scope:t,name:n,pickedDate:r})=>{if(!nu(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."},vx=(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"}},yx=(e,t,n)=>e==="just-these"?t:n,wx=[{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 jx({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,x]=l.useState(""),{data:b}=ie({...et({path:{accountId:e}}),staleTime:1/0}),p=l.useMemo(()=>jr(b?.items??[]).map(M=>({id:M.mailboxId,label:Vs(M.fullPath)})),[b?.items]),y=l.useMemo(()=>({anchorMessageId:r,matchOperator:"And",literalClauses:[],moveMailboxId:u||void 0,expiresAt:i==="temporary"?ru(h):void 0}),[r,u,i,h]),{moveMessages:g}=ct({mailboxId:t,accountId:e}),v=xx(e),j=au(e),w=n.length,N=yx(i,w,a),E=bx({draft:y,scope:i,name:f,pickedDate:h}),S=()=>{if(!E)switch(i){case"just-these":u&&g(n,u),o();return;case"all-like-these":v.start(y);return;case"standing":j.createFilter(y,"standing",f.trim());return;case"temporary":j.createFilter(y,"temporary",f.trim());return}};if(v.isRunning||v.isDone)return s.jsx(Sx,{progress:v.progress,isDone:v.isDone,onClose:o});if(j.isSuccess)return s.jsxs("div",{className:"flex flex-col items-center gap-3 px-5 py-8 text-center",children:[s.jsx(or,{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(X,{variant:"primary",onClick:o,className:"mt-2",children:"Done"})]});const C=i==="standing"||i==="temporary";return s.jsxs("div",{className:"flex min-h-0 flex-col",children:[s.jsxs("div",{className:"border-b border-line px-5 py-3",children:[s.jsx("h2",{className:"text-sm font-semibold text-fg",children:"Organize"}),s.jsxs("p",{className:"mt-0.5 text-xs text-fg-muted",children:[a," similar message",a===1?"":"s"," found",w>0?` from ${w} selected`:"","."]})]}),s.jsxs("div",{className:"min-h-0 flex-1 space-y-5 overflow-y-auto px-5 py-4",children:[s.jsxs("section",{className:"space-y-2 rounded-lg border border-line bg-surface-sunken p-3",children:[s.jsxs("p",{className:"text-sm leading-relaxed text-fg-muted",children:[i==="standing"&&s.jsx("span",{className:"font-semibold text-fg",children:"Always keep "}),i==="standing"?"":"Keep ",i==="just-these"?"these":"emails like these"," in"]}),s.jsxs(su,{"aria-label":"Destination folder",value:u,onChange:k=>d(k.target.value),children:[s.jsx("option",{value:"",children:"Choose a folder…"}),p.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(Je,{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:wx.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(to,{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=>x(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:[E&&s.jsx("p",{className:"text-xs text-fg-subtle",role:"status",children:E}),j.isError&&s.jsx("p",{className:"text-xs text-danger",role:"alert",children:"Couldn't save the filter. Please try again."}),s.jsx(X,{variant:"primary",onClick:S,disabled:!!E||j.isPending||v.isStarting,className:"w-full",children:j.isPending?"Saving…":vx(i,N)}),s.jsx(X,{variant:"ghost",onClick:o,className:"w-full",children:"Not now"})]})]})}function Sx({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(or,{className:"size-8 text-positive"}):s.jsx(St,{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(X,{variant:"primary",onClick:n,className:"mt-2",children:"Done"})]})}function Nx({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}=fx(t);l.useEffect(()=>{!e||!o||i({anchorMessageId:o,matchOperator:"And",literalClauses:[]})},[e,o,i]);const h=()=>{c(),a()};return e?s.jsx(eo,{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(X,{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(St,{className:"size-8 animate-spin text-accent-2"}),s.jsx("p",{className:"text-sm font-medium text-fg",children:"Finding similar messages…"})]}):s.jsx(jx,{accountId:t,mailboxId:n,selectedMessageIds:r,anchorMessageId:o,matchedCount:u,onClose:h})}):null}const kx=({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,x=!!o&&!!u&&!!d&&!f;return s.jsxs("div",{className:"sticky top-0 z-10 flex items-center justify-between px-3 py-2 bg-surface-sunken border-b border-line",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("button",{type:"button",onClick:n,className:"min-h-11 min-w-11 inline-flex items-center justify-center rounded hover:bg-surface-raised transition-colors","aria-label":"Clear selection",children:s.jsx(Pe,{className:"size-4 text-fg-muted"})}),s.jsxs("span",{className:"text-sm font-medium",children:[e," ",e===1?"message":"messages"," ","selected"]}),f&&s.jsx("span",{className:"text-xs text-fg-muted",role:"status","aria-live":"polite",children:f})]}),s.jsxs("div",{className:"flex items-center gap-1",children:[x&&o&&s.jsxs("button",{type:"button",onClick:m?void 0:o,className:"min-h-11 inline-flex items-center justify-center gap-1.5 px-3 rounded text-sm font-medium transition-colors hover:bg-surface-raised","aria-label":"Organize similar messages",children:[s.jsx(Ke,{className:"size-4"}),s.jsx("span",{className:"hidden sm:inline",children:"Organize"})]}),r&&s.jsx("button",{type:"button",onClick:m?void 0:r,className:"min-h-11 min-w-11 inline-flex items-center justify-center rounded text-sm font-medium transition-colors hover:bg-surface-raised","aria-label":"Mark as read","aria-busy":m,children:s.jsx(js,{className:"size-4"})}),h&&a&&u&&d&&s.jsx(ks,{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:fe("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(St,{className:"size-4 animate-spin"}):s.jsx(qe,{className:"size-4"}),s.jsx("span",{className:"hidden sm:inline",children:i?"Deleting...":"Delete"})]})]})]})},Cx=8,Ex=({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)>Cx&&a()},[a]),c=l.useCallback(()=>{a()},[a]),u=l.useCallback(()=>{a()},[a]);return{handlers:{onPointerDown:o,onPointerMove:i,onPointerUp:c,onPointerCancel:u}}},Ix=(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:mt(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:ln(e.category),messageCount:t,suspicious:n}},Rx=({thread:e,mailboxId:t,accountId:n,isSelected:r,isFocused:a=!1,isChecked:o,onToggleCheck:i,onRowSelect:c,messageCount:u,isMultiSelectMode:d=!1,onLongPress:f,isDesktop:m=!0,density:h="comfortable"})=>{const x=je(),b=e.messageId,p=Ix(e,u),y=E=>{E.preventDefault(),E.stopPropagation(),i(e.messageId)},g=l.useCallback(E=>{if(!m)return;c(b,{shiftKey:E.shiftKey,metaKey:E.metaKey,ctrlKey:E.ctrlKey})&&(E.preventDefault(),E.stopPropagation())},[m,c,b]),v=l.useCallback(()=>{f?.(b)},[f,b]),j=Ex({onLongPress:v,delayMs:500}),w=l.useCallback(()=>{x.prefetchQuery(Jn({path:{messageId:e.messageId}}))},[x,e.messageId]),N=!e.isRead;return h==="compact"?s.jsx(Xe,{to:"/mail/$mailboxId",params:{mailboxId:t},search:E=>({...E,selectedMessageId:e.messageId}),"data-message-row":!0,onClick:g,onMouseEnter:w,onFocus:w,...!m&&j.handlers,className:fe(Lo({active:r,focused:a}),o&&"bg-accent-soft",!m&&"min-h-11"),children:s.jsx(zo,{thread:p})}):s.jsxs(Xe,{to:"/mail/$mailboxId",params:{mailboxId:t},search:E=>({...E,selectedMessageId:e.messageId}),"data-message-row":!0,onClick:g,onMouseEnter:w,onFocus:w,...!m&&j.handlers,className:fe("group",Yt({active:r,focused:a}),o&&"bg-accent-soft",!m&&"min-h-11"),children:[N&&s.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),s.jsxs("div",{className:"relative size-7 shrink-0",children:[s.jsx(st,{name:e.fromName??e.fromEmail??"?",email:e.fromEmail??void 0,size:"sm",className:fe("absolute inset-0","sm:group-hover:opacity-0 transition-opacity",(o||d)&&"opacity-0")}),s.jsx("button",{type:"button",onClick:y,className:fe("absolute inset-0 size-7 rounded-full border items-center justify-center transition-opacity",d?"flex":"hidden sm:flex",o?"bg-accent border-accent text-accent-fg opacity-100":d?"border-fg-subtle/40 opacity-100 bg-canvas":"border-fg-subtle/40 opacity-0 group-hover:opacity-100 bg-canvas"),"aria-label":o?"Deselect message":"Select message",children:o&&s.jsx(ws,{className:"size-3"})})]}),s.jsx(Gt,{thread:p,badge:e.autoMoved&&s.jsx(wi,{accountId:n,messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,autoMoved:e.autoMoved,size:"sm"})})]})},Mx=l.memo(Rx),Tx=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:mt(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:ln(e.category),suspicious:t}},Dx=({thread:e,mailboxId:t,accountId:n,isSelected:r,isFocused:a,isChecked:o,onToggleCheck:i,onRowSelect:c,isMultiSelectMode:u,onLongPress:d,isDesktop:f,onDelete:m,onToggleRead:h,density:x})=>{const[b,p]=l.useState("none"),y=l.useCallback(j=>{navigator.vibrate?.(10),j==="trailing"?m(e.messageId):h(e.messageId,e.isRead),p("none")},[m,h,e.messageId,e.isRead]),g=l.useCallback(()=>{d(e.messageId)},[d,e.messageId]),v=l.useCallback(()=>{i(e.messageId)},[i,e.messageId]);return f||u?s.jsx(Mx,{thread:e,mailboxId:t,accountId:n,isSelected:r,isFocused:a,isChecked:o,onToggleCheck:i,onRowSelect:c,isMultiSelectMode:u,onLongPress:d,isDesktop:f,density:x}):s.jsx($o,{thread:Tx(e),selectionMode:!1,checked:!1,active:r,peek:b,onPeek:p,onToggleCheck:v,onLongPress:g,onOpen:()=>{},onAct:y,linkComponent:({onOpenClick:j,children:w,...N})=>s.jsx(Xe,{...N,to:"/mail/$mailboxId",params:{mailboxId:t},search:E=>({...E,selectedMessageId:e.messageId}),"data-message-row":!0,onClick:j,children:w})})},Ax=72,Ox=32,Px=5,Nl="remit:list-density",Lx=()=>{try{const e=localStorage.getItem(Nl);if(e==="compact"||e==="comfortable")return e}catch{}return"comfortable"},zx=({query:e,count:t})=>s.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-line bg-surface-sunken/30",children:[s.jsx(vs,{className:"size-4 text-fg-muted"}),s.jsxs("span",{className:"text-sm text-fg-muted",children:[t," ",t===1?"result":"results"," for “",e,"”"]})]}),_x=({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:x,hasMore:b=!1,isLoadingMore:p=!1,accountId:y,listTitle:g,listMeta:v,onTriageContextChange:j,hideHeader:w=!1})=>{const N=l.useRef(null),E=Ce(),S=kt(),[C,k]=l.useState(!1),[M,T]=l.useState(!1),[D,I]=l.useState(n),[R,O]=l.useState(Lx),B=l.useCallback(()=>{O(P=>{const J=P==="comfortable"?"compact":"comfortable";try{localStorage.setItem(Nl,J)}catch{}return J})},[]),{toggleReadFor:K}=vi({mailboxId:e}),{selectedIds:F,selectedCount:$,hasSelection:U,isSelected:te,toggle:Q,select:L,clearSelection:A,selectRange:Y,setAnchor:le,selectAll:ve}=dx(),[ce,ye]=l.useState(null);l.useEffect(()=>{C&&$===0&&k(!1)},[C,$]);const Se=lx({count:t.length,getScrollElement:()=>N.current,estimateSize:()=>R==="compact"?Ox:Ax,overscan:Px}),G=n?t.findIndex(P=>P.messageId===n):-1,ge=D?t.findIndex(P=>P.messageId===D):-1,Ie=l.useCallback(P=>{if(P<0||P>=t.length)return;const J=t[P];if(C){Q(J.messageId);return}I(J.messageId)},[t,C,Q]),H=l.useCallback(()=>{if(t.length===0)return;const P=ge<0?0:Math.min(ge+1,t.length-1);Ie(P)},[t.length,ge,Ie]),W=l.useCallback(()=>{if(t.length===0)return;const P=ge<=0?0:ge-1;Ie(P)},[t.length,ge,Ie]),ee=l.useCallback(()=>{D&&Q(D)},[D,Q]),ne=l.useMemo(()=>t.map(P=>P.messageId),[t]),Ue=l.useCallback((P,J)=>J.shiftKey?(Y(ne,P),!0):J.metaKey||J.ctrlKey?(Q(P),!0):(A(),le(P),!1),[ne,Y,Q,A,le]),ae=l.useCallback(P=>{!u||P.length===0||ye(P)},[u]),Ne=l.useCallback(P=>{const J=ux(ne,D,P);J!==void 0&&(Y(ne,J),I(J))},[ne,D,Y]),Fe=l.useCallback(()=>Ne(-1),[Ne]),De=l.useCallback(()=>Ne(1),[Ne]),Qe=l.useCallback(()=>{ne.length>0&&ve(ne)},[ne,ve]),He=l.useCallback(()=>{$>0?ae(Array.from(F)):D&&ae([D])},[$,F,D,ae]),Ct=l.useCallback(()=>{D&&E({to:"/mail/$mailboxId",params:{mailboxId:e},search:P=>({...P,selectedMessageId:D})})},[D,E,e]),ht=l.useCallback(()=>{$>0&&ae(Array.from(F))},[ae,$,F]),Et=l.useCallback(()=>{if(!ce||ce.length===0){ye(null);return}const P=new Set(ce),J=t.findIndex(de=>P.has(de.messageId));let me;for(let de=J+1;de<t.length;de++)if(!P.has(t[de].messageId)){me=t[de].messageId;break}if(me===void 0){for(let de=J-1;de>=0;de--)if(!P.has(t[de].messageId)){me=t[de].messageId;break}}u?.(ce),A(),ye(null),me!==void 0&&E({to:"/mail/$mailboxId",params:{mailboxId:e},search:de=>({...de,selectedMessageId:me}),replace:!0})},[ce,t,u,A,E,e]),We=l.useCallback(()=>{ye(null)},[]),rt=l.useCallback(()=>{d&&$>0&&d(Array.from(F))},[d,$,F]),gt=l.useCallback(P=>{!f||$===0||(f(Array.from(F),P),A())},[f,$,F,A]),Re=l.useMemo(()=>{if($===0)return;const P=new Set;for(const J of t)F.has(J.messageId)&&P.add(J.accountConfigId);if(P.size>1)return"Move only works within one account — clear selection or pick messages from a single account"},[$,F,t]),Ve=l.useCallback(P=>{u?.([P])},[u]),It=l.useCallback((P,J)=>{K([P],!J)},[K]),Rt=l.useCallback(P=>{S||(k(!0),L(P))},[S,L]),es=l.useCallback(()=>{k(!1),A()},[A]);l.useEffect(()=>{if(!S&&n)return;const P=ge>=0?ge:G;P>=0&&Se.scrollToIndex(P,{align:"auto"})},[ge,G,Se,S,n]),l.useEffect(()=>{n&&I(n)},[n]),l.useEffect(()=>{D&&(t.some(P=>P.messageId===D)||I(t[0]?.messageId))},[t,D]),l.useEffect(()=>{j?.({focusedMessageId:D,selectedIds:Array.from(F)})},[D,F,j]),l.useEffect(()=>{const P=new Set(t.map(me=>me.messageId));Array.from(F).some(me=>!P.has(me))&&A()},[t,F,A]),l.useEffect(()=>{const P=N.current;if(!P||!b||!x)return;const J=()=>{if(p)return;const{scrollTop:me,scrollHeight:de,clientHeight:Me}=P;me+Me>=de-200&&x()};return P.addEventListener("scroll",J,{passive:!0}),J(),()=>P.removeEventListener("scroll",J)},[b,p,x]),ps({enabled:!r&&t.length>0&&ce===null,bindings:[{key:"j",handler:H,preventDefault:!0},{key:"ArrowDown",handler:H,preventDefault:!0,requireShift:!1},{key:"k",handler:W,preventDefault:!0},{key:"ArrowUp",handler:W,preventDefault:!0,requireShift:!1},{key:"ArrowDown",handler:De,preventDefault:!0,requireShift:!0},{key:"ArrowUp",handler:Fe,preventDefault:!0,requireShift:!0},{key:"x",handler:ee,preventDefault:!0},{key:" ",handler:ee,preventDefault:!0},{key:"a",handler:Qe,preventDefault:!0,requireMeta:!0},{key:"Enter",handler:Ct,preventDefault:!0},{key:"Delete",handler:He,preventDefault:!0},{key:"Backspace",handler:He,preventDefault:!0},{key:"d",handler:B,preventDefault:!0}]}),ps({enabled:U&&ce===null,capture:!0,bindings:[{key:"Escape",handler:A,preventDefault:!0,stopPropagation:!0}]});const Mt=r?"loading":a?"error":t.length===0?"empty":"ready",Le=a?vo(o):void 0,ts=l.useCallback(()=>{const P=sr(tr());window.open(P,"_blank","noopener,noreferrer")},[]),V=[{id:"inbox",threads:[]}],re=U&&S?s.jsx(kx,{selectedCount:$,onDelete:ht,onClearSelection:A,onMarkAsRead:d?rt:void 0,onMove:f?gt:void 0,onOrganize:()=>T(!0),isDeleting:m,isMoving:h,accountId:y,currentMailboxId:e,moveDisabledHint:Re}):void 0,oe=C&&!S?s.jsx(Bo,{count:$,onCancel:es,onDelete:ht,onMarkRead:d?rt:void 0,isBusy:m||h,moveDisabledHint:Re,moveSlot:f&&y&&e?s.jsxs(s.Fragment,{children:[!Re&&s.jsx("button",{type:"button",onClick:()=>T(!0),className:"min-h-11 min-w-11 inline-flex shrink-0 items-center justify-center rounded text-fg-muted hover:bg-surface-raised","aria-label":"Organize similar messages",children:s.jsx(Ke,{className:"size-4"})}),s.jsx(ks,{accountId:y,currentMailboxId:e,onMove:m||h?()=>{}:gt,disabledHint:Re,label:"Move selected messages"})]}):void 0}):void 0,Z=re??oe,ue=!!c?.trim(),pe=s.jsxs(s.Fragment,{children:[ue&&c&&s.jsx(zx,{query:c,count:t.length}),s.jsxs("div",{ref:N,className:"flex-1 overflow-y-auto",children:[s.jsx("div",{className:"relative w-full",style:{height:`${Se.getTotalSize()}px`},children:Se.getVirtualItems().map(P=>{const J=t[P.index];return s.jsx("div",{"data-index":P.index,ref:Se.measureElement,className:"absolute left-0 top-0 w-full border-b border-line",style:{transform:`translateY(${P.start}px)`},children:s.jsx(Dx,{thread:J,mailboxId:e,accountId:y,isSelected:n===J.messageId,isFocused:D===J.messageId,isChecked:te(J.messageId),onToggleCheck:Q,onRowSelect:Ue,isMultiSelectMode:C,onLongPress:Rt,isDesktop:S,onDelete:Ve,onToggleRead:It,density:R})},P.key)})}),p&&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(Ko,{listTitle:g,listMeta:v,sections:V,flatList:!0,listState:Mt,searchQuery:ue?c:void 0,errorMessage:Le,onRetry:i,onReportError:ts,density:R,selectedThreadId:n,onSelectThread:P=>E({to:"/mail/$mailboxId",params:{mailboxId:e},search:J=>({...J,selectedMessageId:P})}),onSelectBriefCategory:()=>{},isDesktop:S,hideHeader:w,selectionBar:Z,listBody:Mt==="ready"?pe:void 0}),s.jsx(ll,{isOpen:ce!==null,title:Zc(ce?.length??0),description:"You can restore them from Trash later.",confirmLabel:"Move to Trash",destructive:!0,isBusy:m,onConfirm:Et,onCancel:We}),M&&y&&s.jsx(Nx,{open:M,accountId:y,mailboxId:e,selectedMessageIds:Array.from(F),onClose:()=>T(!1)})]})},Fx=e=>Vt({path:{accountId:e}}),Bx=e=>{const t=je(),n=xs(),r=xe({...Pc(),onSuccess:()=>{n.recordEvent("sync.triggered"),t.invalidateQueries({queryKey:Fx(e)})}});return{trigger:()=>{r.mutate({path:{accountId:e}})},triggerAsync:()=>r.mutateAsync({path:{accountId:e}}),isPending:r.isPending,error:r.error,reset:r.reset}},$x=({accountId:e,children:t})=>{const{triggerAsync:n,isPending:r}=Bx(e);return s.jsx(Hd,{onRefresh:n,isRefreshing:r,children:t})};function Kx({accountId:e,currentMailboxId:t,candidates:n,onMove:r,children:a}){const[o,i]=l.useState(!1),c=xs(),{t:u}=tn("mail",{useSuspense:!1}),d=l.useCallback((v,j)=>u(v,{defaultValue:j}),[u]),{inboxMailboxId:f}=pr(e),m=yi(e),{data:h}=ie({...et({path:{accountId:e}}),staleTime:1/0}),x=l.useMemo(()=>{const v=jr(h?.items??[],m),j=ys(m);return v.map(w=>({id:w.mailboxId,label:Qt(w,j.get(w.mailboxId),d),searchValue:w.fullPath,isCurrent:w.mailboxId===t}))},[h?.items,m,t,d]),b=l.useMemo(()=>f||(x.find(j=>j.label.toLowerCase()==="inbox")?.id??x.find(j=>!j.isCurrent)?.id??""),[f,x]),p=l.useRef(!1);l.useEffect(()=>{p.current||(p.current=!0,fp(c,n.length))},[c,n.length]);const y=l.useCallback(()=>{mp(c,n.length),i(!0)},[c,n.length]),g=l.useCallback((v,j)=>{hp(c,{selected:v.length,total:n.length,toInbox:j===f}),r(v,j)},[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(Yd,{count:n.length,onReview:y})}),s.jsx("div",{className:"min-h-0 flex-1",children:a}),s.jsx(sf,{open:o,candidates:n,defaultDestinationId:b,availableFolders:x,onConfirmMove:g,onCancel:()=>i(!1)})]})}const qx=({accounts:e})=>{const t=rr({strict:!1}),n=mr(),r=t.mailboxId,{t:a}=tn("mail",{useSuspense:!1}),o=l.useCallback((c,u)=>a(c,{defaultValue:u}),[a]),i=Jt({queries:e.map(c=>({...et({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=ys(e[c].folderAppointments);return Qt(d,f.get(r),o)}return null},Ux=({accounts:e})=>{const n=rr({strict:!1}).mailboxId,r=Jt({queries:e.map(a=>({...et({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},Qx="We can verify this sender";function Hx(e){const{data:t}=ie({...Lc({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:Qx,trustSubReason:dp(r.senderTrust),senderTrust:r.senderTrust}))}}const $s={action:null,nextPrefix:null,preventDefault:!1},Wx={b:"goBrief",i:"goInbox",s:"goSent",f:"goFlagged",",":"goSettings"},Vx={j:{action:"focusNext"},k:{action:"focusPrevious"},enter:{action:"openFocused"},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 Yx(e,t){const n=e.key.toLowerCase(),r=e.metaKey||e.ctrlKey;if(e.inEditable)return{...$s,nextPrefix:t==="g"?null:t};if(r&&n==="n")return{action:"compose",nextPrefix:null,preventDefault:!0};if(r)return{...$s,nextPrefix:t==="g"?null:t};if(n==="escape")return{action:"back",nextPrefix:null,preventDefault:!1};if(t==="g"){const i=Wx[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&&(n==="j"||n==="k"))return{action:n==="j"?"extendSelectDown":"extendSelectUp",nextPrefix:null,preventDefault:!0};const a=Vx[n];if(a){const o=a.requireShift===!0,i=n.length===1&&!/[a-z0-9]/.test(n);return!o&&e.shiftKey&&!i?$s:{action:a.action,nextPrefix:null,preventDefault:!0}}return $s}function Gx(e){if(!(e instanceof HTMLElement))return!1;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"||e.isContentEditable}function Xx({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=Yx({key:u.key,shiftKey:u.shiftKey,metaKey:u.metaKey,ctrlKey:u.ctrlKey,altKey:u.altKey,inEditable:Gx(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 qa=(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]},kl="remit:intelligence-open";function Jx(){try{return localStorage.getItem(kl)!=="closed"}catch{return!0}}function Ua(e){try{localStorage.setItem(kl,e?"open":"closed")}catch{}}const Zx=(e,t)=>e!==t,eb=(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 sb(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 Cl=l.createContext(null);function fn(){const e=l.useContext(Cl);if(!e)throw new Error("MailboxPane.* must be used inside <MailboxPane>");return e}function nb({mailboxId:e,selectedMessageId:t,children:n}){const r=Ce(),o=Es()==="desktop",i=xs(),{accounts:c,mailboxNameIndex:u,accountNameIndex:d,searchQuery:f,searchInput:m,intelligenceOpen:h,onToggleIntelligence:x,onSetIntelligenceOpen:b}=Ee(),p=Ji(f),y=p.length>0,{freeText:g,tokens:v}=Cs(p,{mailboxesByName:u,accountsByName:d}),j=v.find(z=>z.type==="from"),w={order:"desc",...g?{query:g}:{},...j?{from:j.value}:{},...v.some(z=>z.type==="hasAttachment")?{attachments:!0}:{},...v.some(z=>z.type==="isUnread")?{unread:!0}:{}},N=y?ut({path:{mailboxId:e},query:w}):tt({path:{mailboxId:e},query:{order:"desc"}}),{data:E,isLoading:S,isError:C,error:k,refetch:M,fetchNextPage:T,hasNextPage:D,isFetchingNextPage:I}=ui({queryKey:N,queryFn:async({pageParam:z})=>{if(y){const{data:Ae}=await _c({path:{mailboxId:e},query:{...w,continuationToken:z},throwOnError:!0});return Ae}const{data:Te}=await Fc({path:{mailboxId:e},query:{order:"desc",continuationToken:z},throwOnError:!0});return Te},initialPageParam:void 0,getNextPageParam:z=>z.continuationToken,enabled:y?p.length>0:!0,placeholderData:zc}),R=l.useCallback(z=>{t&&z.includes(t)&&r({to:"/mail/$mailboxId",params:{mailboxId:e},search:Te=>({...Te,selectedMessageId:void 0,selectedThreadId:void 0})})},[t,e,r]),{deleteMessages:O,isPending:B}=ds({mailboxId:e,onAfterOptimisticRemove:R}),{accountId:K}=bi(e),F=qx({accounts:c}),{moveMessages:$,isPending:U}=ct({mailboxId:e,accountId:K,onAfterOptimisticRemove:R}),te=Dh(E?.pages.flatMap(z=>z.items??[])??[]),[Q,L]=l.useState("all"),[A,Y]=l.useState(new Set),le=l.useMemo(()=>sb(te,Q,A),[te,Q,A]),ve=l.useCallback(z=>{L(z)},[]),ce=l.useCallback(z=>{Y(Te=>{const Ae=new Set(Te);return Ae.has(z)?Ae.delete(z):Ae.add(z),Ae})},[]),ye=l.useCallback(()=>{L("all"),Y(new Set)},[]),Se=Zx(m,f),G=eb(te,t,Se),{selectedThreadId:ge}=Ut({strict:!1}),Ie=l.useMemo(()=>xl(G,{messageId:t,threadId:Se?void 0:ge,mailboxId:e}),[G,t,ge,Se,e]),[H,W]=l.useState(void 0),[ee,ne]=l.useState([]),Ue=l.useCallback(z=>{W(z.focusedMessageId),ne(z.selectedIds)},[]),ae=le.find(z=>z.messageId===H)??G,Ne=l.useRef(null);l.useEffect(()=>{const z=G?.messageId??null;z&&Ne.current!==z&&G?.authenticity?.dkimMismatch&&(Ne.current=z,h||x())},[G?.messageId,G?.authenticity?.dkimMismatch,h,x]);const Fe=l.useRef(!1);l.useEffect(()=>{Fe.current||o&&G?.messageId&&(Fe.current=!0,Jx()&&!h&&b(!0))},[o,G?.messageId,h,b]);const Qe=Ux({accounts:c})??te.filter(z=>!z.isRead).length,He=je(),{pushError:Ct}=ze(),{deleteMessages:ht}=ds({mailboxId:e,threadId:G?.threadId,onAfterOptimisticRemove:R}),{moveMessages:Et}=ct({mailboxId:e,threadId:G?.threadId,accountId:K,onAfterOptimisticRemove:R}),{draftsMailboxId:We}=Mh(K),rt=We!==void 0&&We===e,{archiveMailboxId:gt}=Rh(K),Re=l.useCallback(z=>{const Te=jt({path:{threadId:z.threadId}}),Pr=He.getQueriesData({queryKey:Te}).flatMap(([,Xl])=>Xl?.items.map(Jl=>Jl.messageId)??[]);return Pr.length>0?Pr:[z.messageId]},[He]),Ve=l.useCallback(()=>{if(!G)return;const z=Re(G);ht(z)},[G,Re,ht]),It=l.useCallback(z=>{if(!G)return;const Te=Re(G);Et(Te,z)},[G,Re,Et]),{toggleStar:Rt}=Fn({threadId:G?.threadId??"",mailboxId:e}),es=l.useCallback(()=>{G&&Rt(G.messageId,G.hasStars)},[G,Rt]),[Mt,Le]=l.useState(null),ts=l.useCallback(()=>{Le("reply")},[]),V=l.useCallback(()=>{Le("reply_all")},[]),re=l.useCallback(()=>{Le("forward")},[]),oe=l.useCallback(()=>{Le(null)},[]),{state:Z,openCompose:ue,closeCompose:pe}=wt(),P=l.useCallback(()=>{ue({mode:"new"})},[ue]),J=xe({...Zs(),onError:z=>{Ct(fs("Couldn't discard draft","The draft wasn't deleted.",z))}}),me=l.useCallback(()=>{const z=Z.outboxMessageId;z&&(J.mutate({path:{outboxMessageId:z}}),He.invalidateQueries({queryKey:nr()}),pe())},[Z.outboxMessageId,J,He,pe]),de=l.useCallback(()=>{t&&r({to:"/mail/$mailboxId",params:{mailboxId:e},search:z=>({...z,selectedMessageId:void 0,selectedThreadId:void 0})})},[t,e,r]),Me=l.useCallback(z=>z?Re(z):[],[Re]),{toggleStar:ke}=Fn({threadId:ae?.threadId??"",mailboxId:e}),{toggleReadFor:pt}=vi({mailboxId:e,accountId:K}),{junkMailboxId:Be}=xr(K),Rr=Be!=null&&Be===e,{candidates:Ol}=Hx(Rr?Be:void 0),{moveMessages:Mr}=ct({mailboxId:e,threadId:ae?.threadId,accountId:K,onAfterOptimisticRemove:R}),{deleteMessages:Tr}=ds({mailboxId:e,threadId:ae?.threadId,onAfterOptimisticRemove:R}),{addressId:ss,address:Is}=ul(ae),{updateFlags:Rs}=dl({addressId:ss,senderEmail:ae?.fromEmail??void 0}),Tt=l.useCallback(()=>t||!H?!1:(r({to:"/mail/$mailboxId",params:{mailboxId:e},search:z=>({...z,selectedMessageId:H})}),!0),[t,H,e,r]),Pl=l.useCallback(()=>{Tt()||G&&Le("reply")},[Tt,G]),Ll=l.useCallback(()=>{Tt()||G&&Le("reply_all")},[Tt,G]),zl=l.useCallback(()=>{Tt()||G&&Le("forward")},[Tt,G]),Dt=l.useCallback(()=>ee.length>0?ee:Me(ae),[ee,Me,ae]),_l=l.useCallback(()=>{const z=Dt();z.length>0&&Tr(z)},[Dt,Tr]),Fl=l.useCallback(()=>{if(!Be)return;const z=Dt();z.length!==0&&(ml(i,{count:z.length,senderTrust:ae?.senderTrust??"unknown",wasRescuable:ae?fl(ae):!1}),Mr(z,Be))},[Be,Dt,Mr,i,ae]),Bl=l.useCallback(()=>{if(ee.length>0){const z=!(ae?.hasStars??!1),Te=new Set(ee);for(const Ae of le)Te.has(Ae.messageId)&&Ae.hasStars!==z&&ke(Ae.messageId,Ae.hasStars);return}ae&&ke(ae.messageId,ae.hasStars)},[ee,le,ae,ke]),$l=l.useCallback(()=>{const z=Dt();if(z.length===0)return;const Te=!(ae?.isRead??!1);pt(z,Te)},[Dt,ae,pt]),Kl=l.useCallback(()=>{if(!ss)return;const z=Is?.flags?.muted?.value!==!0;Rs({muted:{value:z}})},[ss,Is,Rs]),ql=l.useCallback(()=>{if(!ss)return;const z=Is?.flags?.vip?.value!==!0;Rs({vip:{value:z}})},[ss,Is,Rs]),Ul=l.useCallback(()=>{h||x()},[h,x]),ns=l.useCallback(z=>{r({to:z})},[r]),Dr=rt?"drafts":gt===e?"archive":Be===e?"junk":"inbox",Ar=l.useRef("");l.useEffect(()=>{const z=Ar.current;Ar.current=p,p.length>0&&z.length===0&&i.recordEvent("search.submitted",{mailboxType:Dr})},[p,Dr,i]);const Ql=!!G,Hl=rt&&Z.isOpen&&!!Z.outboxMessageId&&!G,Wl=o&&h&&Ql;Xx({enabled:!Z.isOpen,handlers:{back:de,reply:Pl,replyAll:Ll,forward:zl,delete:_l,toggleStar:Bl,toggleRead:$l,muteSender:Kl,blockSender:Ul,vipSender:ql,markJunk:Fl,toggleIntelligence:G?x:void 0,compose:P,goBrief:()=>ns("/mail"),goInbox:()=>ns("/mail"),goSent:()=>ns("/mail"),goFlagged:()=>ns("/mail/flagged"),goSettings:()=>ns("/settings")}}),ps({enabled:Z.isOpen,bindings:[{key:"Escape",handler:pe,preventDefault:!0}]});const Or=le.map(z=>z.messageId),Vl=qa(Or,t,"next")??void 0,Yl=qa(Or,t,"previous")??void 0,Gl={mailboxId:e,selectedMessageId:t,selectedThread:G,conversation:Ie,threads:le,isLoading:S,isError:C,error:k,mailboxAccountId:K,mailboxName:F,unreadCount:Qe,isDraftsMailbox:rt,isSpamFolder:Rr,rescueCandidates:Ol,filterCategory:Q,filterAttributes:A,onSelectFilterCategory:ve,onToggleFilterAttribute:ce,onClearFilters:ye,showIntelligence:Wl,intelligenceOpen:h,onToggleIntelligence:x,onDeleteMessages:O,onMoveMessages:$,isDeleting:B,isMoving:U,onLoadMore:T,hasMore:D,isLoadingMore:I,onTriageContextChange:Ue,onRetry:()=>M(),toolbarComposeRequest:Mt,onToolbarReply:ts,onToolbarReplyAll:V,onToolbarForward:re,onClearComposeRequest:oe,onToolbarDelete:Ve,onToolbarStar:es,onToolbarDiscardDraft:me,onToolbarMove:It,composeState:Z,openCompose:P,closeCompose:pe,hasRemitDraftOpen:Hl,onBack:de,nextMessageId:Vl,previousMessageId:Yl};return s.jsx(Cl.Provider,{value:Gl,children:n})}function El(){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:x,mailboxName:b,unreadCount:p,isDraftsMailbox:y,isSpamFolder:g,rescueCandidates:v,onTriageContextChange:j,onRetry:w,filterCategory:N,filterAttributes:E,onSelectFilterCategory:S,onToggleFilterAttribute:C,onClearFilters:k}=fn(),{searchQuery:M,searchInput:T,accounts:D}=Ee(),I=Es(),R=Ce(),O=b??"Inbox",B=l.useMemo(()=>of(),[]),K=l.useMemo(()=>n.map(Yg),[n]),{hits:F,isLoading:$}=Zi({mailboxId:e,filterCategory:N}),U=l.useMemo(()=>rl(F,n.map(le=>le.threadId)),[F,n]),te=l.useCallback(le=>R({to:"/mail/$mailboxId",params:{mailboxId:e},search:ve=>({...ve,q:T||void 0,selectedMessageId:le.id,selectedThreadId:le.threadId})}),[e,R,T]);if(y&&x)return s.jsx(Qp,{mailboxId:e,accountId:x,selectedMessageId:t,imapThreads:n,title:b??"Drafts",unreadCount:p??void 0});const Q=s.jsx(_x,{mailboxId:e,threads:n,selectedMessageId:t,isLoading:r,isError:a,error:o,onRetry:w,searchQuery:M,onDeleteMessages:i,onMoveMessages:c,isDeleting:u,isMoving:d,onLoadMore:f,hasMore:m,isLoadingMore:h,accountId:x,listTitle:O,hideHeader:!0,onTriageContextChange:j}),L=D[0]?.accountId,A=I==="phone"&&L?s.jsx($x,{accountId:L,children:Q}):Q,Y=g&&v.length>0&&x?s.jsx(Kx,{accountId:x,currentMailboxId:e,candidates:v,onMove:c,children:A}):A;return s.jsx(vl,{title:O,unreadCount:p,preset:B,selectedCategory:N,activeFilters:E,onSelectCategory:S,onToggleFilter:C,onClearFilters:k,searchResults:K,searchLoading:r,relatedResults:U,relatedLoading:$,onSelectSearchResult:te,children:Y})}function rb(){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:x,onToolbarDiscardDraft:b,onToolbarMove:p,composeState:y,openCompose:g}=fn(),{searchInput:v,onSearchChange:j,onSearchClear:w,onSearchClearQuery:N}=Ee(),S=Es()==="desktop",C=!!r,k=y.isOpen&&!r?s.jsx(jl,{}):r?s.jsx(Zt,{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(Xt,{});return s.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[s.jsx(Sr,{hasThread:C,onCompose:g,intelligenceOpen:o,showIntelligenceToggle:S&&C,onToggleIntelligence:i,searchValue:v,onSearchChange:j,onSearchClear:w,onSearchClearQuery:N,onReply:C?u:void 0,onReplyAll:C?d:void 0,onForward:C?f:void 0,canDelete:C||a,onDelete:C?h:a?b:void 0,onToggleStar:C?x:void 0,isStarred:n?.hasStars,moveContext:C&&t?{accountId:t,currentMailboxId:e,onMove:p}:void 0}),s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:k})]})}function ab(){const{mailboxId:e,mailboxAccountId:t,selectedThread:n,onToggleIntelligence:r}=fn();return s.jsx(dn,{onClose:r,thread:n,mailboxId:e,accountId:t})}function ob(){const{mailboxId:e,selectedThread:t,conversation:n,intelligenceOpen:r,onToggleIntelligence:a,onBack:o,nextMessageId:i,previousMessageId:c,composeState:u}=fn(),d=Ce();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(Zt,{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(hr,{isOpen:r,onClose:a,ariaLabel:"Message details",side:"right",children:s.jsx(dn,{onClose:a,thread:t,hideCloseButton:!0})})]})}return u.isOpen?s.jsx("div",{className:"h-full",children:s.jsx(jl,{})}):s.jsx(El,{})}const cs=Object.assign(nb,{List:El,Reading:rb,Intelligence:ab,Phone:ob}),Il=e=>e==="failed"||e==="blocked",Rl=e=>e!=="draft"&&e!=="sent",Er="remit.savedSearches",ib=25;function Xs(){try{const e=localStorage.getItem(Er);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(n=>typeof n=="string"):[]}catch{return[]}}function lb(e){const t=e.trim();if(!t)return Xs();const n=[t,...Xs().filter(r=>r!==t)].slice(0,ib);try{localStorage.setItem(Er,JSON.stringify(n))}catch{return n}return n}function cb(e){const t=Xs().filter(n=>n!==e);try{localStorage.setItem(Er,JSON.stringify(t))}catch{return t}return t}const Qa=e=>/^\d/.test(e),ub=(e,t)=>{const n=Qa(e),r=Qa(t);return n&&!r?-1:!n&&r?1:e.localeCompare(t,void 0,{sensitivity:"base",numeric:!0})};function db(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)=>ub(Qt(o,void 0,n),Qt(i,void 0,n))),{system:r,labels:a}}function fb(e,t,n){const r=tu(t)&&e.unseenCount>0;return{id:e.mailboxId,name:Qt(e,t,n),unseen:r?e.unseenCount:void 0,role:t,fullPath:e.fullPath}}function mb(){const e=mr(),t=rr({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 Ha({accounts:e,onMailboxSelect:t,variant:n="desktop"}){const r=je(),a=Ce(),o=mb(),{searchInput:i,onSearchChange:c}=Ee(),[u,d]=l.useState(Xs),{t:f}=tn("mail",{useSuspense:!1}),m=l.useCallback((C,k)=>f(C,{defaultValue:k}),[f]),h=Jt({queries:e.map(C=>({...et({path:{accountId:C.accountId}}),staleTime:1/0}))}),{data:x}=ie(Js()),b=l.useMemo(()=>(x?.items??[]).filter(C=>Rl(C.status)).length,[x?.items]),p=l.useMemo(()=>e.map((C,k)=>{const M=h[k],T=M?.data?.items??[],D=ys(C.folderAppointments),{system:I,labels:R}=db(T,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:[...I,...R].map(B=>fb(B,D.get(B.mailboxId),m))}}),[e,h,b,m]),y=C=>{r.invalidateQueries({queryKey:tt({path:{mailboxId:C},query:{order:"desc"}})})},g=({navId:C,className:k,ariaLabel:M,title:T,children:D,onClick:I})=>C==="brief"?s.jsx(Xe,{to:"/mail",search:{q:void 0,selectedMessageId:void 0},onClick:()=>I?.(),className:k,"aria-label":M,title:T,children:D}):C==="outbox"?s.jsx(Xe,{to:"/mail/outbox",search:{q:void 0,selectedOutboxMessageId:void 0},onClick:()=>I?.(),className:k,"aria-label":M,title:T,children:D}):C==="flagged"?s.jsx(Xe,{to:"/mail/flagged",search:{q:void 0,selectedMessageId:void 0},onClick:()=>I?.(),className:k,"aria-label":M,title:T,children:D}):s.jsx(Xe,{to:"/mail/$mailboxId",params:{mailboxId:C},search:{q:void 0,selectedMessageId:void 0},onClick:()=>{y(C),I?.()},className:k,"aria-label":M,title:T,children:D}),v=()=>{t?.()},j=i.trim(),w=j.length>0&&!u.includes(j)?j:void 0,N=l.useCallback(()=>{w&&d(lb(w))},[w]),E=l.useCallback(C=>{d(cb(C))},[]),S=l.useCallback(C=>{c(C),a({to:"/mail",search:{q:C,selectedMessageId:void 0}}),t?.()},[c,a,t]);return s.jsx(hd,{accounts:p,selectedNavId:o,onSelectNav:v,linkComponent:g,variant:n,savedSearches:u,saveableQuery:w,onSaveCurrentSearch:N,onSelectSavedSearch:S,onRemoveSavedSearch:E})}function hb({accounts:e,onMailboxSelect:t}){return Zn()?.showNavPane??!0?s.jsx(Ha,{accounts:e}):s.jsxs("div",{className:"flex h-full flex-col",children:[s.jsx("div",{className:"flex-1 overflow-y-auto",children:s.jsx(Ha,{accounts:e,onMailboxSelect:t,variant:"drawer"})}),s.jsxs("div",{className:"border-t border-line px-2 py-2",children:[s.jsxs(Xe,{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(Ao,{className:"size-4 shrink-0"}),s.jsx("span",{className:"flex-1 truncate text-left",children:"Settings"})]}),s.jsx(gl,{variant:"drawer"}),s.jsx(hl,{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(Ro,{className:"size-4 shrink-0"}),s.jsx("span",{className:"flex-1 truncate text-left",children:"Sign out"})]})})]})]})}const Ml={queued:{icon:ir,label:"Queued",className:"text-warning"},sending:{icon:St,label:"Sending…",className:"text-accent-2"},sent:{icon:No,label:"Sent",className:"text-positive"},failed:{icon:yt,label:"Failed",className:"text-danger"},blocked:{icon:Wn,label:"Blocked",className:"text-warning"}},gb=e=>eu(e).toDateString()===new Date().toDateString()?Ws(e,{hour:"numeric",minute:"2-digit"}):Ws(e,{month:"short",day:"numeric"}),Wa=e=>Ws(e,{dateStyle:"medium",timeStyle:"short"}),pb=e=>{const t=e.toAddresses??[];return t.length===0?"No recipients":t.length===1?t[0]:`${t[0]} +${t.length-1}`},Tl=l.createContext(null);function Ir(){const e=l.useContext(Tl);if(!e)throw new Error("OutboxPane.* must be used inside <OutboxPane>");return e}function xb({children:e}){const t=Ce(),{selectedOutboxMessageId:n}=Ut({strict:!1}),{data:r,isLoading:a}=ie(Js()),o=l.useMemo(()=>(r?.items??[]).filter(d=>Rl(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(Tl.Provider,{value:u,children:e})}function Dl({message:e,isSelected:t,onSelect:n}){const r=je(),{openCompose:a}=wt(),{pushError:o}=ze(),i=l.useCallback(()=>{r.invalidateQueries({queryKey:nr()})},[r]),c=xe({...uo(),onSuccess:i,onError:m=>{o(fs("Couldn't resend message","The message wasn't sent.",m))}}),u=xe({...Zs(),onSuccess:i,onError:m=>{o(fs("Couldn't delete message","The message wasn't deleted.",m))}}),d=e.status;if(!Ml[d])return null;const f=Il(e.status);return s.jsx(Ud,{recipients:pb(e),subject:e.subject||"",time:gb(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 Al({message:e,onBack:t}){const n=e.status,r=Ml[n],a=r?.icon??bs,o=e.sentAt?Wa(e.sentAt):Wa(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(jo,{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:fe("size-4",r.className,n==="sending"&&"animate-spin")}),s.jsx("span",{className:fe("text-xs font-medium",r.className),children:r.label}),Il(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(Yi,{html:e.htmlBody,text:e.textBody})})]})}function bb(){const{messages:e,isLoading:t,selectedMessageId:n,onSelectMessage:r}=Ir();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(Xt,{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(Cr,{}),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(Dl,{message:a,isSelected:n===a.outboxMessageId,onSelect:()=>r(a.outboxMessageId)},a.outboxMessageId))})]})}function vb(){const{selectedMessage:e}=Ir();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(Al,{message:e}):s.jsx(Xt,{message:"Select a message to read",showHints:!1})})]})}function yb(){const{messages:e,isLoading:t,selectedMessageId:n,selectedMessage:r,onSelectMessage:a}=Ir();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(Al,{message:r,onBack:()=>a(void 0)}):e.length===0?s.jsx("div",{className:"flex h-full bg-surface",children:s.jsx(Xt,{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(Cr,{}),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(Dl,{message:o,isSelected:n===o.outboxMessageId,onSelect:()=>a(o.outboxMessageId)},o.outboxMessageId))})]})}const Ks=Object.assign(xb,{List:bb,Reading:vb,Phone:yb}),wb=({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:fe("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(Pe,{className:"size-5"})})]}),s.jsx("div",{className:"grid gap-x-8 gap-y-6 sm:grid-cols-2",children:pl.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(Kt,{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(Kt,{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 Sb(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 Nb(e){const t=Jt({queries:e.map(n=>({...et({path:{accountId:n.accountId}}),staleTime:1/0}))});return l.useMemo(()=>Sb(t.map(n=>n.data?.items??[])),[t])}var qs={exports:{}},Va;function kb(){if(Va)return qs.exports;Va=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 x=()=>{if(d)return;const b=u.next(),p=h;if(h++,b.done){f=!0,m===0&&a(c);return}m++,Promise.resolve(b.value).then(y=>n(y,p)).then(y=>{c[p]=y,m--,x()},y=>{d=!0,o(y)})};for(let b=0;b<i&&(x(),!f);b++);});return qs.exports=e,qs.exports.default=e,qs.exports}var Cb=kb();const Eb=Bc(Cb),Ib=900*1e3,Rb=300,Mb=(e,t)=>{if(!e)return t;const n=Number.parseInt(e,10);return Number.isFinite(n)&&n>0?n:t},Tb=60*1e3,Db=e=>Math.max(Mb(e,Rb)*1e3,Tb),Hs=Db(qc().mailboxPollIntervalSeconds),Ab=5,Un=new Set,Ob=(e,t,n=Ib)=>e.filter(r=>{const a=r.lastSyncAt;return a==null?!0:t-a>n}).map(r=>r.accountId),Pb=(e,t,n=Hs)=>e-t>=n,Lb=(e,t)=>e.filter(n=>!t.has(n)),Ya=(e,t)=>{if(Un.delete(e),Kc(t,{softError:!0})){go(t);return}console.warn("[remit] background mailbox sync failed",{accountId:e,error:t})},Ga=(e,t)=>$c({path:{accountId:e},throwOnError:!0}).then(()=>{t.invalidateQueries({queryKey:Vt({path:{accountId:e}})})}),zb=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=Ob(n.current,a).filter(c=>!Un.has(c));if(i.length!==0)for(const c of i)Un.add(c),Ga(c,t).catch(u=>{Ya(c,u)})},[r,t]),l.useEffect(()=>{let a=Date.now(),o;const i=new Set,c=()=>{a=Date.now();const f=Lb(n.current.map(m=>m.accountId),i);for(const m of f)i.add(m);Eb(f,m=>Ga(m,t).catch(h=>{Ya(m,h)}).finally(()=>{i.delete(m)}),{concurrency:Ab})},u=()=>{if(document.visibilityState==="visible"){c(),o=setTimeout(u,Hs);return}},d=()=>{document.visibilityState==="visible"&&Pb(Date.now(),a)&&(o!==void 0&&clearTimeout(o),c(),o=setTimeout(u,Hs))};return o=setTimeout(u,Hs),document.addEventListener("visibilitychange",d),()=>{o!==void 0&&clearTimeout(o),document.removeEventListener("visibilitychange",d)}},[r,t])},_b="/mail/",Fb="/mail/outbox",Bb="/mail/flagged";function $b(e){return e.some(t=>t.routeId===_b)}function Kb(e){return e.some(t=>t.routeId===Bb)}function qb(e){return e.some(t=>t.routeId===Fb)}function Ub(){const{q:e=""}=Ut({from:"/mail"}),t=Ce(),n=Es(),r=Zg(n),[a,o]=l.useState(!1),[i,c]=l.useState(!1),[u,d]=l.useState(!1),f=l.useCallback(Q=>{d(Q),Ua(Q)},[]),[m,h]=l.useState(e),x=bo(m,200),b=l.useRef(e);b.current=e,l.useEffect(()=>{x!==b.current&&t({to:".",search:Q=>{const L=Q.q===x;return{...Q,q:x||void 0,...x&&!L?{selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0}:{}}},replace:!0})},[x,t]);const{data:p,isLoading:y,isError:g,error:v,refetch:j}=ie({...Ze(),staleTime:1/0}),w=!!(p&&(p.accounts?.length??0)===0);l.useEffect(()=>{w&&t({to:"/onboarding",replace:!0})},[w,t]),ps({enabled:!a,bindings:[{key:"?",handler:()=>o(!0),noModifiers:!1,preventDefault:!0}]});const N=l.useCallback(Q=>{h(Q)},[]),E=l.useCallback(()=>{h("")},[]),S=l.useCallback(()=>{h("")},[]),C=l.useCallback(()=>{d(Q=>{const L=!Q;return Ua(L),L})},[]),k=p?.accounts??[],M=Nb(k),T=l.useMemo(()=>jb(k),[k]),D=Ls({select:Q=>Q.matches.find(A=>"mailboxId"in A.params)?.params.mailboxId}),{selectedMessageId:I}=Ut({strict:!1}),R=Ls({select:Q=>$b(Q.matches)}),O=Ls({select:Q=>Kb(Q.matches)}),B=Ls({select:Q=>qb(Q.matches)});zb(k);const K=l.useCallback(()=>{c(!1)},[]),F={accounts:k,mailboxNameIndex:M,accountNameIndex:T,searchQuery:x,searchInput:m,onSearchChange:N,onSearchClear:E,onSearchClearQuery:S,intelligenceOpen:u,onToggleIntelligence:C,onSetIntelligenceOpen:f},$=s.jsx(hb,{accounts:k,onMailboxSelect:K}),U=s.jsx($m,{}),te={navOpen:i,onOpenNav:()=>c(!0),onCloseNav:()=>c(!1)};return s.jsxs(Uc.Provider,{value:F,children:[g?s.jsx("div",{className:"flex h-full items-center justify-center bg-canvas p-4",children:s.jsx(ft,{title:"Couldn't load your account",error:v,onRetry:()=>{j()}})}):R?s.jsx(Fs,{selectedMessageId:I,children:r?s.jsx(at,{nav:$,list:s.jsx(Fs.Phone,{}),intelligenceOpen:u,overlay:U,skeleton:s.jsx(Ye,{}),isLoading:y||w,...te}):s.jsx(at,{nav:$,list:s.jsx(Fs.List,{}),reading:s.jsx(Fs.Reading,{}),intelligenceOpen:u,overlay:U,skeleton:s.jsx(Ye,{}),isLoading:y||w,...te})}):O?s.jsx(Bs,{selectedMessageId:I,children:r?s.jsx(at,{nav:$,list:s.jsx(Bs.Phone,{}),intelligenceOpen:u,overlay:U,skeleton:s.jsx(Ye,{}),isLoading:y||w,...te}):s.jsx(at,{nav:$,list:s.jsx(Bs.List,{}),reading:s.jsx(Bs.Reading,{}),intelligenceOpen:u,overlay:U,skeleton:s.jsx(Ye,{}),isLoading:y||w,...te})}):D?s.jsx(cs,{mailboxId:D,selectedMessageId:I,children:r?s.jsx(at,{nav:$,list:s.jsx(cs.Phone,{}),intelligenceOpen:u,overlay:U,skeleton:s.jsx(Ye,{}),isLoading:y||w,...te}):s.jsx(at,{nav:$,list:s.jsx(cs.List,{}),reading:s.jsx(cs.Reading,{}),intelligence:s.jsx(cs.Intelligence,{}),intelligenceOpen:u,overlay:U,skeleton:s.jsx(Ye,{}),isLoading:y||w,...te})}):B?s.jsx(Ks,{children:r?s.jsx(at,{nav:$,list:s.jsx(Ks.Phone,{}),intelligenceOpen:!1,overlay:U,skeleton:s.jsx(Ye,{}),isLoading:y||w,...te}):s.jsx(at,{nav:$,list:s.jsx(Ks.List,{}),reading:s.jsx(Ks.Reading,{}),intelligenceOpen:!1,overlay:U,skeleton:s.jsx(Ye,{}),isLoading:y||w,...te})}):s.jsx(Ye,{}),s.jsx(wb,{isOpen:a,onClose:()=>o(!1)}),s.jsx(Qc,{})]})}const iv=Object.freeze(Object.defineProperty({__proto__:null,component:Ub,useMailContext:Ee},Symbol.toStringTag,{value:"Module"}));export{ov as S,bu as U,iv as m};