@remit/web-client-dist 0.0.21 → 0.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/{ComposeBody-D8PmiND3.js → ComposeBody-DK_5XIJT.js} +1 -1
- package/assets/{ErrorState-DG6jh7e2.js → ErrorState-DfV1nSfL.js} +1 -1
- package/assets/{OnboardingWizard-DgxqSbdA.js → OnboardingWizard-DMGiIE2m.js} +1 -1
- package/assets/{account-form-helpers-voIR3KwJ.js → account-form-helpers-CyNp4Rtr.js} +1 -1
- package/assets/accounts-CYIO2l1E.js +1 -0
- package/assets/{advanced-BNBIvl7Z.js → advanced-BO78Foz7.js} +1 -1
- package/assets/{appearance-C4sV_Bgs.js → appearance-BJBKoE6a.js} +1 -1
- package/assets/{avatar-WwuE7aom.js → avatar-DpSx3-RK.js} +1 -1
- package/assets/{browser-ponyfill-BBk5Xtq_.js → browser-ponyfill-MW8ko_Tx.js} +1 -1
- package/assets/{filter-status-ybqLOFOR.js → filter-status-nn84yVuB.js} +1 -1
- package/assets/filters-CbZCroGR.js +1 -0
- package/assets/{flagged-Ceo9C3FE.js → flagged-BsXIhLnq.js} +1 -1
- package/assets/folders-hh58ith9.js +1 -0
- package/assets/index-BKPfrhqY.js +1 -0
- package/assets/{index-CCeIZpQ0.js → index-CBHbL9FZ.js} +1 -1
- package/assets/{index-BQKG41NM.js → index-il5av5Ko.js} +60 -60
- package/assets/{index-BkU-X8Kl.css → index-v9SKLUKi.css} +1 -1
- package/assets/{kbd-JYECpmki.js → kbd-Bj-WtqIx.js} +1 -1
- package/assets/mail-Cc6DMsQk.js +112 -0
- package/assets/{onboarding-DfwoEoUJ.js → onboarding-C_F1FOoj.js} +1 -1
- package/assets/{select-DdWCZXwu.js → select-BAEUAEwf.js} +1 -1
- package/assets/{send-BH4zdB7m.js → send-WNE_SERd.js} +1 -1
- package/assets/{senders-D14qF6PF.js → senders-CQYEGZEf.js} +1 -1
- package/assets/settings-B6t5pE7Z.js +1 -0
- package/assets/{settings-screen-VrytBs2p.js → settings-screen-DvPOBmnL.js} +1 -1
- package/assets/{star-Diyw51pt.js → star-DMV_O9nC.js} +1 -1
- package/assets/{suggested-vips-BRyX8ZX3.js → suggested-vips-B78y97R5.js} +1 -1
- package/assets/{trash-2-DTa9lOCZ.js → trash-2-s9JRHvsi.js} +1 -1
- package/assets/{useDebouncedValue-D5vdtQkN.js → useDebouncedValue-D9u8UPp2.js} +1 -1
- package/assets/{useMutation-CXo-HYWj.js → useMutation-Cg5D8A0f.js} +1 -1
- package/assets/{useSignature-ip7HP0v5.js → useSignature-DHQUpTbF.js} +1 -1
- package/index.html +2 -2
- package/package.json +1 -1
- package/assets/accounts-_cJv_LIO.js +0 -1
- package/assets/filters-DGstBlo9.js +0 -1
- package/assets/folders-BNURd924.js +0 -1
- package/assets/index-D6uqSvyo.js +0 -1
- package/assets/mail-wRyPOZOI.js +0 -112
- package/assets/settings-BTbXK9X8.js +0 -1
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ComposeBody-DK_5XIJT.js","assets/index-il5av5Ko.js","assets/index-v9SKLUKi.css","assets/folder-roles-XnseeyyD.js","assets/useDebouncedValue-D9u8UPp2.js","assets/avatar-DpSx3-RK.js","assets/kbd-Bj-WtqIx.js","assets/star-DMV_O9nC.js","assets/trash-2-s9JRHvsi.js","assets/account-form-helpers-CyNp4Rtr.js","assets/send-WNE_SERd.js","assets/useMutation-Cg5D8A0f.js","assets/useSignature-DHQUpTbF.js","assets/ErrorState-DfV1nSfL.js","assets/format-BGdB831k.js","assets/select-BAEUAEwf.js","assets/filter-status-nn84yVuB.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{c as se,r as c,j as s,C as ut,X as Pe,a as K,B as G,b as qe,d as wt,e as oc,f as Zr,p as eo,I as Wn,i as ic,g as to,D as so,O as lc,S as cc,h as uc,F as Vn,k as no,T as Yn,P as dc,l as ao,m as fc,R as Gn,n as Xn,_ as it,o as ro,q as mc,Q as Jn,s as hc,t as gc,u as xc,v as Dn,w as pc,x as bc,y as je,z as vc,A as yc,E as wc,G as jc,H as Sc,J as Nc,K as za,L as kc,M as Cc,N as Ec,U as oo,V as io,W as lo,Y as dt,Z as Ce,$ as He,a0 as fe,a1 as Zn,a2 as ea,a3 as ta,a4 as Ee,a5 as vs,a6 as ie,a7 as co,a8 as Ic,a9 as uo,aa as Rc,ab as en,ac as fo,ad as tt,ae as ze,af as Mc,ag as Ke,ah as mo,ai as gs,aj as tn,ak as Tc,al as st,am as ft,an as Xt,ao as sn,ap as jt,aq as ho,ar as Dc,as as Ac,at as Oc,au as go,av as F,aw as nn,ax as Ht,ay as Pc,az as sa,aA as Lc,aB as zc,aC as xo,aD as na,aE as aa,aF as An,aG as _c,aH as po,aI as et,aJ as Fc,aK as ra,aL as Bc,aM as $c,aN as Kc,aO as qc,aP as oa,aQ as Uc,aR as Hc,aS as Qc,aT as Wc,aU as Vc,aV as Yc,aW as Gc,aX as Xc,aY as Jc,aZ as rt,a_ as Ze,a$ as Zc}from"./index-il5av5Ko.js";import{b as Jt,R as On,g as Ys,l as Qt,s as eu}from"./folder-roles-XnseeyyD.js";import{S as ys,u as bo}from"./useDebouncedValue-D9u8UPp2.js";import{A as Qe,M as ia,C as tu}from"./avatar-DpSx3-RK.js";import{K as qt}from"./kbd-Bj-WtqIx.js";import{S as mt}from"./star-DMV_O9nC.js";import{T as We}from"./trash-2-s9JRHvsi.js";import{L as St,M as vo,a as su}from"./account-form-helpers-CyNp4Rtr.js";import{S as ws,F as nu,M as au,A as ru,a as yo}from"./send-WNE_SERd.js";import{u as pe}from"./useMutation-Cg5D8A0f.js";import{R as ou,u as iu}from"./useSignature-DHQUpTbF.js";import{E as ht,f as wo}from"./ErrorState-DfV1nSfL.js";import{f as jo,a as gt,b as Gs,c as lu,t as cu}from"./format-BGdB831k.js";import{C as js,S as uu}from"./select-BAEUAEwf.js";import{b as So,h as du,p as fu,u as mu}from"./filter-status-nn84yVuB.js";const No=se("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);const hu=se("ArrowRight",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]);const an=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 gu=se("Ban",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m4.9 4.9 14.2 14.2",key:"1m5liu"}]]);const ko=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 xu=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 _a=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 Wt=se("ChevronRight",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]);const Co=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 la=se("CircleCheck",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const ca=se("Clock",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]]);const Eo=se("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]);const Io=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 pu=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 Ro=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 Mo=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 To=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 bu=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 Ss=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 vu=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 yu=se("Minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);const rn=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 wu=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 Do=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 Ao=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 Oo=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 ju=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 Po=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 Ns=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 ks=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 Su=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 Nu=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 Ue=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 ku=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 Cu=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"}]]),Eu=({address:e,showTrustedBadge:t=!1})=>{const n=t?s.jsx(an,{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]})},Iu=({label:e,addresses:t,showTrustedBadge:n=!1})=>{const[a,r]=c.useState(!1);if(t.length===0)return null;const o=t.length>3,i=l=>{const u=n&&l.flags?.trusted?.value===!0;return s.jsx(Eu,{address:l,showTrustedBadge:u})};return s.jsxs("div",{className:"flex gap-2 text-sm",children:[s.jsxs("span",{className:"text-fg-muted shrink-0 w-12",children:[e,":"]}),s.jsx("div",{className:"flex-1 min-w-0",children:a?s.jsx("div",{className:"flex flex-wrap gap-1",children:t.map((l,u)=>s.jsxs("span",{children:[i(l),u<t.length-1&&", "]},u))}):s.jsx("div",{className:"truncate",children:t.map((l,u)=>s.jsxs("span",{children:[i(l),u<t.length-1&&", "]},u))})}),o&&s.jsx("button",{type:"button",onClick:l=>{l.stopPropagation(),r(!a)},className:"shrink-0 text-fg-muted hover:text-fg transition-colors","aria-label":a?"Collapse":"Expand",children:a?s.jsx(ut,{className:"h-4 w-4"}):s.jsx(Wt,{className:"h-4 w-4"})})]})},Ru=({email:e,displayName:t,onRemove:n,className:a})=>s.jsxs("span",{className:K("inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-accent-2-soft text-sm max-w-[200px]",a),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"})})]}),Mu={unknown:{label:"Unknown sender",tone:"neutral"},wellknown:{label:"Known sender",tone:"positive"},vip:{label:"VIP",tone:"accent"}};function Ot({label:e,children:t,className:n}){return s.jsxs("section",{className:K("border-b border-line px-row-inset py-3",n),children:[s.jsx("h3",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e}),s.jsx("div",{className:"mt-2",children:t})]})}function Tu({sender:e}){const t=Mu[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(Qe,{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(qe,{tone:"danger",dot:!0,children:"Address couldn't be verified"}):s.jsx(qe,{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 Du({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(ks,{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(Su,{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(Ns,{className:"mt-0.5 size-4 shrink-0 text-danger"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"text-sm font-semibold text-danger",children:n}),s.jsx("p",{className:"mt-1 text-xs leading-relaxed text-fg",children:e.summary}),!e.addressUnreadable&&e.dkimDomain&&s.jsxs("p",{className:"mt-1 text-2xs text-fg-muted",children:["Sent from"," ",s.jsx("code",{className:"rounded bg-surface px-1 py-0.5",children:e.dkimDomain}),", claims to be"," ",s.jsx("code",{className:"rounded bg-surface px-1 py-0.5",children:e.fromDomain})]})]})]}),e.similarCount!=null&&e.similarCount>0&&s.jsxs(G,{variant:"secondary",size:"sm",className:"mt-2 w-full border-danger/30 text-danger hover:bg-danger-soft",onClick:t,children:[e.similarCount," similar messages"]})]})}function Pt({icon:e,label:t,active:n,danger:a,onClick:r}){const o=r===void 0;return s.jsxs("button",{type:"button",onClick:r,disabled:o,className:K("flex items-center gap-2 rounded-md border px-2 py-1 text-xs transition-colors",n?"border-accent-2 bg-accent-2-soft text-accent-2":"border-line text-fg-muted hover:border-line-strong hover:text-fg",a&&!n&&"text-danger hover:bg-danger-soft",o&&"cursor-not-allowed opacity-50 hover:border-line"),children:[e,t]})}const Au={sender:"matched: sender",recipient:"matched: recipient",subject:"matched: subject",attachment:"matched: attachment",body:"matched: body",entities:"matched: entities"};function Lo({data:e,onClose:t,onShowSimilar:n,actions:a,similarState:r="ready",similarLinkComponent:o,className:i,hideCloseButton:l=!1}){const{sender:u,authenticity:d,category:f,flags:m={},similar:h}=e,p=d.verdict==="mismatch";return s.jsxs("aside",{className:K("flex w-76 shrink-0 flex-col overflow-y-auto border-l border-line bg-surface",i),children:[s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center justify-between border-b border-line px-row-inset",children:[s.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"}),!l&&s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(Pe,{className:"size-3.5"}),onClick:t,"aria-label":"Collapse intelligence sidebar"})]}),s.jsx(Ot,{label:"Sender",children:s.jsx(Tu,{sender:u})}),s.jsx(Ot,{label:"Authenticity",children:s.jsx(Du,{auth:d,onShowSimilar:n})}),s.jsx(Ot,{label:"Category",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(qe,{tone:p?"danger":"neutral",children:f.value}),f.overridden&&s.jsx("span",{className:"text-2xs text-fg-subtle",children:"your override"}),s.jsx("button",{type:"button",className:K("ml-auto text-2xs text-accent hover:underline",!a?.onReclassify&&"cursor-not-allowed opacity-50 hover:no-underline"),disabled:!a?.onReclassify,onClick:a?.onReclassify,children:"reclassify"})]})}),s.jsx(Ot,{label:"Quick actions",children:s.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[s.jsx(Pt,{icon:s.jsx(mt,{className:"size-3.5"}),label:"VIP",active:m.vip,onClick:a?.onToggleVip}),s.jsx(Pt,{icon:s.jsx(ko,{className:"size-3.5"}),label:"Mute",active:m.muted,onClick:a?.onToggleMute}),s.jsx(Pt,{icon:s.jsx(gu,{className:"size-3.5"}),label:"Block",active:m.blocked,danger:!0,onClick:a?.onToggleBlock}),s.jsx(Pt,{icon:s.jsx(vu,{className:"size-3.5"}),label:"Unsubscribe",active:m.unsubscribed,onClick:a?.onToggleUnsubscribe}),a?.onNotSpam&&s.jsx(Pt,{icon:s.jsx(bu,{className:"size-3.5"}),label:"Not spam",onClick:a.onNotSpam}),a?.onMarkSpam&&s.jsx(Pt,{icon:s.jsx(Nu,{className:"size-3.5"}),label:"Mark spam",danger:!0,onClick:a.onMarkSpam})]})}),(r!=="ready"||h.length>0)&&s.jsx(Ot,{label:"Similar messages",children:r==="loading"?s.jsx("div",{className:"animate-pulse space-y-2",children:Array.from({length:3}).map((b,x)=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"h-3 w-3/4 rounded bg-surface-sunken"}),s.jsx("div",{className:"h-2.5 w-1/2 rounded bg-surface-sunken"})]},x))}):r==="error"?s.jsx("p",{className:"text-xs text-fg-subtle",children:"Similarity search unavailable"}):s.jsx("ul",{className:"-mx-1 space-y-1",children:h.map(b=>{const x="block w-full rounded-md px-1 py-1 text-left hover:bg-surface-sunken",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:Au[b.matched]})]});return s.jsx("li",{children:o?o({mailboxId:b.mailboxId,messageId:b.id,className:x,ariaLabel:y,children:g}):s.jsx("div",{className:x,children:g})},b.id)})})}),s.jsx(Ot,{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(Ue,{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(Ue,{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 Ou=[{keys:["j","k"],label:"navigate"},{keys:["m"],label:"mute"},{keys:["?"],label:"all shortcuts"}];function zo({hints:e=Ou,className:t}){return s.jsx("footer",{className:K("flex items-center gap-2 border-t border-line px-row-inset py-1 text-2xs text-fg-subtle",t),children:e.map(n=>s.jsx(Pu,{hint:n},n.label))})}function Pu({hint:e}){return s.jsxs("span",{className:"flex items-center gap-1",children:[e.keys.map(t=>s.jsx(qt,{children:t},t)),s.jsx("span",{children:e.label})]})}function Lu(){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 zu({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 _u({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(wt,{className:"size-8 text-danger","aria-hidden":"true"}),s.jsxs("div",{children:[s.jsx("p",{className:"font-medium text-danger",children:"Couldn't load messages"}),s.jsx("p",{className:"mt-1 break-words text-sm text-fg-muted",children:e})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[t&&s.jsx(G,{variant:"secondary",size:"sm",onClick:t,children:"Retry"}),n&&s.jsx(G,{variant:"ghost",size:"sm",onClick:n,children:"Report a problem"})]})]})})}const _o=({active:e,focused:t})=>K("relative flex h-8 w-full items-center gap-2 px-row-inset text-left",e?"bg-accent-2-soft":t?"bg-surface-sunken":"hover:bg-surface-sunken",t&&!e&&"before:absolute before:inset-y-0 before:left-0 before:w-0.5 before:bg-accent-2"),Zt=({active:e,focused:t})=>K("relative flex w-full items-start gap-3 py-2 pl-5 pr-row-inset text-left transition-colors",e?"bg-accent-2-soft":t?"bg-surface-sunken":"hover:bg-surface-sunken",t&&!e&&"before:absolute before:inset-y-0 before:left-0 before:w-0.5 before:bg-accent-2");function Fo({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(Ns,{className:"size-3.5 text-danger"}):e.starred?s.jsx(mt,{className:"size-3 fill-warning text-warning"}):t?s.jsx("span",{className:"size-1.5 rounded-full bg-accent"}):null}),s.jsx("span",{className:K("w-36 shrink-0 truncate text-xs",t?"font-semibold text-fg":"text-fg-muted"),children:e.fromName}),s.jsxs("span",{className:"min-w-0 flex-1 truncate text-xs",children:[s.jsx("span",{className:K(t?"font-medium text-fg":"text-fg-muted"),children:e.subject}),s.jsxs("span",{className:"text-fg-subtle",children:[" — ",e.snippet]})]}),e.hasAttachment&&s.jsx(rn,{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 es({thread:e,badge:t}){const n=!e.isRead;return s.jsxs("span",{className:"min-w-0 flex-1",children:[s.jsxs("span",{className:"flex items-baseline justify-between gap-2",children:[s.jsxs("span",{className:K("flex min-w-0 items-center gap-1.5 truncate text-sm",n?"font-semibold text-fg":"font-medium text-fg-muted"),children:[e.trust==="vip"&&s.jsx("span",{className:"size-1.5 shrink-0 rounded-full bg-accent-2"}),s.jsx("span",{className:"truncate",children:e.fromName}),e.messageCount!=null&&e.messageCount>1&&s.jsx("span",{className:"shrink-0 text-2xs font-normal text-fg-subtle",children:e.messageCount})]}),s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.timeLabel})]}),s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:K("truncate text-sm",n?"text-fg":"text-fg-muted"),children:e.subject}),e.suspicious&&s.jsx(Ns,{className:"size-3.5 shrink-0 text-danger"}),e.starred&&s.jsx(mt,{className:"size-3 shrink-0 fill-warning text-warning"}),e.hasAttachment&&s.jsx(rn,{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(qe,{tone:oc[e.category],className:"shrink-0",children:e.category}),t]})]})}function Bo({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(Qe,{name:e.fromName,email:e.fromEmail,size:"sm"}),s.jsx(es,{thread:e})]})}function Fu({thread:e,active:t,onClick:n}){return s.jsx("button",{type:"button",onClick:n,className:_o({active:t}),children:s.jsx(Fo,{thread:e})})}function $o({thread:e,active:t,onClick:n}){return s.jsx("button",{type:"button",onClick:n,className:Zt({active:t}),children:s.jsx(Bo,{thread:e})})}function Ko({count:e,onCancel:t,onMarkRead:n,onDelete:a,moveSlot:r,moveDisabledHint:o,isBusy:i=!1}){return s.jsxs("header",{className:"flex shrink-0 flex-col border-b border-line bg-surface-sunken",children:[s.jsxs("div",{className:"flex h-pane-header items-center gap-2 px-row-inset",children:[s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(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(G,{variant:"ghost",size:"sm",icon:s.jsx(Ss,{className:"size-4"}),onClick:i?void 0:n,"aria-label":"Mark as read","aria-busy":i||void 0,className:"shrink-0"}),r,s.jsx(G,{variant:"ghost",size:"sm",icon:i?s.jsx(St,{className:"size-4 animate-spin"}):s.jsx(We,{className:"size-4 text-danger"}),onClick:i?void 0:a,"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 Vt=72,Fa=10;function Ba(e){return e==="leading"?Vt:e==="trailing"?-Vt:0}function Bu(e){return e>=Vt/2?"leading":e<=-Vt/2?"trailing":"none"}function qo({thread:e,selectionMode:t,checked:n,active:a,peek:r,onPeek:o,onToggleCheck:i,onLongPress:l,onOpen:u,onAct:d,linkComponent:f}){const m=c.useRef(void 0),h=c.useRef(null),[p,b]=c.useState(null),x=()=>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),l()},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)>Fa&&Math.abs(D)>Math.abs(T)){M.axis="vertical",x(),h.current=null;return}Math.abs(T)>Fa&&(M.axis="horizontal",M.moved=!0,x(),k.currentTarget.setPointerCapture(k.pointerId))}if(M.axis!=="horizontal")return;const I=Ba(r),R=Math.max(-Vt,Math.min(Vt,I+T));b(R)},v=()=>{x();const k=h.current;h.current=null;const M=p;if(b(null),!!k){if(k.axis==="horizontal"&&M!==null){o(Bu(M));return}if(t){i();return}if(r!=="none"){o("none");return}f||u()}},w=k=>{r!=="none"&&k.preventDefault()},j=p??Ba(r),C=j>0?"leading":j<0?"trailing":"none",N=K("relative touch-pan-y bg-surface",Zt({active:n||a})),S={transform:j!==0?`translateX(${j}px)`:void 0,transition:p===null?"transform 150ms ease":"none",minHeight:44},E=t?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:K("inline-flex size-7 shrink-0 items-center justify-center rounded-full border",n?"border-accent bg-accent text-accent-fg":"border-line-strong bg-canvas"),children:n&&s.jsx(js,{className:"size-3.5"})}),s.jsx(es,{thread:e})]}):s.jsx(Bo,{thread:e});return s.jsxs("div",{className:"relative overflow-hidden",children:[C==="leading"&&s.jsx("button",{type:"button",onClick:()=>d("leading"),"aria-label":e.isRead?"Mark as unread":"Mark as read",className:"absolute inset-y-0 left-0 flex items-center justify-start bg-accent-2 px-6 text-accent-fg",children:e.isRead?s.jsx(vo,{className:"size-6"}):s.jsx(Ss,{className:"size-6"})}),C==="trailing"&&s.jsx("button",{type:"button",onClick:()=>d("trailing"),"aria-label":"Delete message",className:"absolute inset-y-0 right-0 flex items-center justify-end bg-danger px-6 text-canvas",children:s.jsx(We,{className:"size-6"})}),f&&!t?f({className:N,style:S,onPointerDown:y,onPointerMove:g,onPointerUp:v,onPointerCancel:v,onOpenClick:w,children:E}):s.jsx("button",{type:"button",onPointerDown:y,onPointerMove:g,onPointerUp:v,onPointerCancel:v,className:N,style:S,children:E})]})}function $u({sections:e,selectedThreadId:t,selectionMode:n,checkedIds:a,initialPeek:r,onToggleCheck:o,onEnterSelection:i,onOpenThread:l,onRefresh:u,refreshing:d}){const[f,m]=c.useState(()=>e.flatMap(x=>x.threads)),[h,p]=c.useState(r&&r!=="none"&&f[1]?{id:f[1].id,side:r}:null),b=(x,y)=>{m(y==="trailing"?g=>g.filter(v=>v.id!==x):g=>g.map(v=>v.id===x?{...v,isRead:!v.isRead}:v)),p(null)};return s.jsxs("div",{className:"flex-1 overflow-y-auto",children:[d&&s.jsxs("div",{className:"flex items-center justify-center gap-2 border-b border-line py-3 text-fg-muted",children:[s.jsx(Do,{className:"size-4 animate-spin"}),s.jsx("span",{className:"text-xs",children:"Checking for new mail…"})]}),s.jsx("div",{className:"divide-y divide-line",children:f.map(x=>s.jsx(qo,{thread:x,selectionMode:n,checked:a.has(x.id),active:x.id===t,peek:h?.id===x.id?h.side:"none",onPeek:y=>p(y==="none"?null:{id:x.id,side:y}),onToggleCheck:()=>o(x.id),onLongPress:()=>i(x.id),onOpen:()=>l(x.id),onAct:y=>b(x.id,y)},x.id))}),!n&&!d&&s.jsx("button",{type:"button",onClick:u,className:"w-full border-t border-line py-2 text-center text-2xs text-fg-subtle transition-colors hover:bg-surface-sunken",children:"Pull to refresh"})]})}function Uo({listTitle:e,listMeta:t,sections:n,briefFilters:a,flatList:r,listState:o="ready",searchQuery:i,errorMessage:l,onRetry:u,onReportError:d,briefCategory:f,selectedThreadId:m,density:h="comfortable",onSelectThread:p,onSelectBriefCategory:b,onOpenNav:x,isDesktop:y,initialTouchState:g,selectionBar:v,listBody:w,hideHeader:j=!1}){const C=h==="compact"?Fu:$o,N=!y&&!a&&o==="ready",S=n.flatMap(U=>U.threads),[E,k]=c.useState(g==="selection"),[M,T]=c.useState(()=>g==="selection"?new Set(S.slice(0,2).map(U=>U.id)):new Set),[D,I]=c.useState(!1),R=g==="peek-trailing"?"trailing":g==="peek-leading"?"leading":void 0,O=U=>{T(te=>{const J=new Set(te);return J.has(U)?J.delete(U):J.add(U),J.size===0&&k(!1),J})},B=U=>{k(!0),T(new Set([U]))},$=()=>{k(!1),T(new Set)},q=()=>{I(!0),setTimeout(()=>I(!1),1400)},_=!v&&N&&E&&M.size>0;return s.jsxs("section",{className:"flex h-full w-full flex-col bg-surface",children:[v??(_?s.jsx(Ko,{count:M.size,onCancel:$,onMarkRead:$,onDelete:$}):j?null:s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[x&&s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(ia,{className:"size-4"}),onClick:x,"aria-label":"Open folders",className:"-ml-1 shrink-0"}),s.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e}),t&&s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle",children:t})]})),o==="loading"?s.jsx("div",{className:"flex-1 overflow-y-auto",children:s.jsx(Lu,{})}):o==="empty"?s.jsx(zu,{searchQuery:i}):o==="error"?s.jsx(_u,{message:l,onRetry:u,onReport:d}):a?s.jsx(Zr,{sections:n,briefCategory:f,selectedThreadId:m,Row:C,onSelectThread:p,onSelectBriefCategory:b}):w??(N?s.jsx($u,{sections:n,selectedThreadId:m,selectionMode:E,checkedIds:M,initialPeek:R,onToggleCheck:O,onEnterSelection:B,onOpenThread:U=>p?.(U),onRefresh:q,refreshing:D}):s.jsx("div",{className:"flex-1 overflow-y-auto",children:n.map(U=>s.jsxs("div",{children:[!r&&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(C,{thread:te,active:te.id===m,onClick:()=>p?.(te.id)},te.id))})]},U.id))})),y&&s.jsx(zo,{})]})}function Ku({triggerLabel:e,triggerIcon:t,items:n,align:a="end",touch:r=!0,className:o}){const[i,l]=c.useState(!1),u=c.useRef(null);return c.useEffect(()=>{if(!i)return;const d=m=>{u.current&&!u.current.contains(m.target)&&l(!1)},f=m=>{m.key==="Escape"&&l(!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:K("relative",o),children:[s.jsx(G,{variant:"ghost",size:"sm",icon:t??s.jsx(Io,{className:"size-5"}),onClick:()=>l(d=>!d),"aria-label":e,"aria-haspopup":"menu","aria-expanded":i,className:K(r&&"min-h-11 min-w-11 px-0")}),i&&s.jsx("div",{role:"menu",className:K("absolute top-full z-50 mt-1 flex min-w-44 flex-col rounded-md border border-line bg-surface py-1 shadow-lg",a==="end"?"right-0":"left-0"),children:n.map(d=>s.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{l(!1),d.onSelect()},className:"flex min-h-11 items-center gap-3 px-4 py-2.5 text-left text-sm text-fg transition-colors hover:bg-surface-sunken",children:[d.icon&&s.jsx("span",{className:"shrink-0 text-fg-subtle",children:d.icon}),d.label]},d.key))})]})}const is="min-h-11 min-w-11 px-0";function Ho({hasThread:e,onReply:t,onReplyAll:n,onForward:a,isStarred:r,onToggleStar:o,onDelete:i,isRead:l,onToggleRead:u,moveSlot:d,overflowItems:f=[],onUnavailable:m,unavailableHint:h,className:p}){const b=(y,g)=>()=>{if(!e){m?.(y);return}g?.()},x=u?[{key:"toggle-read",label:l?"Mark as unread":"Mark as read",icon:l?s.jsx(vo,{className:"size-4"}):s.jsx(Ss,{className:"size-4"}),onSelect:b("toggleRead",u)}]:[];return s.jsxs("div",{className:K("relative",p),children:[s.jsxs("div",{className:"flex h-12 shrink-0 items-center gap-0.5 border-y border-line bg-canvas px-1",children:[s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(Oo,{className:"size-5"}),onClick:b("reply",t),"aria-label":"Reply",title:"Reply",className:is}),s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(Ao,{className:"size-5"}),onClick:b("replyAll",n),"aria-label":"Reply all",title:"Reply all",className:is}),s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(Mo,{className:"size-5"}),onClick:b("forward",a),"aria-label":"Forward",title:"Forward",className:is}),s.jsx("div",{className:"flex-1"}),s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(mt,{className:K("size-5",r&&"fill-warning text-warning")}),onClick:b("star",o),"aria-label":r?"Unstar":"Star","aria-pressed":r,title:r?"Unstar":"Star",className:is}),d,s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(We,{className:"size-5"}),onClick:b("delete",i),"aria-label":"Move to Trash",title:"Move to Trash",className:is}),s.jsx(Ku,{triggerLabel:"More actions",items:[...x,...f]})]}),!e&&h&&s.jsx("p",{role:"status",className:"border-b border-line bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:h})]})}function qu({hasThread:e,onUnavailable:t,unavailableHint:n,isStarred:a,showTriage:r=!0,onReply:o,onReplyAll:i,onForward:l,onDelete:u,onToggleStar:d,moveSlot:f,onMove:m,replyTitle:h="Reply (r)",replyAllTitle:p="Reply all (a)",forwardTitle:b="Forward (f)",deleteTitle:x="Move to Trash (#)",flagTitle:y="Star (s)",children:g,className:v}){const w=(j,C)=>()=>{if(!e){t?.(j);return}C?.()};return s.jsxs("div",{className:"relative",children:[s.jsxs("header",{className:K("flex h-pane-header shrink-0 items-center gap-1 border-b border-line bg-surface px-3",v),children:[s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(Oo,{className:"size-4"}),title:h,"aria-label":"Reply",onClick:w("reply",o)}),s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(Ao,{className:"size-4"}),title:p,"aria-label":"Reply all",onClick:w("replyAll",i)}),s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(Mo,{className:"size-4"}),title:b,"aria-label":"Forward",onClick:w("forward",l)}),r&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"mx-1 h-4 w-px bg-line","aria-hidden":!0}),s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(We,{className:"size-4"}),title:x,"aria-label":"Move to Trash",onClick:w("delete",u)}),f??s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(Ro,{className:"size-4"}),title:"Move to mailbox","aria-label":"Move to mailbox",onClick:w("move",m)}),s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(mt,{className:K("size-4",a&&"fill-warning text-warning")}),title:y,"aria-label":"Star",onClick:w("flag",d)})]}),s.jsx("div",{className:"flex-1"}),g]}),!e&&n&&s.jsx("p",{role:"status",className:"border-b border-line bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:n})]})}const Uu=(e,t)=>{const a=e==="newsletter"||e==="marketing"||t;return{framed:a,isPlain:!a}},Hu=()=>`
|
|
3
|
+
/* Zero the UA default body margin and clamp the document to the iframe width so
|
|
4
|
+
wide author markup can't push the body (and the page) past the viewport. */
|
|
5
|
+
html, body {
|
|
6
|
+
margin: 0;
|
|
7
|
+
padding: 0;
|
|
8
|
+
max-width: 100%;
|
|
9
|
+
}
|
|
10
|
+
body {
|
|
11
|
+
overflow-wrap: anywhere;
|
|
12
|
+
word-break: break-word;
|
|
13
|
+
}
|
|
14
|
+
/* Media never wider than the frame; keep aspect ratio when width is capped. */
|
|
15
|
+
img, video, iframe, svg, canvas {
|
|
16
|
+
max-width: 100% !important;
|
|
17
|
+
height: auto;
|
|
18
|
+
}
|
|
19
|
+
/* Fixed-width author tables (\`<table width="600">\`) collapse to fit. */
|
|
20
|
+
table {
|
|
21
|
+
max-width: 100% !important;
|
|
22
|
+
table-layout: auto;
|
|
23
|
+
}
|
|
24
|
+
/* Cells carry the fixed widths in real newsletters (\`<td width="600">\`);
|
|
25
|
+
cap them too or the table can't actually shrink. */
|
|
26
|
+
td, th {
|
|
27
|
+
max-width: 100% !important;
|
|
28
|
+
}
|
|
29
|
+
/* \`max-width\` alone can't beat an inline \`min-width\`; zeroing the min lets
|
|
30
|
+
flex / grid / table children actually collapse to the clamped width. */
|
|
31
|
+
* {
|
|
32
|
+
min-width: 0;
|
|
33
|
+
}
|
|
34
|
+
/* Long unbroken strings (URLs, tokens) wrap instead of forcing a wide line. */
|
|
35
|
+
pre, code {
|
|
36
|
+
white-space: pre-wrap;
|
|
37
|
+
overflow-wrap: anywhere;
|
|
38
|
+
word-break: break-word;
|
|
39
|
+
}
|
|
40
|
+
`,Qu=e=>{const t=new Map;for(const n of e){if(!n.contentId||n.contentUrl.length===0)continue;const a=n.contentId.replace(/^<|>$/g,"");t.set(a,n.contentUrl)}return n=>t.get(n.replace(/^<|>$/g,""))},Wu=/^(none|transparent|inherit|initial|unset)\s*$/i,Vu=e=>{const t=[],n=/<style[^>]*>([\s\S]*?)<\/style>/gi;let a;for(a=n.exec(e);a!==null;)t.push(a[1]),a=n.exec(e);return t},Yu=e=>{const t=/background(?:-color)?\s*:\s*([^;}\n]+)/gi;let n;for(n=t.exec(e);n!==null;){const a=n[1].trim();if(!Wu.test(a))return!0;n=t.exec(e)}return!1},Gu=e=>{if(/\bstyle\s*=\s*["'][^"']*background/i.test(e)||/\bbgcolor\s*=/i.test(e))return!0;for(const t of Vu(e))if(Yu(t))return!0;return!1},Xu=["script","iframe","object","embed","form","input","button","textarea","select","meta","link","base"],Ju=["onerror","onload","onclick","onmouseover","onmouseout","onfocus","onblur","onsubmit","onkeydown","onkeyup","formaction","xlink:href","data-bind"],Zu="data:image/svg+xml,"+encodeURIComponent(`
|
|
41
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100">
|
|
42
|
+
<rect fill="#f0f0f0" width="100" height="100"/>
|
|
43
|
+
<text x="50" y="50" text-anchor="middle" dy=".3em" fill="#999" font-size="12">
|
|
44
|
+
Image blocked
|
|
45
|
+
</text>
|
|
46
|
+
</svg>
|
|
47
|
+
`),ed=e=>e.replace(/url\s*\([^)]*\)/gi,"none").replace(/expression\s*\([^)]*\)/gi,"").replace(/-moz-binding\s*:[^;]*/gi,""),td=e=>e.replace(/@import[^;]*;/gi,"/* @import blocked */").replace(/url\s*\([^)]*\)/gi,"none").replace(/expression\s*\([^)]*\)/gi,"").replace(/-moz-binding\s*:[^;]*/gi,""),sd=(e={})=>{const t=eo(),n={FORBID_TAGS:Xu,FORBID_ATTR:Ju,ALLOW_DATA_ATTR:!1,ALLOW_UNKNOWN_PROTOCOLS:!1};return t.addHook("afterSanitizeAttributes",a=>{if(a.tagName==="IMG"){const r=a.getAttribute("src")||"";if(r.startsWith("data:"))return;if(r.startsWith("cid:")){const i=r.slice(4).replace(/^<|>$/g,""),l=e.resolveCid?.(i);l&&(a.setAttribute("src",l),a.classList.add("inline-content"));return}e.allowExternalImages||(a.setAttribute("data-blocked-src",r),a.setAttribute("src",Zu),a.setAttribute("alt","[Blocked image]"),a.classList.add("blocked-image"))}if(a.tagName==="A"){const r=a.getAttribute("href")||"";if(/^(javascript|data):/i.test(r)){a.removeAttribute("href");return}a.setAttribute("target","_blank"),a.setAttribute("rel","noopener noreferrer nofollow"),a.classList.add("external-link")}if(a.hasAttribute("style")){const r=a.getAttribute("style")||"";a.setAttribute("style",ed(r))}}),t.addHook("uponSanitizeElement",(a,r)=>{if(r.tagName==="style"){const o=a.textContent||"";a.textContent=td(o)}}),a=>{const r=Gu(a),o=t.sanitize(a,n);return{html:`<style>${Hu()}</style>${o}`,hasAuthorBackground:r}}},nd='"Geist Variable", "Geist", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',$a={light:{fg:"oklch(0.3 0.025 235)",surface:"oklch(0.975 0.012 90)",accent:"oklch(0.55 0.14 150)"},dark:{fg:"oklch(0.88 0.02 90)",surface:"oklch(0.25 0.025 220)",accent:"oklch(0.78 0.16 150)"}},ad=/prefers-color-scheme\s*:\s*dark|color-scheme\s*:\s*[^;}"']*\bdark\b/i,Ka='<meta name="viewport" content="width=device-width, initial-scale=1">',rd=e=>{const t=e?$a.dark:$a.light;return`
|
|
48
|
+
/* Plain-email base: UI font-stack + theme-aware colors (#424) */
|
|
49
|
+
html, body {
|
|
50
|
+
font-family: ${nd};
|
|
51
|
+
font-size: 14px;
|
|
52
|
+
line-height: 1.6;
|
|
53
|
+
color: ${t.fg};
|
|
54
|
+
background-color: ${t.surface};
|
|
55
|
+
margin: 0;
|
|
56
|
+
padding: 0;
|
|
57
|
+
}
|
|
58
|
+
/* Strip author unreadable text colors and element backgrounds, scoped to body
|
|
59
|
+
descendants so the themed html/body surface above survives this reset. */
|
|
60
|
+
body * {
|
|
61
|
+
color: inherit !important;
|
|
62
|
+
background-color: transparent !important;
|
|
63
|
+
}
|
|
64
|
+
a, a:visited {
|
|
65
|
+
color: ${t.accent} !important;
|
|
66
|
+
text-decoration: underline;
|
|
67
|
+
}
|
|
68
|
+
`},od=(e,t)=>e?t?"html,body{margin:0;color-scheme:dark light}":"html{margin:0;background-color:#ffffff;filter:invert(0.92) hue-rotate(180deg)}body{margin:0}img,picture,video,svg,canvas,[style*='background-image'],[background]{filter:invert(0.92) hue-rotate(180deg)}":"html,body{margin:0;background-color:#ffffff;color-scheme:light}",id=(e,t,n)=>{if(t==="plain")return`${Ka}<style>${rd(n)}</style>${e}`;const a=ad.test(e);return`${Ka}<style>${od(n,a)}</style>${e}`},ld=5e4,cd=1e4,ud="(max-width: 640px)",dd=.4,fd="allow-same-origin allow-popups allow-popups-to-escape-sandbox",qa=(e,t,n)=>Math.min(Math.ceil(Math.max(e,t)),n),md=(e,t)=>e<=0||t<=0||e<=t?1:Math.max(dd,t/e),hd=e=>{const[t,n]=c.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return c.useEffect(()=>{if(typeof window>"u"||!window.matchMedia)return;const a=window.matchMedia(e);n(a.matches);const r=o=>n(o.matches);return a.addEventListener("change",r),()=>a.removeEventListener("change",r)},[e]),t},Ua=({html:e,variant:t="framed",isDark:n=!1,className:a})=>{const r=c.useRef(null),o=c.useRef(null),[i,l]=c.useState(0),[u,d]=c.useState(0),[f,m]=c.useState(0),h=hd(ud),p=c.useMemo(()=>id(e,t,n),[e,t,n]);c.useEffect(()=>{const w=r.current;if(!w)return;const j=()=>m(N=>N===w.clientWidth?N:w.clientWidth);j();const C=new ResizeObserver(j);return C.observe(w),()=>C.disconnect()},[]),c.useEffect(()=>{const w=o.current;if(!w)return;const j=()=>{const S=w.contentDocument;if(!S?.body)return;const E=S.documentElement,k=qa(S.body.scrollHeight,E?.scrollHeight??0,ld);l(T=>T===k?T:k);const M=qa(S.body.scrollWidth,E?.scrollWidth??0,cd);d(T=>T===M?T:M)};let C;const N=()=>{j();const S=w.contentDocument;S?.body&&(C=new ResizeObserver(j),C.observe(S.body),S.documentElement&&C.observe(S.documentElement))};return w.addEventListener("load",N),()=>{w.removeEventListener("load",N),C?.disconnect()}},[]);const b=h?md(u,f):1,x=b<1,y=x?`${u}px`:h?"100%":t==="framed"&&u>0?`max(100%, ${u}px)`:u===0?"100%":`${u}px`,g=i===0?"1px":`${i}px`,v=s.jsx("iframe",{ref:o,title:"Email content",sandbox:fd,srcDoc:p,className:x?void 0:a,scrolling:"no",style:{width:y,maxWidth:x?"none":void 0,border:"none",display:"block",height:g,overflow:"hidden",transform:x?`scale(${b})`:void 0,transformOrigin:x?"top left":void 0,colorScheme:"normal"}});return s.jsx("div",{ref:r,className:x?a:void 0,children:x?s.jsx("div",{style:{width:"100%",height:`${Math.ceil(i*b)}px`,overflow:"hidden"},children:v}):v})},Ha=()=>s.jsx("p",{className:"text-fg-muted text-sm italic",children:"This message has no body content."}),Qo=({html:e,text:t,isDark:n=!1,category:a,allowImages:r=!1,resolveCid:o,className:i,renderBlockedNotice:l})=>{const u=c.useMemo(()=>!e||typeof document>"u"?null:sd({allowExternalImages:r,resolveCid:o})(e),[e,r,o]),d=u?.html??null,{framed:f,isPlain:m}=Uu(a,u?.hasAuthorBackground??!1),h=c.useMemo(()=>!d||r?0:(d.match(/data-blocked-src/g)||[]).length,[d,r]);return!d&&!t?s.jsx("div",{className:K("message-body",i),children:s.jsx(Ha,{})}):s.jsxs("div",{className:K("message-body",i),children:[h>0&&l?.(h),d?f?s.jsx("div",{className:"w-full max-w-full overflow-x-auto",children:s.jsx(Ua,{html:d,variant:"framed",isDark:n})}):s.jsx("div",{className:"max-w-full overflow-x-auto lg:max-w-2xl",children:s.jsx(Ua,{html:d,variant:m?"plain":"framed",isDark:n})}):t?s.jsx("pre",{className:"email-text whitespace-pre-wrap text-sm leading-relaxed",children:t}):s.jsx(Ha,{})]})};function ts({message:e="Select a thread to read",icon:t,showHints:n=!0,className:a}){return s.jsxs("div",{className:K("flex flex-1 flex-col items-center justify-center text-center",a),children:[t??s.jsx(Wn,{className:"size-10 text-fg-subtle"}),s.jsx("p",{className:"mt-3 text-sm text-fg-muted",children:e}),n&&s.jsxs("p",{className:"text-2xs text-fg-subtle",children:[s.jsx(qt,{children:"j"})," / ",s.jsx(qt,{children:"k"})," to move, ",s.jsx(qt,{children:"Enter"})," to open"]})]})}function Wo({message:e,onClick:t,isFocused:n,isUnread:a,trailing:r}){const o=s.jsxs(s.Fragment,{children:[s.jsx(Wt,{className:"size-3.5 shrink-0 text-fg-subtle"}),s.jsxs("div",{className:"relative shrink-0",children:[s.jsx(Qe,{name:e.fromName,email:e.fromEmail,size:"md"}),a&&s.jsx("span",{className:"absolute -top-0.5 -right-0.5 size-2 rounded-full border border-canvas bg-accent"})]}),s.jsx("span",{className:K("w-36 shrink-0 truncate text-sm",a?"font-semibold text-fg":"font-medium text-fg-muted"),children:e.fromName}),s.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-fg-subtle",children:e.snippet}),r??s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.dateLabel})]}),i=K("group flex h-section-row w-full items-center gap-3 border-b border-line px-2 text-left transition-colors hover:bg-surface-sunken lg:px-4",n&&"bg-surface-sunken ring-1 ring-inset ring-accent/30");return t?s.jsx("div",{role:"button",tabIndex:0,"aria-expanded":!1,onClick:t,onKeyDown:l=>{ic(l)&&(l.preventDefault(),t())},className:K(i,"cursor-pointer"),children:o}):s.jsx("div",{className:i,children:o})}function Vo({message:e,warning:t,onHeaderClick:n,isFocused:a,senderBadge:r,trailing:o,to:i,indicators:l,actionMenu:u,actionBar:d,body:f}){const m=s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[s.jsxs("span",{className:"text-sm font-semibold text-fg",children:[e.fromName,r]}),o??s.jsx("span",{className:"text-2xs text-fg-subtle",children:e.dateLabel})]}),s.jsx("div",{className:"text-xs text-fg-subtle",children:e.fromEmail}),i!==null&&s.jsx("div",{className:"text-xs text-fg-subtle",children:i??s.jsxs(s.Fragment,{children:["to ",e.toLabel]})})]});return s.jsxs("div",{className:K("px-2 py-3 lg:px-4",a&&"ring-1 ring-inset ring-accent/30"),children:[s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx(ut,{className:"mt-1 size-3.5 shrink-0 text-fg-subtle"}),s.jsx(Qe,{name:e.fromName,email:e.fromEmail,size:"md"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[n?s.jsx("button",{type:"button",onClick:n,className:"w-full text-left",children:m}):m,l]}),u&&s.jsx("div",{className:"shrink-0",children:u})]}),t&&s.jsxs("div",{className:"mt-3 flex items-start gap-3 rounded-md bg-danger-soft p-3",children:[s.jsx(Ns,{className:"mt-0.5 size-4 shrink-0 text-danger"}),s.jsxs("div",{className:"text-sm text-fg",children:[s.jsx("span",{className:"font-semibold text-danger",children:"Caution: "}),t," ",s.jsx("button",{type:"button",className:"text-accent underline",children:"Why?"})]})]}),d&&s.jsx("div",{className:"mt-3 -mx-2 lg:-mx-4",children:d}),f??s.jsx(Qo,{className:"mt-3",html:e.bodyHtml,category:e.framed?"newsletter":"personal",allowImages:!0})]})}function gd({thread:e,onBack:t,intelligence:n,intelligenceOpen:a,onToggleIntelligence:r,actions:o,children:i,touchHandlers:l}){const[u,d]=c.useState(!1),f=r!==void 0,m=f?a??!1:u,h=!!n||f,p=()=>{if(f){r?.();return}d(x=>!x)},b=()=>{if(f){m&&r?.();return}d(!1)};return s.jsxs("article",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line bg-surface px-row-inset",children:[s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(No,{className:"size-4"}),onClick:t,"aria-label":"Back to messages",className:"-ml-1 shrink-0"}),s.jsx("h2",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e.subject}),h&&s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(to,{className:"size-4"}),onClick:p,"aria-label":m?"Hide intelligence panel":"Show intelligence panel","aria-pressed":m,title:"Intelligence",className:K("shrink-0",m&&"bg-accent-2-soft text-accent-2")})]}),s.jsx("div",{className:"flex-1 overflow-y-auto",style:l?{touchAction:"pan-y"}:void 0,...l,children:i??e.messages.map(x=>{const y=g=>g?()=>g(x.id):void 0;return x.expanded?s.jsx(Vo,{message:x,warning:e.warning,onHeaderClick:y(o?.onToggleExpand),actionBar:s.jsx(Ho,{hasThread:!0,onReply:y(o?.onReply),onReplyAll:y(o?.onReplyAll),onForward:y(o?.onForward),onToggleStar:y(o?.onToggleStar),onDelete:y(o?.onDelete),onToggleRead:y(o?.onToggleRead),moveSlot:o?.moveSlot?.(x.id)})},x.id):s.jsx(Wo,{message:x,onClick:y(o?.onToggleExpand)},x.id)})}),n&&!f&&s.jsx(so,{open:m,onClose:b,title:"Intelligence",anchor:"right",className:"p-0",children:s.jsx(Lo,{data:n,onClose:b,className:"h-full w-full border-l-0"})})]})}function xd({active:e,dimmed:t,indent:n}){return K("flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-sm transition-colors",n&&"pl-7",e?"bg-accent-2-soft font-medium text-accent-2":"text-fg-muted hover:bg-surface hover:text-fg",t&&"opacity-55")}function pd({icon:e,label:t,count:n,active:a}){return s.jsxs(s.Fragment,{children:[e&&s.jsx("span",{className:K("shrink-0",a?"text-accent-2":"text-fg-subtle"),children:e}),s.jsx("span",{className:"flex-1 truncate",children:t}),n!=null&&n>0&&s.jsx("span",{className:K("text-2xs tabular-nums",a?"text-accent-2":"text-fg-subtle"),children:n})]})}function ms({icon:e,label:t,count:n,active:a,dimmed:r,indent:o,navId:i,linkComponent:l,ariaLabel:u,title:d,onClick:f}){const m=xd({active:a,dimmed:r,indent:o}),h=s.jsx(pd,{icon:e,label:t,count:n,active:a});return i&&l?l({navId:i,className:m,ariaLabel:u??t,title:d,onClick:f,children:h}):s.jsx("button",{type:"button",onClick:f,className:m,"aria-label":u,title:d,children:h})}const Qa={inbox:0,flagged:1,drafts:2,sent:3,archive:4,all:5,junk:6,trash:7};function bd(e){switch(e){case"inbox":return s.jsx(Wn,{className:"size-4"});case"flagged":return s.jsx(mt,{className:"size-4"});case"drafts":return s.jsx(yo,{className:"size-4"});case"sent":return s.jsx(ws,{className:"size-4"});case"archive":return s.jsx(ru,{className:"size-4"});case"all":return s.jsx(au,{className:"size-4"});case"junk":return s.jsx(lc,{className:"size-4"});case"trash":return s.jsx(We,{className:"size-4"})}}const Wa=e=>e.role!=null,gn=8,Va="remit.nav.folders.open.",Ya="remit.nav.account.open.";function Ga(e,t,n){if(typeof localStorage>"u")return n;const a=localStorage.getItem(e+t);return a===null?n:a!=="0"}function Xa(e,t,n){typeof localStorage>"u"||localStorage.setItem(e+t,n?"1":"0")}function vd({query:e,onSelect:t,onRemove:n}){return s.jsxs("div",{className:"group flex w-full items-center gap-1 rounded-md pr-1 hover:bg-surface",children:[s.jsxs("button",{type:"button",onClick:t,className:"flex min-w-0 flex-1 items-center gap-2 px-2 py-1 text-left text-sm text-fg-muted transition-colors hover:text-fg",children:[s.jsx(ys,{className:"size-4 shrink-0 text-fg-subtle"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:e})]}),n&&s.jsx("button",{type:"button",onClick:n,"aria-label":`Remove saved search: ${e}`,className:"shrink-0 rounded-full p-1 text-fg-subtle opacity-0 transition-opacity hover:bg-surface-sunken hover:text-fg group-hover:opacity-100 focus-visible:opacity-100",children:s.jsx(Pe,{className:"size-3.5"})})]})}function yd({savedSearches:e,saveableQuery:t,onSelectSavedSearch:n,onRemoveSavedSearch:a,onSaveCurrentSearch:r}){return e.length===0&&!t?null:s.jsxs("div",{className:"mt-3",children:[s.jsx("div",{className:"px-2 pb-1 text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Saved searches"}),t&&s.jsxs("button",{type:"button",onClick:r,className:"flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-sm text-accent transition-colors hover:bg-surface",children:[s.jsx(xu,{className:"size-4 shrink-0"}),s.jsxs("span",{className:"min-w-0 flex-1 truncate",children:["Save “",t,"”"]})]}),e.map(o=>s.jsx(vd,{query:o,onSelect:()=>n?.(o),onRemove:a?()=>a(o):void 0},o))]})}function wd({account:e,selectedNavId:t,onSelectNav:n,linkComponent:a}){const[r,o]=c.useState(()=>Ga(Ya,e.id,!0)),[i,l]=c.useState(()=>Ga(Va,e.id,!0)),[u,d]=c.useState(!1),f=()=>{o(v=>{const w=!v;return Xa(Ya,e.id,w),w})},m=()=>{l(v=>{const w=!v;return Xa(Va,e.id,w),w})},h=e.mailboxes.filter(Wa).sort((v,w)=>Qa[v.role]-Qa[w.role]),p=e.mailboxes.filter(v=>!Wa(v)),b=u||p.length<=gn?p:p.slice(0,gn),x=p.length-b.length,y=e.status??"ready",g=y==="ready"&&h.length===0&&p.length===0;return s.jsxs("div",{className:"mt-3",children:[s.jsxs("button",{type:"button",onClick:f,"aria-expanded":r,className:K("flex w-full items-center gap-1.5 px-2 pb-1 text-left transition-colors hover:text-fg",e.muted&&"opacity-55"),children:[r?s.jsx(ut,{className:"size-3 shrink-0 text-fg-subtle"}):s.jsx(Wt,{className:"size-3 shrink-0 text-fg-subtle"}),s.jsx("span",{className:"truncate text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e.label}),e.muted&&s.jsxs(s.Fragment,{children:[s.jsx(ko,{className:"size-3 shrink-0 text-fg-subtle"}),s.jsx("span",{className:"text-2xs text-fg-subtle",children:"muted"})]})]}),r&&s.jsxs(s.Fragment,{children:[y==="loading"&&s.jsx("div",{className:"px-2 py-1 text-sm text-fg-muted",children:"Loading…"}),y==="error"&&s.jsxs("div",{role:"alert",className:"mx-2 my-1 flex items-start gap-2 rounded-md border border-danger/40 bg-danger-soft px-2 py-1.5 text-sm",children:[s.jsx(wt,{className:"mt-0.5 size-4 shrink-0 text-danger","aria-hidden":"true"}),s.jsx("div",{className:"min-w-0 flex-1",children:s.jsx("p",{className:"font-medium text-danger",children:"Couldn't load mailboxes"})}),e.onRetry&&s.jsx("button",{type:"button",onClick:e.onRetry,className:"shrink-0 text-sm font-medium text-accent hover:underline",children:"Retry"})]}),g&&s.jsx("div",{className:"px-2 py-1 text-sm text-fg-muted",children:"No mailboxes"}),y==="ready"&&s.jsxs(s.Fragment,{children:[h.map(v=>s.jsx(ms,{navId:v.id,linkComponent:a,icon:bd(v.role),label:v.name,ariaLabel:v.name,title:v.fullPath??v.name,count:v.unseen,active:t===v.id,dimmed:e.muted,onClick:()=>n?.(v.id)},v.id)),e.outboxPending!==void 0&&s.jsx(ms,{navId:"outbox",linkComponent:a,icon:s.jsx(ws,{className:"size-4"}),label:"Outbox",ariaLabel:"Outbox",count:e.outboxPending>0?e.outboxPending:void 0,active:t==="outbox",dimmed:e.muted,onClick:()=>n?.("outbox")}),p.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs("button",{type:"button",onClick:m,"aria-expanded":i,className:"mt-1 flex w-full items-center gap-1 px-2 py-1 text-left text-2xs font-semibold uppercase tracking-wider text-fg-subtle transition-colors hover:text-fg",children:[i?s.jsx(ut,{className:"size-3 shrink-0"}):s.jsx(Wt,{className:"size-3 shrink-0"}),s.jsx("span",{className:"flex-1",children:"Folders"}),s.jsx("span",{className:"tabular-nums opacity-70",children:p.length})]}),i&&s.jsxs(s.Fragment,{children:[b.map(v=>s.jsx(ms,{navId:v.id,linkComponent:a,icon:s.jsx(nu,{className:"size-4"}),label:v.name,ariaLabel:v.name,title:v.fullPath??v.name,count:v.unseen,active:t===v.id,dimmed:e.muted,onClick:()=>n?.(v.id)},v.id)),(x>0||u)&&p.length>gn&&s.jsx("button",{type:"button",onClick:()=>d(v=>!v),className:"ml-7 flex items-center px-2 py-1 text-2xs font-medium text-accent transition-colors hover:underline",children:u?"Show less":`Show all (${p.length})`})]})]})]})]})]})}function jd({accounts:e,selectedNavId:t,briefUnseen:n,onSelectNav:a,variant:r="desktop",linkComponent:o,savedSearches:i=[],saveableQuery:l,onSelectSavedSearch:u,onRemoveSavedSearch:d,onSaveCurrentSearch:f}){const m=s.jsxs("nav",{className:r==="drawer"?"px-2 py-2":"flex-1 overflow-y-auto px-2 py-2","aria-label":"Mailboxes",children:[s.jsx(ms,{navId:"brief",linkComponent:o,icon:s.jsx(Ue,{className:"size-4"}),label:"Daily brief",ariaLabel:"Daily brief",count:n,active:t==="brief",onClick:()=>a?.("brief")}),s.jsx(ms,{navId:"flagged",linkComponent:o,icon:s.jsx(mt,{className:"size-4"}),label:"Starred",ariaLabel:"Starred",active:t==="flagged",onClick:()=>a?.("flagged")}),s.jsx(yd,{savedSearches:i,saveableQuery:l,onSelectSavedSearch:u,onRemoveSavedSearch:d,onSaveCurrentSearch:f}),e.length===0?s.jsx("div",{className:"px-2 py-4 text-center text-sm text-fg-muted",children:"No accounts configured"}):e.map(h=>s.jsx(wd,{account:h,selectedNavId:t,onSelectNav:a,linkComponent:o},h.id))]});return r==="drawer"?m:s.jsx("aside",{className:"flex h-full w-full flex-col bg-surface-sunken",children:m})}function Sd({leading:e,search:t,actions:n,className:a}){return s.jsxs("header",{className:K("flex min-h-16 w-full shrink-0 items-center gap-3 border-b border-line bg-canvas px-3 py-2",a),children:[e&&s.jsx("div",{className:"flex shrink-0 items-center gap-2",children:e}),s.jsx("div",{className:"flex min-w-0 flex-1 justify-start",children:s.jsx("div",{className:"w-full max-w-2xl",children:t})}),n&&s.jsx("div",{className:"flex shrink-0 items-center gap-1",children:n})]})}function Nd({label:e,size:t="sm",onUndo:n,undoLabel:a="Undo",className:r}){return s.jsxs(qe,{tone:"accent",className:K(t==="md"&&"py-1 text-xs",r),children:[s.jsx(Cu,{className:K(t==="sm"?"size-3":"size-3.5","shrink-0"),"aria-hidden":!0}),s.jsx("span",{children:e}),n&&s.jsx("button",{type:"button",onClick:o=>{o.stopPropagation(),n()},className:"font-semibold underline decoration-dotted underline-offset-2 hover:decoration-solid",children:a})]})}const kd=320,Cd="cubic-bezier(0.32, 0.9, 0.3, 1)",Ed=.5,Id=.4,Rd=360;function Md(e){return Math.sign(e)*Math.sqrt(Math.abs(e))*4}function Td({open:e,onClose:t,children:n,dismissLabel:a="Dismiss"}){const r=c.useRef(null),[o,i]=c.useState(Rd),[l,u]=c.useState(null);c.useLayoutEffect(()=>{const g=r.current;if(!g)return;const v=()=>i(g.offsetHeight);v();const w=new ResizeObserver(v);return w.observe(g),()=>w.disconnect()},[]);const d=c.useRef(null),f=c.useCallback(g=>{g.currentTarget.setPointerCapture(g.pointerId),d.current={startY:g.clientY,lastY:g.clientY,lastT:g.timeStamp,velocity:0,moved:!1},u(0)},[]),m=c.useCallback(g=>{const v=d.current;if(!v)return;const w=g.timeStamp-v.lastT;w>0&&(v.velocity=(g.clientY-v.lastY)/w),v.lastY=g.clientY,v.lastT=g.timeStamp;const j=g.clientY-v.startY;Math.abs(j)>4&&(v.moved=!0);const C=j<0?Md(j):j;u(C)},[]),h=c.useCallback(()=>{const g=d.current;if(d.current=null,!g)return;const v=g.lastY-g.startY,j=g.velocity>Ed||v>o*Id;u(null),j&&t()},[o,t]),p=l!==null,b=e?l??0:o,x=Math.min(Math.max(1-b/o,0),1),y=p?"none":`transform ${kd}ms ${Cd}`;return s.jsxs("div",{className:K("absolute inset-0 z-40 select-none overflow-hidden",e||p?"":"pointer-events-none"),children:[s.jsx("button",{type:"button","aria-label":a,tabIndex:-1,onClick:t,className:K("absolute inset-0 bg-black/40",x>0?"pointer-events-auto":"pointer-events-none"),style:{opacity:x*.6,transition:y.replace("transform","opacity")}}),s.jsxs("div",{ref:r,className:"absolute inset-x-0 bottom-0 flex max-h-[92%] flex-col rounded-t-3xl border-t border-line bg-surface shadow-2xl shadow-black/30",style:{transform:`translateY(${b}px)`,transition:y},children:[s.jsx("div",{role:"slider","aria-label":"Drag down to dismiss","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(x*100),tabIndex:0,onPointerDown:f,onPointerMove:m,onPointerUp:h,onPointerCancel:h,className:"flex cursor-grab touch-none justify-center pb-1 pt-2.5 active:cursor-grabbing",children:s.jsx("div",{className:"h-1 w-10 rounded-full bg-fg-subtle/40"})}),s.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden",children:n})]})]})}const Dd="peer relative size-5 shrink-0 cursor-pointer appearance-none rounded-md border border-line-strong bg-surface outline-none transition-colors checked:border-positive checked:bg-positive indeterminate:border-positive indeterminate:bg-positive focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-surface",Ja="pointer-events-none absolute inset-0 m-auto size-3.5 text-accent-fg";function Yo({label:e,description:t,indeterminate:n=!1,checked:a,onChange:r,className:o,...i}){const l=c.useRef(null);c.useEffect(()=>{l.current&&(l.current.indeterminate=n)},[n]);const u=s.jsxs("span",{className:"relative inline-flex",children:[s.jsx("input",{ref:l,type:"checkbox",checked:a,onChange:r,className:Dd,...i}),s.jsx(js,{className:K(Ja,"hidden peer-checked:block"),"aria-hidden":!0}),s.jsx(yu,{className:K(Ja,"hidden peer-indeterminate:block"),"aria-hidden":!0})]});return e===void 0&&t===void 0?s.jsx("span",{className:o,children:u}):s.jsxs("label",{className:K("flex min-h-11 cursor-pointer items-center gap-3 text-left",o),children:[u,s.jsxs("span",{className:"flex min-w-0 flex-col",children:[e!==void 0&&s.jsx("span",{className:"text-sm text-fg",children:e}),t!==void 0&&s.jsx("span",{className:"text-xs text-fg-subtle",children:t})]})]})}const Ad=({status:e})=>e==="saving"?s.jsx("span",{className:"animate-pulse text-xs text-fg-muted",children:"Saving..."}):e==="saved"?s.jsx("span",{className:"text-xs text-fg-muted",children:"Draft saved"}):e==="error"?s.jsx("span",{className:"text-xs text-danger",children:"Save failed"}):null;function Od({onSend:e,onDiscard:t,sending:n,canSend:a,saveStatus:r="idle",unavailableReason:o,onUnavailable:i}){return s.jsxs("div",{className:"flex items-center justify-between border-t border-line px-3 py-2",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx(G,{variant:"primary",size:"md","aria-busy":n,title:a?void 0:o,className:"min-h-11 rounded-full px-4",icon:n?s.jsx(St,{className:"size-4 animate-spin"}):s.jsx(ws,{className:"size-4"}),onClick:()=>{if(!n){if(!a){o&&i?.(o);return}e()}},children:"Send"}),s.jsx(Ad,{status:r})]}),s.jsx(G,{variant:"ghost",size:"md","aria-busy":n,"aria-label":"Discard",className:"min-h-11 min-w-11 px-2 hover:text-danger",icon:s.jsx(We,{className:"size-4"}),onClick:()=>{n||t()}})]})}function Pd({banner:e,header:t,children:n,quoted:a,actionBar:r}){return s.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e,t,s.jsxs("div",{className:"min-h-0 flex-1 overflow-auto",children:[n,a&&s.jsx("div",{className:"px-3 pb-2",children:a})]}),r]})}function Ld({key:e,shiftKey:t=!1,repeat:n=!1,caretAtStart:a,hasValue:r,chipCount:o}){const i=o-1;return e==="Escape"?r?{type:"clearQuery"}:{type:"blur"}:e==="Tab"&&t?o===0?{type:"none"}:{type:"focusChip",index:i}:e==="Backspace"||e==="ArrowLeft"?!a||o===0?{type:"none"}:n?{type:"none"}:{type:"focusChip",index:i}:{type:"none"}}function zd({key:e,repeat:t=!1,index:n,chipCount:a}){return e==="Backspace"||e==="Delete"?t?{type:"none"}:{type:"removeChip",index:n}:e==="ArrowLeft"?n===0?{type:"none"}:{type:"focusChip",index:n-1}:e==="ArrowRight"?n>=a-1?{type:"focusInput"}:{type:"focusChip",index:n+1}:e==="Enter"||e===" "?{type:"activateChip",index:n}:e==="Escape"?{type:"focusInput"}:{type:"none"}}function _d(e,t){const n=t-1;return n<=0?null:e<n?e:n-1}const Fd=e=>e instanceof HTMLElement?e.tagName==="INPUT"||e.tagName==="TEXTAREA"||e.isContentEditable:!1,Bd=({chips:e=[],onRemoveChip:t,onActivateChip:n,value:a,onChange:r,onClear:o,onClearQuery:i,placeholder:l="Search mail...",globalFocusKey:u=!0,showClearButton:d=!0,size:f="sm",inputId:m,chipsLabel:h="Search filters",className:p})=>{const b=c.useId(),x=m??b,y=c.useRef(null),g=c.useRef([]),v=i??o,[w,j]=c.useState(null),C=c.useRef(void 0),[N,S]=c.useState(""),E=e.length>0;c.useEffect(()=>{j(R=>R!==null&&R>=e.length?null:R)},[e.length]),c.useEffect(()=>{const R=C.current;if(R!==void 0){if(C.current=void 0,R===null){y.current?.focus();return}g.current[R]?.focus()}});const k=c.useCallback(R=>{j(R),C.current=R},[]),M=c.useCallback(R=>{const O=e[R];O&&t&&(k(_d(R,e.length)),S(`${O.label} removed`),t(O.id))},[e,t,k]),T=c.useCallback(()=>{k(null),o()},[o,k]),D=c.useCallback(R=>{const O=R.currentTarget,B=Ld({key:R.key,shiftKey:R.shiftKey,repeat:R.repeat,caretAtStart:O.selectionStart===0&&O.selectionEnd===0,hasValue:a.length>0,chipCount:e.length});switch(B.type){case"focusChip":R.preventDefault(),k(B.index);return;case"clearQuery":v();return;case"blur":O.blur();return;case"none":return}},[e.length,a,v,k]),I=c.useCallback(R=>O=>{const B=zd({key:O.key,repeat:O.repeat,index:R,chipCount:e.length});switch(B.type!=="none"&&O.preventDefault(),B.type){case"removeChip":M(B.index);return;case"focusChip":k(B.index);return;case"focusInput":k(null);return;case"activateChip":{const $=e[B.index];$&&n&&n($.id);return}case"none":return}},[e,M,k,n]);return c.useEffect(()=>{if(!u)return;const R=O=>{O.key!=="/"||O.metaKey||O.ctrlKey||O.altKey||Fd(O.target)||(O.preventDefault(),y.current?.focus())};return window.addEventListener("keydown",R),()=>window.removeEventListener("keydown",R)},[u]),s.jsxs("label",{htmlFor:x,className:K("flex w-full items-center gap-1.5 text-sm","bg-surface-sunken/50 border border-transparent","focus-within:bg-canvas focus-within:border-line focus-within:ring-2 focus-within:ring-ring","transition-colors",f==="lg"?"rounded-xl px-4 py-2":"rounded-md px-2.5 py-1",p),children:[s.jsx(ys,{className:K("shrink-0 text-fg-muted pointer-events-none",f==="lg"?"size-5":"size-4")}),s.jsxs("div",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-1",children:[E&&s.jsx("div",{role:"grid","aria-label":h,className:"flex min-w-0 flex-wrap items-center gap-1",children:e.map((R,O)=>s.jsx(cc,{ref:B=>{g.current[O]=B},label:R.label,tone:R.tone,focused:w===O,onFocusLabel:()=>j(O),onKeyDown:I(O),onRemove:()=>M(O),onActivate:n?()=>n(R.id):void 0},R.id))}),s.jsx("input",{ref:y,id:x,name:"q",type:"text","aria-label":"Search mail",autoComplete:"off",value:a,tabIndex:w===null?0:-1,onChange:R=>r(R.target.value),onKeyDown:D,onFocus:()=>j(null),placeholder:E?void 0:l,className:"min-w-24 flex-1 bg-transparent text-fg outline-none placeholder:text-fg-muted"})]}),(a||E)&&d&&s.jsx("button",{type:"button",onClick:T,className:"shrink-0 rounded p-0.5 hover:bg-surface-raised transition-colors","aria-label":"Clear search",children:s.jsx(Pe,{className:K("text-fg-muted",f==="lg"?"size-5":"size-4")})}),s.jsx("span",{role:"status","aria-live":"polite",className:"sr-only",children:N})]})},ua=({value:e,onChange:t,onClear:n,onClearQuery:a,chips:r,onRemoveChip:o,placeholder:i="Search mail...",globalFocusKey:l=!0,showClearButton:u=!0,size:d,inputId:f,className:m})=>s.jsx(Bd,{value:e,onChange:t,onClear:n,onClearQuery:a,chips:r,onRemoveChip:o,placeholder:i,globalFocusKey:l,showClearButton:u,size:d,inputId:f,className:m});function $d({title:e,unreadCount:t,isDesktop:n,onMenuClick:a,searchValue:r,onSearchChange:o,onSearchClear:i,searchOpen:l,onSearchOpenChange:u,showSearch:d=!0}){const f=`${t.toLocaleString()} unread`,m=i??(()=>o("")),h=()=>{m(),u(!1)},p=x=>s.jsx(ua,{value:r,onChange:o,onClear:m,globalFocusKey:!1,showClearButton:x}),b=s.jsx(G,{variant:"ghost",icon:s.jsx(ia,{className:"size-5"}),onClick:a,"aria-label":"Menu",className:"min-h-11 min-w-11 shrink-0 px-0"});return s.jsx("header",{className:"flex shrink-0 flex-col bg-canvas",children:s.jsx("div",{className:"flex h-12 items-center gap-2 px-row-inset",children:d?n?s.jsxs(s.Fragment,{children:[b,s.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e}),s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle",children:f}),s.jsx("div",{className:"w-64 max-w-[40%] shrink-0",children:p(!0)})]}):l||r.trim().length>0?s.jsxs("div",{className:"flex flex-1 items-center gap-1",children:[s.jsx("div",{className:"flex-1",children:p(!1)}),s.jsx(G,{variant:"ghost",icon:s.jsx(Pe,{className:"size-5"}),onClick:h,"aria-label":"Close search",className:"min-h-11 min-w-11 shrink-0 px-0"})]}):s.jsxs(s.Fragment,{children:[b,s.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e}),s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle",children:f}),s.jsx(G,{variant:"ghost",icon:s.jsx(ys,{className:"size-5"}),onClick:()=>u(!0),"aria-label":"Search",className:"min-h-11 min-w-11 shrink-0 px-0"})]}):s.jsxs(s.Fragment,{children:[b,s.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e}),s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle",children:f})]})})})}const Kd=(e,t)=>e==="vip"?"vip":e==="unknown"&&t==="md"?"unknown-pill":"hidden",Go=({senderTrust:e,size:t="sm",className:n})=>{const a=Kd(e,t);return a==="vip"?s.jsx(Ue,{className:K("text-warning shrink-0",t==="sm"&&"size-3.5",t==="md"&&"size-4",n),"aria-label":"VIP sender","data-testid":"sender-trust-vip"}):a==="unknown-pill"?s.jsx("span",{className:K("inline-flex items-center rounded border border-dashed border-fg-subtle/40 font-medium uppercase tracking-wide text-fg-muted/80 shrink-0","px-2 py-0.5 text-xs",n),title:"First message from this sender","aria-label":"First message from this sender","data-testid":"sender-trust-unknown",children:"new"}):null};function Za(e,t){const n=t?.trim();if(!n)return e;const a=e.toLowerCase(),r=n.toLowerCase(),o=[];let i=0,l=a.indexOf(r,i),u=0;for(;l!==-1;)l>i&&o.push(e.slice(i,l)),o.push(s.jsx("mark",{className:"bg-transparent font-semibold text-fg",children:e.slice(l,l+r.length)},u++)),i=l+r.length,l=a.indexOf(r,i);return i<e.length&&o.push(e.slice(i)),o}function qd({result:e,onClick:t,query:n}){return s.jsxs("button",{type:"button",onClick:t,className:"flex w-full flex-col gap-0.5 border-b border-line px-row-inset py-2.5 text-left transition-colors hover:bg-surface-sunken",children:[s.jsxs("div",{className:"flex items-baseline gap-2",children:[s.jsx("span",{className:K("min-w-0 flex-1 truncate text-sm",e.unread?"font-semibold text-fg":"font-medium text-fg-muted"),children:e.sender}),s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.date})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:K("min-w-0 flex-1 truncate text-sm",e.unread?"text-fg":"text-fg-muted"),children:Za(e.subject,n)}),e.flagged&&s.jsx(pu,{className:"size-3.5 shrink-0 fill-warning text-warning"})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-fg-subtle",children:Za(e.snippet,n)}),e.category&&s.jsx(qe,{tone:e.category.tone??"neutral",className:"shrink-0",children:e.category.label}),e.matchedChunkLabel&&s.jsx(qe,{tone:"neutral",className:"shrink-0",children:`matched: ${e.matchedChunkLabel}`}),e.score!=null&&s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.score.toFixed(2)})]})]})}const er=6;function Ud({section:e,query:t,onSelectResult:n}){const[a,r]=c.useState(e.initialCollapsed??!1),[o,i]=c.useState(!1),l=e.results.length>er,d=!o&&l?e.results.slice(0,er):e.results,f=e.results.length-d.length;return s.jsxs("div",{children:[s.jsxs("button",{type:"button","aria-expanded":!a,onClick:()=>r(m=>!m),className:"sticky top-0 z-10 flex h-section-row w-full items-center gap-1.5 border-b border-line bg-surface-sunken px-row-inset text-left transition-colors hover:bg-surface",children:[s.jsx("span",{className:"flex-1 text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e.label}),s.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:e.results.length}),s.jsx(ut,{className:K("size-3 shrink-0 text-fg-subtle transition-transform duration-200",a?"rotate-0":"rotate-180")})]}),!a&&s.jsxs(s.Fragment,{children:[d.map(m=>s.jsx(qd,{result:m,query:t,onClick:n?()=>n(m):void 0},m.id)),l&&s.jsxs("button",{type:"button",onClick:()=>i(m=>!m),className:"flex w-full items-center justify-center border-b border-line px-row-inset py-1.5 text-2xs font-medium text-accent transition-colors hover:bg-surface",children:[o?"Show less":`Show ${f} more`,!o&&s.jsx(ut,{className:"ml-1 size-3"})]})]})]})}function Xo({value:e,recentSearches:t,onPickRecent:n,sections:a,loading:r,onSelectResult:o,tokens:i}){const l=e.trim().length>0,u=(a??[]).some(f=>f.results.length>0);if(!l)return t&&t.length>0?s.jsxs("div",{className:"flex flex-col",children:[s.jsx("h3",{className:"px-row-inset pb-1 pt-3 text-2xs font-semibold uppercase tracking-wide text-fg-subtle",children:"Recent searches"}),t.map(f=>s.jsxs("button",{type:"button",onClick:()=>n?.(f),className:"flex w-full items-center gap-2.5 border-b border-line px-row-inset py-2.5 text-left transition-colors hover:bg-surface-sunken",children:[s.jsx(ca,{className:"size-4 shrink-0 text-fg-subtle"}),s.jsx("span",{className:"min-w-0 flex-1 truncate text-sm text-fg-muted",children:f})]},f))]}):s.jsx("p",{className:"px-row-inset py-6 text-center text-sm text-fg-subtle",children:"Search across your mail by sender, subject or words in the message."});const d=i&&i.length>0&&s.jsx(uc,{tokens:i});return r?s.jsxs("div",{className:"flex flex-col",children:[d,s.jsx("div",{className:"flex flex-col gap-3 px-row-inset py-4",children:[0,1,2,3].map(f=>s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("div",{className:"h-3 w-1/3 animate-pulse rounded bg-surface-sunken"}),s.jsx("div",{className:"h-3 w-2/3 animate-pulse rounded bg-surface-sunken"}),s.jsx("div",{className:"h-2.5 w-1/2 animate-pulse rounded bg-surface-sunken"})]},f))})]}):u?s.jsxs("div",{className:"flex flex-col",children:[d,a?.filter(f=>f.results.length>0).map(f=>s.jsx(Ud,{section:f,query:e,onSelectResult:o},f.id))]}):s.jsxs("div",{className:"flex flex-col",children:[d,s.jsxs("div",{className:"px-row-inset py-10 text-center",children:[s.jsxs("p",{className:"text-sm font-medium text-fg",children:["No matches for “",e,"”"]}),s.jsx("p",{className:"mt-1 text-xs text-fg-subtle",children:"Try a different word, or adjust the filters above."})]})]})}function Hd({value:e,onChange:t,onClear:n,onCancel:a,filter:r,recentSearches:o,onPickRecent:i,sections:l,loading:u,onSelectResult:d,tokens:f,chips:m,onRemoveChip:h}){const p=s.jsx(Xo,{value:e,recentSearches:o,onPickRecent:i,sections:l,loading:u,onSelectResult:d,tokens:f});return s.jsxs("article",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line bg-surface px-row-inset",children:[s.jsx("div",{className:"min-w-0 flex-1",children:s.jsx(ua,{value:e,onChange:t,onClear:n,chips:m,onRemoveChip:h,globalFocusKey:!1,showClearButton:!1})}),s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(Pe,{className:"size-4"}),onClick:a,"aria-label":"Clear and close search",className:"-mr-1 shrink-0"})]}),r?s.jsx(Vn,{...r,children:p}):s.jsx("div",{className:"flex-1 overflow-y-auto",children:p})]})}const tr="w-full text-left px-3 py-2.5 min-h-11 flex items-center gap-2 transition-colors text-sm rounded-md focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-canvas",Qd={searchPlaceholder:"Move to…",searchAriaLabel:"Filter folders",listAriaLabel:"Destination folders",currentSuffix:"(current folder)",currentTag:"current",emptyMessage:e=>`No folders match "${e}"`,optionLabel:e=>`Move to ${e}`},xn=e=>{for(let t=0;t<e.length;t+=1)if(!e[t]?.isCurrent)return t;return-1},Wd=e=>{for(let t=e.length-1;t>=0;t-=1)if(!e[t]?.isCurrent)return t;return-1},sr=(e,t,n)=>{const a=e.length;if(a<=0)return-1;const r=t<0?n===1?-1:a:t;for(let o=1;o<=a;o+=1){const i=((r+n*o)%a+a)%a;if(!e[i]?.isCurrent)return i}return-1},Vd=(e,t)=>e.label.toLowerCase().includes(t)?!0:e.searchValue?.toLowerCase().includes(t)??!1,Jo=({mailboxes:e,onSelect:t,onCancel:n,autoFocus:a=!1,labels:r})=>{const o={...Qd,...r},[i,l]=c.useState(""),[u,d]=c.useState(()=>xn(e)),f=c.useRef(null),m=c.useRef([]);c.useEffect(()=>{a&&f.current?.focus()},[a]);const h=i.trim().toLowerCase(),p=c.useMemo(()=>h?e.filter(g=>Vd(g,h)):[...e],[e,h]);c.useEffect(()=>{d(g=>g>=0&&g<p.length&&!p[g]?.isCurrent?g:xn(p))},[p]),c.useEffect(()=>{if(u<0)return;const g=m.current[u];g&&document.activeElement!==f.current&&g.focus()},[u]);const b=c.useCallback(()=>{if(u<0)return;const g=p[u];!g||g.isCurrent||t(g.id)},[u,p,t]),x=c.useCallback(g=>{switch(g.key){case"ArrowDown":g.preventDefault(),d(v=>sr(p,v,1));return;case"ArrowUp":g.preventDefault(),d(v=>sr(p,v,-1));return;case"Home":g.preventDefault(),d(xn(p));return;case"End":g.preventDefault(),d(Wd(p));return;case"Enter":case" ":g.preventDefault(),b();return;case"Escape":g.preventDefault(),n?.();return;default:return}},[p,b,n]),y=c.useCallback(g=>{if(g.key==="ArrowDown"){if(g.preventDefault(),p.length===0)return;m.current[u>=0?u:0]?.focus();return}g.key==="Escape"&&(g.preventDefault(),n?.())},[p.length,u,n]);return s.jsxs("div",{className:"flex flex-col",children:[s.jsx(no,{variant:"inline",className:"border-b border-line px-3 py-2",icon:s.jsx(ys,{className:"size-4","aria-hidden":"true"}),ref:f,type:"search",value:i,onChange:g=>l(g.target.value),onKeyDown:y,placeholder:o.searchPlaceholder,"aria-label":o.searchAriaLabel}),s.jsx("div",{className:"flex-1 overflow-y-auto py-1",role:"listbox","aria-label":o.listAriaLabel,onKeyDown:x,children:p.length===0?s.jsx("div",{className:"px-3 py-3 text-sm text-fg-muted","aria-live":"polite",children:o.emptyMessage(i)}):p.map((g,v)=>{const w=g.isCurrent??!1,j=v===u;return w?s.jsx("div",{children:s.jsxs("div",{role:"option","aria-selected":!1,"aria-current":"true","aria-label":`${g.label} ${o.currentSuffix}`,className:K(tr,"opacity-60 bg-surface-sunken/40"),children:[s.jsx("span",{className:"truncate flex-1",children:g.label}),s.jsx("span",{className:"text-xs text-fg-muted shrink-0",children:o.currentTag})]})},g.id):s.jsx("div",{children:s.jsx("button",{ref:C=>{m.current[v]=C},type:"button",role:"option","aria-selected":!1,tabIndex:j?0:-1,onClick:()=>t(g.id),onFocus:()=>d(v),"aria-label":o.optionLabel(g.label),className:K(tr,"hover:bg-surface-raised"),children:s.jsx("span",{className:"truncate flex-1",children:g.label})})},g.id)})})]})},Yd={queued:{icon:ca,label:"Queued",className:"text-warning"},sending:{icon:St,label:"Sending…",className:"text-accent-2",spin:!0},sent:{icon:Co,label:"Sent",className:"text-positive"},failed:{icon:wt,label:"Failed",className:"text-danger"},blocked:{icon:Yn,label:"Blocked",className:"text-warning"}};function nr({status:e,iconOnly:t,className:n}){const a=Yd[e],r=a.icon;return s.jsxs("span",{className:K("inline-flex items-center gap-1.5 text-xs font-medium",a.className,n),children:[s.jsx(r,{className:K("size-4",a.spin&&"animate-spin")}),!t&&a.label]})}const Gd=(e,t)=>t?"bg-accent-2-soft":e==="failed"?"bg-danger-soft":e==="blocked"?"bg-warning/10":"";function Xd({recipients:e,subject:t,time:n,status:a,error:r,selected:o,onSelect:i,onRetry:l,retrying:u,onEdit:d,onDelete:f,deleting:m}){const h=a==="failed"||a==="blocked";return s.jsxs("div",{className:K("flex items-start gap-3 border-b border-line px-4 py-3 transition-colors hover:bg-surface-raised",Gd(a,o)),children:[s.jsxs("button",{type:"button",onClick:i,className:"flex flex-1 min-w-0 items-start gap-3 text-left",children:[s.jsx("div",{className:"mt-0.5 shrink-0",children:s.jsx(nr,{status:a,iconOnly:!0})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"truncate text-sm font-medium",children:e}),s.jsx("span",{className:"shrink-0 text-xs text-fg-muted",children:n})]}),s.jsx("div",{className:"truncate text-sm",children:t||"No subject"}),s.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[s.jsx(nr,{status:a}),r&&s.jsxs("span",{className:"truncate text-xs text-fg-muted",children:["— ",r]})]})]})]}),h&&s.jsx("div",{className:"shrink-0",children:s.jsx(ou,{actions:[...a==="failed"&&l?[{label:"Retry sending",iconOnly:!0,icon:s.jsx(ju,{className:"size-3.5"}),busy:u,onClick:l}]:[],{label:"Edit as draft",iconOnly:!0,icon:s.jsx(ws,{className:"size-3.5"}),onClick:d}],destructive:{label:"Delete message",iconOnly:!0,icon:s.jsx(We,{className:"size-3.5"}),busy:m,confirm:{prompt:"Delete this message?",confirmLabel:"Delete"},onClick:f}})})]})}const Jd=e=>{const[t,n]=c.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return c.useEffect(()=>{if(typeof window>"u"||!window.matchMedia)return;const a=window.matchMedia(e);n(a.matches);const r=o=>n(o.matches);return a.addEventListener("change",r),()=>a.removeEventListener("change",r)},[e]),t},Zd=({children:e,onRefresh:t,isRefreshing:n})=>Jd("(min-width: 1024px)")?e:s.jsx(dc,{onRefresh:t,isPullable:!n,children:e}),ef=({text:e,html:t,senderName:n,date:a})=>{const[r,o]=c.useState(!1);if(!e&&!t)return null;const i=[n,a].filter(Boolean).join(" on ");return s.jsxs("div",{className:"mt-2 px-3 pb-2",children:[s.jsxs("button",{type:"button",onClick:()=>o(!r),"aria-expanded":r,className:"flex items-center gap-1 text-xs text-fg-muted hover:text-fg transition-colors",children:[r?s.jsx(ut,{className:"size-3"}):s.jsx(Wt,{className:"size-3"}),i?`${i} wrote:`:"Show quoted text"]}),r&&s.jsx("blockquote",{className:"mt-2 pl-3 border-l-2 border-fg-subtle/30 text-sm text-fg-muted [&_a]:text-accent [&_a]:underline [&_blockquote]:pl-3 [&_blockquote]:border-l-2 [&_blockquote]:border-fg-subtle/30",children:t?s.jsx("div",{dangerouslySetInnerHTML:{__html:t}}):e.split(`
|
|
69
|
+
`).map((l,u)=>s.jsx("p",{className:"min-h-[1.2em]",children:l},u))})]})},tf=e=>e===1?"message":"messages";function sf({count:e,onReview:t,onDismiss:n,actionLabel:a="Review & rescue"}){return s.jsx(ao,{tone:"info",variant:"soft",onDismiss:n,children:s.jsxs("div",{className:"flex flex-col gap-2",children:[s.jsxs("p",{className:"flex items-start gap-2 text-sm text-fg",children:[s.jsx(ks,{className:"mt-0.5 size-4 shrink-0 text-positive","aria-hidden":!0}),s.jsxs("span",{children:[s.jsx("span",{className:"font-semibold text-fg",children:`${e} ${tf(e)} here`})," ","may not be spam — they're from senders we can verify."]})]}),s.jsx(G,{variant:"primary",size:"sm",onClick:t,className:"self-start",children:a})]})})}function nf({candidate:e,selected:t,onToggle:n,hideSender:a=!1}){const{senderName:r,senderAddress:o,subject:i,snippet:l,trustReason:u,trustSubReason:d,senderTrust:f}=e;return s.jsxs("label",{className:K("flex w-full cursor-pointer items-start gap-3 px-3 py-2.5 text-left transition-colors",a&&"pl-11",t?"bg-positive/10":"bg-surface hover:bg-surface-sunken"),children:[s.jsx(Yo,{className:"mt-0.5",checked:t,onChange:n,"aria-label":`${t?"Deselect":"Select"} ${a?i:`message from ${r}`}`}),!a&&s.jsx(Qe,{name:r,email:o,size:"sm"}),s.jsxs("span",{className:"min-w-0 flex-1",children:[!a&&s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"truncate text-sm font-medium text-fg",children:r}),f&&s.jsx(Go,{senderTrust:f,size:"sm"}),s.jsx("span",{className:"truncate text-2xs text-fg-subtle",children:o})]}),s.jsx("span",{className:"block truncate text-sm text-fg-muted",children:i}),s.jsx("span",{className:"block line-clamp-1 text-xs text-fg-subtle",children:l}),!a&&s.jsxs("span",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[s.jsxs(qe,{tone:"positive",children:[s.jsx(ks,{className:"size-3","aria-hidden":!0}),u]}),s.jsx("span",{className:"text-2xs text-fg-subtle",children:d})]})]})]})}const af=e=>{const t=new Map,n=[];for(const a of e){const r=(a.senderAddress||a.senderName).toLowerCase(),o=t.get(r);if(o){o.messages.push(a);continue}t.set(r,{key:r,senderName:a.senderName,senderAddress:a.senderAddress,trustReason:a.trustReason,trustSubReason:a.trustSubReason,senderTrust:a.senderTrust,messages:[a]}),n.push(r)}return n.map(a=>t.get(a)).sort((a,r)=>r.messages.length-a.messages.length)},rf=(e,t)=>{const n=e.messages.filter(a=>t.has(a.id)).length;return n===0?"none":n===e.messages.length?"all":"some"},ar=e=>e===1?"message":"messages";function of({group:e,selected:t,onToggleGroup:n,onToggleMessage:a}){const[r,o]=c.useState(!1),i=rf(e,t),l=e.messages.length,u=r?ut:Wt;return s.jsxs("div",{className:K(i!=="none"?"bg-positive/10":"bg-surface"),children:[s.jsxs("div",{className:"flex w-full items-start gap-3 px-3 py-2.5",children:[s.jsx(Yo,{className:"mt-0.5",checked:i==="all",indeterminate:i==="some",onChange:()=>n(e,i!=="all"),"aria-label":`${i==="all"?"Deselect":"Select"} all ${l} ${ar(l)} from ${e.senderName}`}),s.jsx(Qe,{name:e.senderName,email:e.senderAddress,size:"sm"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"truncate text-sm font-medium text-fg",children:e.senderName}),e.senderTrust&&s.jsx(Go,{senderTrust:e.senderTrust,size:"sm"}),s.jsx("span",{className:"truncate text-2xs text-fg-subtle",children:e.senderAddress})]}),s.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[s.jsxs(qe,{tone:"positive",children:[s.jsx(ks,{className:"size-3","aria-hidden":!0}),e.trustReason]}),s.jsx("span",{className:"text-2xs text-fg-subtle",children:e.trustSubReason})]})]}),s.jsxs("button",{type:"button",onClick:()=>o(d=>!d),"aria-expanded":r,className:"flex shrink-0 items-center gap-1 rounded-md px-1.5 py-1 text-2xs text-fg-muted transition-colors hover:bg-surface-sunken hover:text-fg",children:[`${l} ${ar(l)}`,s.jsx(u,{className:"size-3.5","aria-hidden":!0})]})]}),r&&s.jsx("div",{className:"divide-y divide-line border-t border-line",children:e.messages.map(d=>s.jsx(nf,{candidate:d,selected:t.has(d.id),onToggle:()=>a(d.id),hideSender:!0},d.id))})]})}const da=e=>e===1?"message":"messages",lf=(e,t)=>`Moves ${e===1?"this message":`these ${e} ${da(e)}`} out of Spam to ${t} now. Nothing later.`,Pn=(e,t)=>e.find(n=>n.id===t)?.label??"Inbox";function cf(){return s.jsx(ao,{tone:"info",variant:"soft",children:s.jsx("p",{className:"text-2xs text-fg-muted",children:"We list a message here only when we can confirm the sender is who they say — usually someone you've emailed before, write to often, or a service that consistently checks out. We never guess from words in the subject. Anything we can't confirm stays in Spam."})})}function uf({candidates:e,selected:t,onToggle:n,onToggleGroup:a,onSelectAll:r,onSelectNone:o,onContinue:i,onCancel:l}){const[u,d]=c.useState(!1),f=t.size,m=c.useMemo(()=>af(e),[e]);return s.jsxs("div",{className:"flex min-h-0 flex-col",children:[s.jsxs("div",{className:"px-row-inset pb-2 pt-1",children:[s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs("h2",{className:"flex items-center gap-2 text-sm font-semibold text-fg",children:[s.jsx(ks,{className:"size-4 text-positive","aria-hidden":!0}),"Rescue from Spam"]}),s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(tu,{className:"size-3.5"}),onClick:()=>d(h=>!h),className:"-mr-1.5 -mt-0.5",children:"Why these?"})]}),s.jsx("p",{className:"mt-1 text-2xs text-fg-subtle",children:"These look safe — from senders we can verify. Uncheck any sender that belongs in Spam, or open a sender to pick individual messages."}),u&&s.jsx("div",{className:"mt-2",children:s.jsx(cf,{})})]}),s.jsxs("div",{className:"flex items-center justify-between px-row-inset pb-1.5",children:[s.jsx("span",{className:"text-2xs font-medium text-fg-muted",children:`${f} of ${e.length} selected · ${m.length} ${m.length===1?"sender":"senders"}`}),s.jsxs("span",{className:"flex gap-1",children:[s.jsx(G,{variant:"ghost",size:"sm",onClick:r,children:"Select all"}),s.jsx(G,{variant:"ghost",size:"sm",onClick:o,children:"Select none"})]})]}),s.jsx("div",{className:"min-h-0 flex-1 divide-y divide-line overflow-y-auto border-y border-line",children:m.map(h=>s.jsx(of,{group:h,selected:t,onToggleGroup:a,onToggleMessage:n},h.key))}),s.jsxs("div",{className:"space-y-2 border-t border-line bg-surface px-row-inset py-3",children:[s.jsx(G,{variant:"primary",onClick:i,className:"h-11 w-full font-semibold",children:`Continue with ${f} ${da(f)}`}),s.jsx(G,{variant:"ghost",onClick:l,className:"h-11 w-full",children:"Cancel"})]})]})}function df({count:e,folders:t,destination:n,onPick:a,onMove:r,onBack:o}){const[i,l]=c.useState(!1);return s.jsxs("div",{className:"flex min-h-0 flex-col",children:[s.jsxs("div",{className:"px-row-inset pb-2 pt-1",children:[s.jsx("h2",{className:"text-sm font-semibold text-fg",children:"Where should they go?"}),s.jsx("p",{className:"mt-1 text-2xs text-fg-subtle",children:"Pick a folder, then we move them out of Spam."})]}),s.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-row-inset py-2",children:i?s.jsx("div",{className:"overflow-hidden rounded-xl border border-line bg-surface",children:s.jsx(Jo,{mailboxes:t,autoFocus:!0,onSelect:u=>{a(u),l(!1)},onCancel:()=>l(!1)})}):s.jsxs("div",{className:"rounded-xl border border-line bg-surface-sunken p-3",children:[s.jsx("p",{className:"text-2xs text-fg-subtle",children:"Destination"}),s.jsx("p",{className:"mt-0.5 text-sm font-medium text-fg",children:Pn(t,n)}),s.jsx(G,{variant:"ghost",size:"sm",onClick:()=>l(!0),className:"mt-2 px-0",children:"Move to a different folder"})]})}),s.jsxs("div",{className:"space-y-2 border-t border-line bg-surface px-row-inset py-3",children:[s.jsx("p",{className:"text-2xs text-fg-subtle",children:lf(e,Pn(t,n))}),s.jsx(G,{variant:"primary",onClick:r,className:"h-11 w-full font-semibold",children:`Move ${e} out of Spam`}),s.jsx(G,{variant:"ghost",onClick:o,className:"h-11 w-full",children:"Back"})]})]})}function ff({count:e,destinationLabel:t,onClose:n}){return s.jsxs("div",{className:"flex min-h-0 flex-col",children:[s.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 px-row-inset py-10 text-center",children:[s.jsx(la,{className:"size-10 text-positive","aria-hidden":!0}),s.jsx("p",{className:"text-base font-semibold text-fg",children:`Moved ${e} ${da(e)} out of Spam.`}),s.jsx("p",{className:"text-2xs text-fg-subtle",children:`You'll find them in ${t}.`})]}),s.jsx("div",{className:"border-t border-line bg-surface px-row-inset py-3",children:s.jsx(G,{variant:"primary",onClick:n,className:"h-11 w-full font-semibold",children:"Done"})})]})}function mf({open:e,candidates:t,defaultDestinationId:n,availableFolders:a,onConfirmMove:r,onCancel:o}){const[i,l]=c.useState("review"),[u,d]=c.useState(()=>e?new Set(t.map(w=>w.id)):new Set),[f,m]=c.useState(n),[h,p]=c.useState(0),b=c.useRef(!1);c.useEffect(()=>{e&&!b.current&&(l("review"),d(new Set(t.map(w=>w.id))),m(n),p(0)),b.current=e},[e,t,n]);const x=u.size,y=w=>{d(j=>{const C=new Set(j);return C.has(w)?C.delete(w):C.add(w),C})},g=(w,j)=>{d(C=>{const N=new Set(C);for(const S of w.messages)j?N.add(S.id):N.delete(S.id);return N})},v=()=>{const w=Array.from(u);p(w.length),r(w,f),l("done")};return s.jsxs(Td,{open:e,onClose:o,dismissLabel:"Close rescue",children:[i==="review"&&s.jsx(uf,{candidates:t,selected:u,onToggle:y,onToggleGroup:g,onSelectAll:()=>d(new Set(t.map(w=>w.id))),onSelectNone:()=>d(new Set),onContinue:()=>l("destination"),onCancel:o}),i==="destination"&&s.jsx(df,{count:x,folders:a,destination:f,onPick:m,onMove:v,onBack:()=>l("review")}),i==="done"&&s.jsx(ff,{count:h,destinationLabel:Pn(a,f),onClose:o})]})}const fa=[{id:"all",label:"All",tone:"neutral"},{id:"personal",label:"Personal",tone:"accent"},{id:"transactional",label:"Transactional",tone:"positive"},{id:"newsletter",label:"Newsletter",tone:"neutral"},{id:"marketing",label:"Marketing",tone:"warning"},{id:"social",label:"Social",tone:"warning"},{id:"automated",label:"Automated",tone:"neutral"}],Zo={id:"unread",label:"Unread"},hf={id:"flagged",label:"Starred"},ei={id:"attachment",label:"Has attachment"};function gf(e){if(!(e.length<=1))return e.map(t=>({id:t.id,label:t.label,count:t.count,active:t.active}))}function xf(e=[]){return{categories:[...fa],filters:fc,sources:gf(e)}}function pf(){return{categories:[...fa],filters:[Zo,hf,ei]}}function bf(){return{categories:[...fa],filters:[Zo,ei]}}function lt(e,t,{checkForDefaultPrevented:n=!0}={}){return function(r){if(e?.(r),n===!1||!r||!r.defaultPrevented)return t?.(r)}}function rr(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function vf(...e){return t=>{let n=!1;const a=e.map(r=>{const o=rr(r,t);return!n&&typeof o=="function"&&(n=!0),o});if(n)return()=>{for(let r=0;r<a.length;r++){const o=a[r];typeof o=="function"?o():rr(e[r],null)}}}}function Nt(...e){return c.useCallback(vf(...e),e)}function yf(e,t=[]){let n=[];function a(o,i){const l=c.createContext(i);l.displayName=o+"Context";const u=n.length;n=[...n,i];const d=m=>{const{scope:h,children:p,...b}=m,x=h?.[e]?.[u]||l,y=c.useMemo(()=>b,Object.values(b));return s.jsx(x.Provider,{value:y,children:p})};d.displayName=o+"Provider";function f(m,h,p={}){const{optional:b=!1}=p,x=h?.[e]?.[u]||l,y=c.useContext(x);if(y)return y;if(i!==void 0)return i;if(!b)throw new Error(`\`${m}\` must be used within \`${o}\``)}return[d,f]}const r=()=>{const o=n.map(i=>c.createContext(i));return function(l){const u=l?.[e]||o;return c.useMemo(()=>({[`__scope${e}`]:{...l,[e]:u}}),[l,u])}};return r.scopeName=e,[a,wf(r,...t)]}function wf(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const a=e.map(r=>({useScope:r(),scopeName:r.scopeName}));return function(o){const i=a.reduce((l,{useScope:u,scopeName:d})=>{const m=u(o)[`__scope${d}`];return{...l,...m}},{});return c.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var xs=globalThis?.document?c.useLayoutEffect:()=>{},jf=Gn[" useInsertionEffect ".trim().toString()]||xs;function Sf({prop:e,defaultProp:t,onChange:n=()=>{},caller:a}){const[r,o,i]=Nf({defaultProp:t,onChange:n}),l=e!==void 0,u=l?e:r;{const f=c.useRef(e!==void 0);c.useEffect(()=>{const m=f.current;m!==l&&console.warn(`${a} is changing from ${m?"controlled":"uncontrolled"} to ${l?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),f.current=l},[l,a])}const d=c.useCallback(f=>{if(l){const m=kf(f)?f(e):f;m!==e&&i.current?.(m)}else o(f)},[l,e,o,i]);return[u,d]}function Nf({defaultProp:e,onChange:t}){const[n,a]=c.useState(e),r=c.useRef(n),o=c.useRef(t);return jf(()=>{o.current=t},[t]),c.useEffect(()=>{r.current!==n&&(o.current?.(n),r.current=n)},[n,r]),[n,a,o]}function kf(e){return typeof e=="function"}function ma(e){const t=c.forwardRef((n,a)=>{let{children:r,...o}=n,i=null,l=!1;const u=[];or(r)&&typeof Ds=="function"&&(r=Ds(r._payload)),c.Children.forEach(r,h=>{if(Mf(h)){l=!0;const p=h;let b="child"in p.props?p.props.child:p.props.children;or(b)&&typeof Ds=="function"&&(b=Ds(b._payload)),i=Ef(p,b),u.push(i?.props?.children)}else u.push(h)}),i?i=c.cloneElement(i,void 0,u):!l&&c.Children.count(r)===1&&c.isValidElement(r)&&(i=r);const d=i?Rf(i):void 0,f=Nt(a,d);if(!i){if(r||r===0)throw new Error(l?Of(e):Af(e));return r}const m=If(o,i.props??{});return i.type!==c.Fragment&&(m.ref=a?f:d),c.cloneElement(i,m)});return t.displayName=`${e}.Slot`,t}var Nv=ma("Slot"),Cf=Symbol.for("radix.slottable"),Ef=(e,t)=>{if("child"in e.props){const n=e.props.child;return c.isValidElement(n)?c.cloneElement(n,void 0,e.props.children(n.props.children)):null}return c.isValidElement(t)?t:null};function If(e,t){const n={...t};for(const a in t){const r=e[a],o=t[a];/^on[A-Z]/.test(a)?r&&o?n[a]=(...l)=>{const u=o(...l);return r(...l),u}:r&&(n[a]=r):a==="style"?n[a]={...r,...o}:a==="className"&&(n[a]=[r,o].filter(Boolean).join(" "))}return{...e,...n}}function Rf(e){let t=Object.getOwnPropertyDescriptor(e.props,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=Object.getOwnPropertyDescriptor(e,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}function Mf(e){return c.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===Cf}var Tf=Symbol.for("react.lazy");function or(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===Tf&&"_payload"in e&&Df(e._payload)}function Df(e){return typeof e=="object"&&e!==null&&"then"in e}var Af=e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,Of=e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,Ds=Gn[" use ".trim().toString()],Pf=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],nt=Pf.reduce((e,t)=>{const n=ma(`Primitive.${t}`),a=c.forwardRef((r,o)=>{const{asChild:i,...l}=r,u=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),s.jsx(u,{...l,ref:o})});return a.displayName=`Primitive.${t}`,{...e,[t]:a}},{});function Lf(e,t){e&&Xn.flushSync(()=>e.dispatchEvent(t))}function ps(e){const t=c.useRef(e);return c.useEffect(()=>{t.current=e}),c.useMemo(()=>((...n)=>t.current?.(...n)),[])}var zf="DismissableLayer",Ln="dismissableLayer.update",_f="dismissableLayer.pointerDownOutside",Ff="dismissableLayer.focusOutside",ir,ha=c.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),ti=c.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,deferPointerDownOutside:a=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:i,onInteractOutside:l,onDismiss:u,...d}=e,f=c.useContext(ha),[m,h]=c.useState(null),p=m?.ownerDocument??globalThis?.document,[,b]=c.useState({}),x=Nt(t,h),y=Array.from(f.layers),[g]=[...f.layersWithOutsidePointerEventsDisabled].slice(-1),v=g?y.indexOf(g):-1,w=m?y.indexOf(m):-1,j=f.layersWithOutsidePointerEventsDisabled.size>0,C=w>=v,N=c.useRef(!1),S=Uf(T=>{o?.(T),l?.(T),T.defaultPrevented||u?.()},{ownerDocument:p,deferPointerDownOutside:a,isDeferredPointerDownOutsideRef:N,dismissableSurfaces:f.dismissableSurfaces,shouldHandlePointerDownOutside:c.useCallback(T=>{if(!(T instanceof Node))return!1;const D=[...f.branches].some(I=>I.contains(T));return C&&!D},[f.branches,C])}),E=Hf(T=>{if(a&&N.current)return;const D=T.target;[...f.branches].some(R=>R.contains(D))||(i?.(T),l?.(T),T.defaultPrevented||u?.())},p),k=m?w===y.length-1:!1,M=ps(T=>{T.key==="Escape"&&(r?.(T),!T.defaultPrevented&&u&&(T.preventDefault(),u()))});return c.useEffect(()=>{if(k)return p.addEventListener("keydown",M,{capture:!0}),()=>p.removeEventListener("keydown",M,{capture:!0})},[p,k,M]),c.useEffect(()=>{if(m)return n&&(f.layersWithOutsidePointerEventsDisabled.size===0&&(ir=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),f.layersWithOutsidePointerEventsDisabled.add(m)),f.layers.add(m),lr(),()=>{n&&(f.layersWithOutsidePointerEventsDisabled.delete(m),f.layersWithOutsidePointerEventsDisabled.size===0&&(p.body.style.pointerEvents=ir))}},[m,p,n,f]),c.useEffect(()=>()=>{m&&(f.layers.delete(m),f.layersWithOutsidePointerEventsDisabled.delete(m),lr())},[m,f]),c.useEffect(()=>{const T=()=>b({});return document.addEventListener(Ln,T),()=>document.removeEventListener(Ln,T)},[]),s.jsx(nt.div,{...d,ref:x,style:{pointerEvents:j?C?"auto":"none":void 0,...e.style},onFocusCapture:lt(e.onFocusCapture,E.onFocusCapture),onBlurCapture:lt(e.onBlurCapture,E.onBlurCapture),onPointerDownCapture:lt(e.onPointerDownCapture,S.onPointerDownCapture)})});ti.displayName=zf;var Bf="DismissableLayerBranch",$f=c.forwardRef((e,t)=>{const n=c.useContext(ha),a=c.useRef(null),r=Nt(t,a);return c.useEffect(()=>{const o=a.current;if(o)return n.branches.add(o),()=>{n.branches.delete(o)}},[n.branches]),s.jsx(nt.div,{...e,ref:r})});$f.displayName=Bf;function Kf(){const e=c.useContext(ha),[t,n]=c.useState(null);return c.useEffect(()=>{if(t)return e.dismissableSurfaces.add(t),()=>{e.dismissableSurfaces.delete(t)}},[t,e.dismissableSurfaces]),n}var qf=()=>!0;function Uf(e,t){const{ownerDocument:n=globalThis?.document,deferPointerDownOutside:a=!1,isDeferredPointerDownOutsideRef:r,dismissableSurfaces:o,shouldHandlePointerDownOutside:i=qf}=t,l=ps(e),u=c.useRef(!1),d=c.useRef(!1),f=c.useRef(new Map),m=c.useRef(()=>{});return c.useEffect(()=>{function h(){d.current=!1,r.current=!1,f.current.clear()}function p(){return Array.from(f.current.values()).some(Boolean)}function b(w){if(!d.current)return;const j=w.target;j instanceof Node&&[...o].some(N=>N.contains(j))||f.current.set(w.type,!0),w.type==="click"&&window.setTimeout(()=>{d.current&&m.current()},0)}function x(w){d.current&&f.current.set(w.type,!1)}const y=w=>{if(w.target&&!u.current){let j=function(){n.removeEventListener("click",m.current);const N=p();h(),N||si(_f,l,C,{discrete:!0})};if(!i(w.target)){n.removeEventListener("click",m.current),h(),u.current=!1;return}const C={originalEvent:w};d.current=!0,r.current=a&&w.button===0,f.current.clear(),!a||w.button!==0?j():(n.removeEventListener("click",m.current),m.current=j,n.addEventListener("click",m.current,{once:!0}))}else n.removeEventListener("click",m.current),h();u.current=!1},g=["pointerup","mousedown","mouseup","touchstart","touchend","click"];for(const w of g)n.addEventListener(w,b,!0),n.addEventListener(w,x);const v=window.setTimeout(()=>{n.addEventListener("pointerdown",y)},0);return()=>{window.clearTimeout(v),n.removeEventListener("pointerdown",y),n.removeEventListener("click",m.current);for(const w of g)n.removeEventListener(w,b,!0),n.removeEventListener(w,x)}},[n,l,a,r,o,i]),{onPointerDownCapture:()=>u.current=!0}}function Hf(e,t=globalThis?.document){const n=ps(e),a=c.useRef(!1);return c.useEffect(()=>{const r=o=>{o.target&&!a.current&&si(Ff,n,{originalEvent:o},{discrete:!1})};return t.addEventListener("focusin",r),()=>t.removeEventListener("focusin",r)},[t,n]),{onFocusCapture:()=>a.current=!0,onBlurCapture:()=>a.current=!1}}function lr(){const e=new CustomEvent(Ln);document.dispatchEvent(e)}function si(e,t,n,{discrete:a}){const r=n.originalEvent.target,o=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});t&&r.addEventListener(e,t,{once:!0}),a?Lf(r,o):r.dispatchEvent(o)}var As=0,Lt=null;function Qf(){c.useEffect(()=>{Lt||(Lt={start:cr(),end:cr()});const{start:e,end:t}=Lt;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==t&&document.body.insertAdjacentElement("beforeend",t),As++,()=>{As===1&&(Lt?.start.remove(),Lt?.end.remove(),Lt=null),As=Math.max(0,As-1)}},[])}function cr(){const e=document.createElement("span");return e.setAttribute("data-radix-focus-guard",""),e.tabIndex=0,e.style.outline="none",e.style.opacity="0",e.style.position="fixed",e.style.pointerEvents="none",e}var pn="focusScope.autoFocusOnMount",bn="focusScope.autoFocusOnUnmount",ur={bubbles:!1,cancelable:!0},Wf="FocusScope",ni=c.forwardRef((e,t)=>{const{loop:n=!1,trapped:a=!1,onMountAutoFocus:r,onUnmountAutoFocus:o,...i}=e,[l,u]=c.useState(null),d=ps(r),f=ps(o),m=c.useRef(null),h=Nt(t,u),p=c.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;c.useEffect(()=>{if(a){let x=function(w){if(p.paused||!l)return;const j=w.target;l.contains(j)?m.current=j:ot(m.current,{select:!0})},y=function(w){if(p.paused||!l)return;const j=w.relatedTarget;j!==null&&(l.contains(j)||ot(m.current,{select:!0}))},g=function(w){if(document.activeElement===document.body)for(const C of w)C.removedNodes.length>0&&ot(l)};document.addEventListener("focusin",x),document.addEventListener("focusout",y);const v=new MutationObserver(g);return l&&v.observe(l,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",x),document.removeEventListener("focusout",y),v.disconnect()}}},[a,l,p.paused]),c.useEffect(()=>{if(l){fr.add(p);const x=document.activeElement;if(!l.contains(x)){const g=new CustomEvent(pn,ur);l.addEventListener(pn,d),l.dispatchEvent(g),g.defaultPrevented||(Vf(Zf(ai(l)),{select:!0}),document.activeElement===x&&ot(l))}return()=>{l.removeEventListener(pn,d),setTimeout(()=>{const g=new CustomEvent(bn,ur);l.addEventListener(bn,f),l.dispatchEvent(g),g.defaultPrevented||ot(x??document.body,{select:!0}),l.removeEventListener(bn,f),fr.remove(p)},0)}}},[l,d,f,p]);const b=c.useCallback(x=>{if(!n&&!a||p.paused)return;const y=x.key==="Tab"&&!x.altKey&&!x.ctrlKey&&!x.metaKey,g=document.activeElement;if(y&&g){const v=x.currentTarget,[w,j]=Yf(v);w&&j?!x.shiftKey&&g===j?(x.preventDefault(),n&&ot(w,{select:!0})):x.shiftKey&&g===w&&(x.preventDefault(),n&&ot(j,{select:!0})):g===v&&x.preventDefault()}},[n,a,p.paused]);return s.jsx(nt.div,{tabIndex:-1,...i,ref:h,onKeyDown:b})});ni.displayName=Wf;function Vf(e,{select:t=!1}={}){const n=document.activeElement;for(const a of e)if(ot(a,{select:t}),document.activeElement!==n)return}function Yf(e){const t=ai(e),n=dr(t,e),a=dr(t.reverse(),e);return[n,a]}function ai(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:a=>{const r=a.tagName==="INPUT"&&a.type==="hidden";return a.disabled||a.hidden||r?NodeFilter.FILTER_SKIP:a.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function dr(e,t){const n=typeof t.checkVisibility=="function"&&t.checkVisibility({checkVisibilityCSS:!0});for(const a of e)if(!(n?!a.checkVisibility({checkVisibilityCSS:!0}):Gf(a,{upTo:t})))return a}function Gf(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}function Xf(e){return e instanceof HTMLInputElement&&"select"in e}function ot(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Xf(e)&&t&&e.select()}}var fr=Jf();function Jf(){let e=[];return{add(t){const n=e[0];t!==n&&n?.pause(),e=mr(e,t),e.unshift(t)},remove(t){e=mr(e,t),e[0]?.resume()}}}function mr(e,t){const n=[...e],a=n.indexOf(t);return a!==-1&&n.splice(a,1),n}function Zf(e){return e.filter(t=>t.tagName!=="A")}var em=Gn[" useId ".trim().toString()]||(()=>{}),tm=0;function vn(e){const[t,n]=c.useState(em());return xs(()=>{n(a=>a??String(tm++))},[e]),e||(t?`radix-${t}`:"")}var sm="Portal",ri=c.forwardRef((e,t)=>{const{container:n,...a}=e,[r,o]=c.useState(!1);xs(()=>o(!0),[]);const i=n||r&&globalThis?.document?.body;return i?Xn.createPortal(s.jsx(nt.div,{...a,ref:t}),i):null});ri.displayName=sm;function nm(e,t){return c.useReducer((n,a)=>t[n][a]??n,e)}var on=e=>{const{present:t,children:n}=e,a=am(t),r=typeof n=="function"?n({present:a.isPresent}):c.Children.only(n),o=rm(a.ref,om(r));return typeof n=="function"||a.isPresent?c.cloneElement(r,{ref:o}):null};on.displayName="Presence";function am(e){const[t,n]=c.useState(),a=c.useRef(null),r=c.useRef(e),o=c.useRef("none"),i=c.useRef(void 0),l=e?"mounted":"unmounted",[u,d]=nm(l,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return c.useEffect(()=>{u==="mounted"?(o.current=i.current??ls(a.current),i.current=void 0):o.current="none"},[u]),xs(()=>{const f=a.current,m=r.current;if(m!==e){const p=o.current,b=ls(f);e?(i.current=b,d("MOUNT")):b==="none"||f?.display==="none"?d("UNMOUNT"):d(m&&p!==b?"ANIMATION_OUT":"UNMOUNT"),r.current=e}},[e,d]),xs(()=>{if(t){let f;const m=t.ownerDocument.defaultView??window,h=b=>{const y=ls(a.current).includes(CSS.escape(b.animationName));if(b.target===t&&y&&(d("ANIMATION_END"),!r.current)){const g=t.style.animationFillMode;t.style.animationFillMode="forwards",f=m.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=g)})}},p=b=>{b.target===t&&(o.current=ls(a.current))};return t.addEventListener("animationstart",p),t.addEventListener("animationcancel",h),t.addEventListener("animationend",h),()=>{m.clearTimeout(f),t.removeEventListener("animationstart",p),t.removeEventListener("animationcancel",h),t.removeEventListener("animationend",h)}}else d("ANIMATION_END")},[t,d]),{isPresent:["mounted","unmountSuspended"].includes(u),ref:c.useCallback(f=>{if(f){const m=getComputedStyle(f);a.current=m,i.current=ls(m)}else a.current=null;n(f)},[])}}function hr(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function rm(...e){const t=c.useRef(e);return t.current=e,c.useCallback(n=>{const a=t.current;let r=!1;const o=a.map(i=>{const l=hr(i,n);return!r&&typeof l=="function"&&(r=!0),l});if(r)return()=>{for(let i=0;i<o.length;i++){const l=o[i];typeof l=="function"?l():hr(a[i],null)}}},[])}function ls(e){return e?.animationName||"none"}function om(e){let t=Object.getOwnPropertyDescriptor(e.props,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=Object.getOwnPropertyDescriptor(e,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var im=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},zt=new WeakMap,Os=new WeakMap,Ps={},yn=0,oi=function(e){return e&&(e.host||oi(e.parentNode))},lm=function(e,t){return t.map(function(n){if(e.contains(n))return n;var a=oi(n);return a&&e.contains(a)?a:(console.error("aria-hidden",n,"in not contained inside",e,". Doing nothing"),null)}).filter(function(n){return!!n})},cm=function(e,t,n,a){var r=lm(t,Array.isArray(e)?e:[e]);Ps[n]||(Ps[n]=new WeakMap);var o=Ps[n],i=[],l=new Set,u=new Set(r),d=function(m){!m||l.has(m)||(l.add(m),d(m.parentNode))};r.forEach(d);var f=function(m){!m||u.has(m)||Array.prototype.forEach.call(m.children,function(h){if(l.has(h))f(h);else try{var p=h.getAttribute(a),b=p!==null&&p!=="false",x=(zt.get(h)||0)+1,y=(o.get(h)||0)+1;zt.set(h,x),o.set(h,y),i.push(h),x===1&&b&&Os.set(h,!0),y===1&&h.setAttribute(n,"true"),b||h.setAttribute(a,"true")}catch(g){console.error("aria-hidden: cannot operate on ",h,g)}})};return f(t),l.clear(),yn++,function(){i.forEach(function(m){var h=zt.get(m)-1,p=o.get(m)-1;zt.set(m,h),o.set(m,p),h||(Os.has(m)||m.removeAttribute(a),Os.delete(m)),p||m.removeAttribute(n)}),yn--,yn||(zt=new WeakMap,zt=new WeakMap,Os=new WeakMap,Ps={})}},um=function(e,t,n){n===void 0&&(n="data-aria-hidden");var a=Array.from(Array.isArray(e)?e:[e]),r=im(e);return r?(a.push.apply(a,Array.from(r.querySelectorAll("[aria-live], script"))),cm(a,r,n,"aria-hidden")):function(){return null}},Qs="right-scroll-bar-position",Ws="width-before-scroll-bar",dm="with-scroll-bars-hidden",fm="--removed-body-scroll-bar-size";function wn(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function mm(e,t){var n=c.useState(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(a){var r=n.value;r!==a&&(n.value=a,n.callback(a,r))}}}})[0];return n.callback=t,n.facade}var hm=typeof window<"u"?c.useLayoutEffect:c.useEffect,gr=new WeakMap;function gm(e,t){var n=mm(null,function(a){return e.forEach(function(r){return wn(r,a)})});return hm(function(){var a=gr.get(n);if(a){var r=new Set(a),o=new Set(e),i=n.current;r.forEach(function(l){o.has(l)||wn(l,null)}),o.forEach(function(l){r.has(l)||wn(l,i)})}gr.set(n,e)},[e]),n}function xm(e){return e}function pm(e,t){t===void 0&&(t=xm);var n=[],a=!1,r={read:function(){if(a)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(o){var i=t(o,a);return n.push(i),function(){n=n.filter(function(l){return l!==i})}},assignSyncMedium:function(o){for(a=!0;n.length;){var i=n;n=[],i.forEach(o)}n={push:function(l){return o(l)},filter:function(){return n}}},assignMedium:function(o){a=!0;var i=[];if(n.length){var l=n;n=[],l.forEach(o),i=n}var u=function(){var f=i;i=[],f.forEach(o)},d=function(){return Promise.resolve().then(u)};d(),n={push:function(f){i.push(f),d()},filter:function(f){return i=i.filter(f),n}}}};return r}function bm(e){e===void 0&&(e={});var t=pm(null);return t.options=it({async:!0,ssr:!1},e),t}var ii=function(e){var t=e.sideCar,n=ro(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var a=t.read();if(!a)throw new Error("Sidecar medium not found");return c.createElement(a,it({},n))};ii.isSideCarExport=!0;function vm(e,t){return e.useMedium(t),ii}var li=bm(),jn=function(){},ln=c.forwardRef(function(e,t){var n=c.useRef(null),a=c.useState({onScrollCapture:jn,onWheelCapture:jn,onTouchMoveCapture:jn}),r=a[0],o=a[1],i=e.forwardProps,l=e.children,u=e.className,d=e.removeScrollBar,f=e.enabled,m=e.shards,h=e.sideCar,p=e.noRelative,b=e.noIsolation,x=e.inert,y=e.allowPinchZoom,g=e.as,v=g===void 0?"div":g,w=e.gapMode,j=ro(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),C=h,N=gm([n,t]),S=it(it({},j),r);return c.createElement(c.Fragment,null,f&&c.createElement(C,{sideCar:li,removeScrollBar:d,shards:m,noRelative:p,noIsolation:b,inert:x,setCallbacks:o,allowPinchZoom:!!y,lockRef:n,gapMode:w}),i?c.cloneElement(c.Children.only(l),it(it({},S),{ref:N})):c.createElement(v,it({},S,{className:u,ref:N}),l))});ln.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};ln.classNames={fullWidth:Ws,zeroRight:Qs};var ym=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function wm(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=ym();return t&&e.setAttribute("nonce",t),e}function jm(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Sm(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Nm=function(){var e=0,t=null;return{add:function(n){e==0&&(t=wm())&&(jm(t,n),Sm(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},km=function(){var e=Nm();return function(t,n){c.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},ci=function(){var e=km(),t=function(n){var a=n.styles,r=n.dynamic;return e(a,r),null};return t},Cm={left:0,top:0,right:0,gap:0},Sn=function(e){return parseInt(e||"",10)||0},Em=function(e){var t=window.getComputedStyle(document.body),n=t[e==="padding"?"paddingLeft":"marginLeft"],a=t[e==="padding"?"paddingTop":"marginTop"],r=t[e==="padding"?"paddingRight":"marginRight"];return[Sn(n),Sn(a),Sn(r)]},Im=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Cm;var t=Em(e),n=document.documentElement.clientWidth,a=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,a-n+t[2]-t[0])}},Rm=ci(),Ut="data-scroll-locked",Mm=function(e,t,n,a){var r=e.left,o=e.top,i=e.right,l=e.gap;return n===void 0&&(n="margin"),`
|
|
70
|
+
.`.concat(dm,` {
|
|
71
|
+
overflow: hidden `).concat(a,`;
|
|
72
|
+
padding-right: `).concat(l,"px ").concat(a,`;
|
|
73
|
+
}
|
|
74
|
+
body[`).concat(Ut,`] {
|
|
75
|
+
overflow: hidden `).concat(a,`;
|
|
76
|
+
overscroll-behavior: contain;
|
|
77
|
+
`).concat([t&&"position: relative ".concat(a,";"),n==="margin"&&`
|
|
78
|
+
padding-left: `.concat(r,`px;
|
|
79
|
+
padding-top: `).concat(o,`px;
|
|
80
|
+
padding-right: `).concat(i,`px;
|
|
81
|
+
margin-left:0;
|
|
82
|
+
margin-top:0;
|
|
83
|
+
margin-right: `).concat(l,"px ").concat(a,`;
|
|
84
|
+
`),n==="padding"&&"padding-right: ".concat(l,"px ").concat(a,";")].filter(Boolean).join(""),`
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.`).concat(Qs,` {
|
|
88
|
+
right: `).concat(l,"px ").concat(a,`;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.`).concat(Ws,` {
|
|
92
|
+
margin-right: `).concat(l,"px ").concat(a,`;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.`).concat(Qs," .").concat(Qs,` {
|
|
96
|
+
right: 0 `).concat(a,`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.`).concat(Ws," .").concat(Ws,` {
|
|
100
|
+
margin-right: 0 `).concat(a,`;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
body[`).concat(Ut,`] {
|
|
104
|
+
`).concat(fm,": ").concat(l,`px;
|
|
105
|
+
}
|
|
106
|
+
`)},xr=function(){var e=parseInt(document.body.getAttribute(Ut)||"0",10);return isFinite(e)?e:0},Tm=function(){c.useEffect(function(){return document.body.setAttribute(Ut,(xr()+1).toString()),function(){var e=xr()-1;e<=0?document.body.removeAttribute(Ut):document.body.setAttribute(Ut,e.toString())}},[])},Dm=function(e){var t=e.noRelative,n=e.noImportant,a=e.gapMode,r=a===void 0?"margin":a;Tm();var o=c.useMemo(function(){return Im(r)},[r]);return c.createElement(Rm,{styles:Mm(o,!t,r,n?"":"!important")})},zn=!1;if(typeof window<"u")try{var Ls=Object.defineProperty({},"passive",{get:function(){return zn=!0,!0}});window.addEventListener("test",Ls,Ls),window.removeEventListener("test",Ls,Ls)}catch{zn=!1}var _t=zn?{passive:!1}:!1,Am=function(e){return e.tagName==="TEXTAREA"},ui=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!Am(e)&&n[t]==="visible")},Om=function(e){return ui(e,"overflowY")},Pm=function(e){return ui(e,"overflowX")},pr=function(e,t){var n=t.ownerDocument,a=t;do{typeof ShadowRoot<"u"&&a instanceof ShadowRoot&&(a=a.host);var r=di(e,a);if(r){var o=fi(e,a),i=o[1],l=o[2];if(i>l)return!0}a=a.parentNode}while(a&&a!==n.body);return!1},Lm=function(e){var t=e.scrollTop,n=e.scrollHeight,a=e.clientHeight;return[t,n,a]},zm=function(e){var t=e.scrollLeft,n=e.scrollWidth,a=e.clientWidth;return[t,n,a]},di=function(e,t){return e==="v"?Om(t):Pm(t)},fi=function(e,t){return e==="v"?Lm(t):zm(t)},_m=function(e,t){return e==="h"&&t==="rtl"?-1:1},Fm=function(e,t,n,a,r){var o=_m(e,window.getComputedStyle(t).direction),i=o*a,l=n.target,u=t.contains(l),d=!1,f=i>0,m=0,h=0;do{if(!l)break;var p=fi(e,l),b=p[0],x=p[1],y=p[2],g=x-y-o*b;(b||g)&&di(e,l)&&(m+=g,h+=b);var v=l.parentNode;l=v&&v.nodeType===Node.DOCUMENT_FRAGMENT_NODE?v.host:v}while(!u&&l!==document.body||u&&(t.contains(l)||t===l));return(f&&Math.abs(m)<1||!f&&Math.abs(h)<1)&&(d=!0),d},zs=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},br=function(e){return[e.deltaX,e.deltaY]},vr=function(e){return e&&"current"in e?e.current:e},Bm=function(e,t){return e[0]===t[0]&&e[1]===t[1]},$m=function(e){return`
|
|
107
|
+
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
108
|
+
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
109
|
+
`)},Km=0,Ft=[];function qm(e){var t=c.useRef([]),n=c.useRef([0,0]),a=c.useRef(),r=c.useState(Km++)[0],o=c.useState(ci)[0],i=c.useRef(e);c.useEffect(function(){i.current=e},[e]),c.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(r));var x=mc([e.lockRef.current],(e.shards||[]).map(vr),!0).filter(Boolean);return x.forEach(function(y){return y.classList.add("allow-interactivity-".concat(r))}),function(){document.body.classList.remove("block-interactivity-".concat(r)),x.forEach(function(y){return y.classList.remove("allow-interactivity-".concat(r))})}}},[e.inert,e.lockRef.current,e.shards]);var l=c.useCallback(function(x,y){if("touches"in x&&x.touches.length===2||x.type==="wheel"&&x.ctrlKey)return!i.current.allowPinchZoom;var g=zs(x),v=n.current,w="deltaX"in x?x.deltaX:v[0]-g[0],j="deltaY"in x?x.deltaY:v[1]-g[1],C,N=x.target,S=Math.abs(w)>Math.abs(j)?"h":"v";if("touches"in x&&S==="h"&&N.type==="range")return!1;var E=window.getSelection(),k=E&&E.anchorNode,M=k?k===N||k.contains(N):!1;if(M)return!1;var T=pr(S,N);if(!T)return!0;if(T?C=S:(C=S==="v"?"h":"v",T=pr(S,N)),!T)return!1;if(!a.current&&"changedTouches"in x&&(w||j)&&(a.current=C),!C)return!0;var D=a.current||C;return Fm(D,y,x,D==="h"?w:j)},[]),u=c.useCallback(function(x){var y=x;if(!(!Ft.length||Ft[Ft.length-1]!==o)){var g="deltaY"in y?br(y):zs(y),v=t.current.filter(function(C){return C.name===y.type&&(C.target===y.target||y.target===C.shadowParent)&&Bm(C.delta,g)})[0];if(v&&v.should){y.cancelable&&y.preventDefault();return}if(!v){var w=(i.current.shards||[]).map(vr).filter(Boolean).filter(function(C){return C.contains(y.target)}),j=w.length>0?l(y,w[0]):!i.current.noIsolation;j&&y.cancelable&&y.preventDefault()}}},[]),d=c.useCallback(function(x,y,g,v){var w={name:x,delta:y,target:g,should:v,shadowParent:Um(g)};t.current.push(w),setTimeout(function(){t.current=t.current.filter(function(j){return j!==w})},1)},[]),f=c.useCallback(function(x){n.current=zs(x),a.current=void 0},[]),m=c.useCallback(function(x){d(x.type,br(x),x.target,l(x,e.lockRef.current))},[]),h=c.useCallback(function(x){d(x.type,zs(x),x.target,l(x,e.lockRef.current))},[]);c.useEffect(function(){return Ft.push(o),e.setCallbacks({onScrollCapture:m,onWheelCapture:m,onTouchMoveCapture:h}),document.addEventListener("wheel",u,_t),document.addEventListener("touchmove",u,_t),document.addEventListener("touchstart",f,_t),function(){Ft=Ft.filter(function(x){return x!==o}),document.removeEventListener("wheel",u,_t),document.removeEventListener("touchmove",u,_t),document.removeEventListener("touchstart",f,_t)}},[]);var p=e.removeScrollBar,b=e.inert;return c.createElement(c.Fragment,null,b?c.createElement(o,{styles:$m(r)}):null,p?c.createElement(Dm,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Um(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const Hm=vm(li,qm);var mi=c.forwardRef(function(e,t){return c.createElement(ln,it({},e,{ref:t,sideCar:Hm}))});mi.classNames=ln.classNames;var Qm=class extends Jn{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,a=super.createResult(e,t),{isFetching:r,isRefetching:o,isError:i,isRefetchError:l}=a,u=n.fetchMeta?.fetchMore?.direction,d=i&&u==="forward",f=r&&u==="forward",m=i&&u==="backward",h=r&&u==="backward";return{...a,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:gc(t,n.data),hasPreviousPage:hc(t,n.data),isFetchNextPageError:d,isFetchingNextPage:f,isFetchPreviousPageError:m,isFetchingPreviousPage:h,isRefetchError:l&&!d&&!m,isRefetching:o&&!f&&!h}}};function yr(e,t){const n=new Set(t);return e.filter(a=>!n.has(a))}function Wm(e,t,n){const a=e.slice(0);return a[t]=n,a}var Vm=class extends xc{#a;#e;#r;#n;#t;#s;#o;#i;#l;#c=[];constructor(e,t,n){super(),this.#a=e,this.#n=n,this.#r=[],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.#r=e,this.#n=t,Dn.batch(()=>{const n=this.#t,a=this.#f(this.#r);a.forEach(f=>f.observer.setOptions(f.defaultedQueryOptions));const r=a.map(f=>f.observer),o=r.map(f=>f.getCurrentResult()),i=n.length!==r.length,l=r.some((f,m)=>f!==n[m]),u=i||l,d=u?!0:o.some((f,m)=>{const h=this.#e[m];return!h||!pc(f,h)});!u&&!d||(u&&(this.#c=a,this.#t=r),this.#e=o,this.hasListeners()&&(u&&(yr(n,r).forEach(f=>{f.destroy()}),yr(r,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),a=n.map(o=>o.observer.getOptimisticResult(o.defaultedQueryOptions)),r=n.map(o=>o.defaultedQueryOptions.queryHash);return[a,o=>this.#d(o??a,t,r),()=>this.#u(a,n)]}#u(e,t){return t.map((n,a)=>{const r=e[a];return n.defaultedQueryOptions.notifyOnChangeProps?r:n.observer.trackResult(r,o=>{t.forEach(i=>{i.observer.trackProp(o)})})})}#d(e,t,n){if(t){const a=this.#l,r=n!==void 0&&a!==void 0&&(a.length!==n.length||n.some((o,i)=>o!==a[i]));return(!this.#s||this.#e!==this.#i||r||t!==this.#o)&&(this.#o=t,this.#i=this.#e,n!==void 0&&(this.#l=n),this.#s=bc(this.#s,t(e))),this.#s}return e}#g(){return this.#n?.combine!==void 0&&this.#t.some((e,t)=>e.options.suspense&&this.#e[t]?.data===void 0)}#f(e){const t=new Map;this.#t.forEach(a=>{const r=a.options.queryHash;if(!r)return;const o=t.get(r);o?o.push(a):t.set(r,[a])});const n=[];return e.forEach(a=>{const r=this.#a.defaultQueryOptions(a),i=t.get(r.queryHash)?.shift()??new Jn(this.#a,r);n.push({defaultedQueryOptions:r,observer:i})}),n}#m(e,t){const n=this.#t.indexOf(e);n!==-1&&(this.#e=Wm(this.#e,n,t),this.#h())}#h(){if(this.hasListeners()){const e=this.#u(this.#e,this.#c),t=this.#g(),n=this.#s,a=t?n:this.#d(e,this.#n?.combine);(t||n!==a)&&Dn.batch(()=>{this.listeners.forEach(r=>{r(this.#e)})})}}};function kt({queries:e,...t},n){const a=je(),r=vc(),o=yc(),i=c.useMemo(()=>e.map(x=>{const y=a.defaultQueryOptions(x);return y._optimisticResults=r?"isRestoring":"optimistic",y}),[e,a,r]);i.forEach(x=>{wc(x);const y=a.getQueryCache().get(x.queryHash);jc(x,o,y)}),Sc(o);const[l]=c.useState(()=>new Vm(a,i,t)),[u,d,f]=l.getOptimisticResult(i,t.combine),m=!r&&t.subscribed!==!1;c.useSyncExternalStore(c.useCallback(x=>m?l.subscribe(Dn.batchCalls(x)):Nc,[l,m]),()=>l.getCurrentResult(),()=>l.getCurrentResult()),c.useEffect(()=>{l.setQueries(i,t)},[i,t,l]);const p=u.some((x,y)=>za(i[y],x))?u.flatMap((x,y)=>{const g=i[y];if(g&&za(g,x)){const v=new Jn(a,g);return kc(g,v,o)}return[]}):[];if(p.length>0)throw Promise.all(p);const b=u.find((x,y)=>{const g=i[y];return g&&Cc({result:x,errorResetBoundary:o,throwOnError:g.throwOnError,query:a.getQueryCache().get(g.queryHash),suspense:g.suspense})});if(b?.error)throw b.error;return d(f())}function hi(e,t){return Ec(e,Qm)}function _s(e){const t=oo({warn:e?.router===void 0}),n=e?.router||t;return io(n.stores.__store,lo(e,n))}function cn(e){const t=oo();return io(t.stores.location,lo(e,t))}const Ym=new Set(["outbox","flagged"]),Gm=e=>{const[,t,n]=e.split(/[?#]/)[0].split("/");return t!=="mail"||!n?!1:!Ym.has(n)};function Xm(e){const t=kt({queries:e.map(n=>({...He({path:{accountId:n.accountId}}),staleTime:1/0}))});for(const[n,a]of e.entries()){const r=t[n];if(!r||r.isPending)return;const o=r.data?.items??[];if(o.length===0)continue;const i=Jt(a.folderAppointments);return(o.find(u=>i.get(u.mailboxId)==="inbox")??o[0])?.mailboxId}}function gi(e){const{openCompose:t}=dt(),n=Ce(),a=cn(),r=Xm(e);return c.useCallback(()=>{if(Gm(a.pathname)){c.startTransition(()=>{t({mode:"new"})});return}r&&(c.startTransition(()=>{t({mode:"new"})}),n({to:"/mail/$mailboxId",params:{mailboxId:r}}))},[t,n,a.pathname,r])}const Jm=e=>e.startsWith("/mail")||e.startsWith("/settings"),Zm=({accounts:e})=>{const{state:t}=dt(),n=cn(),a=gi(e),r=n.search,o=typeof r?.selectedMessageId=="string"&&r.selectedMessageId.length>0;return!Jm(n.pathname)||t.isOpen||o?null:s.jsx("button",{type:"button",onClick:a,"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(wu,{className:"size-6"})})},xi=({trigger:e,children:t,align:n="right"})=>{const[a,r]=c.useState(!1),o=c.useRef(null),i=c.useCallback(u=>{o.current&&!o.current.contains(u.target)&&r(!1)},[]),l=c.useCallback(u=>{u.key==="Escape"&&r(!1)},[]);return c.useEffect(()=>(a&&(document.addEventListener("mousedown",i),document.addEventListener("keydown",l)),()=>{document.removeEventListener("mousedown",i),document.removeEventListener("keydown",l)}),[a,i,l]),s.jsxs("div",{ref:o,className:"relative",children:[s.jsx("button",{type:"button",onClick:u=>{u.stopPropagation(),r(!a)},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}),a&&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})]})},Kt=({onClick:e,disabled:t,destructive:n,children:a})=>s.jsx("button",{type:"button",onClick:r=>{r.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:a}),_n=()=>s.jsx("div",{className:"my-1 h-px bg-line"}),pi=({children:e})=>{const{Account:t}=Zn();return s.jsx(t,{children:e})},eh=({email:e,onSignOut:t})=>{const n=Ce(),a=e??"Account";return s.jsxs(xi,{trigger:s.jsx(Qe,{name:a,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(_n,{})]}),s.jsxs(Kt,{onClick:()=>n({to:"/settings/accounts"}),children:[s.jsx(Po,{className:"size-4"}),"Settings"]}),s.jsx(_n,{}),s.jsxs(Kt,{onClick:t,children:[s.jsx(To,{className:"size-4"}),"Sign out"]})]})},th=()=>s.jsx(pi,{children:({email:e,signOut:t})=>s.jsx(eh,{email:e,onSignOut:t})}),wr=()=>{const e=ea(),t=ta(e);window.open(t,"_blank","noopener,noreferrer")};function bi({variant:e="icon"}){return e==="drawer"?s.jsxs("button",{type:"button",onClick:wr,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(_a,{className:"size-4 shrink-0"}),s.jsx("span",{className:"flex-1 truncate text-left",children:"Report a bug"})]}):s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(_a,{className:"size-4"}),title:"Report a bug","aria-label":"Report a bug",onClick:wr})}const vi=[{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 sh(e){for(const t of vi){const n=t.hints.find(a=>a.action===e);if(n)return n.keys}}function $t(e){const t=sh(e);return!t||t.length===0?"":t.length===1?`(${t[0]})`:t[0]==="g"?`(${t.join(" then ")})`:`(${t.join("")})`}function nh({accounts:e}){const{searchInput:t,onSearchChange:n,onSearchClear:a,onSearchClearQuery:r}=Ee(),o=gi(e);return s.jsx(Sd,{leading:s.jsx("span",{className:"px-1 text-sm font-semibold tracking-tight text-fg",children:"remit"}),search:s.jsx(ua,{value:t,onChange:n,onClear:a,onClearQuery:r,placeholder:"Search all mail",size:"lg"}),actions:s.jsxs(s.Fragment,{children:[s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(ku,{className:"size-4"}),title:`Compose ${$t("compose")}`,"aria-label":"Compose",onClick:o}),s.jsx(bi,{}),s.jsx(th,{})]})})}const ga=({isOpen:e,onClose:t,children:n,ariaLabel:a="Navigation",side:r="left",widthClassName:o="w-[80vw] max-w-[320px]"})=>{const i=c.useRef(null),l=c.useRef(null);if(c.useEffect(()=>{if(!e)return;l.current=document.activeElement;const d=h=>{h.key==="Escape"&&(h.preventDefault(),t())};document.addEventListener("keydown",d),i.current?.querySelector("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])")?.focus();const m=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",d),document.body.style.overflow=m,l.current?.focus()}},[e,t]),!e)return null;const u=r==="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":a,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})]})]})},ah=e=>{const t=e.filter(r=>!r.isMultipart&&r.disposition!=="attachment"&&r.mediaType==="TEXT"&&r.contentUrl.length>0),n=t.find(r=>r.mediaSubtype.toUpperCase()==="HTML");if(n)return{kind:"html",contentUrl:n.contentUrl};const a=t.find(r=>r.mediaSubtype.toUpperCase()==="PLAIN");return a?{kind:"text",contentUrl:a.contentUrl}:null},Fn={all:["messages"],detail:e=>[...Fn.all,"detail",e],body:e=>[...Fn.detail(e),"body"]};class yt extends Error{reason;status;retryAfterSeconds;constructor(t,n,a,r){super(n),this.name="BodyFetchError",this.reason=t,this.status=a,this.retryAfterSeconds=r}}const rh=e=>{const t=Number.parseInt(e??"",10);return!Number.isFinite(t)||t<=0?1:Math.min(t,30)},oh=8,ih="x-remit-403-reason",lh=(e,t)=>{const n=t?.trim()??"";return e===401?"auth":e===403?n.length>0?"auth":"body-missing":e===404?"body-missing":"generic"},ch=(e,t)=>(t??"").toLowerCase().startsWith("text/html")?/<div\s+id=["']root["']/i.test(e):!1,uh=(e,t)=>{const n=(t??"").toLowerCase();return!!(e==="text"&&n.startsWith("text/html"))},dh=async(e,t,n=async()=>null)=>{const a={},r=await n();r&&(a.Authorization=`Bearer ${r}`);const o=await Ic(e,{headers:a});if(o.status===202)throw new yt("not-ready","Message body is still syncing",202,rh(o.headers.get("Retry-After")));if(!o.ok){const u=o.headers.get(ih),d=lh(o.status,u);throw new yt(d,`Failed to load message body (${o.status} ${o.statusText})`,o.status)}const i=o.headers.get("content-type");if(uh(t,i))throw new yt("content-type-mismatch",`Refusing to render message body — expected ${t}, got Content-Type ${i}`);const l=await o.text();if(ch(l,i))throw new yt("spa-shell-leak","Refusing to render message body — response looks like the SPA shell (CloudFront 403/404 fallback leaked through to /content/*)");return l},fh=async(e,t)=>(t.isRetryAfterNotReady&&await e.refetchDescribeMessage(),e.fetchContent(t.contentUrl,t.kind)),yi=({messageId:e,bodyParts:t,enabled:n=!0})=>{const a=t?ah(t):null,r=vs(),{getToken:o}=Zn(),i=c.useRef(null),l=je(),u=c.useRef(!1),d=c.useRef(null),f=e&&a?`${e}:${a.contentUrl}`:null;d.current!==f&&(d.current=f,u.current=!1);const m=ie({queryKey:e?[...Fn.body(e),a?.contentUrl??null]:["messages","body","noop"],queryFn:()=>{if(!a)throw new Error("No renderable body part");if(!e)throw new Error("No messageId");const b=u.current;return u.current=!1,fh({fetchContent:(x,y)=>dh(x,y,o),refetchDescribeMessage:()=>l.refetchQueries({queryKey:co({path:{messageId:e}})})},{contentUrl:a.contentUrl,kind:a.kind,isRetryAfterNotReady:b})},enabled:n&&!!e&&!!a,staleTime:300*1e3,gcTime:1800*1e3,retry:(b,x)=>x instanceof yt&&x.reason==="not-ready"?b<oh:b<1,retryDelay:(b,x)=>x instanceof yt&&x.reason==="not-ready"?(u.current=!0,(x.retryAfterSeconds??1)*1e3):1e3,meta:{softError:!0}}),h=m.isLoading&&!!a;c.useEffect(()=>{h&&(i.current=performance.now())},[h]),c.useEffect(()=>{m.isSuccess&&i.current!==null&&(r.recordTiming("message.body.load",Math.round(performance.now()-i.current)),i.current=null)},[m.isSuccess,r]);const p=m.data&&a?{kind:a.kind,body:m.data}:void 0;return{picked:a,data:p,isLoading:h,isError:m.isError,error:m.error,refetch:m.refetch}},mh=({outboxMessageId:e,onDraftCreated:t})=>{const[n,a]=c.useState("idle"),[r,o]=c.useState(null),i=c.useRef(void 0),l=je(),u=pe(uo()),d=pe(Rc()),f=c.useCallback(async b=>{if(a("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 a("saved"),y}const x=await u.mutateAsync({body:{...b,sendImmediately:!1}});return t(x.outboxMessageId),a("saved"),l.invalidateQueries({queryKey:en().queryKey}),x},[e,u,d,t,l]),m=c.useCallback(b=>{i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{f(b).catch(x=>{o(x),a("error")})},2e3)},[f]),h=c.useCallback(b=>(i.current&&clearTimeout(i.current),f(b)),[f]),p=c.useCallback(()=>{i.current&&clearTimeout(i.current)},[]);return{saveStatus:n,saveError:r,saveDraft:m,saveImmediately:h,cancelAutoSave:p}},wi=e=>"text"in e&&!("children"in e),ji=e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),hh=e=>{let t=ji(e.text);return e.bold&&(t=`<strong>${t}</strong>`),e.italic&&(t=`<em>${t}</em>`),t},Si=e=>{const t=e.children.map(n=>wi(n)?hh(n):Si(n)).join("");switch(e.type){case"blockquote":return`<blockquote>${t}</blockquote>`;case"a":{const n=e.url??"";return`<a href="${ji(n)}">${t}</a>`}default:return`<p>${t}</p>`}},jr=e=>e.map(Si).join(""),Ni=e=>wi(e)?e.text:e.children.map(Ni).join(""),Bn=e=>e.map(Ni).join(`
|
|
110
|
+
`),gh=e=>e.displayName?`${e.displayName} <${e.normalizedEmail}>`:e.normalizedEmail,Sr=e=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.trim()),xh=e=>{const t=e.trim();if(!t)return;const n=t.match(/^(.+?)\s*<([^>]+)>$/);if(n){const a=n[1].trim(),r=n[2].trim();if(Sr(r))return{email:r,displayName:a}}if(Sr(t))return{email:t}},Nn=({label:e,addresses:t,onChange:n,placeholder:a})=>{const[r,o]=c.useState(""),[i,l]=c.useState(-1),[u,d]=c.useState(!1),f=c.useRef(null),m=c.useRef(null),h=bo(r,200),{data:p}=ie({...fo({query:{q:h,limit:8}}),enabled:h.length>=2}),b=p?.items??[],x=new Set(t.map(S=>S.email.toLowerCase())),y=b.filter(S=>!x.has(S.normalizedEmail.toLowerCase()));c.useEffect(()=>{l(-1),d(y.length>0&&r.length>=2)},[y.length,r.length]);const g=c.useCallback(S=>{x.has(S.email.toLowerCase())||(n([...t,S]),o(""),d(!1))},[t,x,n]),v=c.useCallback(S=>{n(t.filter((E,k)=>k!==S))},[t,n]),w=c.useCallback(S=>{g({email:S.normalizedEmail,displayName:S.displayName}),f.current?.focus()},[g]),j=c.useCallback(()=>{const S=xh(r);S&&g(S)},[r,g]),C=c.useCallback(S=>{if(S.key==="Backspace"&&r===""&&t.length>0){v(t.length-1);return}if(S.key==="Enter"||S.key==="Tab"||S.key===","){if(i>=0&&y[i]){S.preventDefault(),w(y[i]);return}r.trim()&&(S.preventDefault(),j());return}if(S.key==="ArrowDown"&&u){S.preventDefault(),l(E=>E<y.length-1?E+1:0);return}if(S.key==="ArrowUp"&&u){S.preventDefault(),l(E=>E>0?E-1:y.length-1);return}S.key==="Escape"&&(d(!1),l(-1))},[r,t.length,i,y,u,v,w,j]),N=c.useCallback(()=>{setTimeout(()=>{j(),d(!1)},150)},[j]);return s.jsxs("div",{className:"relative",children:[s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("label",{htmlFor:`address-field-${e}`,className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:[e,":"]}),s.jsxs("div",{className:"flex-1 flex flex-wrap items-center gap-1 min-h-[36px] px-2 py-1 border rounded-md bg-canvas cursor-text",onClick:()=>f.current?.focus(),onKeyDown:S=>{(S.key==="Enter"||S.key===" ")&&f.current?.focus()},children:[t.map((S,E)=>s.jsx(Ru,{email:S.email,displayName:S.displayName,onRemove:()=>v(E)},S.email)),s.jsx("input",{ref:f,id:`address-field-${e}`,type:"text",value:r,onChange:S=>o(S.target.value),onKeyDown:C,onBlur:N,placeholder:t.length===0?a:"",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,E)=>s.jsx("li",{className:fe("px-3 py-2 text-sm cursor-pointer transition-colors",E===i&&"bg-accent-2-soft"),onMouseDown:k=>{k.preventDefault(),w(S)},onMouseEnter:()=>l(E),children:gh(S)},S.addressId))})]})},ph=({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(Yn,{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(hu,{className:"size-3","aria-hidden":"true"})]})]})]})},$n=e=>{const[t,n]=c.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return c.useEffect(()=>{if(typeof window>"u"||!window.matchMedia)return;const a=window.matchMedia(e),r=o=>n(o.matches);return n(a.matches),a.addEventListener("change",r),()=>a.removeEventListener("change",r)},[e]),t},Ct=()=>$n("(min-width: 1024px)"),Nr=150,bh=()=>{const[e,t]=c.useState(()=>{if(typeof window>"u"||!window.visualViewport)return{viewportHeight:0,isKeyboardOpen:!1};const n=window.visualViewport.height;return{viewportHeight:n,isKeyboardOpen:window.innerHeight-n>Nr}});return c.useEffect(()=>{if(typeof window>"u"||!window.visualViewport)return;const n=window.visualViewport,a=()=>{const r=n.height;t({viewportHeight:r,isKeyboardOpen:window.innerHeight-r>Nr})};return a(),n.addEventListener("resize",a),()=>n.removeEventListener("resize",a)},[]),e},vh=({selectedAccountId:e,onSelect:t})=>{const{data:n}=ie({...tt(),staleTime:1/0}),a=n?.accounts??[];if(c.useEffect(()=>{!e&&a.length===1&&a[0]&&t(a[0])},[e,a,t]),a.length<=1){const r=a[0];return r?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:r.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:r=>{const o=a.find(i=>i.accountId===r.target.value);o&&t(o)},className:"flex-1 px-2 py-1.5 border rounded-md bg-canvas text-sm",children:a.map(r=>s.jsx("option",{value:r.accountId,children:r.email},r.accountId))})]})},yh=({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})]}),wh=["p","br","strong","b","em","i","a","blockquote","ul","ol","li"],jh=["href"],Sh=e=>eo.sanitize(e,{ALLOWED_TAGS:wh,ALLOWED_ATTR:jh}),Nh=c.lazy(()=>Tc(()=>import("./ComposeBody-DK_5XIJT.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}))),kh=()=>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"})]}),ki=[{type:"p",children:[{text:""}]}],Ch=[{type:"p",children:[{text:""}]},{type:"p",children:[{text:"-- "}]}],Eh=e=>e?[...Ch,{type:"p",children:[{text:e}]}]:ki,Ih=e=>e?/^re:\s/i.test(e)?e:`Re: ${e}`:"Re: ",Rh=e=>e?/^fwd?:\s/i.test(e)?e:`Fwd: ${e}`:"Fwd: ",Mh=(e,t,n)=>{const{envelope:a}=e,o=(a.replyTo.length>0?a.replyTo:a.from).map(d=>({email:d.normalizedEmail,displayName:d.displayName}));if(t!=="reply_all")return{to:o,cc:[]};const i=n?.toLowerCase(),l=new Set(o.map(d=>d.email.toLowerCase())),u=[...a.to,...a.cc].filter(d=>d.normalizedEmail.toLowerCase()!==i&&!l.has(d.normalizedEmail.toLowerCase())).map(d=>({email:d.normalizedEmail,displayName:d.displayName}));return{to:o,cc:u}},Th=e=>{const t=e.envelope.messageIdValue,a=[...e.references.filter(r=>r.referenceType==="references").sort((r,o)=>r.referenceOrder-o.referenceOrder).map(r=>r.messageIdValue)];return t&&!a.includes(t)&&a.push(t),{inReplyTo:t,references:a}},Dh=(e,t,n,a,r)=>e.length===0&&t.length===0&&n.length===0&&a.trim()===""&&Bn(r).trim()==="",Ah=({selectedAccountId:e,onAccountChange:t,toAddresses:n,setToAddresses:a,ccAddresses:r,setCcAddresses:o,bccAddresses:i,setBccAddresses:l,showCc:u,setShowCc:d,showBcc:f,setShowBcc:m,subject:h,setSubject:p})=>{const b=Ct(),{isKeyboardOpen:x}=bh();if(!b&&x){const g=[];return n.length>0&&g.push(`To: ${n.map(v=>v.displayName??v.email).join(", ")}`),r.length>0&&g.push(`Cc: ${r.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(vh,{selectedAccountId:e,onSelect:t}),s.jsx(Nn,{label:"To",addresses:n,onChange:a,placeholder:"Recipients"}),u?s.jsx(Nn,{label:"Cc",addresses:r,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(Nn,{label:"Bcc",addresses:i,onChange:l}),s.jsx(yh,{value:h,onChange:p})]})},xa=({mode:e,account:t,sourceMessage:n,onClose:a,onAccountChange:r})=>{const{state:o,setOutboxMessageId:i,startSendPolling:l}=dt(),{pushError:u}=ze(),{outboxMessageId:d}=o,[f,m]=c.useState([]),[h,p]=c.useState([]),[b,x]=c.useState([]),[y,g]=c.useState(""),[v,w]=c.useState(!1),[j,C]=c.useState(!1),[N,S]=c.useState(t?.accountId),[E,k]=c.useState(!1),M=c.useRef(d);c.useEffect(()=>{M.current!==d&&(M.current=d,d&&(m([]),p([]),x([]),g(""),w(!1),C(!1),I(ki),k(!1)))},[d]);const{signature:T}=iu(N),[D,I]=c.useState(()=>Eh(T.plainText)),{data:R}=ie({...Mc({path:{outboxMessageId:d??""}}),enabled:!!d&&!E});c.useEffect(()=>{!R||E||(m(R.toAddresses.map(W=>({email:W,displayName:void 0}))),R.ccAddresses&&R.ccAddresses.length>0&&(p(R.ccAddresses.map(W=>({email:W,displayName:void 0}))),w(!0)),R.bccAddresses&&R.bccAddresses.length>0&&(x(R.bccAddresses.map(W=>({email:W,displayName:void 0}))),C(!0)),R.subject&&g(R.subject),R.textBody&&I([{type:"p",children:[{text:R.textBody}]}]),S(R.accountId),k(!0))},[R,E]),c.useEffect(()=>{if(n){if(e==="reply"||e==="reply_all"){const{to:W,cc:ee}=Mh(n,e,t?.email);m(W),p(ee),ee.length>0&&w(!0),g(Ih(n.envelope.subject))}e==="forward"&&g(Rh(n.envelope.subject))}},[e,n,t?.email]);const O=e==="reply"||e==="reply_all"||e==="forward",{data:B}=yi({messageId:n?.message.messageId,bodyParts:n?.bodyParts,enabled:O&&!!n}),$=B?.kind==="text"?B.body:"",q=B?.kind==="html"?Sh(B.body):void 0,_=n?.envelope.from[0]?.displayName??n?.envelope.from[0]?.normalizedEmail,{saveStatus:U,saveError:te,saveDraft:J,cancelAutoSave:P}=mh({outboxMessageId:d,onDraftCreated:i});c.useEffect(()=>{te&&u({title:"Couldn't save draft",detail:Ke(te)??"Saving the draft failed.",error:te})},[te,u]);const A=pe(uo()),Q=pe(mo()),le=pe({...tn(),onError:W=>{u(gs("Couldn't discard draft","The draft wasn't discarded.",W))}}),{data:ve}=ie({...tt(),staleTime:1/0}),ce=ve?.accounts.find(W=>W.accountId===N),ye=ce?su(ce):!1,Se=A.isPending||Q.isPending,Y=f.length>0&&!!N&&!ye;c.useEffect(()=>{if(!N||d&&!E||Dh(f,h,b,y,D))return;const W=Bn(D),ee=jr(D);J({accountId:N,toAddresses:f.map(ne=>ne.email),ccAddresses:h.length>0?h.map(ne=>ne.email):void 0,bccAddresses:b.length>0?b.map(ne=>ne.email):void 0,subject:y||void 0,textBody:W||void 0,htmlBody:ee||void 0})},[N,d,E,f,h,b,y,D,J]);const ge=c.useCallback(async()=>{if(!N||f.length===0)return;P();const W=n&&(e==="reply"||e==="reply_all")?Th(n):{};let ee=d,ne=!1;if(!ee){const re=Bn(D),Ne=jr(D),Fe=await A.mutateAsync({body:{accountId:N,toAddresses:f.map(Re=>Re.email),ccAddresses:h.length>0?h.map(Re=>Re.email):void 0,bccAddresses:b.length>0?b.map(Re=>Re.email):void 0,subject:y||void 0,textBody:re||void 0,htmlBody:Ne||void 0,sendImmediately:!0,...W}}).catch(Re=>(u({title:"Couldn't send message",detail:Ke(Re)??"Saving the draft failed.",error:Re}),null));if(Fe===null)return;ee=Fe.outboxMessageId,ne=!0,i(ee)}await Q.mutateAsync({path:{outboxMessageId:ee}}).catch(re=>(u({title:"Couldn't send message",detail:Ke(re)??(ne?"The draft was saved but the send request failed. Try again from the Outbox.":"The send request failed. Try again."),error:re}),null))!==null&&(l(ee),a())},[N,f,h,b,y,D,e,n,d,A,Q,P,l,i,u,a]),Ie=c.useCallback(()=>{P(),d&&le.mutate({path:{outboxMessageId:d}}),a()},[P,d,le,a]),H=c.useCallback(W=>{S(W.accountId),r?.(W)},[r]);return s.jsx(Pd,{banner:ce&&ye?s.jsx(ph,{accountId:ce.accountId}):void 0,header:s.jsx(Ah,{selectedAccountId:N,onAccountChange:H,toAddresses:f,setToAddresses:m,ccAddresses:h,setCcAddresses:p,bccAddresses:b,setBccAddresses:x,showCc:v,setShowCc:w,showBcc:j,setShowBcc:C,subject:y,setSubject:g}),quoted:$||q?s.jsx(ef,{text:$,html:q,senderName:_}):void 0,actionBar:s.jsx(Od,{onSend:ge,onDiscard:Ie,sending:Se,canSend:Y,saveStatus:U,unavailableReason:ye?"SMTP not configured":void 0,onUnavailable:W=>u({title:"Can't send yet",detail:W})}),children:s.jsx(c.Suspense,{fallback:s.jsx(kh,{}),children:s.jsx(Nh,{value:D,onChange:I,onSubmit:ge,autoFocus:e==="new"})})})},kr=({mode:e,account:t,sourceMessage:n,onClose:a})=>s.jsx("div",{className:"border-t border-line bg-canvas max-h-[400px] flex flex-col",children:s.jsx(xa,{mode:e,account:t,sourceMessage:n,onClose:a})}),Ci=({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})]}),bs=({enabled:e=!0,bindings:t,capture:n=!1})=>{const a=c.useCallback(r=>{const o=r.target;if(!(o.tagName==="INPUT"||o.tagName==="TEXTAREA"||o.isContentEditable))for(const i of t){if(!(r.key.toLowerCase()===i.key.toLowerCase())||i.requireShift!==void 0&&i.requireShift!==r.shiftKey)continue;const u=r.ctrlKey||r.metaKey;if(i.requireMeta!==void 0){if(i.requireMeta!==u)continue}else{const d=i.noModifiers??!0,f=u||r.altKey||i.requireShift===void 0&&r.shiftKey;if(d&&f)continue}i.preventDefault&&r.preventDefault(),i.stopPropagation&&(r.stopPropagation(),r.stopImmediatePropagation()),i.handler(r);return}},[t]);c.useEffect(()=>{if(e)return window.addEventListener("keydown",a,n),()=>window.removeEventListener("keydown",a,n)},[e,a,n])},Ei=e=>{const{data:t,isLoading:n}=ie({...tt(),staleTime:1/0}),a=c.useMemo(()=>(t?.accounts??[]).map(l=>l.accountId),[t?.accounts]),r=kt({queries:a.map(l=>({...He({path:{accountId:l}}),staleTime:1/0,enabled:!!e}))}),o=n||r.some(l=>l.isLoading);return{accountId:c.useMemo(()=>{if(e){for(let l=0;l<a.length;l++)if((r[l].data?.items??[]).some(f=>f.mailboxId===e))return a[l]}},[e,a,r]),isLoading:o}},Oh=e=>typeof e=="object"&&e!==null&&Array.isArray(e.pages),Ph=e=>typeof e=="object"&&e!==null&&Array.isArray(e.items),Yt=(e,t)=>e===void 0?e:Oh(e)?{...e,pages:e.pages.map(n=>({...n,items:t(n.items)}))}:Ph(e)?{...e,items:t(e.items)}:e,Lh=(e,t,n)=>{const a=new Map(t.map(o=>[o.messageId,o.mailboxId])),r=new Set;for(const o of e)r.add(a.get(o)??n);return[...r]},Cr=(e,t,n)=>e.map(a=>t.has(a.messageId)?{...a,isRead:n}:a),zh=(e,t,n,a)=>e.filter(r=>!r.isRead&&t.has(r.threadMessageId)&&!n.has(r.messageId)&&!a.has(r.messageId)).map(r=>r.messageId),_h=({messages:e,expandedIds:t,threadId:n,mailboxId:a,accountId:r})=>{const o=je(),{pushError:i}=ze(),l=c.useRef(new Set),u=c.useRef(new Set),{mutate:d}=pe({...sn(),onMutate:async h=>{const p=new Set(h.body.messageIds??[]),b=h.body.isRead??!0,x=jt({path:{threadId:n}}),y=Lh(p,e,a),g=y.map(N=>st({path:{mailboxId:N}})),v=y.map(N=>ft({path:{mailboxId:N}}));await Promise.all([o.cancelQueries({queryKey:x}),...g.map(N=>o.cancelQueries({queryKey:N})),...v.map(N=>o.cancelQueries({queryKey:N}))]);const w=o.getQueriesData({queryKey:x}).filter(N=>N[1]!==void 0).map(([N,S])=>({queryKey:N,data:S})),j=[...g,...v].flatMap(N=>o.getQueriesData({queryKey:N})).filter(N=>N[1]!==void 0).map(([N,S])=>({queryKey:N,data:S}));o.setQueriesData({queryKey:x},N=>N&&{...N,items:Cr(N.items,p,b)});const C=N=>Yt(N,S=>Cr(S,p,b));for(const N of[...g,...v])o.setQueriesData({queryKey:N},C);return{threadMessagesPrefix:x,threadsListPrefixes:g,threadsSearchPrefixes:v,previousThreadMessages:w,previousThreadsList:j}},onSuccess:(h,p)=>{const b=p.body.messageIds??[];for(const x of b)l.current.add(x),u.current.delete(x)},onError:(h,p,b)=>{const x=p.body.messageIds??[];for(const g of x)u.current.delete(g);if(b){for(const g of b.previousThreadMessages)o.setQueryData(g.queryKey,g.data);for(const g of b.previousThreadsList)o.setQueryData(g.queryKey,g.data)}const y=p.body.isRead??!0;i({title:y?"Couldn't mark as read":"Couldn't mark as unread",detail:Ke(h),error:h})},onSettled:(h,p,b,x)=>{if(x){o.invalidateQueries({queryKey:x.threadMessagesPrefix});for(const y of[...x.threadsListPrefixes,...x.threadsSearchPrefixes])o.invalidateQueries({queryKey:y});r&&o.invalidateQueries({queryKey:Xt({path:{accountId:r}})})}}}),f=c.useCallback(h=>{const p=h.filter(b=>!l.current.has(b)&&!u.current.has(b));if(p.length!==0){for(const b of p)u.current.add(b);d({body:{messageIds:p,isRead:!0}})}},[d]),m=c.useMemo(()=>zh(e,t,l.current,u.current),[e,t]);c.useEffect(()=>{m.length!==0&&f(m)},[m,f]),c.useEffect(()=>{l.current.clear(),u.current.clear()},[n])},Ii=e=>{const{mailboxId:t,accountId:n}=e,a=je(),{pushError:r}=ze(),{mutate:o,isPending:i}=pe({...sn(),onError:(u,d)=>{const f=d.body.isRead??!0;r({title:f?"Couldn't mark as read":"Couldn't mark as unread",detail:Ke(u),error:u})},onSettled:()=>{a.invalidateQueries({queryKey:st({path:{mailboxId:t}})}),a.invalidateQueries({queryKey:ft({path:{mailboxId:t}})}),n&&a.invalidateQueries({queryKey:Xt({path:{accountId:n}})})}});return{toggleReadFor:c.useCallback((u,d)=>{u.length!==0&&o({body:{messageIds:u,isRead:d}})},[o]),isPending:i}},Fh=60,Bh=1.5,$h=(e,t,n)=>{const a=Math.abs(e),r=Math.abs(t);return a<n?{direction:null}:a<r*Bh?{direction:null}:{direction:e<0?"left":"right"}},Kh=({onSwipeLeft:e,onSwipeRight:t,thresholdPx:n=Fh})=>{const a=c.useRef(null),r=c.useCallback(u=>{if(u.pointerType==="mouse"){a.current=null;return}a.current={x:u.clientX,y:u.clientY}},[]),o=c.useCallback(()=>{},[]),i=c.useCallback(u=>{const d=a.current;if(a.current=null,!d)return;const{direction:f}=$h(u.clientX-d.x,u.clientY-d.y,n);f==="left"&&e?.(),f==="right"&&t?.()},[e,t,n]),l=c.useCallback(()=>{a.current=null},[]);return{handlers:{onPointerDown:r,onPointerMove:o,onPointerUp:i,onPointerCancel:l}}},qh=(e,t,n)=>t?.find(a=>a.messageId===e)?.mailboxId??n,Er=(e,t,n)=>e.map(a=>a.messageId===t?{...a,hasStars:n}:a),Kn=({threadId:e,mailboxId:t,messages:n})=>{const a=je(),{pushError:r}=ze(),{mutate:o,isPending:i,variables:l}=pe({...Dc(),onMutate:async d=>{const f=d.path.messageId,m=d.body.isStarred??!1,h=jt({path:{threadId:e}}),p=qh(f,n,t),b=st({path:{mailboxId:p}}),x=ft({path:{mailboxId:p}}),y=ho();await Promise.all([a.cancelQueries({queryKey:h}),a.cancelQueries({queryKey:b}),a.cancelQueries({queryKey:x}),a.cancelQueries({queryKey:y})]);const g=a.getQueriesData({queryKey:h}).filter(N=>N[1]!==void 0).map(([N,S])=>({queryKey:N,data:S})),v=a.getQueriesData({queryKey:b}).concat(a.getQueriesData({queryKey:x})).filter(N=>N[1]!==void 0).map(([N,S])=>({queryKey:N,data:S})),w=a.getQueriesData({queryKey:y}).filter(N=>N[1]!==void 0).map(([N,S])=>({queryKey:N,data:S})),j=N=>Yt(N,S=>Er(S,f,m));a.setQueriesData({queryKey:h},j),a.setQueriesData({queryKey:y},j);const C=N=>Yt(N,S=>Er(S,f,m));return a.setQueriesData({queryKey:b},C),a.setQueriesData({queryKey:x},C),{threadMessagesPrefix:h,threadsListPrefix:b,threadsSearchPrefix:x,unifiedThreadsPrefix:y,previousThreadMessages:g,previousThreadsList:v,previousUnifiedThreads:w}},onError:(d,f,m)=>{if(m){for(const p of m.previousThreadMessages)a.setQueryData(p.queryKey,p.data);for(const p of m.previousThreadsList)a.setQueryData(p.queryKey,p.data);for(const p of m.previousUnifiedThreads)a.setQueryData(p.queryKey,p.data)}const h=f.body.isStarred??!1;r({title:h?"Couldn't star message":"Couldn't unstar message",detail:Ke(d),error:d})},onSettled:(d,f,m,h)=>{h&&(a.invalidateQueries({queryKey:h.threadMessagesPrefix}),a.invalidateQueries({queryKey:h.threadsListPrefix}),a.invalidateQueries({queryKey:h.threadsSearchPrefix}),a.invalidateQueries({queryKey:h.unifiedThreadsPrefix}))}});return{toggleStar:(d,f)=>{o({path:{messageId:d},body:{isStarred:!f}})},isPending:i,pendingMessageId:i?l?.path.messageId:void 0}};function un(e){return e===void 0?"uncategorized":e}const $e={uncategorized:"uncategorized",personal:"personal",newsletter:"newsletter",marketing:"marketing",automated:"automated",transactional:"transactional",social:"social"},Ir={MoveToInbox:"MoveToInbox",MoveToJunk:"MoveToJunk"},Uh={inbox:"Inbox",junk:"Junk"},Hh=e=>`Moved from ${Uh[e]??"another folder"} by Remit`,Qh=(e,t)=>{if(e===Ir.MoveToInbox)return t.inboxMailboxId;if(e===Ir.MoveToJunk)return t.junkMailboxId},Wh=(e,t,n)=>{if(!e||!t)return!1;const a=Qh(e.action,n);return a!==void 0&&a===t},Vh=(e,t)=>{if(e==="inbox")return t.inboxMailboxId;if(e==="junk")return t.junkMailboxId},dn=(e,t)=>{const{data:n,isLoading:a}=ie({...tt(),staleTime:1/0,enabled:!!e});return{mailboxId:c.useMemo(()=>e?n?.accounts.find(i=>i.accountId===e)?.folderAppointments.find(i=>i.role===t)?.mailboxId:void 0,[n,e,t]),isLoading:a}},Yh=e=>{const{mailboxId:t,isLoading:n}=dn(e,"Archive");return{archiveMailboxId:t,isLoading:n}},Gh=e=>{const{mailboxId:t,isLoading:n}=dn(e,"Drafts");return{draftsMailboxId:t,isLoading:n}},pa=e=>{const{mailboxId:t,isLoading:n}=dn(e,"Inbox");return{inboxMailboxId:t,isLoading:n}},ba=e=>{const{mailboxId:t,isLoading:n}=dn(e,"Junk");return{junkMailboxId:t,isLoading:n}},Ri=e=>{const{data:t}=ie({...tt(),staleTime:1/0,enabled:!!e});return c.useMemo(()=>t?.accounts.find(n=>n.accountId===e)?.folderAppointments??[],[t,e])},Rr=(e,t)=>e.filter(n=>!t.has(n.messageId)),ct=({mailboxId:e,threadId:t,accountId:n,onAfterOptimisticRemove:a})=>{const r=je(),{pushError:o}=ze(),{mutate:i,isPending:l}=pe({...Ac(),onMutate:async d=>{const f=new Set(d.body.messageIds??[]),m=t?jt({path:{threadId:t}}):[],h=st({path:{mailboxId:e}}),p=ft({path:{mailboxId:e}});await Promise.all([...t?[r.cancelQueries({queryKey:m})]:[],r.cancelQueries({queryKey:h}),r.cancelQueries({queryKey:p})]);const b=t?r.getQueriesData({queryKey:m}).filter(g=>g[1]!==void 0).map(([g,v])=>({queryKey:g,data:v})):[],x=r.getQueriesData({queryKey:h}).concat(r.getQueriesData({queryKey:p})).filter(g=>g[1]!==void 0).map(([g,v])=>({queryKey:g,data:v}));t&&r.setQueriesData({queryKey:m},g=>g&&{...g,items:Rr(g.items,f)});const y=g=>Yt(g,v=>Rr(v,f));return r.setQueriesData({queryKey:h},y),r.setQueriesData({queryKey:p},y),a?.(Array.from(f)),{threadMessagesPrefix:m,threadsListPrefix:h,threadsSearchPrefix:p,previousThreadMessages:b,previousThreadsList:x}},onError:(d,f,m)=>{if(m){for(const p of m.previousThreadMessages)r.setQueryData(p.queryKey,p.data);for(const p of m.previousThreadsList)r.setQueryData(p.queryKey,p.data)}const h=f.body.messageIds?.length??0;o({title:h>1?`Couldn't move ${h} messages`:"Couldn't move this message",detail:Ke(d),error:d})},onSettled:(d,f,m,h)=>{h&&(t&&r.invalidateQueries({queryKey:h.threadMessagesPrefix}),r.invalidateQueries({queryKey:h.threadsListPrefix}),r.invalidateQueries({queryKey:h.threadsSearchPrefix}),n&&r.invalidateQueries({queryKey:Xt({path:{accountId:n}})}))}});return{moveMessages:c.useCallback((d,f)=>{d.length!==0&&i({body:{messageIds:d,destinationMailboxId:f}})},[i]),isPending:l}},Xh=({accountId:e,messageId:t,threadId:n,mailboxId:a,autoMoved:r})=>{const{inboxMailboxId:o}=pa(e),{junkMailboxId:i}=ba(e),{moveMessages:l,isPending:u}=ct({mailboxId:a,threadId:n,accountId:e}),d={inboxMailboxId:o,junkMailboxId:i},f=Wh(r,a,d),m=r?Vh(r.fromPlacement,d):void 0,h=c.useCallback(()=>{m&&l([t],m)},[l,t,m]);return!f||!r?{show:!1,label:"",isUndoing:!1}:{show:!0,label:Hh(r.fromPlacement),onUndo:m?h:void 0,isUndoing:u}};function Mi({accountId:e,messageId:t,threadId:n,mailboxId:a,autoMoved:r,size:o="sm"}){const i=Xh({accountId:e,messageId:t,threadId:n,mailboxId:a,autoMoved:r});return i.show?s.jsx(Nd,{label:i.label,size:o,onUndo:i.onUndo,undoLabel:i.isUndoing?"Undoing…":"Undo"}):null}const Mr=(e,t)=>e.filter(n=>!t.has(n.messageId)),Jh=e=>e.filter(t=>t.isDeleted!==!0),hs=({mailboxId:e,threadId:t,accountId:n,onAfterOptimisticRemove:a})=>{const r=je(),{pushError:o}=ze(),{mutate:i,isPending:l}=pe({...Oc(),onMutate:async d=>{const f=new Set(d.body.messageIds??[]),m=t?jt({path:{threadId:t}}):[],h=st({path:{mailboxId:e}}),p=ft({path:{mailboxId:e}});await Promise.all([r.cancelQueries({queryKey:m}),r.cancelQueries({queryKey:h}),r.cancelQueries({queryKey:p})]);const b=t?r.getQueriesData({queryKey:m}).filter(g=>g[1]!==void 0).map(([g,v])=>({queryKey:g,data:v})):[],x=r.getQueriesData({queryKey:h}).concat(r.getQueriesData({queryKey:p})).filter(g=>g[1]!==void 0).map(([g,v])=>({queryKey:g,data:v}));t&&r.setQueriesData({queryKey:m},g=>g&&{...g,items:Mr(g.items,f)});const y=g=>Yt(g,v=>Mr(v,f));return r.setQueriesData({queryKey:h},y),r.setQueriesData({queryKey:p},y),a?.(Array.from(f)),{threadMessagesPrefix:m,threadsListPrefix:h,threadsSearchPrefix:p,previousThreadMessages:b,previousThreadsList:x}},onError:(d,f,m)=>{if(m){for(const p of m.previousThreadMessages)r.setQueryData(p.queryKey,p.data);for(const p of m.previousThreadsList)r.setQueryData(p.queryKey,p.data)}const h=f.body.messageIds?.length??0;o({title:h>1?`Couldn't delete ${h} messages`:"Couldn't delete this message",detail:Ke(d),error:d})},onSettled:(d,f,m,h)=>{h&&(t&&r.invalidateQueries({queryKey:h.threadMessagesPrefix}),r.invalidateQueries({queryKey:h.threadsListPrefix}),r.invalidateQueries({queryKey:h.threadsSearchPrefix}),n&&r.invalidateQueries({queryKey:Xt({path:{accountId:n}})}))}});return{deleteMessages:c.useCallback(d=>{d.length!==0&&i({body:{messageIds:d}})},[i]),isPending:l}},Ti=(e,t=Date.now())=>({value:e,setAt:t}),Zh=(e,t,n,a)=>{if(e.addressId!==t)return e;const r={...e.flags??{}};return n?r.trusted=Ti(!0,a):delete r.trusted,{...e,flags:r}},eg=(e,t,n,a)=>{const r=o=>o.map(i=>Zh(i,t,n,a));return{...e,envelope:{...e.envelope,from:r(e.envelope.from),to:r(e.envelope.to),cc:r(e.envelope.cc),bcc:r(e.envelope.bcc),replyTo:r(e.envelope.replyTo)}}},va=({messageId:e})=>{const t=je(),{pushError:n}=ze(),{mutate:a,isPending:r,error:o,reset:i}=pe({...go(),onMutate:async u=>{const d=u.path.addressId,m=u.body.flags?.trusted?.value===!0,h=co({path:{messageId:e}});await t.cancelQueries({queryKey:h});const p=t.getQueriesData({queryKey:h}).filter(b=>b[1]!==void 0).map(([b,x])=>({queryKey:b,data:x}));return t.setQueriesData({queryKey:h},b=>b&&eg(b,d,m)),{describePrefix:h,previous:p}},onError:(u,d,f)=>{if(f)for(const m of f.previous)t.setQueryData(m.queryKey,m.data);n(gs("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)=>{a({path:{addressId:u},body:{flags:{trusted:Ti(!d)}}})},isPending:r,error:o,reset:i}};var fn="Dialog",[Di]=yf(fn),[tg,_e]=Di(fn),Ai=e=>{const{__scopeDialog:t,children:n,open:a,defaultOpen:r,onOpenChange:o,modal:i=!0}=e,l=c.useRef(null),u=c.useRef(null),[d,f]=Sf({prop:a,defaultProp:r??!1,onChange:o,caller:fn});return s.jsx(tg,{scope:t,triggerRef:l,contentRef:u,contentId:vn(),titleId:vn(),descriptionId:vn(),open:d,onOpenChange:f,onOpenToggle:c.useCallback(()=>f(m=>!m),[f]),modal:i,children:n})};Ai.displayName=fn;var Oi="DialogTrigger",sg=c.forwardRef((e,t)=>{const{__scopeDialog:n,...a}=e,r=_e(Oi,n),o=Nt(t,r.triggerRef);return s.jsx(nt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":r.open,"aria-controls":r.open?r.contentId:void 0,"data-state":wa(r.open),...a,ref:o,onClick:lt(e.onClick,r.onOpenToggle)})});sg.displayName=Oi;var ya="DialogPortal",[ng,Pi]=Di(ya,{forceMount:void 0}),Li=e=>{const{__scopeDialog:t,forceMount:n,children:a,container:r}=e,o=_e(ya,t);return s.jsx(ng,{scope:t,forceMount:n,children:c.Children.map(a,i=>s.jsx(on,{present:n||o.open,children:s.jsx(ri,{asChild:!0,container:r,children:i})}))})};Li.displayName=ya;var Xs="DialogOverlay",zi=c.forwardRef((e,t)=>{const n=Pi(Xs,e.__scopeDialog),{forceMount:a=n.forceMount,...r}=e,o=_e(Xs,e.__scopeDialog);return o.modal?s.jsx(on,{present:a||o.open,children:s.jsx(rg,{...r,ref:t})}):null});zi.displayName=Xs;var ag=ma("DialogOverlay.RemoveScroll"),rg=c.forwardRef((e,t)=>{const{__scopeDialog:n,...a}=e,r=_e(Xs,n),o=Kf(),i=Nt(t,o);return s.jsx(mi,{as:ag,allowPinchZoom:!0,shards:[r.contentRef],children:s.jsx(nt.div,{"data-state":wa(r.open),...a,ref:i,style:{pointerEvents:"auto",...a.style}})})}),Gt="DialogContent",_i=c.forwardRef((e,t)=>{const n=Pi(Gt,e.__scopeDialog),{forceMount:a=n.forceMount,...r}=e,o=_e(Gt,e.__scopeDialog);return s.jsx(on,{present:a||o.open,children:o.modal?s.jsx(og,{...r,ref:t}):s.jsx(ig,{...r,ref:t})})});_i.displayName=Gt;var og=c.forwardRef((e,t)=>{const n=_e(Gt,e.__scopeDialog),a=c.useRef(null),r=Nt(t,n.contentRef,a);return c.useEffect(()=>{const o=a.current;if(o)return um(o)},[]),s.jsx(Fi,{...e,ref:r,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,l=i.button===0&&i.ctrlKey===!0;(i.button===2||l)&&o.preventDefault()}),onFocusOutside:lt(e.onFocusOutside,o=>o.preventDefault())})}),ig=c.forwardRef((e,t)=>{const n=_e(Gt,e.__scopeDialog),a=c.useRef(!1),r=c.useRef(!1);return s.jsx(Fi,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{e.onCloseAutoFocus?.(o),o.defaultPrevented||(a.current||n.triggerRef.current?.focus(),o.preventDefault()),a.current=!1,r.current=!1},onInteractOutside:o=>{e.onInteractOutside?.(o),o.defaultPrevented||(a.current=!0,o.detail.originalEvent.type==="pointerdown"&&(r.current=!0));const i=o.target;n.triggerRef.current?.contains(i)&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&r.current&&o.preventDefault()}})}),Fi=c.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:a,onOpenAutoFocus:r,onCloseAutoFocus:o,...i}=e,l=_e(Gt,n);return Qf(),s.jsx(s.Fragment,{children:s.jsx(ni,{asChild:!0,loop:!0,trapped:a,onMountAutoFocus:r,onUnmountAutoFocus:o,children:s.jsx(ti,{role:"dialog",id:l.contentId,"aria-describedby":l.descriptionId,"aria-labelledby":l.titleId,"data-state":wa(l.open),...i,ref:t,deferPointerDownOutside:!0,onDismiss:()=>l.onOpenChange(!1)})})})}),Bi="DialogTitle",$i=c.forwardRef((e,t)=>{const{__scopeDialog:n,...a}=e,r=_e(Bi,n);return s.jsx(nt.h2,{id:r.titleId,...a,ref:t})});$i.displayName=Bi;var Ki="DialogDescription",lg=c.forwardRef((e,t)=>{const{__scopeDialog:n,...a}=e,r=_e(Ki,n);return s.jsx(nt.p,{id:r.descriptionId,...a,ref:t})});lg.displayName=Ki;var qi="DialogClose",cg=c.forwardRef((e,t)=>{const{__scopeDialog:n,...a}=e,r=_e(qi,n);return s.jsx(nt.button,{type:"button",...a,ref:t,onClick:lt(e.onClick,()=>r.onOpenChange(!1))})});cg.displayName=qi;function wa(e){return e?"open":"closed"}function ug(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 Ui=F.createContext({drawerRef:{current:null},overlayRef:{current:null},onPress:()=>{},onRelease:()=>{},onDrag:()=>{},onNestedDrag:()=>{},onNestedOpenChange:()=>{},onNestedRelease:()=>{},openProp:void 0,dismissible:!1,isOpen:!1,isDragging:!1,keyboardIsOpen:{current:!1},snapPointsOffset:null,snapPoints:null,handleOnly:!1,modal:!1,shouldFade:!1,activeSnapPoint:null,onOpenChange:()=>{},setActiveSnapPoint:()=>{},closeDrawer:()=>{},direction:"bottom",shouldAnimate:{current:!0},shouldScaleBackground:!1,setBackgroundColorOnScale:!0,noBodyStyles:!1,container:null,autoFocus:!1}),Cs=()=>{const e=F.useContext(Ui);if(!e)throw new Error("useDrawerContext must be used within a Drawer.Root");return e};ug(`[data-vaul-drawer]{touch-action:none;will-change:transform;transition:transform .5s cubic-bezier(.32, .72, 0, 1);animation-duration:.5s;animation-timing-function:cubic-bezier(0.32,0.72,0,1)}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=bottom][data-state=open]{animation-name:slideFromBottom}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=bottom][data-state=closed]{animation-name:slideToBottom}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=top][data-state=open]{animation-name:slideFromTop}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=top][data-state=closed]{animation-name:slideToTop}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=left][data-state=open]{animation-name:slideFromLeft}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=left][data-state=closed]{animation-name:slideToLeft}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=right][data-state=open]{animation-name:slideFromRight}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=right][data-state=closed]{animation-name:slideToRight}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=bottom]{transform:translate3d(0,var(--initial-transform,100%),0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=top]{transform:translate3d(0,calc(var(--initial-transform,100%) * -1),0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=left]{transform:translate3d(calc(var(--initial-transform,100%) * -1),0,0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=right]{transform:translate3d(var(--initial-transform,100%),0,0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=top]{transform:translate3d(0,var(--snap-point-height,0),0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=bottom]{transform:translate3d(0,var(--snap-point-height,0),0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=left]{transform:translate3d(var(--snap-point-height,0),0,0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=right]{transform:translate3d(var(--snap-point-height,0),0,0)}[data-vaul-overlay][data-vaul-snap-points=false]{animation-duration:.5s;animation-timing-function:cubic-bezier(0.32,0.72,0,1)}[data-vaul-overlay][data-vaul-snap-points=false][data-state=open]{animation-name:fadeIn}[data-vaul-overlay][data-state=closed]{animation-name:fadeOut}[data-vaul-animate=false]{animation:none!important}[data-vaul-overlay][data-vaul-snap-points=true]{opacity:0;transition:opacity .5s cubic-bezier(.32, .72, 0, 1)}[data-vaul-overlay][data-vaul-snap-points=true]{opacity:1}[data-vaul-drawer]:not([data-vaul-custom-container=true])::after{content:'';position:absolute;background:inherit;background-color:inherit}[data-vaul-drawer][data-vaul-drawer-direction=top]::after{top:initial;bottom:100%;left:0;right:0;height:200%}[data-vaul-drawer][data-vaul-drawer-direction=bottom]::after{top:100%;bottom:initial;left:0;right:0;height:200%}[data-vaul-drawer][data-vaul-drawer-direction=left]::after{left:initial;right:100%;top:0;bottom:0;width:200%}[data-vaul-drawer][data-vaul-drawer-direction=right]::after{left:100%;right:initial;top:0;bottom:0;width:200%}[data-vaul-overlay][data-vaul-snap-points=true]:not([data-vaul-snap-points-overlay=true]):not(
|
|
111
|
+
[data-state=closed]
|
|
112
|
+
){opacity:0}[data-vaul-overlay][data-vaul-snap-points-overlay=true]{opacity:1}[data-vaul-handle]{display:block;position:relative;opacity:.7;background:#e2e2e4;margin-left:auto;margin-right:auto;height:5px;width:32px;border-radius:1rem;touch-action:pan-y}[data-vaul-handle]:active,[data-vaul-handle]:hover{opacity:1}[data-vaul-handle-hitarea]{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);width:max(100%,2.75rem);height:max(100%,2.75rem);touch-action:inherit}@media (hover:hover) and (pointer:fine){[data-vaul-drawer]{user-select:none}}@media (pointer:fine){[data-vaul-handle-hitarea]:{width:100%;height:100%}}@keyframes fadeIn{from{opacity:0}to{opacity:1}}@keyframes fadeOut{to{opacity:0}}@keyframes slideFromBottom{from{transform:translate3d(0,var(--initial-transform,100%),0)}to{transform:translate3d(0,0,0)}}@keyframes slideToBottom{to{transform:translate3d(0,var(--initial-transform,100%),0)}}@keyframes slideFromTop{from{transform:translate3d(0,calc(var(--initial-transform,100%) * -1),0)}to{transform:translate3d(0,0,0)}}@keyframes slideToTop{to{transform:translate3d(0,calc(var(--initial-transform,100%) * -1),0)}}@keyframes slideFromLeft{from{transform:translate3d(calc(var(--initial-transform,100%) * -1),0,0)}to{transform:translate3d(0,0,0)}}@keyframes slideToLeft{to{transform:translate3d(calc(var(--initial-transform,100%) * -1),0,0)}}@keyframes slideFromRight{from{transform:translate3d(var(--initial-transform,100%),0,0)}to{transform:translate3d(0,0,0)}}@keyframes slideToRight{to{transform:translate3d(var(--initial-transform,100%),0,0)}}`);function dg(){const e=navigator.userAgent;return typeof window<"u"&&(/Firefox/.test(e)&&/Mobile/.test(e)||/FxiOS/.test(e))}function fg(){return ja(/^Mac/)}function mg(){return ja(/^iPhone/)}function Tr(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function hg(){return ja(/^iPad/)||fg()&&navigator.maxTouchPoints>1}function Hi(){return mg()||hg()}function ja(e){return typeof window<"u"&&window.navigator!=null?e.test(window.navigator.platform):void 0}const gg=24,xg=typeof window<"u"?c.useLayoutEffect:c.useEffect;function Dr(...e){return(...t)=>{for(let n of e)typeof n=="function"&&n(...t)}}const kn=typeof document<"u"&&window.visualViewport;function Ar(e){let t=window.getComputedStyle(e);return/(auto|scroll)/.test(t.overflow+t.overflowX+t.overflowY)}function Qi(e){for(Ar(e)&&(e=e.parentElement);e&&!Ar(e);)e=e.parentElement;return e||document.scrollingElement||document.documentElement}const pg=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);let Fs=0,Cn;function bg(e={}){let{isDisabled:t}=e;xg(()=>{if(!t)return Fs++,Fs===1&&Hi()&&(Cn=vg()),()=>{Fs--,Fs===0&&Cn?.()}},[t])}function vg(){let e,t=0,n=m=>{e=Qi(m.target),!(e===document.documentElement&&e===document.body)&&(t=m.changedTouches[0].pageY)},a=m=>{if(!e||e===document.documentElement||e===document.body){m.preventDefault();return}let h=m.changedTouches[0].pageY,p=e.scrollTop,b=e.scrollHeight-e.clientHeight;b!==0&&((p<=0&&h>t||p>=b&&h<t)&&m.preventDefault(),t=h)},r=m=>{let h=m.target;qn(h)&&h!==document.activeElement&&(m.preventDefault(),h.style.transform="translateY(-2000px)",h.focus(),requestAnimationFrame(()=>{h.style.transform=""}))},o=m=>{let h=m.target;qn(h)&&(h.style.transform="translateY(-2000px)",requestAnimationFrame(()=>{h.style.transform="",kn&&(kn.height<window.innerHeight?requestAnimationFrame(()=>{Or(h)}):kn.addEventListener("resize",()=>Or(h),{once:!0}))}))},i=()=>{window.scrollTo(0,0)},l=window.pageXOffset,u=window.pageYOffset,d=Dr(yg(document.documentElement,"paddingRight",`${window.innerWidth-document.documentElement.clientWidth}px`));window.scrollTo(0,0);let f=Dr(cs(document,"touchstart",n,{passive:!1,capture:!0}),cs(document,"touchmove",a,{passive:!1,capture:!0}),cs(document,"touchend",r,{passive:!1,capture:!0}),cs(document,"focus",o,!0),cs(window,"scroll",i));return()=>{d(),f(),window.scrollTo(l,u)}}function yg(e,t,n){let a=e.style[t];return e.style[t]=n,()=>{e.style[t]=a}}function cs(e,t,n,a){return e.addEventListener(t,n,a),()=>{e.removeEventListener(t,n,a)}}function Or(e){let t=document.scrollingElement||document.documentElement;for(;e&&e!==t;){let n=Qi(e);if(n!==document.documentElement&&n!==document.body&&n!==e){let a=n.getBoundingClientRect().top,r=e.getBoundingClientRect().top,o=e.getBoundingClientRect().bottom;const i=n.getBoundingClientRect().bottom+gg;o>i&&(n.scrollTop+=r-a)}e=n.parentElement}}function qn(e){return e instanceof HTMLInputElement&&!pg.has(e.type)||e instanceof HTMLTextAreaElement||e instanceof HTMLElement&&e.isContentEditable}function wg(e,t){typeof e=="function"?e(t):e!=null&&(e.current=t)}function jg(...e){return t=>e.forEach(n=>wg(n,t))}function Wi(...e){return c.useCallback(jg(...e),e)}const Vi=new WeakMap;function we(e,t,n=!1){if(!e||!(e instanceof HTMLElement))return;let a={};Object.entries(t).forEach(([r,o])=>{if(r.startsWith("--")){e.style.setProperty(r,o);return}a[r]=e.style[r],e.style[r]=o}),!n&&Vi.set(e,a)}function Sg(e,t){if(!e||!(e instanceof HTMLElement))return;let n=Vi.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 Bs(e,t){if(!e)return null;const n=window.getComputedStyle(e),a=n.transform||n.webkitTransform||n.mozTransform;let r=a.match(/^matrix3d\((.+)\)$/);return r?parseFloat(r[1].split(", ")[be(t)?13:12]):(r=a.match(/^matrix\((.+)\)$/),r?parseFloat(r[1].split(", ")[be(t)?5:4]):null)}function Ng(e){return 8*(Math.log(e+1)-2)}function En(e,t){if(!e)return()=>{};const n=e.style.cssText;return Object.assign(e.style,t),()=>{e.style.cssText=n}}function kg(...e){return(...t)=>{for(const n of e)typeof n=="function"&&n(...t)}}const he={DURATION:.5,EASE:[.32,.72,0,1]},Yi=.4,Cg=.25,Eg=100,Gi=8,vt=16,Un=26,In="vaul-dragging";function Xi(e){const t=F.useRef(e);return F.useEffect(()=>{t.current=e}),F.useMemo(()=>(...n)=>t.current==null?void 0:t.current.call(t,...n),[])}function Ig({defaultProp:e,onChange:t}){const n=F.useState(e),[a]=n,r=F.useRef(a),o=Xi(t);return F.useEffect(()=>{r.current!==a&&(o(a),r.current=a)},[a,r,o]),n}function Ji({prop:e,defaultProp:t,onChange:n=()=>{}}){const[a,r]=Ig({defaultProp:t,onChange:n}),o=e!==void 0,i=o?e:a,l=Xi(n),u=F.useCallback(d=>{if(o){const m=typeof d=="function"?d(e):d;m!==e&&l(m)}else r(d)},[o,e,r,l]);return[i,u]}function Rg({activeSnapPointProp:e,setActiveSnapPointProp:t,snapPoints:n,drawerRef:a,overlayRef:r,fadeFromIndex:o,onSnapPointChange:i,direction:l="bottom",container:u,snapToSequentialPoint:d}){const[f,m]=Ji({prop:e,defaultProp:n?.[0],onChange:t}),[h,p]=F.useState(typeof window<"u"?{innerWidth:window.innerWidth,innerHeight:window.innerHeight}:void 0);F.useEffect(()=>{function S(){p({innerWidth:window.innerWidth,innerHeight:window.innerHeight})}return window.addEventListener("resize",S),()=>window.removeEventListener("resize",S)},[]);const b=F.useMemo(()=>f===n?.[n.length-1]||null,[n,f]),x=F.useMemo(()=>{var S;return(S=n?.findIndex(E=>E===f))!=null?S:null},[n,f]),y=n&&n.length>0&&(o||o===0)&&!Number.isNaN(o)&&n[o]===f||!n,g=F.useMemo(()=>{const S=u?{width:u.getBoundingClientRect().width,height:u.getBoundingClientRect().height}:typeof window<"u"?{width:window.innerWidth,height:window.innerHeight}:{width:0,height:0};var E;return(E=n?.map(k=>{const M=typeof k=="string";let T=0;if(M&&(T=parseInt(k,10)),be(l)){const I=M?T:h?k*S.height:0;return h?l==="bottom"?S.height-I:-S.height+I:I}const D=M?T:h?k*S.width:0;return h?l==="right"?S.width-D:-S.width+D:D}))!=null?E:[]},[n,h,u]),v=F.useMemo(()=>x!==null?g?.[x]:null,[g,x]),w=F.useCallback(S=>{var E;const k=(E=g?.findIndex(M=>M===S))!=null?E:null;i(k),we(a.current,{transition:`transform ${he.DURATION}s cubic-bezier(${he.EASE.join(",")})`,transform:be(l)?`translate3d(0, ${S}px, 0)`:`translate3d(${S}px, 0, 0)`}),g&&k!==g.length-1&&o!==void 0&&k!==o&&k<o?we(r.current,{transition:`opacity ${he.DURATION}s cubic-bezier(${he.EASE.join(",")})`,opacity:"0"}):we(r.current,{transition:`opacity ${he.DURATION}s cubic-bezier(${he.EASE.join(",")})`,opacity:"1"}),m(n?.[Math.max(k,0)])},[a.current,n,g,o,r,m]);F.useEffect(()=>{if(f||e){var S;const E=(S=n?.findIndex(k=>k===e||k===f))!=null?S:-1;g&&E!==-1&&typeof g[E]=="number"&&w(g[E])}},[f,e,n,g,w]);function j({draggedDistance:S,closeDrawer:E,velocity:k,dismissible:M}){if(o===void 0)return;const T=l==="bottom"||l==="right"?(v??0)-S:(v??0)+S,D=x===o-1,I=x===0,R=S>0;if(D&&we(r.current,{transition:`opacity ${he.DURATION}s cubic-bezier(${he.EASE.join(",")})`}),!d&&k>2&&!R){M?E():w(g[0]);return}if(!d&&k>2&&R&&g&&n){w(g[n.length-1]);return}const O=g?.reduce(($,q)=>typeof $!="number"||typeof q!="number"?$:Math.abs(q-T)<Math.abs($-T)?q:$),B=be(l)?window.innerHeight:window.innerWidth;if(k>Yi&&Math.abs(S)<B*.4){const $=R?1:-1;if($>0&&b&&n){w(g[n.length-1]);return}if(I&&$<0&&M&&E(),x===null)return;w(g[x+$]);return}w(O)}function C({draggedDistance:S}){if(v===null)return;const E=l==="bottom"||l==="right"?v-S:v+S;(l==="bottom"||l==="right")&&E<g[g.length-1]||(l==="top"||l==="left")&&E>g[g.length-1]||we(a.current,{transform:be(l)?`translate3d(0, ${E}px, 0)`:`translate3d(${E}px, 0, 0)`})}function N(S,E){if(!n||typeof x!="number"||!g||o===void 0)return null;const k=x===o-1;if(x>=o&&E)return 0;if(k&&!E)return 1;if(!y&&!k)return null;const T=k?x+1:x-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:N,setActiveSnapPoint:m,activeSnapPointIndex:x,onRelease:j,onDrag:C,snapPointsOffset:g}}const Mg=()=>()=>{};function Tg(){const{direction:e,isOpen:t,shouldScaleBackground:n,setBackgroundColorOnScale:a,noBodyStyles:r}=Cs(),o=F.useRef(null),i=c.useMemo(()=>document.body.style.backgroundColor,[]);function l(){return(window.innerWidth-Un)/window.innerWidth}F.useEffect(()=>{if(t&&n){o.current&&clearTimeout(o.current);const u=document.querySelector("[data-vaul-drawer-wrapper]")||document.querySelector("[vaul-drawer-wrapper]");if(!u)return;kg(a&&!r?En(document.body,{background:"black"}):Mg,En(u,{transformOrigin:be(e)?"top":"left",transitionProperty:"transform, border-radius",transitionDuration:`${he.DURATION}s`,transitionTimingFunction:`cubic-bezier(${he.EASE.join(",")})`}));const d=En(u,{borderRadius:`${Gi}px`,overflow:"hidden",...be(e)?{transform:`scale(${l()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`}:{transform:`scale(${l()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)`}});return()=>{d(),o.current=window.setTimeout(()=>{i?document.body.style.background=i:document.body.style.removeProperty("background")},he.DURATION*1e3)}}},[t,n,i])}let us=null;function Dg({isOpen:e,modal:t,nested:n,hasBeenOpened:a,preventScrollRestoration:r,noBodyStyles:o}){const[i,l]=F.useState(()=>typeof window<"u"?window.location.href:""),u=F.useRef(0),d=F.useCallback(()=>{if(Tr()&&us===null&&e&&!o){us={position:document.body.style.position,top:document.body.style.top,left:document.body.style.left,height:document.body.style.height,right:"unset"};const{scrollX:m,innerHeight:h}=window;document.body.style.setProperty("position","fixed","important"),Object.assign(document.body.style,{top:`${-u.current}px`,left:`${-m}px`,right:"0px",height:"auto"}),window.setTimeout(()=>window.requestAnimationFrame(()=>{const p=h-window.innerHeight;p&&u.current>=h&&(document.body.style.top=`${-(u.current+p)}px`)}),300)}},[e]),f=F.useCallback(()=>{if(Tr()&&us!==null&&!o){const m=-parseInt(document.body.style.top,10),h=-parseInt(document.body.style.left,10);Object.assign(document.body.style,us),window.requestAnimationFrame(()=>{if(r&&i!==window.location.href){l(window.location.href);return}window.scrollTo(h,m)}),us=null}},[i]);return F.useEffect(()=>{function m(){u.current=window.scrollY}return m(),window.addEventListener("scroll",m),()=>{window.removeEventListener("scroll",m)}},[]),F.useEffect(()=>{if(t)return()=>{typeof document>"u"||document.querySelector("[data-vaul-drawer]")||f()}},[t,f]),F.useEffect(()=>{n||!a||(e?(!window.matchMedia("(display-mode: standalone)").matches&&d(),t||window.setTimeout(()=>{f()},500)):f())},[e,a,i,t,n,d,f]),{restorePositionSetting:f}}function Ag({open:e,onOpenChange:t,children:n,onDrag:a,onRelease:r,snapPoints:o,shouldScaleBackground:i=!1,setBackgroundColorOnScale:l=!0,closeThreshold:u=Cg,scrollLockTimeout:d=Eg,dismissible:f=!0,handleOnly:m=!1,fadeFromIndex:h=o&&o.length-1,activeSnapPoint:p,setActiveSnapPoint:b,fixed:x,modal:y=!0,onClose:g,nested:v,noBodyStyles:w=!1,direction:j="bottom",defaultOpen:C=!1,disablePreventScroll:N=!0,snapToSequentialPoint:S=!1,preventScrollRestoration:E=!1,repositionInputs:k=!0,onAnimationEnd:M,container:T,autoFocus:D=!1}){var I,R;const[O=!1,B]=Ji({defaultProp:C,prop:e,onChange:V=>{t?.(V),!V&&!v&&It(),setTimeout(()=>{M?.(V)},he.DURATION*1e3),V&&!y&&typeof window<"u"&&window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"}),V||(document.body.style.pointerEvents="auto")}}),[$,q]=F.useState(!1),[_,U]=F.useState(!1),[te,J]=F.useState(!1),P=F.useRef(null),A=F.useRef(null),Q=F.useRef(null),le=F.useRef(null),ve=F.useRef(null),ce=F.useRef(!1),ye=F.useRef(null),Se=F.useRef(0),Y=F.useRef(!1),ge=F.useRef(!C),Ie=F.useRef(0),H=F.useRef(null),W=F.useRef(((I=H.current)==null?void 0:I.getBoundingClientRect().height)||0),ee=F.useRef(((R=H.current)==null?void 0:R.getBoundingClientRect().width)||0),ne=F.useRef(0),Ve=F.useCallback(V=>{o&&V===Ye.length-1&&(A.current=new Date)},[]),{activeSnapPoint:re,activeSnapPointIndex:Ne,setActiveSnapPoint:Fe,onRelease:Re,snapPointsOffset:Ye,onDrag:Ge,shouldFade:Et,getPercentageDragged:xt}=Rg({snapPoints:o,activeSnapPointProp:p,setActiveSnapPointProp:b,drawerRef:H,fadeFromIndex:h,overlayRef:P,onSnapPointChange:Ve,direction:j,container:T,snapToSequentialPoint:S});bg({isDisabled:!O||_||!y||te||!$||!k||!N});const{restorePositionSetting:It}=Dg({isOpen:O,modal:y,nested:v??!1,hasBeenOpened:$,preventScrollRestoration:E,noBodyStyles:w});function Xe(){return(window.innerWidth-Un)/window.innerWidth}function at(V){var ae,oe;!f&&!o||H.current&&!H.current.contains(V.target)||(W.current=((ae=H.current)==null?void 0:ae.getBoundingClientRect().height)||0,ee.current=((oe=H.current)==null?void 0:oe.getBoundingClientRect().width)||0,U(!0),Q.current=new Date,Hi()&&window.addEventListener("touchend",()=>ce.current=!1,{once:!0}),V.target.setPointerCapture(V.pointerId),Se.current=be(j)?V.pageY:V.pageX)}function pt(V,ae){var oe;let Z=V;const ue=(oe=window.getSelection())==null?void 0:oe.toString(),xe=H.current?Bs(H.current,j):null,L=new Date;if(Z.tagName==="SELECT"||Z.hasAttribute("data-vaul-no-drag")||Z.closest("[data-vaul-no-drag]"))return!1;if(j==="right"||j==="left")return!0;if(A.current&&L.getTime()-A.current.getTime()<500)return!1;if(xe!==null&&(j==="bottom"?xe>0:xe<0))return!0;if(ue&&ue.length>0)return!1;if(ve.current&&L.getTime()-ve.current.getTime()<d&&xe===0||ae)return ve.current=L,!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 Me(V){if(H.current&&_){const ae=j==="bottom"||j==="right"?1:-1,oe=(Se.current-(be(j)?V.pageY:V.pageX))*ae,Z=oe>0,ue=o&&!f&&!Z;if(ue&&Ne===0)return;const xe=Math.abs(oe),L=document.querySelector("[data-vaul-drawer-wrapper]"),X=j==="bottom"||j==="top"?W.current:ee.current;let me=xe/X;const de=xt(xe,Z);if(de!==null&&(me=de),ue&&me>=1||!ce.current&&!pt(V.target,Z))return;if(H.current.classList.add(In),ce.current=!0,we(H.current,{transition:"none"}),we(P.current,{transition:"none"}),o&&Ge({draggedDistance:oe}),Z&&!o){const ke=Ng(oe),bt=Math.min(ke*-1,0)*ae;we(H.current,{transform:be(j)?`translate3d(0, ${bt}px, 0)`:`translate3d(${bt}px, 0, 0)`});return}const Te=1-me;if((Et||h&&Ne===h-1)&&(a?.(V,me),we(P.current,{opacity:`${Te}`,transition:"none"},!0)),L&&P.current&&i){const ke=Math.min(Xe()+me*(1-Xe()),1),bt=8-me*8,Be=Math.max(0,14-me*14);we(L,{borderRadius:`${bt}px`,transform:be(j)?`scale(${ke}) translate3d(0, ${Be}px, 0)`:`scale(${ke}) translate3d(${Be}px, 0, 0)`,transition:"none"},!0)}if(!o){const ke=xe*ae;we(H.current,{transform:be(j)?`translate3d(0, ${ke}px, 0)`:`translate3d(${ke}px, 0, 0)`})}}}F.useEffect(()=>{window.requestAnimationFrame(()=>{ge.current=!0})},[]),F.useEffect(()=>{var V;function ae(){if(!H.current||!k)return;const oe=document.activeElement;if(qn(oe)||Y.current){var Z;const ue=((Z=window.visualViewport)==null?void 0:Z.height)||0,xe=window.innerHeight;let L=xe-ue;const X=H.current.getBoundingClientRect().height||0,me=X>xe*.8;ne.current||(ne.current=X);const de=H.current.getBoundingClientRect().top;if(Math.abs(Ie.current-L)>60&&(Y.current=!Y.current),o&&o.length>0&&Ye&&Ne){const Te=Ye[Ne]||0;L+=Te}if(Ie.current=L,X>ue||Y.current){const Te=H.current.getBoundingClientRect().height;let ke=Te;Te>ue&&(ke=ue-(me?de:Un)),x?H.current.style.height=`${Te-Math.max(L,0)}px`:H.current.style.height=`${Math.max(ke,ue-de)}px`}else dg()||(H.current.style.height=`${ne.current}px`);o&&o.length>0&&!Y.current?H.current.style.bottom="0px":H.current.style.bottom=`${Math.max(L,0)}px`}}return(V=window.visualViewport)==null||V.addEventListener("resize",ae),()=>{var oe;return(oe=window.visualViewport)==null?void 0:oe.removeEventListener("resize",ae)}},[Ne,o,Ye]);function Je(V){Mt(),g?.(),V||B(!1),setTimeout(()=>{o&&Fe(o[0])},he.DURATION*1e3)}function Rt(){if(!H.current)return;const V=document.querySelector("[data-vaul-drawer-wrapper]"),ae=Bs(H.current,j);we(H.current,{transform:"translate3d(0, 0, 0)",transition:`transform ${he.DURATION}s cubic-bezier(${he.EASE.join(",")})`}),we(P.current,{transition:`opacity ${he.DURATION}s cubic-bezier(${he.EASE.join(",")})`,opacity:"1"}),i&&ae&&ae>0&&O&&we(V,{borderRadius:`${Gi}px`,overflow:"hidden",...be(j)?{transform:`scale(${Xe()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`,transformOrigin:"top"}:{transform:`scale(${Xe()}) 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 Mt(){!_||!H.current||(H.current.classList.remove(In),ce.current=!1,U(!1),le.current=new Date)}function ns(V){if(!_||!H.current)return;H.current.classList.remove(In),ce.current=!1,U(!1),le.current=new Date;const ae=Bs(H.current,j);if(!V||!pt(V.target,!1)||!ae||Number.isNaN(ae)||Q.current===null)return;const oe=le.current.getTime()-Q.current.getTime(),Z=Se.current-(be(j)?V.pageY:V.pageX),ue=Math.abs(Z)/oe;if(ue>.05&&(J(!0),setTimeout(()=>{J(!1)},200)),o){Re({draggedDistance:Z*(j==="bottom"||j==="right"?1:-1),closeDrawer:Je,velocity:ue,dismissible:f}),r?.(V,!0);return}if(j==="bottom"||j==="right"?Z>0:Z<0){Rt(),r?.(V,!0);return}if(ue>Yi){Je(),r?.(V,!1);return}var xe;const L=Math.min((xe=H.current.getBoundingClientRect().height)!=null?xe:0,window.innerHeight);var X;const me=Math.min((X=H.current.getBoundingClientRect().width)!=null?X:0,window.innerWidth),de=j==="left"||j==="right";if(Math.abs(ae)>=(de?me:L)*u){Je(),r?.(V,!1);return}r?.(V,!0),Rt()}F.useEffect(()=>(O&&(we(document.documentElement,{scrollBehavior:"auto"}),A.current=new Date),()=>{Sg(document.documentElement,"scrollBehavior")}),[O]);function Tt(V){const ae=V?(window.innerWidth-vt)/window.innerWidth:1,oe=V?-vt:0;ye.current&&window.clearTimeout(ye.current),we(H.current,{transition:`transform ${he.DURATION}s cubic-bezier(${he.EASE.join(",")})`,transform:be(j)?`scale(${ae}) translate3d(0, ${oe}px, 0)`:`scale(${ae}) translate3d(${oe}px, 0, 0)`}),!V&&H.current&&(ye.current=setTimeout(()=>{const Z=Bs(H.current,j);we(H.current,{transition:"none",transform:be(j)?`translate3d(0, ${Z}px, 0)`:`translate3d(${Z}px, 0, 0)`})},500))}function Le(V,ae){if(ae<0)return;const oe=(window.innerWidth-vt)/window.innerWidth,Z=oe+ae*(1-oe),ue=-vt+ae*vt;we(H.current,{transform:be(j)?`scale(${Z}) translate3d(0, ${ue}px, 0)`:`scale(${Z}) translate3d(${ue}px, 0, 0)`,transition:"none"})}function as(V,ae){const oe=be(j)?window.innerHeight:window.innerWidth,Z=ae?(oe-vt)/oe:1,ue=ae?-vt:0;ae&&we(H.current,{transition:`transform ${he.DURATION}s cubic-bezier(${he.EASE.join(",")})`,transform:be(j)?`scale(${Z}) translate3d(0, ${ue}px, 0)`:`scale(${Z}) translate3d(${ue}px, 0, 0)`})}return F.useEffect(()=>{y||window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"})},[y]),F.createElement(Ai,{defaultOpen:C,onOpenChange:V=>{!f&&!V||(V?q(!0):Je(!0),B(V))},open:O},F.createElement(Ui.Provider,{value:{activeSnapPoint:re,snapPoints:o,setActiveSnapPoint:Fe,drawerRef:H,overlayRef:P,onOpenChange:t,onPress:at,onRelease:ns,onDrag:Me,dismissible:f,shouldAnimate:ge,handleOnly:m,isOpen:O,isDragging:_,shouldFade:Et,closeDrawer:Je,onNestedDrag:Le,onNestedOpenChange:Tt,onNestedRelease:as,keyboardIsOpen:Y,modal:y,snapPointsOffset:Ye,activeSnapPointIndex:Ne,direction:j,shouldScaleBackground:i,setBackgroundColorOnScale:l,noBodyStyles:w,container:T,autoFocus:D}},n))}const Zi=F.forwardRef(function({...e},t){const{overlayRef:n,snapPoints:a,onRelease:r,shouldFade:o,isOpen:i,modal:l,shouldAnimate:u}=Cs(),d=Wi(t,n),f=a&&a.length>0;if(!l)return null;const m=F.useCallback(h=>r(h),[r]);return F.createElement(zi,{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})});Zi.displayName="Drawer.Overlay";const el=F.forwardRef(function({onPointerDownOutside:e,style:t,onOpenAutoFocus:n,...a},r){const{drawerRef:o,onPress:i,onRelease:l,onDrag:u,keyboardIsOpen:d,snapPointsOffset:f,activeSnapPointIndex:m,modal:h,isOpen:p,direction:b,snapPoints:x,container:y,handleOnly:g,shouldAnimate:v,autoFocus:w}=Cs(),[j,C]=F.useState(!1),N=Wi(r,o),S=F.useRef(null),E=F.useRef(null),k=F.useRef(!1),M=x&&x.length>0;Tg();const T=(I,R,O=0)=>{if(k.current)return!0;const B=Math.abs(I.y),$=Math.abs(I.x),q=$>B,_=["bottom","right"].includes(R)?1:-1;if(R==="left"||R==="right"){if(!(I.x*_<0)&&$>=0&&$<=O)return q}else if(!(I.y*_<0)&&B>=0&&B<=O)return!q;return k.current=!0,!0};F.useEffect(()=>{M&&window.requestAnimationFrame(()=>{C(!0)})},[]);function D(I){S.current=null,k.current=!1,l(I)}return F.createElement(_i,{"data-vaul-drawer-direction":b,"data-vaul-drawer":"","data-vaul-delayed-snap-points":j?"true":"false","data-vaul-snap-points":p&&M?"true":"false","data-vaul-custom-container":y?"true":"false","data-vaul-animate":v?.current?"true":"false",...a,ref:N,style:f&&f.length>0?{"--snap-point-height":`${f[m??0]}px`,...t}:t,onPointerDown:I=>{g||(a.onPointerDown==null||a.onPointerDown.call(a,I),S.current={x:I.pageX,y:I.pageY},i(I))},onOpenAutoFocus:I=>{n?.(I),w||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(E.current=I,g||(a.onPointerMove==null||a.onPointerMove.call(a,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=>{a.onPointerUp==null||a.onPointerUp.call(a,I),S.current=null,k.current=!1,l(I)},onPointerOut:I=>{a.onPointerOut==null||a.onPointerOut.call(a,I),D(E.current)},onContextMenu:I=>{a.onContextMenu==null||a.onContextMenu.call(a,I),E.current&&D(E.current)}})});el.displayName="Drawer.Content";const Og=250,Pg=120,tl=F.forwardRef(function({preventCycle:e=!1,children:t,...n},a){const{closeDrawer:r,isDragging:o,snapPoints:i,activeSnapPoint:l,setActiveSnapPoint:u,dismissible:d,handleOnly:f,isOpen:m,onPress:h,onDrag:p}=Cs(),b=F.useRef(null),x=F.useRef(!1);function y(){if(x.current){w();return}window.setTimeout(()=>{g()},Pg)}function g(){if(o||e||x.current){w();return}if(w(),!i||i.length===0){d||r();return}if(l===i[i.length-1]&&d){r();return}const C=i.findIndex(S=>S===l);if(C===-1)return;const N=i[C+1];u(N)}function v(){b.current=window.setTimeout(()=>{x.current=!0},Og)}function w(){b.current&&window.clearTimeout(b.current),x.current=!1}return F.createElement("div",{onClick:y,onPointerCancel:w,onPointerDown:j=>{f&&h(j),v()},onPointerMove:j=>{f&&p(j)},ref:a,"data-vaul-drawer-visible":m?"true":"false","data-vaul-handle":"","aria-hidden":"true",...n},F.createElement("span",{"data-vaul-handle-hitarea":"","aria-hidden":"true"},t))});tl.displayName="Drawer.Handle";function Lg(e){const t=Cs(),{container:n=t.container,...a}=e;return F.createElement(Li,{container:n,...a})}const Oe={Root:Ag,Content:el,Overlay:Zi,Portal:Lg,Handle:tl,Title:$i},zg=new Set(["outbox","postvak uit","boîte d'envoi","postausgang","buzón de salida","posta in uscita","送信トレイ","送件匣","发件箱","skrzynka nadawcza"]),_g=e=>{const t=Ys(e.fullPath).trim().toLowerCase();return zg.has(t)},Pr=On.length,Sa=(e,t=[])=>{const n=Jt(t);return[...e.filter(r=>{const o=n.get(r.mailboxId);return o==="drafts"||o==="sent"?!1:!_g(r)})].sort((r,o)=>{const i=n.has(r.mailboxId)?On.indexOf(n.get(r.mailboxId)??"inbox"):Pr,l=n.has(o.mailboxId)?On.indexOf(n.get(o.mailboxId)??"inbox"):Pr;return i!==l?i-l:Ys(r.fullPath).localeCompare(Ys(o.fullPath),void 0,{sensitivity:"base",numeric:!0})})},sl="inline-flex items-center justify-center transition-colors",Fg=fe(sl,"min-h-11 min-w-11 rounded hover:bg-surface-raised"),Bg=fe(sl,"min-h-11 gap-1.5 px-3 rounded text-sm font-medium hover:bg-surface-raised"),Es=({accountId:e,currentMailboxId:t,onMove:n,disabled:a=!1,disabledHint:r,variant:o="icon-only",label:i})=>{const[l,u]=c.useState(!1),d=Ct(),f=c.useRef(null),m=i??"Move to folder",h=c.useId(),{t:p}=nn("mail",{useSuspense:!1}),b=c.useCallback((M,T)=>p(M,{defaultValue:T}),[p]),{data:x,isLoading:y,isError:g,error:v,refetch:w}=ie({...He({path:{accountId:e}}),staleTime:1/0,enabled:l}),j=Ri(e),C=c.useMemo(()=>{const M=Sa(x?.items??[],j),T=Jt(j);return M.map(D=>({id:D.mailboxId,label:Qt(D,T.get(D.mailboxId),b),searchValue:D.fullPath,isCurrent:D.mailboxId===t}))},[x?.items,j,t,b]),N=c.useCallback(M=>{u(!1),n(M)},[n]);c.useEffect(()=>{if(!l||!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)}},[l,d]);const S=a||!!r,E=s.jsxs("button",{type:"button",onClick:M=>{M.stopPropagation(),!S&&u(T=>!T)},"aria-label":m,"aria-haspopup":d?"listbox":"dialog","aria-expanded":l,"aria-controls":l?h:void 0,title:r,className:o==="icon-only"?Fg:Bg,children:[s.jsx(Ro,{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(ht,{variant:"inline",title:"Couldn't load folders",error:v,onRetry:()=>w()})}):s.jsx(Jo,{mailboxes:C,onSelect:N,onCancel:()=>u(!1),autoFocus:!d,labels:{searchPlaceholder:p("move_picker_placeholder",{defaultValue:"Move to…"}),searchAriaLabel:p("move_picker_filter_label",{defaultValue:"Filter folders"}),optionLabel:M=>`Move to ${M}`,currentSuffix:"(current folder)",currentTag:"current",emptyMessage:M=>`No folders match "${M}"`}});return d?s.jsxs("div",{ref:f,className:"relative inline-block",children:[E,l&&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:[E,s.jsx(Oe.Root,{open:l,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})]})]})})]})},$g=({messageId:e,threadId:t,mailboxId:n,isRead:a,accountId:r,fromAddressId:o,isTrusted:i=!1,showRaw:l=!1,onToggleRaw:u})=>{const d=je(),f=Ce(),{pushError:m}=ze(),{selectedMessageId:h}=Ht({strict:!1}),{mutate:p,isPending:b}=pe({...sn(),onMutate:async O=>{const B=O.body.isRead??!0,$=new Set(O.body.messageIds??[]),q=jt({path:{threadId:t}}),_=st({path:{mailboxId:n}}),U=ft({path:{mailboxId:n}});await Promise.all([d.cancelQueries({queryKey:q}),d.cancelQueries({queryKey:_}),d.cancelQueries({queryKey:U})]);const te=d.getQueriesData({queryKey:q}).filter(A=>A[1]!==void 0).map(([A,Q])=>({queryKey:A,data:Q})),J=d.getQueriesData({queryKey:_}).concat(d.getQueriesData({queryKey:U})).filter(A=>A[1]!==void 0).map(([A,Q])=>({queryKey:A,data:Q}));d.setQueriesData({queryKey:q},A=>A&&{...A,items:A.items.map(Q=>$.has(Q.messageId)?{...Q,isRead:B}:Q)});const P=A=>Yt(A,Q=>Q.map(le=>$.has(le.messageId)?{...le,isRead:B}:le));return d.setQueriesData({queryKey:_},P),d.setQueriesData({queryKey:U},P),{threadMessagesPrefix:q,threadsListPrefix:_,threadsSearchPrefix:U,previousThreadMessages:te,previousThreadsList:J}},onError:(O,B,$)=>{if($){for(const _ of $.previousThreadMessages)d.setQueryData(_.queryKey,_.data);for(const _ of $.previousThreadsList)d.setQueryData(_.queryKey,_.data)}const q=B.body.isRead??!0;m({title:q?"Couldn't mark as read":"Couldn't mark as unread",detail:Ke(O),error:O})},onSettled:(O,B,$,q)=>{q&&(d.invalidateQueries({queryKey:q.threadMessagesPrefix}),d.invalidateQueries({queryKey:q.threadsListPrefix}),d.invalidateQueries({queryKey:q.threadsSearchPrefix}))}}),x=c.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}=hs({mailboxId:n,threadId:t,onAfterOptimisticRemove:x}),{moveMessages:v,isPending:w}=ct({mailboxId:n,threadId:t,accountId:r,onAfterOptimisticRemove:x}),{toggleTrusted:j,isPending:C,error:N,reset:S}=va({messageId:e}),E=()=>{p({body:{messageIds:[e],isRead:!1}})},k=()=>{y([e])},M=()=>{o&&j(o,i)},T=b||g||w||C,D=T||!o,I=c.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:[r&&s.jsx(Es,{accountId:r,currentMailboxId:n,onMove:I,disabled:T,label:"Move this message"}),s.jsxs(xi,{trigger:s.jsx(Io,{className:"size-4"}),children:[s.jsxs(Kt,{onClick:M,disabled:D,children:[i?s.jsx(an,{className:"size-4 text-positive"}):s.jsx(js,{className:"size-4 opacity-0"}),s.jsx("span",{title:R,children:"Trusted sender"})]}),a&&s.jsxs(Kt,{onClick:E,disabled:T,children:[s.jsx(Ss,{className:"size-4"}),"Mark as unread"]}),u&&s.jsxs(Kt,{onClick:u,children:[s.jsx(Eo,{className:"size-4"}),l?"Show formatted":"Show raw email"]}),s.jsx(_n,{}),s.jsxs(Kt,{onClick:k,disabled:T,destructive:!0,children:[s.jsx(We,{className:"size-4"}),"Delete"]})]})]}),N&&s.jsx("div",{className:"w-64",children:s.jsx(ht,{variant:"inline",title:"Couldn't update trust",error:N,onRetry:()=>{S(),M()}})})]})},Kg=()=>{const[e,t]=c.useState(()=>typeof document<"u"&&document.documentElement.classList.contains("dark"));return c.useEffect(()=>{const n=document.documentElement,a=new MutationObserver(()=>{t(n.classList.contains("dark"))});return a.observe(n,{attributes:!0,attributeFilter:["class"]}),()=>a.disconnect()},[]),e},qg=({blockedImageCount:e,canAlwaysTrust:t,isTrustPending:n,onLoadOnce:a,onAlwaysTrust:r})=>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:a,className:"text-accent hover:underline",children:"Load once"}),t&&s.jsx("button",{type:"button",onClick:r,"aria-busy":n,className:"text-accent hover:underline aria-busy:opacity-50",children:n?"Trusting…":"Always trust"})]})]}),Ug=(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}}},Hg=e=>e instanceof yt?e.reason:"generic",Qg=e=>e instanceof Error?e.message:typeof e=="string"?e:"An unexpected error occurred while loading the message body.",Wg=({error:e,onRetry:t})=>{const n=Hg(e),a=Qg(e),{title:r,detail:o}=Ug(n,a),[i,l]=c.useState(!1),{Account:u}=Zn();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(wt,{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:r}),s.jsx("p",{className:"text-fg-muted mt-1 break-words",children:o})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-3",children:[n==="auth"&&s.jsx(u,{children:({signOut:d})=>s.jsx("button",{type:"button",onClick:()=>d(),className:"text-sm font-medium text-accent hover:underline",children:"Sign in again"})}),t&&s.jsx("button",{type:"button",onClick:t,className:"text-sm font-medium text-accent hover:underline",children:"Retry"}),s.jsx("button",{type:"button",onClick:()=>l(!0),"aria-label":"Dismiss message body error",className:"rounded-md p-1 text-fg-muted hover:bg-surface-raised hover:text-fg transition-colors",children:s.jsx(Pe,{className:"size-4","aria-hidden":"true"})})]})]})},Vg=()=>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"})]}),Lr=()=>s.jsx("p",{className:"text-fg-muted text-sm italic",children:"This message has no body content."}),nl=({bodyParts:e,html:t,text:n,isTrusted:a=!1,messageId:r,fromAddressId:o,category:i,className:l})=>{const[u,d]=c.useState(!1),f=a||u,m=Kg(),{toggleTrusted:h,isPending:p}=va({messageId:r??""}),b=!!e&&e.length>0,{picked:x,data:y,isLoading:g,isError:v,error:w,refetch:j}=yi({messageId:r,bodyParts:e,enabled:b}),C=c.useMemo(()=>Qu(e??[]),[e]),N=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",l),children:s.jsx(Vg,{})});if(v)return s.jsx("div",{className:fe("message-body",l),children:s.jsx(Wg,{error:w,onRetry:()=>j()})});if(!x)return s.jsx("div",{className:fe("message-body",l),children:s.jsx(Lr,{})})}else if(!t&&!n)return s.jsx("div",{className:fe("message-body",l),children:s.jsx(Lr,{})});const E=!!(o&&r),k=()=>{!o||p||(d(!0),h(o,!1))};return s.jsx(Qo,{className:l,html:N,text:S,isDark:m,category:i,allowImages:f,resolveCid:C,renderBlockedNotice:M=>s.jsx(qg,{blockedImageCount:M,canAlwaysTrust:E,isTrustPending:p,onLoadOnce:()=>d(!0),onAlwaysTrust:k})})},Yg=({messageId:e,threadId:t,mailboxId:n,accountId:a,isRead:r,isStarred:o,onToggleStar:i,fromAddressId:l,isTrusted:u,showRaw:d,onToggleRaw:f,onReply:m,onReplyAll:h,onForward:p})=>{const b=je(),{deleteMessages:x}=hs({mailboxId:n,threadId:t}),{moveMessages:y}=ct({mailboxId:n,threadId:t,accountId:a}),{toggleTrusted:g}=va({messageId:e}),{mutate:v}=pe({...sn(),onSettled:()=>{b.invalidateQueries({queryKey:jt({path:{threadId:t}})}),b.invalidateQueries({queryKey:st({path:{mailboxId:n}})}),b.invalidateQueries({queryKey:ft({path:{mailboxId:n}})})}}),w=c.useCallback(S=>{y([e],S)},[y,e]),j=c.useCallback(()=>{x([e])},[x,e]),C=c.useCallback(()=>{v({body:{messageIds:[e],isRead:!r}})},[v,e,r]),N=[];return l&&N.push({key:"trusted",label:u?"Trusted sender":"Mark sender trusted",icon:u?s.jsx(an,{className:"size-4 text-positive"}):s.jsx(js,{className:"size-4"}),onSelect:()=>g(l,u)}),f&&N.push({key:"raw",label:d?"Show formatted":"Show raw email",icon:s.jsx(Eo,{className:"size-4"}),onSelect:f}),s.jsx(Ho,{hasThread:!0,onReply:m,onReplyAll:h,onForward:p,isStarred:o,onToggleStar:i,onDelete:j,isRead:r,onToggleRead:C,overflowItems:N,moveSlot:a?s.jsx(Es,{accountId:a,currentMailboxId:n,onMove:w,label:"Move this message"}):void 0})},Gg=()=>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"})]}),Xg=({messageId:e,enabled:t=!0})=>{const{data:n,isLoading:a,isError:r,error:o,refetch:i}=ie({...Pc({path:{messageId:e}}),enabled:t});if(a)return s.jsx("div",{className:"message-body",children:s.jsx(Gg,{})});if(r)return s.jsx("div",{className:"message-body",children:s.jsx(ht,{variant:"inline",title:"Couldn't load the raw email",error:o,onRetry:()=>i()})});const l=n?.raw??"";return l===""?s.jsx("div",{className:"message-body",children:s.jsx("p",{className:"text-fg-muted text-sm italic",children:"No raw source available for this message."})}):s.jsx("div",{className:"message-body",children:s.jsx("pre",{className:"email-text whitespace-pre-wrap break-words text-sm leading-relaxed bg-surface-sunken rounded-md p-3 max-h-[32rem] overflow-auto",children:l})})},Jg=()=>s.jsx(an,{className:"inline-block size-4 ml-1 -mt-0.5 text-positive align-middle","aria-label":"Trusted sender","data-testid":"trusted-sender-badge"}),al=(e,t)=>({id:e.messageId,fromName:e.fromName??e.fromEmail??"?",fromEmail:e.fromEmail??"",toLabel:"",dateLabel:t,snippet:e.snippet||"",bodyHtml:""}),rl=({isStarred:e,onToggleStar:t,isStarPending:n,hoverReveal:a})=>s.jsx("button",{type:"button",onClick:r=>{r.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",a&&"opacity-0 group-hover:opacity-100 focus:opacity-100"),n&&"opacity-50"),children:s.jsx(mt,{className:fe("size-3.5",e&&"fill-current")})}),Zg=({threadMessage:e,isFocused:t,onToggle:n,onToggleStar:a,isStarPending:r})=>{const o=jo(e.sentDate,"datetime"),i=al(e,o);return s.jsx(Wo,{message:i,onClick:n,isFocused:t,isUnread:!e.isRead,trailing:s.jsxs(s.Fragment,{children:[e.hasAttachment&&s.jsx(rn,{className:"size-3 shrink-0 text-fg-subtle"}),s.jsx(rl,{isStarred:e.hasStars,onToggleStar:a,isStarPending:r,hoverReveal:!0}),s.jsx("span",{"data-testid":"message-date",className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:o})]})})},ex=({threadMessage:e,messageData:t,isLoading:n,isError:a,error:r,onRetry:o,isFocused:i,onToggle:l,onToggleStar:u,isStarPending:d,accountId:f,showRaw:m,onToggleRaw:h,mobile:p,onReply:b,onReplyAll:x,onForward:y})=>{const g=jo(e.sentDate,"long"),v=!e.isRead,w=t?.envelope.from[0]?.flags?.trusted?.value===!0,j=t?.envelope.from[0]?.addressId,C=al(e,g),N=e.autoMoved?s.jsx(Mi,{accountId:f,messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,autoMoved:e.autoMoved,size:"md"}):null;return s.jsx(Vo,{message:C,isFocused:i,onHeaderClick:l,senderBadge:w?s.jsx(Jg,{}):void 0,trailing:s.jsx("span",{"data-testid":"message-date",className:"text-2xs text-fg-subtle",children:g}),to:t?s.jsx(Iu,{label:"To",addresses:t.envelope.to}):null,indicators:N||!p?s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mt-0.5",children:[N,!p&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex items-center justify-end gap-1",children:[s.jsx(rl,{isStarred:e.hasStars,onToggleStar:u,isStarPending:d}),e.hasAttachment&&s.jsx("span",{className:"text-fg-subtle p-0.5",children:s.jsx(rn,{className:"size-3.5"})})]}),v&&s.jsx("span",{className:"size-1.5 rounded-full bg-accent","aria-label":"Unread"})]})]}):void 0,actionMenu:p?void 0:s.jsx($g,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,isRead:e.isRead,accountId:f,fromAddressId:j,isTrusted:w,showRaw:m,onToggleRaw:h}),actionBar:p?s.jsx(Yg,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,accountId:f,isRead:e.isRead,isStarred:e.hasStars,onToggleStar:u,fromAddressId:j,isTrusted:w,showRaw:m,onToggleRaw:h,onReply:b,onReplyAll:x,onForward: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"})]}):a&&Lc(r)?s.jsx("div",{className:"mt-3",children:s.jsx(Ci,{message:"This message has been deleted"})}):a?s.jsx("div",{className:"mt-3",children:s.jsx(ht,{variant:"inline",title:"Couldn't load this message",error:r,onRetry:o})}):m?s.jsx("div",{className:"mt-3",children:s.jsx(Xg,{messageId:e.messageId})}):s.jsx("div",{className:"mt-3",children:s.jsx(nl,{bodyParts:t?.bodyParts,messageId:e.messageId,fromAddressId:t?.envelope.from[0]?.addressId,isTrusted:w,category:un(e.category)})})})},tx=({threadMessage:e,isExpanded:t,isFocused:n,onToggle:a,onToggleStar:r,isStarPending:o,accountId:i,mobile:l,onReply:u,onReplyAll:d,onForward:f})=>{const[m,h]=c.useState(!1),{data:p,isLoading:b,isError:x,error:y,refetch:g}=ie({...sa({path:{messageId:e.messageId}}),enabled:t,meta:{softError:!0}});return t?s.jsx(ex,{threadMessage:e,messageData:p,isLoading:b,isError:x,error:y,onRetry:()=>g(),isFocused:n,onToggle:a,onToggleStar:r,isStarPending:o,accountId:i,showRaw:m,onToggleRaw:()=>h(v=>!v),mobile:l,onReply:u,onReplyAll:d,onForward:f}):s.jsx(Zg,{threadMessage:e,isFocused:n,onToggle:a,onToggleStar:r,isStarPending:o})},sx=()=>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 zr({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(Ns,{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 ss=({threadId:e,mailboxId:t,subject:n,selectedMessageId:a,authenticity:r,onOpenIntelligence:o,onBack:i,composeRequest:l,onComposeClose:u,onSwipeNext:d,onSwipePrevious:f,mobileIntelligenceOpen:m})=>{const h=Ct(),{handlers:p}=Kh({onSwipeLeft:d,onSwipeRight:f}),{accountId:b}=Ei(t),{data:x,isLoading:y,isError:g,error:v,refetch:w}=ie({...zc({path:{threadId:e},query:{order:"desc"}})}),j=c.useMemo(()=>x?.items??[],[x?.items]),C=c.useRef(new Map),[N,S]=c.useState(new Set),[E,k]=c.useState(null),[M,T]=c.useState(0);c.useEffect(()=>{if(j.length>0&&e!==E){k(e);const W=new Set([j[0].threadMessageId]);if(a){const ee=j.find(ne=>ne.messageId===a);ee&&W.add(ee.threadMessageId)}S(W),T(0)}},[e,j,E,a]);const D=c.useCallback(W=>{S(ee=>{const ne=new Set(ee);return ne.has(W)?ne.delete(W):ne.add(W),ne})},[]),I=c.useCallback(W=>{const ee=j[W];if(!ee)return;C.current.get(ee.threadMessageId)?.scrollIntoView({behavior:"smooth",block:"nearest"})},[j]),R=c.useCallback(()=>{if(j.length===0)return;const W=Math.min(M+1,j.length-1);T(W),I(W)},[j.length,M,I]),O=c.useCallback(()=>{if(j.length===0)return;const W=Math.max(M-1,0);T(W),I(W)},[j.length,M,I]),B=c.useCallback(()=>{const W=j[M];W&&D(W.threadMessageId)},[j,M,D]),{data:$}=ie({...tt(),staleTime:1/0}),q=$?.accounts?.[0],_=!!q?.smtpHost;_h({messages:j,expandedIds:N,threadId:e,mailboxId:t,accountId:q?.accountId});const{toggleStar:U,isPending:te,pendingMessageId:J}=Kn({threadId:e,mailboxId:t,messages:j}),[P,A]=c.useState(null);c.useEffect(()=>{l&&l!=="new"&&(A(l),u?.())},[l,u]);const Q=j[0],{data:le}=ie({...sa({path:{messageId:Q?.messageId??""}}),enabled:!!Q&&P!==null}),ve=c.useCallback(()=>{A("reply")},[]),ce=c.useCallback(()=>{A("reply_all")},[]),ye=c.useCallback(()=>{A("forward")},[]),Se=c.useCallback(()=>{A(null),u?.()},[u]);if(bs({enabled:!y&&j.length>0&&P===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(sx,{});if(g)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsx(ht,{title:"Couldn't load this conversation",error:v,onRetry:()=>w()})});if(j.length===0)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsx(Ci,{message:"No messages in this thread"})});const Y=n||j[0]?.subject||"(No subject)",ge=j.length,Ie=W=>s.jsx("div",{children:j.map((ee,ne)=>s.jsx("div",{ref:Ve=>{Ve&&C.current.set(ee.threadMessageId,Ve)},children:s.jsx(tx,{threadMessage:ee,isExpanded:N.has(ee.threadMessageId),isFocused:ne===M,onToggle:()=>D(ee.threadMessageId),onToggleStar:()=>U(ee.messageId,ee.hasStars),isStarPending:te&&J===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:Y}),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,r?.dkimMismatch&&s.jsx(zr,{authenticity:r,onOpenIntelligence:o}),s.jsx("div",{className:"flex-1 overflow-auto",children:Ie(!1)}),P!==null&&s.jsx(kr,{mode:P,account:q,sourceMessage:le,onClose:Se})]}):s.jsxs(gd,{thread:{subject:Y,messages:[]},onBack:i??(()=>{}),intelligenceOpen:m,onToggleIntelligence:o,touchHandlers:p,children:[r?.dkimMismatch&&s.jsx(zr,{authenticity:r,onOpenIntelligence:o}),Ie(!0),P!==null&&s.jsx(kr,{mode:P,account:q,sourceMessage:le,onClose:Se})]})},ol=e=>e.trim().toLocaleLowerCase(),nx=/^\d{4}-\d{2}-\d{2}$/;function _r(e,t,n){if(!nx.test(n))return;const a=Date.parse(`${n}T00:00:00Z`);if(!Number.isNaN(a))return{type:e,raw:t,value:n,epochSeconds:Math.floor(a/1e3)}}function ax(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 _r("before",e,e.slice(7));if(n.startsWith("after:")&&e.length>6)return _r("after",e,e.slice(6));if(n.startsWith("in:")&&e.length>3){const a=e.slice(3),r=t.mailboxesByName?.get(a.toLowerCase());return r?{type:"in",raw:e,value:a,mailboxId:r}:void 0}if(n.startsWith("account:")&&e.length>8){const a=e.slice(8),r=t.accountsByName?.get(a.toLowerCase());return r?{type:"account",raw:e,value:a,accountId:r}:void 0}}function Is(e,t={}){const n=e.split(/\s+/).filter(o=>o.length>0),a=[],r=[];for(const o of n){const i=ax(o,t);i?a.push(i):r.push(o)}return{freeText:r.join(" "),tokens:a}}function rx(e,t){return e.split(/\s+/).filter(n=>n.length>0&&n!==t.raw).join(" ")}function ox(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 ix=20,lx=new Set(Object.values($e)),cx=e=>e!==void 0&&lx.has(e)?e:void 0;function il({mailboxId:e,filterCategory:t}={}){const{searchQuery:n,mailboxNameIndex:a,accountNameIndex:r}=Ee(),o=ol(n),{freeText:i,tokens:l}=Is(o,{mailboxesByName:a,accountsByName:r}),u=o.length>0,d=cx(t),f=l.some(v=>v.type==="hasAttachment")?!0:void 0,m=l.some(v=>v.type==="isUnread")?!1:void 0,h=l.find(v=>v.type==="after"),p=l.find(v=>v.type==="before"),x=l.find(v=>v.type==="in")?.mailboxId??e,{data:y,isLoading:g}=ie({...xo({query:{query:i,mailboxId:x,limit:ix,...d!==void 0?{category:d}:{},...f!==void 0?{hasAttachment:f}:{},...m!==void 0?{isRead:m}:{},...h?{sentDateFrom:h.epochSeconds}:{},...p?{sentDateTo:p.epochSeconds}:{}}}),enabled:u,staleTime:6e4});return{hits:y?.items??[],isLoading:u&&g}}const ux=(e,t)=>e.createdAt!==t.createdAt?e.createdAt-t.createdAt:e.accountId.localeCompare(t.accountId),dx=e=>[...e].sort(ux);function ll(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:gt(e.sentDate),sentDate:e.sentDate,isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:un(e.category),suspicious:t}}const Fr=[{id:"personal",label:"Personal",category:$e.personal},{id:"transactional",label:"Transactional",category:$e.transactional},{id:"newsletter",label:"Newsletter",category:$e.newsletter},{id:"marketing",label:"Marketing",category:$e.marketing},{id:"social",label:"Social",category:$e.social},{id:"automated",label:"Automated",category:$e.automated},{id:"uncategorized",label:"Unclassified",category:$e.uncategorized}];function fx(e){const t=new Map(Fr.map(a=>[a.category,[]]));for(const a of e){const r=a.category??$e.uncategorized;(t.get(r)??t.get($e.uncategorized))?.push(a)}const n=[];for(const a of Fr){const r=t.get(a.category);r&&r.length>0&&n.push({id:a.id,label:a.label,threads:r})}return n}function cl(e,t){return e.fromName.toLowerCase().includes(t)||e.fromEmail.toLowerCase().includes(t)||e.subject.toLowerCase().includes(t)||e.snippet.toLowerCase().includes(t)}function ul(e,t){return t.every(n=>{switch(n.type){case"from":{const a=n.value.toLowerCase();return e.fromEmail.toLowerCase().includes(a)||e.fromName.toLowerCase().includes(a)}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 mx={sender:"sender",recipient:"recipient",subject:"subject",attachment:"attachment",body:"body",entities:"entities"};function hx(e){return mx[e]??e}function gx(e){return{id:e.messageId,sender:e.fromName??e.fromEmail??"Unknown",subject:e.subject??"(No subject)",snippet:e.snippet??"",date:gt(e.sentDate),unread:!e.isRead,flagged:e.hasStars===!0,threadId:e.threadId,mailboxId:e.mailboxId}}function dl(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 xx(e){return{id:e.messageId,sender:e.fromName??"Unknown",subject:e.subject??"(No subject)",snippet:"",date:e.sentDate!=null?gt(e.sentDate*1e3):"",threadId:e.threadId,matchedChunkLabel:hx(e.matchedChunkType),score:e.score,...e.mailboxIds[0]!=null?{mailboxId:e.mailboxIds[0]}:{}}}function fl(e,t){const n=new Set(t),a=[];for(const r of[...e].sort((o,i)=>i.score-o.score))n.has(r.threadId)||(n.add(r.threadId),a.push(xx(r)));return a}const px=768,bx=1024,ml=e=>e!=="desktop",Rs=()=>{const e=$n(`(min-width: ${px}px)`);return $n(`(min-width: ${bx}px)`)?"desktop":e?"tablet":"phone"},hl="remit.recentSearches",vx=5;function Hn(){try{const e=localStorage.getItem(hl);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(n=>typeof n=="string"):[]}catch{return[]}}function Br(e){const t=e.trim();if(!t)return Hn();const n=[t,...Hn().filter(a=>a!==t)].slice(0,vx);try{localStorage.setItem(hl,JSON.stringify(n))}catch{return n}return n}function gl({title:e,unreadCount:t,children:n,footer:a,searchFilter:r,searchResults:o,searchLoading:i,relatedResults:l,relatedLoading:u,onSelectSearchResult:d}){const{searchInput:f,onSearchChange:m,onSearchClear:h,mailboxNameIndex:p,accountNameIndex:b}=Ee(),x=na(),y=Rs(),[g,v]=c.useState(!1),[w,j]=c.useState(Hn),C=f.trim().length>0,N=Is(f,{mailboxesByName:p,accountsByName:b}).tokens.map(B=>({label:ox(B),onRemove:()=>m(rx(f,B))})),S=o??[],E=l??[],k=C?[{id:"top",label:"Top matches",results:S},{id:"related",label:"Related",results:E}]:[],T=!(S.length+E.length>0)&&(i===!0||u===!0);if(y==="phone"&&g){const B=$=>{j(Br(f)),v(!1),d?.($)};return s.jsx(Hd,{value:f,onChange:m,onClear:h,onCancel:()=>{v(!1),h()},filter:r,recentSearches:w,onPickRecent:m,sections:k,loading:T,onSelectResult:B,tokens:N})}const D=y!=="phone"&&C,I=B=>{j(Br(f)),d?.(B)},R=s.jsx(Xo,{value:f,sections:k,loading:T,onSelectResult:I,tokens:N}),O=D?r?s.jsx(Vn,{...r,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($d,{title:e,unreadCount:t,isDesktop:!1,showSearch:ml(y),onMenuClick:()=>x?.openNav(),searchValue:f,onSearchChange:m,onSearchClear:h,searchOpen:g,onSearchOpenChange:v}),s.jsx("div",{className:"min-h-0 flex-1",children:O}),a]})}const yx={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()},$r=()=>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))}),wx=({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(wt,{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"})]})},jx=({thread:e,active:t,onClick:n})=>{const a=!e.isRead;return s.jsxs("button",{type:"button",onClick:n,className:K("group w-full",Zt({active:t})),children:[a&&s.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),s.jsx(Qe,{name:e.fromName,email:e.fromEmail,size:"sm"}),s.jsx(es,{thread:e})]})};function xl({accounts:e,selectedMessageId:t,onSelectMessage:n,onSelectSearchResult:a}){const{searchQuery:r,mailboxNameIndex:o,accountNameIndex:i}=Ee(),l=Ct(),u=c.useMemo(()=>dx(e.filter(P=>!P.muted?.value)),[e]),[d,f]=c.useState("all"),[m,h]=c.useState("all"),[p,b]=c.useState(new Set),[x,y]=c.useState(!1),g=c.useCallback(P=>{b(A=>{const Q=new Set(A);return Q.has(P)?Q.delete(P):Q.add(P),Q})},[]),{data:v,isLoading:w,isError:j,refetch:C}=ie({...aa(),staleTime:6e4}),N=kt({queries:u.map(P=>({...He({path:{accountId:P.accountId}}),staleTime:1/0,meta:{softError:!0}}))}),S=c.useMemo(()=>{const P=new Map;for(let A=0;A<u.length;A++){const Q=u[A].accountId,ve=(N[A]?.data?.items??[]).reduce((ce,ye)=>ce+(ye.unseenCount??0),0);P.set(Q,ve)}return P},[u,N]),E=c.useMemo(()=>u.filter((P,A)=>{const Q=N[A];return Q?.isError?!An(Q.error):!1}),[u,N]),{freeText:k,tokens:M}=Is(r.trim().toLowerCase(),{mailboxesByName:o,accountsByName:i}),T=c.useMemo(()=>(v?.items??[]).filter(A=>d==="all"||(A.accountId??A.accountConfigId)===d).map(ll).filter(A=>(!k||cl(A,k))&&ul(A,M)),[v,d,k,M]),D=c.useMemo(()=>fx(T),[T]),I=c.useMemo(()=>u.length<=1?[]:[{id:"all",label:"All",active:d==="all"},...u.map(P=>({id:P.accountId,label:P.email.split("@")[0]??P.email,count:S.get(P.accountId),active:d===P.accountId}))],[u,S,d]),R=c.useMemo(()=>e.filter(P=>P.muted?.value).length,[e]),O=c.useMemo(()=>Array.from(S.values()).reduce((P,A)=>P+A,0),[S]),B=c.useMemo(()=>{const P=Array.from(p).map(A=>yx[A]).filter(A=>A!=null);return T.filter(A=>(m==="all"||A.category===m)&&P.every(Q=>Q(A))).map(dl)},[T,m,p]),{hits:$,isLoading:q}=il(),_=c.useMemo(()=>{const P=new Map;for(const Q of v?.items??[])P.set(Q.messageId,Q.threadId);const A=B.map(Q=>P.get(Q.id)).filter(Q=>Q!=null);return fl($,A)},[$,B,v]),U=c.useMemo(()=>{const P=xf(I.map(A=>({id:A.id,label:A.label,count:A.count,active:A.active})));return{categories:P.categories,filters:P.filters,sources:P.sources,sourcesNote:R>0?`+${R} muted`:void 0,selectedCategory:m,activeFilters:p,expanded:x,onExpandedChange:y,onSelectCategory:A=>h(A),onSelectSource:f,onToggleFilter:g,onClear:()=>{h("all"),f("all"),b(new Set)}}},[I,R,m,p,x,g]),te=D.length===0&&d==="all"&&k.length===0,J=w?s.jsxs("div",{className:"h-full overflow-y-auto",children:[s.jsx($r,{}),s.jsx($r,{})]}):j?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 py-12 text-sm text-fg-muted",children:[s.jsx(wt,{className:"size-8 text-danger"}),s.jsx("p",{children:"Couldn't load your messages"}),s.jsxs("button",{type:"button",onClick:()=>C(),className:"flex items-center gap-1 text-accent underline text-xs",children:[s.jsx(Do,{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(Ue,{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(Zr,{sections:D,Row:jx,briefCategory:m,onSelectBriefCategory:h,sources:I,sourcesNote:R>0?`+${R} muted`:void 0,onSelectSource:f,selectedThreadId:t,onSelectThread:n});return s.jsx(gl,{title:"Daily brief",unreadCount:O,footer:l?s.jsx(zo,{}):void 0,searchFilter:U,searchResults:B,searchLoading:w,relatedResults:_,relatedLoading:q,onSelectSearchResult:a,children:s.jsxs("div",{className:"flex h-full flex-col",children:[E.map(P=>s.jsx(wx,{accountEmail:P.email,accountId:P.accountId},P.accountId)),s.jsx("div",{className:"min-h-0 flex-1",children:J})]})})}const pl=({isOpen:e,title:t,description:n,confirmLabel:a,cancelLabel:r="Cancel",destructive:o=!1,isBusy:i=!1,onConfirm:l,onCancel:u})=>{const d=c.useRef(null),f=c.useCallback(m=>{m.key==="Escape"&&(m.preventDefault(),m.stopPropagation(),m.stopImmediatePropagation(),u())},[u]);return c.useEffect(()=>{if(e)return window.addEventListener("keydown",f,!0),()=>window.removeEventListener("keydown",f,!0)},[e,f]),c.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:r}),s.jsx("button",{type:"button",onClick:l,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:a})]})]})]}):null},Sx=10,bl=e=>({q:e?.toLowerCase()??"",limit:Sx}),Nx=(e,t)=>{if(!t)return;const n=t.toLowerCase();return e?.find(a=>a.normalizedEmail===n)};function kx(e){const t=new Date(e),n=new Date;return t.toDateString()===n.toDateString()?"today":Gs(t,{month:"short",year:"numeric"})}function vl(e){if(!e)return!0;const[,t]=e.split("@");return t?!t.includes("."):!0}const Cx="We can't verify the sender of this email, which could mean it's from an insecure source.",Ex="We couldn't read this sender's address, so we can't confirm who really sent this message.";function Ix(e,t){return{name:e.fromName??e.fromEmail??"Unknown",email:e.fromEmail??"",trust:e.senderTrust,firstSeenLabel:t?kx(t.createdAt):"unknown",inboundCount:t?.inboundCount,replyCount:t?.replyCount,addressUnverified:vl(e.fromEmail)}}function Rx(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 Mx(e,t){const n=t>0?t:void 0;if(vl(e.fromEmail))return{verdict:"mismatch",fromDomain:"",addressUnreadable:!0,summary:Ex,similarCount:n};const a=e.authenticity;if(!a)return{verdict:"caution",fromDomain:e.fromEmail?.split("@")[1]??"",summary:Cx};if(!a.dkimMismatch)return{verdict:"aligned",fromDomain:a.fromDomain,dkimDomain:a.dkimDomain,summary:a.dkimDomain?`We verified this message was really sent by ${a.fromDomain}.`:"Nothing looks unusual about this sender."};const r=a.fromDomain,o=a.dkimDomain,i=e.fromName&&e.fromName!==e.fromEmail?e.fromName:void 0,l=i?`The display name claims "${i}", but this message was actually sent from ${o??"another sender"} — not ${r}. Real senders use their own address.`:`This message claims to be from ${r}, but it was actually sent from ${o??"a different sender"}.`;return{verdict:"mismatch",fromDomain:r,dkimDomain:o,claimedBrand:i,summary:l,similarCount:n}}function yl(e,t){const n=e?.fromEmail??null,a=e?.subject??"",{data:r,error:o}=ie({...fo({query:bl(n??void 0)}),enabled:!!n,staleTime:3e4}),i=Nx(r?.items,n??void 0),l=[a,n].filter(Boolean).join(" "),{data:u,isLoading:d,error:f}=ie({...xo({query:{query:l,limit:5}}),enabled:!!(e&&l.length>3),staleTime:6e4,retry:1});return{data:c.useMemo(()=>{if(!e)return null;const h=(u?.items??[]).filter(g=>g.messageId!==e.messageId).map(g=>({id:g.messageId,mailboxId:t!=null&&g.mailboxIds.includes(t)?t:g.mailboxIds[0]??"",fromName:g.fromName??"",subject:g.subject??"(No subject)",timeLabel:g.sentDate!=null?gt(g.sentDate*1e3):"",matched:g.matchedChunkType})),p=Ix(e,i),b=Mx(e,h.length),x={value:e.category??"personal",overridden:i?.flags?.category?.value!=null&&i.flags.category.value!==e.category},y=Rx(i);return{sender:p,authenticity:b,category:x,flags:y,similar:h}},[e,i,u,t]),isSimilarLoading:d,similarError:f,similarErrorIsFatal:An(f),addressErrorIsFatal:An(o),addressId:i?.addressId,address:i}}function Tx(e,t){const n={...e??{}};for(const[a,r]of Object.entries(t))r==null?delete n[a]:n[a]={...r,setAt:r.setAt??Date.now()};return n}function wl({addressId:e,senderEmail:t}){const n=je(),{pushError:a}=ze(),r=_c({query:bl(t)}),{mutate:o,isPending:i}=pe({...go(),onMutate:async u=>{const d=u.body.flags??{};await n.cancelQueries({queryKey:r});const f=n.getQueryData(r);return n.setQueryData(r,m=>m&&{...m,items:m.items.map(h=>h.addressId===u.path.addressId?{...h,flags:Tx(h.flags,d)}:h)}),{previous:f}},onError:(u,d,f)=>{f?.previous!==void 0&&n.setQueryData(r,f.previous),a({title:"Couldn't update sender preference",detail:Ke(u),error:u})},onSettled:()=>{n.invalidateQueries({queryKey:r})}});return{updateFlags:c.useCallback(u=>{if(!e){po(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 Dx=e=>e==="vip"?"A sender you know":e==="wellknown"?"You've emailed them before":"Passed authentication",jl=e=>e.senderTrust!=="vip"&&e.senderTrust!=="wellknown"?!1:e.authenticity?.dkimMismatch!==!0;function Ax(e,t){e.recordEvent("rescue.candidates_surfaced",{count:String(t)})}function Ox(e,t){e.recordEvent("rescue.flow_opened",{count:String(t)})}function Px(e,t){e.recordEvent("rescue.committed",{selected:String(t.selected),total:String(t.total),destination:t.toInbox?"inbox":"other"})}function Sl(e,t){e.recordEvent("rescue.sent_to_junk",{count:String(t.count),senderTrust:t.senderTrust,wasRescuable:String(t.wasRescuable)})}const Lx=["personal","newsletter","marketing","automated","transactional","social"],zx=e=>{const{mailboxId:t,junkMailboxId:n,inboxMailboxId:a}=e;return t?n&&t===n?a?"notSpam":null:n?"markSpam":null:null},_x=e=>{const{similarError:t,similarErrorIsFatal:n,isSimilarLoading:a}=e;return t&&!n?"error":a?"loading":"ready"};function Fx(){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(Ue,{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 Bx({isOpen:e,current:t,onSelect:n,onCancel:a}){return e?s.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center","aria-hidden":"true",onClick:a,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:r=>r.stopPropagation(),onKeyDown:r=>r.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:Lx.map(r=>s.jsxs("button",{type:"button",onClick:()=>n(r),className:`flex min-h-11 items-center justify-between rounded px-3 text-left text-sm capitalize transition-colors hover:bg-surface-raised ${r===t?"font-semibold text-accent":"text-fg"}`,children:[r,r===t&&s.jsx("span",{className:"text-2xs text-fg-subtle",children:"current"})]},r))}),s.jsx("div",{className:"mt-6 flex justify-end",children:s.jsx("button",{type:"button",onClick:a,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 $x({thread:e,onClose:t,mailboxId:n,accountId:a,hideCloseButton:r}){const{data:o,addressId:i,isSimilarLoading:l,similarError:u,similarErrorIsFatal:d}=yl(e,n),[f,m]=c.useState(!1),[h,p]=c.useState(!1),b=e.fromEmail??void 0,{updateFlags:x,isPending:y}=wl({addressId:i,senderEmail:b}),{junkMailboxId:g}=ba(a),{inboxMailboxId:v}=pa(a),{moveMessages:w}=ct({mailboxId:n??"",threadId:e.threadId,accountId:a}),j=vs(),C=zx({mailboxId:n,junkMailboxId:g,inboxMailboxId:v}),N=c.useCallback(()=>{v&&w([e.messageId],v)},[v,w,e.messageId]),S=c.useCallback(()=>{g&&(Sl(j,{count:1,senderTrust:e.senderTrust,wasRescuable:jl(e)}),w([e.messageId],g))},[g,w,e,j]),E=c.useCallback(()=>{},[]),k=c.useCallback(()=>{const _=o?.flags?.vip!==!0;x({vip:{value:_}})},[o?.flags?.vip,x]),M=c.useCallback(()=>{const _=o?.flags?.muted!==!0;x({muted:{value:_}})},[o?.flags?.muted,x]),T=c.useCallback(()=>{o?.flags?.blocked===!0?x({blocked:{value:!1}}):m(!0)},[o?.flags?.blocked,x]),D=c.useCallback(()=>{m(!1),x({blocked:{value:!0}})},[x]),I=c.useCallback(()=>{const _=o?.flags?.unsubscribed!==!0;x({unsubscribed:{value:_}})},[o?.flags?.unsubscribed,x]),R=c.useCallback(_=>{p(!1),x({category:{value:_}})},[x]),O=i!==void 0,B={onToggleVip:O?k:void 0,onToggleMute:O?M:void 0,onToggleBlock:O?T:void 0,onToggleUnsubscribe:O?I:void 0,onReclassify:O?()=>p(!0):void 0,onNotSpam:C==="notSpam"?N:void 0,onMarkSpam:C==="markSpam"?S:void 0},$=({mailboxId:_,messageId:U,className:te,ariaLabel:J,children:P})=>s.jsx(et,{to:"/mail/$mailboxId",params:{mailboxId:_},search:A=>({...A,selectedMessageId:U}),className:te,"aria-label":J,children:P});if(!o)return s.jsx(Fx,{});const q=_x({similarError:u,similarErrorIsFatal:d,isSimilarLoading:l});return s.jsxs(s.Fragment,{children:[s.jsx(Lo,{data:o,onClose:t,hideCloseButton:r,onShowSimilar:E,actions:B,similarState:q,similarLinkComponent:$,className:"border-l-0 h-full w-full"}),s.jsx(pl,{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(Bx,{isOpen:h,current:o.category.value,onSelect:R,onCancel:()=>p(!1)})]})}const mn=({onClose:e,thread:t,mailboxId:n,accountId:a,hideCloseButton:r})=>t?s.jsx($x,{thread:t,onClose:e,mailboxId:n,accountId:a,hideCloseButton:r}):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(Ue,{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(Ue,{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."})]})]}),Rn="Open a message first",Na=({hasThread:e,intelligenceOpen:t,showIntelligenceToggle:n,onToggleIntelligence:a,onReply:r,onReplyAll:o,onForward:i,onDelete:l,canDelete:u,onToggleStar:d,isStarred:f,moveContext:m})=>{const[h,p]=c.useState(null),b=u??e,x=y=>()=>p(y);return s.jsx(qu,{hasThread:e,isStarred:f,onUnavailable:y=>p(Rn),unavailableHint:h,replyTitle:`Reply ${$t("reply")}`,replyAllTitle:`Reply all ${$t("replyAll")}`,forwardTitle:`Forward ${$t("forward")}`,deleteTitle:`Move to Trash ${$t("delete")}`,flagTitle:`Star ${$t("toggleStar")}`,onReply:r,onReplyAll:o,onForward:i,onDelete:b?l:x(Rn),onToggleStar:d,onMove:x(Rn),moveSlot:m?s.jsx(Es,{accountId:m.accountId,currentMailboxId:m.currentMailboxId,onMove:m.onMove,label:"Move to mailbox"}):void 0,children:n&&s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(to,{className:"size-4"}),title:"Intelligence","aria-label":t?"Hide intelligence sidebar":"Show intelligence sidebar","aria-pressed":t,onClick:a,className:t?"bg-accent-2-soft text-accent-2":void 0})})};function Kx(e){return{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,messageId:e.messageId,authenticity:e.authenticity}}function Nl(e,t){if(e)return Kx(e);if(t.messageId&&t.threadId&&t.mailboxId)return{threadId:t.threadId,mailboxId:t.mailboxId,messageId:t.messageId}}const kl=c.createContext(null);function ka(){const e=c.useContext(kl);if(!e)throw new Error("BriefPane.* must be used inside <BriefPane>");return e}function qx({selectedMessageId:e,children:t}){const n=Ce(),{searchInput:a}=Ee(),{selectedThreadId:r,selectedMailboxId:o}=Ht({strict:!1}),{data:i}=ie({...aa(),staleTime:6e4}),l=c.useMemo(()=>{if(e)return i?.items.find(p=>p.messageId===e)},[i,e]),u=c.useMemo(()=>Nl(l,{messageId:e,threadId:r,mailboxId:o}),[l,e,r,o]),d=c.useCallback(p=>{n({to:"/mail",search:b=>({...b,selectedMessageId:p,selectedThreadId:void 0,selectedMailboxId:void 0})})},[n]),f=c.useCallback(p=>{n({to:"/mail",search:b=>({...b,q:a||void 0,selectedMessageId:p.id,selectedThreadId:p.threadId,selectedMailboxId:p.mailboxId})})},[n,a]),m=c.useCallback(()=>{n({to:"/mail",search:p=>({...p,selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0})})},[n]),h={selectedMessageId:e,selectedThread:l,conversation:u,onSelectMessage:d,onSelectSearchResult:f,onCloseThread:m};return s.jsx(kl.Provider,{value:h,children:t})}function Ux(){const{selectedMessageId:e,onSelectMessage:t,onSelectSearchResult:n}=ka(),{accounts:a}=Ee();return s.jsx(xl,{accounts:a,selectedMessageId:e,onSelectMessage:t,onSelectSearchResult:n})}function Hx(){const{conversation:e}=ka(),{onToggleIntelligence:t}=Ee();return s.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[s.jsx(Na,{hasThread:!!e,intelligenceOpen:!1,showIntelligenceToggle:!1,onToggleIntelligence:t}),s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?s.jsx(ss,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,selectedMessageId:e.messageId,authenticity:e.authenticity}):s.jsx(ts,{})})]})}function Qx(){const{selectedThread:e,conversation:t,selectedMessageId:n,onSelectMessage:a,onSelectSearchResult:r,onCloseThread:o}=ka(),{accounts:i,intelligenceOpen:l,onToggleIntelligence:u}=Ee();return t?s.jsxs(s.Fragment,{children:[s.jsx(ss,{threadId:t.threadId,mailboxId:t.mailboxId,subject:t.subject,selectedMessageId:t.messageId,authenticity:t.authenticity,onBack:o,onOpenIntelligence:u}),s.jsx(ga,{isOpen:l,onClose:u,ariaLabel:"Message details",side:"right",children:s.jsx(mn,{onClose:u,thread:e,hideCloseButton:!0})})]}):s.jsx("div",{className:"h-full",children:s.jsx(xl,{accounts:i,selectedMessageId:n,onSelectMessage:a,onSelectSearchResult:r})})}const $s=Object.assign(qx,{List:Ux,Reading:Hx,Phone:Qx}),Wx=e=>{const t=new Set;return e.filter(n=>t.has(n.threadId)?!1:(t.add(n.threadId),!0))};function Cl({title:e,unreadCount:t,preset:n,selectedCategory:a,activeFilters:r,onSelectCategory:o,onToggleFilter:i,onSelectSource:l,onClearFilters:u,children:d,footer:f,searchResults:m,searchLoading:h,relatedResults:p,relatedLoading:b,onSelectSearchResult:x}){const[y,g]=c.useState(!1),v={categories:n.categories,filters:n.filters,sources:n.sources,selectedCategory:a,activeFilters:r,expanded:y,onExpandedChange:g,onSelectCategory:o,onSelectSource:l,onToggleFilter:i,onClear:u};return s.jsx(gl,{title:e,unreadCount:t,footer:f,searchFilter:v,searchResults:m,searchLoading:h,relatedResults:p,relatedLoading:b,onSelectSearchResult:x,children:s.jsx(Vn,{...v,children:d})})}const Vx={unread:e=>!e.isRead,attachment:e=>e.hasAttachment===!0};function Yx({selectedMessageId:e,onSelectMessage:t}){const{searchQuery:n,mailboxNameIndex:a,accountNameIndex:r}=Ee(),o=Ct(),[i,l]=c.useState("all"),[u,d]=c.useState(new Set),f=c.useCallback(I=>{d(R=>{const O=new Set(R);return O.has(I)?O.delete(I):O.add(I),O})},[]),m=c.useCallback(()=>{l("all"),d(new Set)},[]),{data:h,isLoading:p,isError:b,error:x,refetch:y,fetchNextPage:g,hasNextPage:v,isFetchingNextPage:w}=hi({queryKey:ho({query:{starred:!0,order:"desc"}}),queryFn:async({pageParam:I})=>{const{data:R}=await Fc({query:{starred:!0,order:"desc",continuationToken:I},throwOnError:!0});return R},initialPageParam:void 0,getNextPageParam:I=>I.continuationToken,staleTime:6e4}),{freeText:j,tokens:C}=Is(n.trim().toLowerCase(),{mailboxesByName:a,accountsByName:r}),N=c.useMemo(()=>{const I=Array.from(u).map(R=>Vx[R]).filter(R=>R!=null);return Wx((h?.pages??[]).flatMap(R=>R.items??[])).map(ll).filter(R=>(i==="all"||R.category===i)&&I.every(O=>O(R))&&(!j||cl(R,j))&&ul(R,C))},[h,i,u,j,C]),S=c.useMemo(()=>bf(),[]),E=c.useMemo(()=>N.map(dl),[N]),k=c.useMemo(()=>N.filter(I=>!I.isRead).length,[N]),M=p?"loading":b?"error":N.length===0?"empty":"ready",T=c.useCallback(()=>{const I=ta(ea());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:N.map(I=>s.jsx($o,{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:w,children:w?"Loading…":"Load more"}):null]});return s.jsx(Cl,{title:"Starred",unreadCount:k,preset:S,selectedCategory:i,activeFilters:u,onSelectCategory:l,onToggleFilter:f,onClearFilters:m,searchResults:E,searchLoading:p,onSelectSearchResult:I=>t?.(I.id),children:s.jsx(Uo,{listTitle:"Starred",sections:[{id:"flagged",threads:N}],flatList:!0,hideHeader:!0,listState:M,searchQuery:j?n:void 0,errorMessage:b?wo(x):void 0,onRetry:()=>y(),onReportError:T,selectedThreadId:e,onSelectThread:t,onSelectBriefCategory:()=>{},isDesktop:o,listBody:M==="ready"?D:void 0})})}const El=c.createContext(null);function Ca(){const e=c.useContext(El);if(!e)throw new Error("FlaggedPane.* must be used inside <FlaggedPane>");return e}function Gx({selectedMessageId:e,children:t}){const n=Ce(),{data:a}=ie({...aa(),staleTime:6e4}),r=c.useMemo(()=>{if(e)return a?.items.find(u=>u.messageId===e)},[a,e]),o=c.useCallback(u=>{n({to:"/mail/flagged",search:d=>({...d,selectedMessageId:u})})},[n]),i=c.useCallback(()=>{n({to:"/mail/flagged",search:u=>({...u,selectedMessageId:void 0})})},[n]),l={selectedMessageId:e,selectedThread:r,onSelectMessage:o,onCloseThread:i};return s.jsx(El.Provider,{value:l,children:t})}function Il(){const{selectedMessageId:e,onSelectMessage:t}=Ca();return s.jsx(Yx,{selectedMessageId:e,onSelectMessage:t})}function Xx(){const{selectedThread:e}=Ca(),{onToggleIntelligence:t}=Ee();return s.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[s.jsx(Na,{hasThread:!!e,intelligenceOpen:!1,showIntelligenceToggle:!1,onToggleIntelligence:t}),s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?s.jsx(ss,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,authenticity:e.authenticity}):s.jsx(ts,{})})]})}function Jx(){const{selectedThread:e,onCloseThread:t}=Ca(),{intelligenceOpen:n,onToggleIntelligence:a}=Ee();return e?s.jsxs(s.Fragment,{children:[s.jsx(ss,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,authenticity:e.authenticity,onBack:t,onOpenIntelligence:a}),s.jsx(ga,{isOpen:n,onClose:a,ariaLabel:"Message details",side:"right",children:s.jsx(mn,{onClose:a,thread:e,hideCloseButton:!0})})]}):s.jsx("div",{className:"h-full",children:s.jsx(Il,{})})}const Ks=Object.assign(Gx,{List:Il,Reading:Xx,Phone:Jx}),Zx={reply:"Reply",reply_all:"Reply All",forward:"Forward",new:"New Message"},ep=()=>{const e=c.useRef(!1);return c.useCallback(()=>{const n=document.querySelector("[data-subject-field]")?.value??"",o=(document.querySelector("[data-slate-editor]")?.textContent??"").replace(/--\s*/g,"").trim();return e.current=n.trim().length>0||o.length>0,e.current},[])},tp=()=>{const{state:e,closeCompose:t}=dt(),n=ep(),[a,r]=c.useState(!1),{isError:o,error:i,refetch:l}=ie({...tt(),staleTime:1/0}),u=c.useCallback(h=>{h||(n()?r(!0):t())},[t,n]),d=c.useCallback(()=>{r(!1),t()},[t]),f=c.useCallback(()=>{r(!1)},[]);if(!e.isOpen)return null;const m=Zx[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(ht,{title:"Couldn't load compose",error:i,onRetry:()=>{l()}})}):s.jsx("div",{className:"flex-1 overflow-hidden",children:s.jsx(xa,{mode:e.mode,account:e.account,sourceMessage:e.sourceMessage,onClose:t})})]})]}),a&&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"})]})]})})]})},sp={reply:"Reply",reply_all:"Reply All",forward:"Forward",new:"New Message"},Rl=()=>{const{state:e,closeCompose:t}=dt(),n=Ct(),{isError:a,error:r,refetch:o}=ie({...tt(),staleTime:1/0});if(!n)return s.jsx(tp,{});if(!e.isOpen)return null;const i=sp[e.mode]??"New Message",l=s.jsxs("header",{className:"flex items-center justify-between gap-2 px-4 py-3 border-b border-line shrink-0",children:[s.jsx("div",{className:"flex items-center gap-2 min-w-0",children:s.jsx("h2",{className:"text-lg font-semibold truncate",children:i})}),s.jsx("button",{type:"button",onClick:t,className:"p-2 rounded-md hover:bg-surface-raised transition-colors min-h-11 min-w-11 inline-flex items-center justify-center","aria-label":"Close",children:s.jsx(Pe,{className:"size-5"})})]});return a?s.jsxs("div",{className:"h-full flex flex-col bg-canvas",children:[l,s.jsx("div",{className:"flex-1 flex items-center justify-center p-4",children:s.jsx(ht,{title:"Couldn't load compose",error:r,onRetry:()=>{o()}})})]}):s.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-canvas",children:[l,s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:s.jsx(xa,{mode:e.mode,account:e.account,sourceMessage:e.sourceMessage,onClose:t},e.outboxMessageId??"new")})]})};function np(e){const t=e.toAddresses.join(", ");return{id:e.outboxMessageId,accountId:e.accountId,fromName:e.fromName??e.fromAddress??"Me",fromEmail:e.fromAddress??"",subject:e.subject??"(No subject)",snippet:t?`To: ${t}`:"(No recipients)",timeLabel:gt(e.updatedAt),isRead:!0}}function ap(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:gt(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0}}function rp({outboxMessages:e,accountId:t,imapThreads:n}){const a=e.filter(i=>i.status==="draft"&&i.accountId===t).map(np),r=n.map(ap),o=[];return a.length>0&&o.push({id:"remit-drafts",label:"Not yet sent (Remit)",threads:a}),r.length>0&&o.push({id:"imap-drafts",label:"On the server",threads:r}),o}function Ea(){const e=na();return!e||e.showNavPane?null:s.jsx(G,{variant:"ghost",size:"sm",icon:s.jsx(ia,{className:"size-4"}),onClick:e.openNav,"aria-label":"Open folders",className:"-ml-1 shrink-0"})}const op=({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})]}),ip=({row:e,isSelected:t,onOpen:n,onDelete:a,isDeleting:r})=>s.jsxs("button",{type:"button",onClick:()=>n(e.id),className:K("group",Zt({active:t})),children:[s.jsx(yo,{className:"size-7 shrink-0 text-fg-muted mt-0.5"}),s.jsx(es,{thread:e}),s.jsx("div",{className:"flex items-center gap-1 shrink-0",children:s.jsx("button",{type:"button",onClick:o=>{o.stopPropagation(),a(e.id)},disabled:r,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(We,{className:"size-3.5"})})})]}),lp=({row:e,isSelected:t,onOpen:n})=>{const a=!e.isRead;return s.jsxs("button",{type:"button",onClick:()=>n(e.id),className:K("group",Zt({active:t})),children:[a&&s.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),s.jsx(Qe,{name:e.fromName,email:e.fromEmail,size:"sm"}),s.jsx(es,{thread:e})]})};function cp({mailboxId:e,accountId:t,selectedMessageId:n,imapThreads:a,title:r,unreadCount:o}){const{openCompose:i,state:l}=dt(),u=Ce(),d=je(),{data:f}=ie(en()),m=c.useMemo(()=>rp({outboxMessages:f?.items??[],accountId:t,imapThreads:a}),[f?.items,t,a]),h=pe({...tn(),onSuccess:()=>{d.invalidateQueries({queryKey:ra()})}}),p=g=>{h.mutate({path:{outboxMessageId:g}})},b=g=>{n&&u({to:"/mail/$mailboxId",params:{mailboxId:e},search:{selectedMessageId:void 0}}),i({mode:"new",outboxMessageId:g})},x=g=>{u({to:"/mail/$mailboxId",params:{mailboxId:e},search:{selectedMessageId:g}})},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(Ea,{}),s.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:r}),(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(Wn,{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(op,{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(ip,{row:v,isSelected:l.isOpen&&v.id===l.outboxMessageId,onOpen:b,onDelete:p,isDeleting:h.isPending},v.id):s.jsx(lp,{row:v,isSelected:v.id===n,onOpen:x},v.id))})]},g.id))})]})}function up(e,t,n){const a=new Array(e);return new Proxy(a,{get(r,o,i){if(typeof o=="string"){const l=o.charCodeAt(0);if(l>=48&&l<=57){const u=+o;if(Number.isInteger(u)&&u>=0&&u<e){let d=r[u];if(!d){const f=t[u*2];d=r[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(r,o,i)}})}function Bt(e,t,n){let a=n.initialDeps??[],r,o=!0;function i(){const l=e();return(l.length!==a.length||l.some((d,f)=>a[f]!==d))&&(a=l,r=t(...l),n?.onChange&&!(o&&n.skipInitialOnChange)&&n.onChange(r),o=!1),r}return i.updateDeps=l=>{a=l},i}function Kr(e,t){if(e===void 0)throw new Error("Unexpected undefined");return e}const dp=(e,t)=>Math.abs(e-t)<1.01,fp=(e,t,n)=>{let a;return function(...r){e.clearTimeout(a),a=e.setTimeout(()=>t.apply(this,r),n)}};let ds;const Mn=()=>{if(ds!==void 0)return ds;if(typeof navigator>"u")return ds=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return ds=!0;const e=navigator.maxTouchPoints;return ds=navigator.platform==="MacIntel"&&e!==void 0&&e>0},qr=e=>{const{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},mp=e=>e,hp=e=>{const t=Math.max(e.startIndex-e.overscan,0),a=Math.min(e.endIndex+e.overscan,e.count-1)-t+1,r=new Array(a);for(let o=0;o<a;o++)r[o]=t+o;return r},gp=(e,t)=>{const n=e.scrollElement;if(!n)return;const a=e.targetWindow;if(!a)return;const r=i=>{const{width:l,height:u}=i;t({width:Math.round(l),height:Math.round(u)})};if(r(qr(n)),!a.ResizeObserver)return()=>{};const o=new a.ResizeObserver(i=>{const l=()=>{const u=i[0];if(u?.borderBoxSize){const d=u.borderBoxSize[0];if(d){r({width:d.inlineSize,height:d.blockSize});return}}r(qr(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(l):l()});return o.observe(n,{box:"border-box"}),()=>{o.unobserve(n)}},Js={passive:!0},xp=typeof window>"u"?!0:"onscrollend"in window,pp=(e,t,n)=>{const a=e.scrollElement;if(!a)return;const r=e.targetWindow;if(!r)return;const o=e.options.useScrollendEvent&&xp;let i=0;const l=o?null:fp(r,()=>t(i,!1),e.options.isScrollingResetDelay),u=m=>()=>{i=n(a),l?.(),t(i,m)},d=u(!0),f=u(!1);return a.addEventListener("scroll",d,Js),o&&a.addEventListener("scrollend",f,Js),()=>{a.removeEventListener("scroll",d),o&&a.removeEventListener("scrollend",f)}},bp=(e,t)=>pp(e,t,n=>{const{horizontal:a,isRtl:r}=e.options;return a?n.scrollLeft*(r&&-1||1):n.scrollTop}),vp=(e,t,n)=>{if(n.options.useCachedMeasurements){const a=n.indexFromElement(e),r=n.options.getItemKey(a);return n.itemSizeCache.get(r)??n.options.estimateSize(a)}if(t?.borderBoxSize){const a=t.borderBoxSize[0];if(a)return Math.round(a[n.options.horizontal?"inlineSize":"blockSize"])}if(!t){const a=n.indexFromElement(e),r=n.options.getItemKey(a),o=n.itemSizeCache.get(r);if(o!==void 0)return o}return e[n.options.horizontal?"offsetWidth":"offsetHeight"]},yp=(e,{adjustments:t=0,behavior:n},a)=>{var r,o;(o=(r=a.scrollElement)==null?void 0:r.scrollTo)==null||o.call(r,{[a.options.horizontal?"left":"top"]:e+t,behavior:n})},wp=yp;class jp{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,a,r;return((r=(a=(n=this.targetWindow)==null?void 0:n.performance)==null?void 0:a.now)==null?void 0:r.call(a))??Date.now()},this.observer=(()=>{let n=null;const a=()=>n||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:n=new this.targetWindow.ResizeObserver(r=>{r.forEach(o=>{const i=()=>{const l=o.target,u=this.indexFromElement(l);if(!l.isConnected){this.observer.unobserve(l);for(const[d,f]of this.elementsCache)if(f===l){this.elementsCache.delete(d);break}return}this.shouldMeasureDuringScroll(u)&&this.resizeItem(u,this.options.measureElement(l,o,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(i):i()})}));return{disconnect:()=>{var r;(r=a())==null||r.disconnect(),n=null},observe:r=>{var o;return(o=a())==null?void 0:o.observe(r,{box:"border-box"})},unobserve:r=>{var o;return(o=a())==null?void 0:o.unobserve(r)}}})(),this.range=null,this.setOptions=n=>{var a,r;const o={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:mp,rangeExtractor:hp,onChange:()=>{},measureElement:vp,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,anchorTo:"start",followOnAppend:!1,scrollEndThreshold:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:"estimate",useCachedMeasurements:!1};for(const h in n){const p=n[h];p!==void 0&&(o[h]=p)}const i=this.options;let l=null,u=null,d=!1;if(i!==void 0&&i.enabled&&o.enabled&&o.anchorTo==="end"&&this.scrollElement!==null){const h=i.count,p=o.count,b=this.getMeasurements(),x=h>0?((a=b[0])==null?void 0:a.key)??i.getItemKey(0):null,y=h>0?((r=b[h-1])==null?void 0:r.key)??i.getItemKey(h-1):null;if(p!==h||h>0&&p>0&&(o.getItemKey(0)!==x||o.getItemKey(p-1)!==y)){d=!0;const w=h>0?this.getVirtualItemForOffset(this.getScrollOffset())??b[0]:null;w&&(l=[w.key,this.getScrollOffset()-w.start]);const j=o.followOnAppend===!0?"auto":o.followOnAppend||null;j&&p>h&&this.isAtEnd(i.scrollEndThreshold)&&(h===0||o.getItemKey(p-1)!==y)&&(u=j)}}this.options=o,d&&(this.pendingMin=0,this.itemSizeCacheVersion++);let f=!1,m=0;if(l&&this.scrollOffset!==null){const[h,p]=l,b=this.getMeasurements(),{count:x,getItemKey:y}=this.options;let g=0;for(;g<x&&y(g)!==h;)g++;if(g<x){const v=b[g];if(v){const w=v.start+p;w!==this.scrollOffset&&(m=w-this.scrollOffset,this.scrollOffset=w,f=!0)}}}(f||u)&&(this.pendingScrollAnchor=[f?l[0]:null,f?l[1]:0,u,m])},this.notify=n=>{var a,r;(r=(a=this.options).onChange)==null||r.call(a,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 a=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==a){if(this.cleanup(),!a){this.maybeNotify();return}if(this.scrollElement=a,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((n=this.scrollElement)==null?void 0:n.window)??null,this.elementsCache.forEach(o=>{this.observer.observe(o)}),this.unsubs.push(this.options.observeElementRect(this,o=>{this.scrollRect=o,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(o,i)=>{if(i&&this._intendedScrollOffset===null&&o===this.scrollOffset)return;this._intendedScrollOffset!==null&&Math.abs(o-this._intendedScrollOffset)<1.5&&(o=this._intendedScrollOffset),this._intendedScrollOffset=null,this.scrollAdjustments=0;const l=this.getScrollOffset();this.scrollDirection=i?l===o?this.scrollDirection:l<o?"forward":"backward":null,this.scrollOffset=o,this.isScrolling=i,this._flushIosDeferredIfReady(),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),"addEventListener"in this.scrollElement){const o=this.scrollElement,i=()=>{this._iosTouching=!0,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)},l=()=>{this._iosTouching=!1,!(!Mn()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};o.addEventListener("touchstart",i,Js),o.addEventListener("touchend",l,Js),this.unsubs.push(()=>{o.removeEventListener("touchstart",i),o.removeEventListener("touchend",l),this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)})}this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}const r=this.pendingScrollAnchor;if(this.pendingScrollAnchor=null,r&&this.scrollElement&&this.options.enabled){const[o,i,l,u]=r;o!==null&&!l&&(Mn()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?u!==0&&(this._iosDeferredAdjustment+=u):this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})),l&&this.scrollToEnd({behavior:l})}},this._flushIosDeferredIfReady=()=>{if(this._iosDeferredAdjustment===0||this.isScrolling||this._iosTouching||this._iosJustTouchEnded)return;const n=this.getScrollOffset(),a=this.getMaxScrollOffset();if(n<0||n>a)return;const r=this._iosDeferredAdjustment;this._iosDeferredAdjustment=0,this._scrollToOffset(n,{adjustments:this.scrollAdjustments+=r,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,a,r,o,i,l,u,d)=>(this.prevLanes!==void 0&&this.prevLanes!==l&&(this.lanesChangedFlag=!0),this.prevLanes=l,this.pendingMin=null,{count:n,paddingStart:a,scrollMargin:r,getItemKey:o,enabled:i,lanes:l,laneAssignmentMode:u,gap:d}),{key:!1}),this.getMeasurements=Bt(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:n,paddingStart:a,scrollMargin:r,getItemKey:o,enabled:i,lanes:l,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),l===1){const g=n*2;let v=this._flatMeasurements;if(!v||v.length<g){const C=new Float64Array(g);v&&h>0&&C.set(v.subarray(0,h*2)),v=C,this._flatMeasurements=v}let w;if(h===0)w=a+r;else{const C=h-1;w=v[C*2]+v[C*2+1]+d}for(let C=h;C<n;C++){const N=o(C),S=m.get(N),E=typeof S=="number"?S:this.options.estimateSize(C);v[C*2]=w,v[C*2+1]=E,w+=E+d}const j=up(n,v,o);return this.measurementsCache=j,j}const p=this.measurementsCache.slice(0,h),b=new Array(l).fill(void 0),x=new Float64Array(l);let y=0;for(let g=0;g<h;g++){const v=p[g];v&&(b[v.lane]===void 0&&y++,b[v.lane]=g,x[v.lane]=v.end)}for(let g=h;g<n;g++){const v=o(g),w=this.laneAssignments.get(g);let j,C;const N=u==="estimate"||m.has(v);if(w!==void 0&&this.options.lanes>1){j=w;const M=b[j],T=M!==void 0?p[M]:void 0;C=T?T.end+d:a+r}else if(y===l){let M=0,T=x[0],D=b[0];for(let I=1;I<l;I++){const R=x[I];(R<T||R===T&&b[I]<D)&&(M=I,T=R,D=b[I])}j=M,C=T+d,N&&this.laneAssignments.set(g,j)}else j=g%this.options.lanes,C=a+r,N&&this.laneAssignments.set(g,j);const S=m.get(v),E=typeof S=="number"?S:this.options.estimateSize(g),k=C+E;p[g]={index:g,start:C,size:E,end:k,key:v,lane:j},b[j]===void 0&&y++,b[j]=g,x[j]=k}return this.measurementsCache=p,p},{key:!1,debug:()=>this.options.debug}),this.calculateRange=Bt(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(n,a,r,o)=>n.length===0||a===0?(this.range=null,null):(this.range=Np(n,a,r,o,o===1&&this._flatMeasurements!=null?this._flatMeasurements:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=Bt(()=>{let n=null,a=null;const r=this.calculateRange();return r&&(n=r.startIndex,a=r.endIndex),this.maybeNotify.updateDeps([this.isScrolling,n,a]),[this.options.rangeExtractor,this.options.overscan,this.options.count,n,a]},(n,a,r,o,i)=>o===null||i===null?[]:n({startIndex:o,endIndex:i,overscan:a,count:r}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=n=>{const a=this.options.indexAttribute,r=n.getAttribute(a);return r?parseInt(r,10):(console.warn(`Missing attribute name '${a}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=n=>{var a;if(!this.scrollState||this.scrollState.behavior!=="smooth")return!0;const r=this.scrollState.index??((a=this.getVirtualItemForOffset(this.scrollState.lastTargetOffset))==null?void 0:a.index);if(r!==void 0&&this.range){const o=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),i=Math.max(0,r-o),l=Math.min(this.options.count-1,r+o);return n>=i&&n<=l}return!0},this.measureElement=n=>{if(!n){this.elementsCache.forEach((i,l)=>{i.isConnected||(this.observer.unobserve(i),this.elementsCache.delete(l))});return}const a=this.indexFromElement(n),r=this.options.getItemKey(a),o=this.elementsCache.get(r);o!==n&&(o&&this.observer.unobserve(o),this.observer.observe(n),this.elementsCache.set(r,n)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(a)&&this.resizeItem(a,this.options.measureElement(n,void 0,this))},this.resizeItem=(n,a)=>{var r,o;if(n<0||n>=this.options.count)return;let i,l,u;const d=this._flatMeasurements;if(this.options.lanes===1&&d!==null)u=this.options.getItemKey(n),l=d[n*2],i=d[n*2+1];else{const h=this.measurementsCache[n];if(!h)return;u=h.key,l=h.start,i=h.size}const f=this.itemSizeCache.get(u)??i,m=a-f;if(m!==0){const h=this.options.anchorTo==="end"&&((r=this.scrollState)==null?void 0:r.behavior)!=="smooth"&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,p=h?this.getTotalSize():0,b=((o=this.scrollState)==null?void 0:o.behavior)!=="smooth"&&(this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[n]??{index:n,key:u,start:l,size:i,end:l+i,lane:0},m,this):l<this.getScrollOffset()+this.scrollAdjustments&&(!this.itemSizeCache.has(u)||this.scrollDirection!=="backward"));(this.pendingMin===null||n<this.pendingMin)&&(this.pendingMin=n),this.itemSizeCache.set(u,a),this.itemSizeCacheVersion++,h?this.applyScrollAdjustment(this.getTotalSize()-p):b&&this.applyScrollAdjustment(m),this.notify(!1)}},this.getVirtualItems=Bt(()=>[this.getVirtualIndexes(),this.getMeasurements()],(n,a)=>{const r=[];for(let o=0,i=n.length;o<i;o++){const l=n[o],u=a[l];r.push(u)}return r},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=n=>{const a=this.getMeasurements();if(a.length===0)return;const r=this._flatMeasurements,o=this.options.lanes===1&&r!=null,i=Ml(0,a.length-1,o?l=>r[l*2]:l=>Kr(a[l]).start,n);return Kr(a[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,a,r=0)=>{if(!this.scrollElement)return 0;const o=this.getSize(),i=this.getScrollOffset();a==="auto"&&(a=n>=i+o?"end":"start"),a==="center"?n+=(r-o)/2:a==="end"&&(n-=o);const l=this.getMaxScrollOffset();return Math.max(Math.min(l,n),0)},this.getOffsetForIndex=(n,a="auto")=>{n=Math.max(0,Math.min(n,this.options.count-1));const r=this.getSize(),o=this.getScrollOffset(),i=this.measurementsCache[n];if(!i)return;if(a==="auto")if(i.end>=o+r-this.options.scrollPaddingEnd)a="end";else if(i.start<=o+this.options.scrollPaddingStart)a="start";else return[o,a];if(a==="end"&&n===this.options.count-1)return[this.getMaxScrollOffset(),a];const l=a==="end"?i.end+this.options.scrollPaddingEnd:i.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(l,a,i.size),a]},this.scrollToOffset=(n,{align:a="start",behavior:r="auto"}={})=>{const o=this.getOffsetForAlignment(n,a),i=this.now();this.scrollState={index:null,align:a,behavior:r,startedAt:i,lastTargetOffset:o,stableFrames:0},this._scrollToOffset(o,{adjustments:void 0,behavior:r}),this.scheduleScrollReconcile()},this.scrollToIndex=(n,{align:a="auto",behavior:r="auto"}={})=>{n=Math.max(0,Math.min(n,this.options.count-1));const o=this.getOffsetForIndex(n,a);if(!o)return;const[i,l]=o,u=this.now();this.scrollState={index:n,align:l,behavior:r,startedAt:u,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:r}),this.scheduleScrollReconcile()},this.scrollBy=(n,{behavior:a="auto"}={})=>{const r=this.getScrollOffset()+n,o=this.now();this.scrollState={index:null,align:"start",behavior:a,startedAt:o,lastTargetOffset:r,stableFrames:0},this._scrollToOffset(r,{adjustments:void 0,behavior:a}),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 a=this.getMeasurements();let r;if(a.length===0)r=this.options.paddingStart;else if(this.options.lanes===1){const o=a.length-1,i=this._flatMeasurements;i!=null?r=i[o*2]+i[o*2+1]:r=((n=a[o])==null?void 0:n.end)??0}else{const o=Array(this.options.lanes).fill(null);let i=a.length-1;for(;i>=0&&o.some(l=>l===null);){const l=a[i];o[l.lane]===null&&(o[l.lane]=l.end),i--}r=Math.max(...o.filter(l=>l!==null))}return Math.max(r-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{const n=[];if(this.itemSizeCache.size===0)return n;const a=this.getMeasurements();for(const r of a)r&&this.itemSizeCache.has(r.key)&&n.push({index:r.index,key:r.key,start:r.start,size:r.size,end:r.end,lane:r.lane});return n},this._scrollToOffset=(n,{adjustments:a,behavior:r})=>{this._intendedScrollOffset=n+(a??0),this.options.scrollToFn(n,{behavior:r,adjustments:a},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&&(Mn()&&(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 a=this.scrollState.index!=null?this.getOffsetForIndex(this.scrollState.index,this.scrollState.align):void 0,r=a?a[0]:this.scrollState.lastTargetOffset,o=1,i=r!==this.scrollState.lastTargetOffset;if(!i&&dp(r,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=o){this.getScrollOffset()!==r&&this._scrollToOffset(r,{adjustments:void 0,behavior:"auto"}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,i){const l=this.getSize()||600,u=Math.abs(r-this.getScrollOffset()),d=this.scrollState.behavior==="smooth"&&u>l;this.scrollState.lastTargetOffset=r,d||(this.scrollState.behavior="auto"),this._scrollToOffset(r,{adjustments:void 0,behavior:d?"smooth":"auto"})}this.scheduleScrollReconcile()}}const Ml=(e,t,n,a)=>{for(;e<=t;){const r=(e+t)/2|0,o=n(r);if(o<a)e=r+1;else if(o>a)t=r-1;else return r}return e>0?e-1:0};function Sp(e,t,n){let a=0;for(;a<=t;){const r=(a+t)/2|0,o=e[r*2];if(o<n)a=r+1;else if(o>n)t=r-1;else return r}return a>0?a-1:0}function Np(e,t,n,a,r){const o=e.length-1;if(e.length<=a)return{startIndex:0,endIndex:o};if(a===1&&r!==null){const d=Sp(r,o,n);let f=d;const m=n+t;for(;f<o&&r[f*2]+r[f*2+1]<m;)f++;return{startIndex:d,endIndex:f}}let l=Ml(0,o,d=>e[d].start,n),u=l;if(a===1)for(;u<o&&e[u].end<n+t;)u++;else if(a>1){const d=Array(a).fill(0);for(;u<o&&d.some(m=>m<n+t);){const m=e[u];d[m.lane]=m.end,u++}const f=Array(a).fill(n+t);for(;l>=0&&f.some(m=>m>=n);){const m=e[l];f[m.lane]=m.start,l--}l=Math.max(0,l-l%a),u=Math.min(o,u+(a-1-u%a))}return{startIndex:l,endIndex:u}}const Tn=typeof document<"u"?c.useLayoutEffect:c.useEffect;function kp({useFlushSync:e=!0,directDomUpdates:t=!1,directDomUpdatesMode:n="transform",...a}){const r=c.useReducer(d=>d+1,0)[1],o=c.useRef({enabled:t,mode:n,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});o.current.enabled=t,o.current.mode=n;const i=d=>{const f=o.current;if(!f.enabled||!f.container)return;const m=d.getTotalSize();if(m!==f.lastSize){f.lastSize=m;const g=d.options.horizontal?"width":"height";f.container.style[g]=`${m}px`}const h=!!d.options.horizontal,p=f.mode==="transform",b=h?"left":"top",x=d.options.scrollMargin,y=d.getVirtualItems();for(const g of y){const v=g.start-x,w=d.elementsCache.get(g.key);w&&f.lastPositions.get(w)!==v&&(f.lastPositions.set(w,v),p?w.style.transform=h?`translate3d(${v}px, 0, 0)`:`translate3d(0, ${v}px, 0)`:w.style[b]=`${v}px`)}},l={...a,onChange:(d,f)=>{var m;const h=o.current;let p=!0;if(h.enabled){i(d);const b=d.range,x=h.prevRange;p=!x||x.isScrolling!==d.isScrolling||x.startIndex!==b?.startIndex||x.endIndex!==b?.endIndex,p&&(h.prevRange=b?{startIndex:b.startIndex,endIndex:b.endIndex,isScrolling:d.isScrolling}:null)}p&&(e&&f?Xn.flushSync(r):r()),(m=a.onChange)==null||m.call(a,d,f)}},[u]=c.useState(()=>{const d=new jp(l);return Object.assign(d,{containerRef:f=>{const m=o.current;if(m.container=f,m.lastSize=null,f&&m.enabled){const h=d.getTotalSize();m.lastSize=h;const p=d.options.horizontal?"width":"height";f.style[p]=`${h}px`}}})});return u.setOptions(l),Tn(()=>u._didMount(),[]),Tn(()=>u._willUpdate()),Tn(()=>{i(u)}),u}function Cp(e){return kp({observeElementRect:gp,observeElementOffset:bp,scrollToFn:wp,...e})}const Ep=(e,t,n)=>{const a=e.indexOf(n);if(a===-1)return[];const r=t===void 0?-1:e.indexOf(t);if(r===-1)return[n];const o=Math.min(r,a),i=Math.max(r,a);return e.slice(o,i+1)},Ip=(e,t,n)=>{if(e.length===0)return;const a=t===void 0?-1:e.indexOf(t);if(a===-1)return n>0?e[0]:e[e.length-1];const r=Math.min(Math.max(a+n,0),e.length-1);return e[r]},Rp=e=>{const[t,n]=c.useState(new Set),[a,r]=c.useState(void 0),o=c.useCallback(b=>t.has(b),[t]),i=c.useCallback(b=>{r(b),n(x=>{const y=new Set(x);return y.has(b)?y.delete(b):y.add(b),y})},[]),l=c.useCallback(b=>{r(b),n(x=>{if(x.has(b))return x;const y=new Set(x);return y.add(b),y})},[]),u=c.useCallback(b=>{n(x=>{if(!x.has(b))return x;const y=new Set(x);return y.delete(b),y})},[]),d=c.useCallback(b=>{n(new Set(b))},[]),f=c.useCallback(()=>{r(void 0),n(new Set)},[]),m=c.useCallback(b=>{n(x=>b.every(g=>x.has(g))?new Set:new Set(b))},[]),h=c.useCallback(b=>{r(b)},[]),p=c.useCallback((b,x)=>{n(y=>{const g=Ep(b,a,x);if(g.length===0)return y;const v=new Set(y);for(const w of g)v.add(w);return v}),r(y=>y??x)},[a]);return{selectedIds:t,selectedCount:t.size,hasSelection:t.size>0,isSelected:o,toggle:i,select:l,deselect:u,selectAll:d,clearSelection:f,toggleAll:m,selectRange:p,setAnchor:h,anchorId:a}},Mp=e=>{const t=pe(Bc()),{mutate:n}=t;return{preview:c.useCallback(r=>{e&&n({path:{accountId:e},body:So(r)})},[e,n]),reset:t.reset,matchedCount:t.data?.matchedCount,messageIds:t.data?.messageIds,isPending:t.isPending,isError:t.isError,error:t.error}},Tp=new Set(["Complete","Failed"]),Ur=e=>e!==void 0&&Tp.has(e),Dp=1e3,Ap=15e3,Op=e=>{const t=Math.max(0,e),n=Dp*2**t;return Math.min(n,Ap)},Pp=e=>{const[t,n]=c.useState(),a=pe({...$c(),onSuccess:m=>n(m.organizeJobId)}),{mutate:r}=a,o=ie({...Kc({path:{accountId:e??"",organizeJobId:t??""}}),enabled:!!e&&!!t,refetchInterval:m=>{const h=m.state.data?.state;return Ur(h)?!1:Op(m.state.dataUpdateCount)}}),i=c.useCallback(m=>{e&&(n(void 0),r({path:{accountId:e},body:So(m)}))},[e,r]),l=o.data,u=l?.state??a.data?.state,d=Ur(l?.state),f={state:u,matchedCount:l?.matchedCount??0,appliedCount:l?.appliedCount??0,failedCount:l?.failedCount??0,errorMessage:l?.errorMessage??""};return{start:i,progress:f,isStarting:a.isPending,isRunning:!!t&&!d,isDone:d,isError:a.isError||o.isError,error:a.error??o.error}},Lp=({draft:e,scope:t,name:n,pickedDate:a})=>{if(!du(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"&&a==="")return"Pick the date this should stop on."},zp=(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"}},_p=(e,t,n)=>e==="just-these"?t:n,Fp=[{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 Bp({accountId:e,mailboxId:t,selectedMessageIds:n,anchorMessageId:a,matchedCount:r,onClose:o}){const[i,l]=c.useState("all-like-these"),[u,d]=c.useState(""),[f,m]=c.useState(""),[h,p]=c.useState(""),{data:b}=ie({...He({path:{accountId:e}}),staleTime:1/0}),x=c.useMemo(()=>Sa(b?.items??[]).map(M=>({id:M.mailboxId,label:Ys(M.fullPath)})),[b?.items]),y=c.useMemo(()=>({anchorMessageId:a,matchOperator:"And",literalClauses:[],moveMailboxId:u||void 0,expiresAt:i==="temporary"?fu(h):void 0}),[a,u,i,h]),{moveMessages:g}=ct({mailboxId:t,accountId:e}),v=Pp(e),w=mu(e),j=n.length,C=_p(i,j,r),N=Lp({draft:y,scope:i,name:f,pickedDate:h}),S=()=>{if(!N)switch(i){case"just-these":u&&g(n,u),o();return;case"all-like-these":v.start(y);return;case"standing":w.createFilter(y,"standing",f.trim());return;case"temporary":w.createFilter(y,"temporary",f.trim());return}};if(v.isRunning||v.isDone)return s.jsx($p,{progress:v.progress,isDone:v.isDone,onClose:o});if(w.isSuccess)return s.jsxs("div",{className:"flex flex-col items-center gap-3 px-5 py-8 text-center",children:[s.jsx(la,{className:"size-8 text-positive"}),s.jsx("p",{className:"text-sm font-medium text-fg",children:"Filter saved"}),s.jsx("p",{className:"max-w-xs text-xs text-fg-muted",children:"You can see it, and when it expires, under Settings › Filters."}),s.jsx(G,{variant:"primary",onClick:o,className:"mt-2",children:"Done"})]});const E=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:[r," similar message",r===1?"":"s"," found",j>0?` from ${j} selected`:"","."]})]}),s.jsxs("div",{className:"min-h-0 flex-1 space-y-5 overflow-y-auto px-5 py-4",children:[s.jsxs("section",{className:"space-y-2 rounded-lg border border-line bg-surface-sunken p-3",children:[s.jsxs("p",{className:"text-sm leading-relaxed text-fg-muted",children:[i==="standing"&&s.jsx("span",{className:"font-semibold text-fg",children:"Always keep "}),i==="standing"?"":"Keep ",i==="just-these"?"these":"emails like these"," in"]}),s.jsxs(uu,{"aria-label":"Destination folder",value:u,onChange:k=>d(k.target.value),children:[s.jsx("option",{value:"",children:"Choose a folder…"}),x.map(k=>s.jsx("option",{value:k.id,children:k.label},k.id))]}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx(qe,{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:Fp.map(k=>{const M=i===k.id;return s.jsxs("button",{type:"button",onClick:()=>l(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)})}),E&&s.jsxs("section",{className:"space-y-2",children:[s.jsx(no,{value:f,onChange:k=>m(k.target.value),placeholder:"Name this filter (e.g. Travel)","aria-label":"Filter name"}),i==="temporary"&&s.jsxs("label",{className:"flex items-center gap-2 text-xs text-fg-muted",children:["Until",s.jsx("input",{type:"date",value:h,onChange:k=>p(k.target.value),"aria-label":"Expiry date",className:"rounded-md border border-line bg-surface-sunken px-2 py-1 text-sm text-fg"})]})]})]}),s.jsxs("div",{className:"space-y-2 border-t border-line px-5 py-3",children:[N&&s.jsx("p",{className:"text-xs text-fg-subtle",role:"status",children:N}),w.isError&&s.jsx("p",{className:"text-xs text-danger",role:"alert",children:"Couldn't save the filter. Please try again."}),s.jsx(G,{variant:"primary",onClick:S,disabled:!!N||w.isPending||v.isStarting,className:"w-full",children:w.isPending?"Saving…":zp(i,C)}),s.jsx(G,{variant:"ghost",onClick:o,className:"w-full",children:"Not now"})]})]})}function $p({progress:e,isDone:t,onClose:n}){const a=e.state==="Failed";return s.jsxs("div",{className:"flex flex-col items-center gap-3 px-5 py-8 text-center",children:[t?a?s.jsx("span",{className:"text-sm font-semibold text-danger",children:"Organize failed"}):s.jsx(la,{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&&!a&&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&&a&&s.jsx("p",{className:"max-w-xs text-xs text-fg-muted",children:e.errorMessage||"Something went wrong. Please try again."}),t&&s.jsx(G,{variant:"primary",onClick:n,className:"mt-2",children:"Done"})]})}function Kp({open:e,accountId:t,mailboxId:n,selectedMessageIds:a,onClose:r}){const o=a[0],{preview:i,reset:l,matchedCount:u,isPending:d,isError:f,error:m}=Mp(t);c.useEffect(()=>{!e||!o||i({anchorMessageId:o,matchOperator:"And",literalClauses:[]})},[e,o,i]);const h=()=>{l(),r()};return e?s.jsx(so,{open:e,onClose:h,title:"Organize similar mail",children:d||u===void 0?f?s.jsxs("div",{className:"flex flex-col items-center gap-3 px-5 py-8 text-center",children:[s.jsx("p",{className:"text-sm font-medium text-danger",children:"Couldn't find similar messages"}),s.jsx("p",{className:"max-w-xs text-xs text-fg-muted",children:m instanceof Error?m.message:"Please try again."}),s.jsx(G,{variant:"ghost",onClick:h,className:"mt-2",children:"Close"})]}):s.jsxs("div",{className:"flex flex-col items-center gap-3 px-5 py-10 text-center",children:[s.jsx(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(Bp,{accountId:t,mailboxId:n,selectedMessageIds:a,anchorMessageId:o,matchedCount:u,onClose:h})}):null}const qp=({selectedCount:e,onDelete:t,onClearSelection:n,onMarkAsRead:a,onMove:r,onOrganize:o,isDeleting:i=!1,isMoving:l=!1,accountId:u,currentMailboxId:d,moveDisabledHint:f})=>{const m=i||l;if(e===0)return null;const h=!!r&&!!u&&!!d,p=!!o&&!!u&&!!d&&!f;return s.jsxs("div",{className:"sticky top-0 z-10 flex items-center justify-between px-3 py-2 bg-surface-sunken border-b border-line",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("button",{type:"button",onClick:n,className:"min-h-11 min-w-11 inline-flex items-center justify-center rounded hover:bg-surface-raised transition-colors","aria-label":"Clear selection",children:s.jsx(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:[p&&o&&s.jsxs("button",{type:"button",onClick:m?void 0:o,className:"min-h-11 inline-flex items-center justify-center gap-1.5 px-3 rounded text-sm font-medium transition-colors hover:bg-surface-raised","aria-label":"Organize similar messages",children:[s.jsx(Ue,{className:"size-4"}),s.jsx("span",{className:"hidden sm:inline",children:"Organize"})]}),a&&s.jsx("button",{type:"button",onClick:m?void 0:a,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(Ss,{className:"size-4"})}),h&&r&&u&&d&&s.jsx(Es,{accountId:u,currentMailboxId:d,onMove:m?()=>{}:r,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(We,{className:"size-4"}),s.jsx("span",{className:"hidden sm:inline",children:i?"Deleting...":"Delete"})]})]})]})},Up=8,Hp=({onLongPress:e,delayMs:t=500})=>{const n=c.useRef(null),a=c.useRef(null),r=c.useCallback(()=>{n.current&&(clearTimeout(n.current),n.current=null),a.current=null},[]),o=c.useCallback(d=>{r(),a.current={x:d.clientX,y:d.clientY},n.current=setTimeout(()=>{e(),r()},t)},[e,t,r]),i=c.useCallback(d=>{if(!a.current)return;const f=d.clientX-a.current.x,m=d.clientY-a.current.y;Math.sqrt(f*f+m*m)>Up&&r()},[r]),l=c.useCallback(()=>{r()},[r]),u=c.useCallback(()=>{r()},[r]);return{handlers:{onPointerDown:o,onPointerMove:i,onPointerUp:l,onPointerCancel:u}}},Qp=(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:gt(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:un(e.category),messageCount:t,suspicious:n}},Wp=({thread:e,mailboxId:t,accountId:n,isSelected:a,isFocused:r=!1,isChecked:o,onToggleCheck:i,onRowSelect:l,messageCount:u,isMultiSelectMode:d=!1,onLongPress:f,isDesktop:m=!0,density:h="comfortable"})=>{const p=je(),b=e.messageId,x=Qp(e,u),y=N=>{N.preventDefault(),N.stopPropagation(),i(e.messageId)},g=c.useCallback(N=>{if(!m)return;l(b,{shiftKey:N.shiftKey,metaKey:N.metaKey,ctrlKey:N.ctrlKey})&&(N.preventDefault(),N.stopPropagation())},[m,l,b]),v=c.useCallback(()=>{f?.(b)},[f,b]),w=Hp({onLongPress:v,delayMs:500}),j=c.useCallback(()=>{p.prefetchQuery(sa({path:{messageId:e.messageId}}))},[p,e.messageId]),C=!e.isRead;return h==="compact"?s.jsx(et,{to:"/mail/$mailboxId",params:{mailboxId:t},search:N=>({...N,selectedMessageId:e.messageId}),"data-message-row":!0,onClick:g,onMouseEnter:j,onFocus:j,...!m&&w.handlers,className:fe(_o({active:a,focused:r}),o&&"bg-accent-soft",!m&&"min-h-11"),children:s.jsx(Fo,{thread:x})}):s.jsxs(et,{to:"/mail/$mailboxId",params:{mailboxId:t},search:N=>({...N,selectedMessageId:e.messageId}),"data-message-row":!0,onClick:g,onMouseEnter:j,onFocus:j,...!m&&w.handlers,className:fe("group",Zt({active:a,focused:r}),o&&"bg-accent-soft",!m&&"min-h-11"),children:[C&&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(Qe,{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(js,{className:"size-3"})})]}),s.jsx(es,{thread:x,badge:e.autoMoved&&s.jsx(Mi,{accountId:n,messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,autoMoved:e.autoMoved,size:"sm"})})]})},Vp=c.memo(Wp),Yp=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:gt(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:un(e.category),suspicious:t}},Gp=({thread:e,mailboxId:t,accountId:n,isSelected:a,isFocused:r,isChecked:o,onToggleCheck:i,onRowSelect:l,isMultiSelectMode:u,onLongPress:d,isDesktop:f,onDelete:m,onToggleRead:h,density:p})=>{const[b,x]=c.useState("none"),y=c.useCallback(w=>{navigator.vibrate?.(10),w==="trailing"?m(e.messageId):h(e.messageId,e.isRead),x("none")},[m,h,e.messageId,e.isRead]),g=c.useCallback(()=>{d(e.messageId)},[d,e.messageId]),v=c.useCallback(()=>{i(e.messageId)},[i,e.messageId]);return f||u?s.jsx(Vp,{thread:e,mailboxId:t,accountId:n,isSelected:a,isFocused:r,isChecked:o,onToggleCheck:i,onRowSelect:l,isMultiSelectMode:u,onLongPress:d,isDesktop:f,density:p}):s.jsx(qo,{thread:Yp(e),selectionMode:!1,checked:!1,active:a,peek:b,onPeek:x,onToggleCheck:v,onLongPress:g,onOpen:()=>{},onAct:y,linkComponent:({onOpenClick:w,children:j,...C})=>s.jsx(et,{...C,to:"/mail/$mailboxId",params:{mailboxId:t},search:N=>({...N,selectedMessageId:e.messageId}),"data-message-row":!0,onClick:w,children:j})})},Xp=72,Jp=32,Zp=5,Tl="remit:list-density",eb=()=>{try{const e=localStorage.getItem(Tl);if(e==="compact"||e==="comfortable")return e}catch{}return"comfortable"},tb=({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(ys,{className:"size-4 text-fg-muted"}),s.jsxs("span",{className:"text-sm text-fg-muted",children:[t," ",t===1?"result":"results"," for “",e,"”"]})]}),sb=({mailboxId:e,threads:t,selectedMessageId:n,isLoading:a,isError:r=!1,error:o,onRetry:i,searchQuery:l,onDeleteMessages:u,onMarkAsRead:d,onMoveMessages:f,isDeleting:m=!1,isMoving:h=!1,onLoadMore:p,hasMore:b=!1,isLoadingMore:x=!1,accountId:y,listTitle:g,listMeta:v,onTriageContextChange:w,hideHeader:j=!1})=>{const C=c.useRef(null),N=Ce(),S=Ct(),[E,k]=c.useState(!1),[M,T]=c.useState(!1),[D,I]=c.useState(n),[R,O]=c.useState(eb),B=c.useCallback(()=>{O(L=>{const X=L==="comfortable"?"compact":"comfortable";try{localStorage.setItem(Tl,X)}catch{}return X})},[]),{toggleReadFor:$}=Ii({mailboxId:e}),{selectedIds:q,selectedCount:_,hasSelection:U,isSelected:te,toggle:J,select:P,clearSelection:A,selectRange:Q,setAnchor:le,selectAll:ve}=Rp(),[ce,ye]=c.useState(null);c.useEffect(()=>{E&&_===0&&k(!1)},[E,_]);const Se=Cp({count:t.length,getScrollElement:()=>C.current,estimateSize:()=>R==="compact"?Jp:Xp,overscan:Zp}),Y=n?t.findIndex(L=>L.messageId===n):-1,ge=D?t.findIndex(L=>L.messageId===D):-1,Ie=c.useCallback(L=>{if(L<0||L>=t.length)return;const X=t[L];if(E){J(X.messageId);return}I(X.messageId)},[t,E,J]),H=c.useCallback(()=>{if(t.length===0)return;const L=ge<0?0:Math.min(ge+1,t.length-1);Ie(L)},[t.length,ge,Ie]),W=c.useCallback(()=>{if(t.length===0)return;const L=ge<=0?0:ge-1;Ie(L)},[t.length,ge,Ie]),ee=c.useCallback(()=>{D&&J(D)},[D,J]),ne=c.useMemo(()=>t.map(L=>L.messageId),[t]),Ve=c.useCallback((L,X)=>X.shiftKey?(Q(ne,L),!0):X.metaKey||X.ctrlKey?(J(L),!0):(A(),le(L),!1),[ne,Q,J,A,le]),re=c.useCallback(L=>{!u||L.length===0||ye(L)},[u]),Ne=c.useCallback(L=>{const X=Ip(ne,D,L);X!==void 0&&(Q(ne,X),I(X))},[ne,D,Q]),Fe=c.useCallback(()=>Ne(-1),[Ne]),Re=c.useCallback(()=>Ne(1),[Ne]),Ye=c.useCallback(()=>{ne.length>0&&ve(ne)},[ne,ve]),Ge=c.useCallback(()=>{_>0?re(Array.from(q)):D&&re([D])},[_,q,D,re]),Et=c.useCallback(()=>{D&&N({to:"/mail/$mailboxId",params:{mailboxId:e},search:L=>({...L,selectedMessageId:D})})},[D,N,e]),xt=c.useCallback(()=>{_>0&&re(Array.from(q))},[re,_,q]),It=c.useCallback(()=>{if(!ce||ce.length===0){ye(null);return}const L=new Set(ce),X=t.findIndex(de=>L.has(de.messageId));let me;for(let de=X+1;de<t.length;de++)if(!L.has(t[de].messageId)){me=t[de].messageId;break}if(me===void 0){for(let de=X-1;de>=0;de--)if(!L.has(t[de].messageId)){me=t[de].messageId;break}}u?.(ce),A(),ye(null),me!==void 0&&N({to:"/mail/$mailboxId",params:{mailboxId:e},search:de=>({...de,selectedMessageId:me}),replace:!0})},[ce,t,u,A,N,e]),Xe=c.useCallback(()=>{ye(null)},[]),at=c.useCallback(()=>{d&&_>0&&d(Array.from(q))},[d,_,q]),pt=c.useCallback(L=>{!f||_===0||(f(Array.from(q),L),A())},[f,_,q,A]),Me=c.useMemo(()=>{if(_===0)return;const L=new Set;for(const X of t)q.has(X.messageId)&&L.add(X.accountConfigId);if(L.size>1)return"Move only works within one account — clear selection or pick messages from a single account"},[_,q,t]),Je=c.useCallback(L=>{u?.([L])},[u]),Rt=c.useCallback((L,X)=>{$([L],!X)},[$]),Mt=c.useCallback(L=>{S||(k(!0),P(L))},[S,P]),ns=c.useCallback(()=>{k(!1),A()},[A]);c.useEffect(()=>{if(!S&&n)return;const L=ge>=0?ge:Y;L>=0&&Se.scrollToIndex(L,{align:"auto"})},[ge,Y,Se,S,n]),c.useEffect(()=>{n&&I(n)},[n]),c.useEffect(()=>{D&&(t.some(L=>L.messageId===D)||I(t[0]?.messageId))},[t,D]),c.useEffect(()=>{w?.({focusedMessageId:D,selectedIds:Array.from(q)})},[D,q,w]),c.useEffect(()=>{const L=new Set(t.map(me=>me.messageId));Array.from(q).some(me=>!L.has(me))&&A()},[t,q,A]),c.useEffect(()=>{const L=C.current;if(!L||!b||!p)return;const X=()=>{if(x)return;const{scrollTop:me,scrollHeight:de,clientHeight:Te}=L;me+Te>=de-200&&p()};return L.addEventListener("scroll",X,{passive:!0}),X(),()=>L.removeEventListener("scroll",X)},[b,x,p]),bs({enabled:!a&&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:Re,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:Ye,preventDefault:!0,requireMeta:!0},{key:"Enter",handler:Et,preventDefault:!0},{key:"Delete",handler:Ge,preventDefault:!0},{key:"Backspace",handler:Ge,preventDefault:!0},{key:"d",handler:B,preventDefault:!0}]}),bs({enabled:U&&ce===null,capture:!0,bindings:[{key:"Escape",handler:A,preventDefault:!0,stopPropagation:!0}]});const Tt=a?"loading":r?"error":t.length===0?"empty":"ready",Le=r?wo(o):void 0,as=c.useCallback(()=>{const L=ta(ea());window.open(L,"_blank","noopener,noreferrer")},[]),V=[{id:"inbox",threads:[]}],ae=U&&S?s.jsx(qp,{selectedCount:_,onDelete:xt,onClearSelection:A,onMarkAsRead:d?at:void 0,onMove:f?pt:void 0,onOrganize:()=>T(!0),isDeleting:m,isMoving:h,accountId:y,currentMailboxId:e,moveDisabledHint:Me}):void 0,oe=E&&!S?s.jsx(Ko,{count:_,onCancel:ns,onDelete:xt,onMarkRead:d?at:void 0,isBusy:m||h,moveDisabledHint:Me,moveSlot:f&&y&&e?s.jsxs(s.Fragment,{children:[!Me&&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(Ue,{className:"size-4"})}),s.jsx(Es,{accountId:y,currentMailboxId:e,onMove:m||h?()=>{}:pt,disabledHint:Me,label:"Move selected messages"})]}):void 0}):void 0,Z=ae??oe,ue=!!l?.trim(),xe=s.jsxs(s.Fragment,{children:[ue&&l&&s.jsx(tb,{query:l,count:t.length}),s.jsxs("div",{ref:C,className:"flex-1 overflow-y-auto",children:[s.jsx("div",{className:"relative w-full",style:{height:`${Se.getTotalSize()}px`},children:Se.getVirtualItems().map(L=>{const X=t[L.index];return s.jsx("div",{"data-index":L.index,ref:Se.measureElement,className:"absolute left-0 top-0 w-full border-b border-line",style:{transform:`translateY(${L.start}px)`},children:s.jsx(Gp,{thread:X,mailboxId:e,accountId:y,isSelected:n===X.messageId,isFocused:D===X.messageId,isChecked:te(X.messageId),onToggleCheck:J,onRowSelect:Ve,isMultiSelectMode:E,onLongPress:Mt,isDesktop:S,onDelete:Je,onToggleRead:Rt,density:R})},L.key)})}),x&&s.jsx("div",{className:"flex justify-center py-4",children:s.jsx("div",{className:"h-5 w-5 animate-spin rounded-full border-2 border-fg-muted border-t-transparent"})})]})]});return s.jsxs(s.Fragment,{children:[s.jsx(Uo,{listTitle:g,listMeta:v,sections:V,flatList:!0,listState:Tt,searchQuery:ue?l:void 0,errorMessage:Le,onRetry:i,onReportError:as,density:R,selectedThreadId:n,onSelectThread:L=>N({to:"/mail/$mailboxId",params:{mailboxId:e},search:X=>({...X,selectedMessageId:L})}),onSelectBriefCategory:()=>{},isDesktop:S,hideHeader:j,selectionBar:Z,listBody:Tt==="ready"?xe:void 0}),s.jsx(pl,{isOpen:ce!==null,title:lu(ce?.length??0),description:"You can restore them from Trash later.",confirmLabel:"Move to Trash",destructive:!0,isBusy:m,onConfirm:It,onCancel:Xe}),M&&y&&s.jsx(Kp,{open:M,accountId:y,mailboxId:e,selectedMessageIds:Array.from(q),onClose:()=>T(!1)})]})},nb=e=>Xt({path:{accountId:e}}),ab=e=>{const t=je(),n=vs(),a=pe({...qc(),onSuccess:()=>{n.recordEvent("sync.triggered"),t.invalidateQueries({queryKey:nb(e)})}});return{trigger:()=>{a.mutate({path:{accountId:e}})},triggerAsync:()=>a.mutateAsync({path:{accountId:e}}),isPending:a.isPending,error:a.error,reset:a.reset}},rb=({accountId:e,children:t})=>{const{triggerAsync:n,isPending:a}=ab(e);return s.jsx(Zd,{onRefresh:n,isRefreshing:a,children:t})};function ob({accountId:e,currentMailboxId:t,candidates:n,onMove:a,children:r}){const[o,i]=c.useState(!1),l=vs(),{t:u}=nn("mail",{useSuspense:!1}),d=c.useCallback((v,w)=>u(v,{defaultValue:w}),[u]),{inboxMailboxId:f}=pa(e),m=Ri(e),{data:h}=ie({...He({path:{accountId:e}}),staleTime:1/0}),p=c.useMemo(()=>{const v=Sa(h?.items??[],m),w=Jt(m);return v.map(j=>({id:j.mailboxId,label:Qt(j,w.get(j.mailboxId),d),searchValue:j.fullPath,isCurrent:j.mailboxId===t}))},[h?.items,m,t,d]),b=c.useMemo(()=>f||(p.find(w=>w.label.toLowerCase()==="inbox")?.id??p.find(w=>!w.isCurrent)?.id??""),[f,p]),x=c.useRef(!1);c.useEffect(()=>{x.current||(x.current=!0,Ax(l,n.length))},[l,n.length]);const y=c.useCallback(()=>{Ox(l,n.length),i(!0)},[l,n.length]),g=c.useCallback((v,w)=>{Px(l,{selected:v.length,total:n.length,toInbox:w===f}),a(v,w)},[l,n.length,f,a]);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(sf,{count:n.length,onReview:y})}),s.jsx("div",{className:"min-h-0 flex-1",children:r}),s.jsx(mf,{open:o,candidates:n,defaultDestinationId:b,availableFolders:p,onConfirmMove:g,onCancel:()=>i(!1)})]})}const ib=({accounts:e})=>{const t=oa({strict:!1}),n=cn(),a=t.mailboxId,{t:r}=nn("mail",{useSuspense:!1}),o=c.useCallback((l,u)=>r(l,{defaultValue:u}),[r]),i=kt({queries:e.map(l=>({...He({path:{accountId:l.accountId}}),staleTime:1/0}))});if(n.pathname.startsWith("/mail/outbox"))return"Outbox";if(!a)return null;for(let l=0;l<e.length;l++){const u=i[l]?.data?.items;if(!u)continue;const d=u.find(m=>m.mailboxId===a);if(!d)continue;const f=Jt(e[l].folderAppointments);return Qt(d,f.get(a),o)}return null},lb=({accounts:e})=>{const n=oa({strict:!1}).mailboxId,a=kt({queries:e.map(r=>({...He({path:{accountId:r.accountId}}),staleTime:1/0}))});if(!n)return null;for(const r of a){const o=r.data?.items;if(!o)continue;const i=o.find(l=>l.mailboxId===n);if(i)return i.unseenCount}return null},cb="We can verify this sender";function ub(e){const{data:t}=ie({...Uc({path:{mailboxId:e??""},query:{senderTrust:["vip","wellknown"],dkimMismatch:!1,results:!0,limit:500}}),enabled:!!e,staleTime:6e4});return{candidates:(t?.items??[]).map(a=>({id:a.messageId,senderName:a.fromName||a.fromEmail||"Unknown sender",senderAddress:a.fromEmail??"",subject:a.subject||"(no subject)",snippet:a.snippet??"",trustReason:cb,trustSubReason:Dx(a.senderTrust),senderTrust:a.senderTrust}))}}const qs={action:null,nextPrefix:null,preventDefault:!1},db={b:"goBrief",i:"goInbox",s:"goSent",f:"goFlagged",",":"goSettings"},fb={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 mb(e,t){const n=e.key.toLowerCase(),a=e.metaKey||e.ctrlKey;if(e.inEditable)return{...qs,nextPrefix:t==="g"?null:t};if(a&&n==="n")return{action:"compose",nextPrefix:null,preventDefault:!0};if(a)return{...qs,nextPrefix:t==="g"?null:t};if(n==="escape")return{action:"back",nextPrefix:null,preventDefault:!1};if(t==="g"){const i=db[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 r=fb[n];if(r){const o=r.requireShift===!0,i=n.length===1&&!/[a-z0-9]/.test(n);return!o&&e.shiftKey&&!i?qs:{action:r.action,nextPrefix:null,preventDefault:!0}}return qs}function hb(e){if(!(e instanceof HTMLElement))return!1;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"||e.isContentEditable}function gb({handlers:e,enabled:t=!0,sequenceTimeoutMs:n=1e3}){const a=c.useRef(e);a.current=e;const r=c.useRef(null),o=c.useRef(null);c.useEffect(()=>{if(!t)return;const i=()=>{o.current!==null&&(clearTimeout(o.current),o.current=null)},l=u=>{const d=mb({key:u.key,shiftKey:u.shiftKey,metaKey:u.metaKey,ctrlKey:u.ctrlKey,altKey:u.altKey,inEditable:hb(u.target)},r.current);if(i(),r.current=d.nextPrefix,d.nextPrefix!==null&&(o.current=setTimeout(()=>{r.current=null,o.current=null},n)),d.action===null)return;const f=a.current[d.action];f&&(d.preventDefault&&u.preventDefault(),f())};return window.addEventListener("keydown",l),()=>{window.removeEventListener("keydown",l),i(),r.current=null}},[t,n])}const Hr=(e,t,n)=>{if(!t)return null;const a=e.indexOf(t);if(a===-1)return null;const r=n==="next"?a+1:a-1;return r<0||r>=e.length?null:e[r]},Dl="remit:intelligence-open";function xb(){try{return localStorage.getItem(Dl)!=="closed"}catch{return!0}}function Qr(e){try{localStorage.setItem(Dl,e?"open":"closed")}catch{}}const pb=(e,t)=>e!==t,bb=(e,t,n)=>{if(!(n||!t))return e.find(a=>a.messageId===t)},vb={unread:e=>!e.isRead,flagged:e=>e.hasStars===!0,attachment:e=>!!e.hasAttachment};function yb(e,t,n){const a=Array.from(n).map(r=>vb[r]).filter(r=>r!=null);return t==="all"&&a.length===0?e:e.filter(r=>(t==="all"||r.category===t)&&a.every(o=>o(r)))}const Al=c.createContext(null);function hn(){const e=c.useContext(Al);if(!e)throw new Error("MailboxPane.* must be used inside <MailboxPane>");return e}function wb({mailboxId:e,selectedMessageId:t,children:n}){const a=Ce(),o=Rs()==="desktop",i=vs(),{accounts:l,mailboxNameIndex:u,accountNameIndex:d,searchQuery:f,searchInput:m,intelligenceOpen:h,onToggleIntelligence:p,onSetIntelligenceOpen:b}=Ee(),x=ol(f),y=x.length>0,{freeText:g,tokens:v}=Is(x,{mailboxesByName:u,accountsByName:d}),w=v.find(z=>z.type==="from"),j={order:"desc",...g?{query:g}:{},...w?{from:w.value}:{},...v.some(z=>z.type==="hasAttachment")?{attachments:!0}:{},...v.some(z=>z.type==="isUnread")?{unread:!0}:{}},C=y?ft({path:{mailboxId:e},query:j}):st({path:{mailboxId:e},query:{order:"desc"}}),{data:N,isLoading:S,isError:E,error:k,refetch:M,fetchNextPage:T,hasNextPage:D,isFetchingNextPage:I}=hi({queryKey:C,queryFn:async({pageParam:z})=>{if(y){const{data:Ae}=await Qc({path:{mailboxId:e},query:{...j,continuationToken:z},throwOnError:!0});return Ae}const{data:De}=await Wc({path:{mailboxId:e},query:{order:"desc",continuationToken:z},throwOnError:!0});return De},initialPageParam:void 0,getNextPageParam:z=>z.continuationToken,enabled:y?x.length>0:!0,placeholderData:Hc}),R=c.useCallback(z=>{t&&z.includes(t)&&a({to:"/mail/$mailboxId",params:{mailboxId:e},search:De=>({...De,selectedMessageId:void 0,selectedThreadId:void 0})})},[t,e,a]),{deleteMessages:O,isPending:B}=hs({mailboxId:e,onAfterOptimisticRemove:R}),{accountId:$}=Ei(e),q=ib({accounts:l}),{moveMessages:_,isPending:U}=ct({mailboxId:e,accountId:$,onAfterOptimisticRemove:R}),te=Jh(N?.pages.flatMap(z=>z.items??[])??[]),[J,P]=c.useState("all"),[A,Q]=c.useState(new Set),le=c.useMemo(()=>yb(te,J,A),[te,J,A]),ve=c.useCallback(z=>{P(z)},[]),ce=c.useCallback(z=>{Q(De=>{const Ae=new Set(De);return Ae.has(z)?Ae.delete(z):Ae.add(z),Ae})},[]),ye=c.useCallback(()=>{P("all"),Q(new Set)},[]),Se=pb(m,f),Y=bb(te,t,Se),{selectedThreadId:ge}=Ht({strict:!1}),Ie=c.useMemo(()=>Nl(Y,{messageId:t,threadId:Se?void 0:ge,mailboxId:e}),[Y,t,ge,Se,e]),[H,W]=c.useState(void 0),[ee,ne]=c.useState([]),Ve=c.useCallback(z=>{W(z.focusedMessageId),ne(z.selectedIds)},[]),re=le.find(z=>z.messageId===H)??Y,Ne=c.useRef(null);c.useEffect(()=>{const z=Y?.messageId??null;z&&Ne.current!==z&&Y?.authenticity?.dkimMismatch&&(Ne.current=z,h||p())},[Y?.messageId,Y?.authenticity?.dkimMismatch,h,p]);const Fe=c.useRef(!1);c.useEffect(()=>{Fe.current||o&&Y?.messageId&&(Fe.current=!0,xb()&&!h&&b(!0))},[o,Y?.messageId,h,b]);const Ye=lb({accounts:l})??te.filter(z=>!z.isRead).length,Ge=je(),{pushError:Et}=ze(),{deleteMessages:xt}=hs({mailboxId:e,threadId:Y?.threadId,onAfterOptimisticRemove:R}),{moveMessages:It}=ct({mailboxId:e,threadId:Y?.threadId,accountId:$,onAfterOptimisticRemove:R}),{draftsMailboxId:Xe}=Gh($),at=Xe!==void 0&&Xe===e,{archiveMailboxId:pt}=Yh($),Me=c.useCallback(z=>{const De=jt({path:{threadId:z.threadId}}),La=Ge.getQueriesData({queryKey:De}).flatMap(([,ac])=>ac?.items.map(rc=>rc.messageId)??[]);return La.length>0?La:[z.messageId]},[Ge]),Je=c.useCallback(()=>{if(!Y)return;const z=Me(Y);xt(z)},[Y,Me,xt]),Rt=c.useCallback(z=>{if(!Y)return;const De=Me(Y);It(De,z)},[Y,Me,It]),{toggleStar:Mt}=Kn({threadId:Y?.threadId??"",mailboxId:e}),ns=c.useCallback(()=>{Y&&Mt(Y.messageId,Y.hasStars)},[Y,Mt]),[Tt,Le]=c.useState(null),as=c.useCallback(()=>{Le("reply")},[]),V=c.useCallback(()=>{Le("reply_all")},[]),ae=c.useCallback(()=>{Le("forward")},[]),oe=c.useCallback(()=>{Le(null)},[]),{state:Z,openCompose:ue,closeCompose:xe}=dt(),L=c.useCallback(()=>{ue({mode:"new"})},[ue]),X=pe({...tn(),onError:z=>{Et(gs("Couldn't discard draft","The draft wasn't deleted.",z))}}),me=c.useCallback(()=>{const z=Z.outboxMessageId;z&&(X.mutate({path:{outboxMessageId:z}}),Ge.invalidateQueries({queryKey:ra()}),xe())},[Z.outboxMessageId,X,Ge,xe]),de=c.useCallback(()=>{t&&a({to:"/mail/$mailboxId",params:{mailboxId:e},search:z=>({...z,selectedMessageId:void 0,selectedThreadId:void 0})})},[t,e,a]),Te=c.useCallback(z=>z?Me(z):[],[Me]),{toggleStar:ke}=Kn({threadId:re?.threadId??"",mailboxId:e}),{toggleReadFor:bt}=Ii({mailboxId:e,accountId:$}),{junkMailboxId:Be}=ba($),Ma=Be!=null&&Be===e,{candidates:$l}=ub(Ma?Be:void 0),{moveMessages:Ta}=ct({mailboxId:e,threadId:re?.threadId,accountId:$,onAfterOptimisticRemove:R}),{deleteMessages:Da}=hs({mailboxId:e,threadId:re?.threadId,onAfterOptimisticRemove:R}),{addressId:rs,address:Ms}=yl(re),{updateFlags:Ts}=wl({addressId:rs,senderEmail:re?.fromEmail??void 0}),Dt=c.useCallback(()=>t||!H?!1:(a({to:"/mail/$mailboxId",params:{mailboxId:e},search:z=>({...z,selectedMessageId:H})}),!0),[t,H,e,a]),Kl=c.useCallback(()=>{Dt()||Y&&Le("reply")},[Dt,Y]),ql=c.useCallback(()=>{Dt()||Y&&Le("reply_all")},[Dt,Y]),Ul=c.useCallback(()=>{Dt()||Y&&Le("forward")},[Dt,Y]),At=c.useCallback(()=>ee.length>0?ee:Te(re),[ee,Te,re]),Hl=c.useCallback(()=>{const z=At();z.length>0&&Da(z)},[At,Da]),Ql=c.useCallback(()=>{if(!Be)return;const z=At();z.length!==0&&(Sl(i,{count:z.length,senderTrust:re?.senderTrust??"unknown",wasRescuable:re?jl(re):!1}),Ta(z,Be))},[Be,At,Ta,i,re]),Wl=c.useCallback(()=>{if(ee.length>0){const z=!(re?.hasStars??!1),De=new Set(ee);for(const Ae of le)De.has(Ae.messageId)&&Ae.hasStars!==z&&ke(Ae.messageId,Ae.hasStars);return}re&&ke(re.messageId,re.hasStars)},[ee,le,re,ke]),Vl=c.useCallback(()=>{const z=At();if(z.length===0)return;const De=!(re?.isRead??!1);bt(z,De)},[At,re,bt]),Yl=c.useCallback(()=>{if(!rs)return;const z=Ms?.flags?.muted?.value!==!0;Ts({muted:{value:z}})},[rs,Ms,Ts]),Gl=c.useCallback(()=>{if(!rs)return;const z=Ms?.flags?.vip?.value!==!0;Ts({vip:{value:z}})},[rs,Ms,Ts]),Xl=c.useCallback(()=>{h||p()},[h,p]),os=c.useCallback(z=>{a({to:z})},[a]),Aa=at?"drafts":pt===e?"archive":Be===e?"junk":"inbox",Oa=c.useRef("");c.useEffect(()=>{const z=Oa.current;Oa.current=x,x.length>0&&z.length===0&&i.recordEvent("search.submitted",{mailboxType:Aa})},[x,Aa,i]);const Jl=!!Y,Zl=at&&Z.isOpen&&!!Z.outboxMessageId&&!Y,ec=o&&h&&Jl;gb({enabled:!Z.isOpen,handlers:{back:de,reply:Kl,replyAll:ql,forward:Ul,delete:Hl,toggleStar:Wl,toggleRead:Vl,muteSender:Yl,blockSender:Xl,vipSender:Gl,markJunk:Ql,toggleIntelligence:Y?p:void 0,compose:L,goBrief:()=>os("/mail"),goInbox:()=>os("/mail"),goSent:()=>os("/mail"),goFlagged:()=>os("/mail/flagged"),goSettings:()=>os("/settings")}}),bs({enabled:Z.isOpen,bindings:[{key:"Escape",handler:xe,preventDefault:!0}]});const Pa=le.map(z=>z.messageId),tc=Hr(Pa,t,"next")??void 0,sc=Hr(Pa,t,"previous")??void 0,nc={mailboxId:e,selectedMessageId:t,selectedThread:Y,conversation:Ie,threads:le,isLoading:S,isError:E,error:k,mailboxAccountId:$,mailboxName:q,unreadCount:Ye,isDraftsMailbox:at,isSpamFolder:Ma,rescueCandidates:$l,filterCategory:J,filterAttributes:A,onSelectFilterCategory:ve,onToggleFilterAttribute:ce,onClearFilters:ye,showIntelligence:ec,intelligenceOpen:h,onToggleIntelligence:p,onDeleteMessages:O,onMoveMessages:_,isDeleting:B,isMoving:U,onLoadMore:T,hasMore:D,isLoadingMore:I,onTriageContextChange:Ve,onRetry:()=>M(),toolbarComposeRequest:Tt,onToolbarReply:as,onToolbarReplyAll:V,onToolbarForward:ae,onClearComposeRequest:oe,onToolbarDelete:Je,onToolbarStar:ns,onToolbarDiscardDraft:me,onToolbarMove:Rt,composeState:Z,closeCompose:xe,hasRemitDraftOpen:Zl,onBack:de,nextMessageId:tc,previousMessageId:sc};return s.jsx(Al.Provider,{value:nc,children:n})}function Ol(){const{mailboxId:e,selectedMessageId:t,threads:n,isLoading:a,isError:r,error:o,onDeleteMessages:i,onMoveMessages:l,isDeleting:u,isMoving:d,onLoadMore:f,hasMore:m,isLoadingMore:h,mailboxAccountId:p,mailboxName:b,unreadCount:x,isDraftsMailbox:y,isSpamFolder:g,rescueCandidates:v,onTriageContextChange:w,onRetry:j,filterCategory:C,filterAttributes:N,onSelectFilterCategory:S,onToggleFilterAttribute:E,onClearFilters:k}=hn(),{searchQuery:M,searchInput:T,accounts:D}=Ee(),I=Rs(),R=Ce(),O=b??"Inbox",B=c.useMemo(()=>pf(),[]),$=c.useMemo(()=>n.map(gx),[n]),{hits:q,isLoading:_}=il({mailboxId:e,filterCategory:C}),U=c.useMemo(()=>fl(q,n.map(le=>le.threadId)),[q,n]),te=c.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&&p)return s.jsx(cp,{mailboxId:e,accountId:p,selectedMessageId:t,imapThreads:n,title:b??"Drafts",unreadCount:x??void 0});const J=s.jsx(sb,{mailboxId:e,threads:n,selectedMessageId:t,isLoading:a,isError:r,error:o,onRetry:j,searchQuery:M,onDeleteMessages:i,onMoveMessages:l,isDeleting:u,isMoving:d,onLoadMore:f,hasMore:m,isLoadingMore:h,accountId:p,listTitle:O,hideHeader:!0,onTriageContextChange:w}),P=D[0]?.accountId,A=I==="phone"&&P?s.jsx(rb,{accountId:P,children:J}):J,Q=g&&v.length>0&&p?s.jsx(ob,{accountId:p,currentMailboxId:e,candidates:v,onMove:l,children:A}):A;return s.jsx(Cl,{title:O,unreadCount:x,preset:B,selectedCategory:C,activeFilters:N,onSelectCategory:S,onToggleFilter:E,onClearFilters:k,searchResults:$,searchLoading:a,relatedResults:U,relatedLoading:_,onSelectSearchResult:te,children:Q})}function jb(){const{mailboxId:e,mailboxAccountId:t,selectedThread:n,conversation:a,hasRemitDraftOpen:r,showIntelligence:o,onToggleIntelligence:i,toolbarComposeRequest:l,onToolbarReply:u,onToolbarReplyAll:d,onToolbarForward:f,onClearComposeRequest:m,onToolbarDelete:h,onToolbarStar:p,onToolbarDiscardDraft:b,onToolbarMove:x,composeState:y}=hn(),v=Rs()==="desktop",w=!!a,j=y.isOpen&&!a?s.jsx(Rl,{}):a?s.jsx(ss,{threadId:a.threadId,mailboxId:a.mailboxId,subject:a.subject,selectedMessageId:a.messageId,authenticity:a.authenticity,onOpenIntelligence:a.authenticity?.dkimMismatch?i:void 0,composeRequest:l,onComposeClose:m}):s.jsx(ts,{});return s.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[s.jsx(Na,{hasThread:w,intelligenceOpen:o,showIntelligenceToggle:v&&w,onToggleIntelligence:i,onReply:w?u:void 0,onReplyAll:w?d:void 0,onForward:w?f:void 0,canDelete:w||r,onDelete:w?h:r?b:void 0,onToggleStar:w?p:void 0,isStarred:n?.hasStars,moveContext:w&&t?{accountId:t,currentMailboxId:e,onMove:x}:void 0}),s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:j})]})}function Sb(){const{mailboxId:e,mailboxAccountId:t,selectedThread:n,onToggleIntelligence:a}=hn();return s.jsx(mn,{onClose:a,thread:n,mailboxId:e,accountId:t})}function Nb(){const{mailboxId:e,selectedThread:t,conversation:n,intelligenceOpen:a,onToggleIntelligence:r,onBack:o,nextMessageId:i,previousMessageId:l,composeState:u}=hn(),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(ss,{threadId:n.threadId,mailboxId:n.mailboxId,subject:n.subject,selectedMessageId:n.messageId,authenticity:n.authenticity,onBack:o,onOpenIntelligence:r,onSwipeNext:i?()=>f(i):void 0,onSwipePrevious:l?()=>f(l):void 0,mobileIntelligenceOpen:a}),s.jsx(ga,{isOpen:a,onClose:r,ariaLabel:"Message details",side:"right",children:s.jsx(mn,{onClose:r,thread:t,hideCloseButton:!0})})]})}return u.isOpen?s.jsx("div",{className:"h-full",children:s.jsx(Rl,{})}):s.jsx(Ol,{})}const fs=Object.assign(wb,{List:Ol,Reading:jb,Intelligence:Sb,Phone:Nb}),Pl=e=>e==="failed"||e==="blocked",Ll=e=>e!=="draft"&&e!=="sent",Ia="remit.savedSearches",kb=25;function Zs(){try{const e=localStorage.getItem(Ia);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(n=>typeof n=="string"):[]}catch{return[]}}function Cb(e){const t=e.trim();if(!t)return Zs();const n=[t,...Zs().filter(a=>a!==t)].slice(0,kb);try{localStorage.setItem(Ia,JSON.stringify(n))}catch{return n}return n}function Eb(e){const t=Zs().filter(n=>n!==e);try{localStorage.setItem(Ia,JSON.stringify(t))}catch{return t}return t}const Wr=e=>/^\d/.test(e),Ib=(e,t)=>{const n=Wr(e),a=Wr(t);return n&&!a?-1:!n&&a?1:e.localeCompare(t,void 0,{sensitivity:"base",numeric:!0})};function Rb(e,t,n){const a=[],r=[];for(const o of e)t.has(o.mailboxId)?a.push(o):r.push(o);return r.sort((o,i)=>Ib(Qt(o,void 0,n),Qt(i,void 0,n))),{system:a,labels:r}}function Mb(e,t,n){const a=eu(t)&&e.unseenCount>0;return{id:e.mailboxId,name:Qt(e,t,n),unseen:a?e.unseenCount:void 0,role:t,fullPath:e.fullPath}}function Tb(){const e=cn(),t=oa({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 Vr({accounts:e,onMailboxSelect:t,variant:n="desktop"}){const a=je(),r=Ce(),o=Tb(),{searchInput:i,onSearchChange:l}=Ee(),[u,d]=c.useState(Zs),{t:f}=nn("mail",{useSuspense:!1}),m=c.useCallback((E,k)=>f(E,{defaultValue:k}),[f]),h=kt({queries:e.map(E=>({...He({path:{accountId:E.accountId}}),staleTime:1/0}))}),{data:p}=ie(en()),b=c.useMemo(()=>(p?.items??[]).filter(E=>Ll(E.status)).length,[p?.items]),x=c.useMemo(()=>e.map((E,k)=>{const M=h[k],T=M?.data?.items??[],D=Jt(E.folderAppointments),{system:I,labels:R}=Rb(T,D,m),O=M?.isError?"error":M?.isLoading?"loading":"ready";return{id:E.accountId,label:E.email,email:E.email,muted:!!E.muted,outboxPending:b,status:O,onRetry:()=>M?.refetch(),mailboxes:[...I,...R].map(B=>Mb(B,D.get(B.mailboxId),m))}}),[e,h,b,m]),y=E=>{a.invalidateQueries({queryKey:st({path:{mailboxId:E},query:{order:"desc"}})})},g=({navId:E,className:k,ariaLabel:M,title:T,children:D,onClick:I})=>E==="brief"?s.jsx(et,{to:"/mail",search:{q:void 0,selectedMessageId:void 0},onClick:()=>I?.(),className:k,"aria-label":M,title:T,children:D}):E==="outbox"?s.jsx(et,{to:"/mail/outbox",search:{q:void 0,selectedOutboxMessageId:void 0},onClick:()=>I?.(),className:k,"aria-label":M,title:T,children:D}):E==="flagged"?s.jsx(et,{to:"/mail/flagged",search:{q:void 0,selectedMessageId:void 0},onClick:()=>I?.(),className:k,"aria-label":M,title:T,children:D}):s.jsx(et,{to:"/mail/$mailboxId",params:{mailboxId:E},search:{q:void 0,selectedMessageId:void 0},onClick:()=>{y(E),I?.()},className:k,"aria-label":M,title:T,children:D}),v=()=>{t?.()},w=i.trim(),j=w.length>0&&!u.includes(w)?w:void 0,C=c.useCallback(()=>{j&&d(Cb(j))},[j]),N=c.useCallback(E=>{d(Eb(E))},[]),S=c.useCallback(E=>{l(E),r({to:"/mail",search:{q:E,selectedMessageId:void 0}}),t?.()},[l,r,t]);return s.jsx(jd,{accounts:x,selectedNavId:o,onSelectNav:v,linkComponent:g,variant:n,savedSearches:u,saveableQuery:j,onSaveCurrentSearch:C,onSelectSavedSearch:S,onRemoveSavedSearch:N})}function Db({accounts:e,onMailboxSelect:t}){return na()?.showNavPane??!0?s.jsx(Vr,{accounts:e}):s.jsxs("div",{className:"flex h-full flex-col",children:[s.jsx("div",{className:"flex-1 overflow-y-auto",children:s.jsx(Vr,{accounts:e,onMailboxSelect:t,variant:"drawer"})}),s.jsxs("div",{className:"border-t border-line px-2 py-2",children:[s.jsxs(et,{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(Po,{className:"size-4 shrink-0"}),s.jsx("span",{className:"flex-1 truncate text-left",children:"Settings"})]}),s.jsx(bi,{variant:"drawer"}),s.jsx(pi,{children:({signOut:r})=>s.jsxs("button",{type:"button",onClick:()=>{t?.(),r()},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(To,{className:"size-4 shrink-0"}),s.jsx("span",{className:"flex-1 truncate text-left",children:"Sign out"})]})})]})]})}const zl={queued:{icon:ca,label:"Queued",className:"text-warning"},sending:{icon:St,label:"Sending…",className:"text-accent-2"},sent:{icon:Co,label:"Sent",className:"text-positive"},failed:{icon:wt,label:"Failed",className:"text-danger"},blocked:{icon:Yn,label:"Blocked",className:"text-warning"}},Ab=e=>cu(e).toDateString()===new Date().toDateString()?Gs(e,{hour:"numeric",minute:"2-digit"}):Gs(e,{month:"short",day:"numeric"}),Yr=e=>Gs(e,{dateStyle:"medium",timeStyle:"short"}),Ob=e=>{const t=e.toAddresses??[];return t.length===0?"No recipients":t.length===1?t[0]:`${t[0]} +${t.length-1}`},_l=c.createContext(null);function Ra(){const e=c.useContext(_l);if(!e)throw new Error("OutboxPane.* must be used inside <OutboxPane>");return e}function Pb({children:e}){const t=Ce(),{selectedOutboxMessageId:n}=Ht({strict:!1}),{data:a,isLoading:r}=ie(en()),o=c.useMemo(()=>(a?.items??[]).filter(d=>Ll(d.status)),[a]),i=c.useMemo(()=>o.find(d=>d.outboxMessageId===n),[o,n]),l=c.useCallback(d=>{t({to:"/mail/outbox",search:f=>({...f,selectedOutboxMessageId:d})})},[t]),u={messages:o,isLoading:r,selectedMessageId:n,selectedMessage:i,onSelectMessage:l};return s.jsx(_l.Provider,{value:u,children:e})}function Fl({message:e,isSelected:t,onSelect:n}){const a=je(),{openCompose:r}=dt(),{pushError:o}=ze(),i=c.useCallback(()=>{a.invalidateQueries({queryKey:ra()})},[a]),l=pe({...mo(),onSuccess:i,onError:m=>{o(gs("Couldn't resend message","The message wasn't sent.",m))}}),u=pe({...tn(),onSuccess:i,onError:m=>{o(gs("Couldn't delete message","The message wasn't deleted.",m))}}),d=e.status;if(!zl[d])return null;const f=Pl(e.status);return s.jsx(Xd,{recipients:Ob(e),subject:e.subject||"",time:Ab(e.sentAt??e.updatedAt),status:d,error:f?e.lastError??void 0:void 0,selected:t,onSelect:n,onRetry:d==="failed"?()=>l.mutate({path:{outboxMessageId:e.outboxMessageId}}):void 0,retrying:l.isPending,onEdit:()=>r({mode:"new",outboxMessageId:e.outboxMessageId}),onDelete:()=>u.mutate({path:{outboxMessageId:e.outboxMessageId}}),deleting:u.isPending})}function Bl({message:e,onBack:t}){const n=e.status,a=zl[n],r=a?.icon??ws,o=e.sentAt?Yr(e.sentAt):Yr(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(No,{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})]}),a&&s.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[s.jsx(r,{className:fe("size-4",a.className,n==="sending"&&"animate-spin")}),s.jsx("span",{className:fe("text-xs font-medium",a.className),children:a.label}),Pl(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(nl,{html:e.htmlBody,text:e.textBody})})]})}function Lb(){const{messages:e,isLoading:t,selectedMessageId:n,onSelectMessage:a}=Ra();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(ts,{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(Ea,{}),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(r=>s.jsx(Fl,{message:r,isSelected:n===r.outboxMessageId,onSelect:()=>a(r.outboxMessageId)},r.outboxMessageId))})]})}function zb(){const{selectedMessage:e}=Ra();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(Bl,{message:e}):s.jsx(ts,{message:"Select a message to read",showHints:!1})})]})}function _b(){const{messages:e,isLoading:t,selectedMessageId:n,selectedMessage:a,onSelectMessage:r}=Ra();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..."})}):a?s.jsx(Bl,{message:a,onBack:()=>r(void 0)}):e.length===0?s.jsx("div",{className:"flex h-full bg-surface",children:s.jsx(ts,{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(Ea,{}),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(Fl,{message:o,isSelected:n===o.outboxMessageId,onSelect:()=>r(o.outboxMessageId)},o.outboxMessageId))})]})}const Us=Object.assign(Pb,{List:Lb,Reading:zb,Phone:_b}),Fb=({isOpen:e,onClose:t})=>{const n=c.useCallback(a=>{a.key==="Escape"&&(a.preventDefault(),t())},[t]);return c.useEffect(()=>{if(e)return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[e,n]),e?s.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",role:"dialog","aria-modal":"true","aria-label":"Keyboard shortcuts",onClick:t,onKeyDown:a=>a.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:a=>a.stopPropagation(),onKeyDown:a=>{a.key!=="Escape"&&a.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:vi.map(a=>s.jsxs("div",{children:[s.jsx("h3",{className:"mb-3 text-sm font-medium text-fg-muted",children:a.title}),s.jsx("div",{className:"space-y-2",children:a.hints.map(r=>s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"text-sm",children:r.description}),s.jsx("span",{className:"flex shrink-0 items-center gap-1",children:r.keys.map((o,i)=>s.jsxs(c.Fragment,{children:[i>0&&r.keys[0]==="g"&&s.jsx("span",{className:"text-2xs text-fg-subtle",children:"then"}),s.jsx(qt,{children:o})]},o))})]},`${r.action}-${r.keys.join("+")}`))})]},a.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(qt,{children:"Esc"})," to close"]})})]})]}):null};function Bb(e){const t=new Map;for(const n of e){const a=n.email.toLowerCase(),r=a.split("@")[0];r&&!t.has(r)&&t.set(r,n.accountId),t.has(a)||t.set(a,n.accountId)}return t}function $b(e){const t=new Map;for(const n of e)for(const a of n){const r=a.fullPath?.toLowerCase();if(!r)continue;const o=r.split("/").pop();t.has(r)||t.set(r,a.mailboxId),o&&!t.has(o)&&t.set(o,a.mailboxId)}return t}function Kb(e){const t=kt({queries:e.map(n=>({...He({path:{accountId:n.accountId}}),staleTime:1/0}))});return c.useMemo(()=>$b(t.map(n=>n.data?.items??[])),[t])}var Hs={exports:{}},Gr;function qb(){if(Gr)return Hs.exports;Gr=1;const e=(t,n,a)=>new Promise((r,o)=>{if(a=Object.assign({concurrency:1/0},a),typeof n!="function")throw new TypeError("Mapper function is required");const{concurrency:i}=a;if(!(typeof i=="number"&&i>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${i}\` (${typeof i})`);const l=[],u=t[Symbol.iterator]();let d=!1,f=!1,m=0,h=0;const p=()=>{if(d)return;const b=u.next(),x=h;if(h++,b.done){f=!0,m===0&&r(l);return}m++,Promise.resolve(b.value).then(y=>n(y,x)).then(y=>{l[x]=y,m--,p()},y=>{d=!0,o(y)})};for(let b=0;b<i&&(p(),!f);b++);});return Hs.exports=e,Hs.exports.default=e,Hs.exports}var Ub=qb();const Hb=Vc(Ub),Qb=900*1e3,Wb=300,Vb=(e,t)=>{if(!e)return t;const n=Number.parseInt(e,10);return Number.isFinite(n)&&n>0?n:t},Yb=60*1e3,Gb=e=>Math.max(Vb(e,Wb)*1e3,Yb),Vs=Gb(Xc().mailboxPollIntervalSeconds),Xb=5,Qn=new Set,Jb=(e,t,n=Qb)=>e.filter(a=>{const r=a.lastSyncAt;return r==null?!0:t-r>n}).map(a=>a.accountId),Zb=(e,t,n=Vs)=>e-t>=n,ev=(e,t)=>e.filter(n=>!t.has(n)),Xr=(e,t)=>{if(Qn.delete(e),Gc(t,{softError:!0})){po(t);return}console.warn("[remit] background mailbox sync failed",{accountId:e,error:t})},Jr=(e,t)=>Yc({path:{accountId:e},throwOnError:!0}).then(()=>{t.invalidateQueries({queryKey:Xt({path:{accountId:e}})})}),tv=e=>{const t=je(),n=c.useRef(e);n.current=e;const a=e.map(r=>r.accountId).join(",");c.useEffect(()=>{const r=Date.now(),i=Jb(n.current,r).filter(l=>!Qn.has(l));if(i.length!==0)for(const l of i)Qn.add(l),Jr(l,t).catch(u=>{Xr(l,u)})},[a,t]),c.useEffect(()=>{let r=Date.now(),o;const i=new Set,l=()=>{r=Date.now();const f=ev(n.current.map(m=>m.accountId),i);for(const m of f)i.add(m);Hb(f,m=>Jr(m,t).catch(h=>{Xr(m,h)}).finally(()=>{i.delete(m)}),{concurrency:Xb})},u=()=>{if(document.visibilityState==="visible"){l(),o=setTimeout(u,Vs);return}},d=()=>{document.visibilityState==="visible"&&Zb(Date.now(),r)&&(o!==void 0&&clearTimeout(o),l(),o=setTimeout(u,Vs))};return o=setTimeout(u,Vs),document.addEventListener("visibilitychange",d),()=>{o!==void 0&&clearTimeout(o),document.removeEventListener("visibilitychange",d)}},[a,t])},sv="/mail/",nv="/mail/outbox",av="/mail/flagged";function rv(e){return e.some(t=>t.routeId===sv)}function ov(e){return e.some(t=>t.routeId===av)}function iv(e){return e.some(t=>t.routeId===nv)}function lv(){const{q:e=""}=Ht({from:"/mail"}),t=Ce(),n=Rs(),a=ml(n),[r,o]=c.useState(!1),[i,l]=c.useState(!1),[u,d]=c.useState(!1),f=c.useCallback(P=>{d(P),Qr(P)},[]),[m,h]=c.useState(e),p=bo(m,200),b=c.useRef(e);b.current=e,c.useEffect(()=>{p!==b.current&&t({to:".",search:P=>{const A=P.q===p;return{...P,q:p||void 0,...p&&!A?{selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0}:{}}},replace:!0})},[p,t]);const{data:x,isLoading:y,isError:g,error:v,refetch:w}=ie({...tt(),staleTime:1/0}),j=!!(x&&(x.accounts?.length??0)===0);c.useEffect(()=>{j&&t({to:"/onboarding",replace:!0})},[j,t]),bs({enabled:!r,bindings:[{key:"?",handler:()=>o(!0),noModifiers:!1,preventDefault:!0}]});const C=c.useCallback(P=>{h(P)},[]),N=c.useCallback(()=>{h("")},[]),S=c.useCallback(()=>{h("")},[]),E=c.useCallback(()=>{d(P=>{const A=!P;return Qr(A),A})},[]),k=x?.accounts??[],M=Kb(k),T=c.useMemo(()=>Bb(k),[k]),D=_s({select:P=>P.matches.find(Q=>"mailboxId"in Q.params)?.params.mailboxId}),{selectedMessageId:I}=Ht({strict:!1}),R=_s({select:P=>rv(P.matches)}),O=_s({select:P=>ov(P.matches)}),B=_s({select:P=>iv(P.matches)});tv(k);const $=c.useCallback(()=>{l(!1)},[]),q={accounts:k,mailboxNameIndex:M,accountNameIndex:T,searchQuery:p,searchInput:m,onSearchChange:C,onSearchClear:N,onSearchClearQuery:S,intelligenceOpen:u,onToggleIntelligence:E,onSetIntelligenceOpen:f},_=s.jsx(Db,{accounts:k,onMailboxSelect:$}),U=a?s.jsx(Zm,{accounts:k}):void 0,te=a?void 0:s.jsx(nh,{accounts:k}),J={navOpen:i,onOpenNav:()=>l(!0),onCloseNav:()=>l(!1)};return s.jsxs(Jc.Provider,{value:q,children:[g?s.jsx("div",{className:"flex h-full items-center justify-center bg-canvas p-4",children:s.jsx(ht,{title:"Couldn't load your account",error:v,onRetry:()=>{w()}})}):R?s.jsx($s,{selectedMessageId:I,children:a?s.jsx(rt,{nav:_,list:s.jsx($s.Phone,{}),intelligenceOpen:u,overlay:U,skeleton:s.jsx(Ze,{}),isLoading:y||j,...J}):s.jsx(rt,{nav:_,topBar:te,list:s.jsx($s.List,{}),reading:s.jsx($s.Reading,{}),intelligenceOpen:u,overlay:U,skeleton:s.jsx(Ze,{}),isLoading:y||j,...J})}):O?s.jsx(Ks,{selectedMessageId:I,children:a?s.jsx(rt,{nav:_,list:s.jsx(Ks.Phone,{}),intelligenceOpen:u,overlay:U,skeleton:s.jsx(Ze,{}),isLoading:y||j,...J}):s.jsx(rt,{nav:_,topBar:te,list:s.jsx(Ks.List,{}),reading:s.jsx(Ks.Reading,{}),intelligenceOpen:u,overlay:U,skeleton:s.jsx(Ze,{}),isLoading:y||j,...J})}):D?s.jsx(fs,{mailboxId:D,selectedMessageId:I,children:a?s.jsx(rt,{nav:_,list:s.jsx(fs.Phone,{}),intelligenceOpen:u,overlay:U,skeleton:s.jsx(Ze,{}),isLoading:y||j,...J}):s.jsx(rt,{nav:_,topBar:te,list:s.jsx(fs.List,{}),reading:s.jsx(fs.Reading,{}),intelligence:s.jsx(fs.Intelligence,{}),intelligenceOpen:u,overlay:U,skeleton:s.jsx(Ze,{}),isLoading:y||j,...J})}):B?s.jsx(Us,{children:a?s.jsx(rt,{nav:_,list:s.jsx(Us.Phone,{}),intelligenceOpen:!1,overlay:U,skeleton:s.jsx(Ze,{}),isLoading:y||j,...J}):s.jsx(rt,{nav:_,topBar:te,list:s.jsx(Us.List,{}),reading:s.jsx(Us.Reading,{}),intelligenceOpen:!1,overlay:U,skeleton:s.jsx(Ze,{}),isLoading:y||j,...J})}):s.jsx(Ze,{}),s.jsx(Fb,{isOpen:r,onClose:()=>o(!1)}),s.jsx(Zc,{})]})}const kv=Object.freeze(Object.defineProperty({__proto__:null,component:lv,useMailContext:Ee},Symbol.toStringTag,{value:"Module"}));export{Nv as S,Cu as U,kv as m};
|