@remit/web-client-dist 0.0.8 → 0.0.10
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-Bv4ZgOEg.js → ComposeBody-CJCPS_su.js} +1 -1
- package/assets/{ErrorState-Cs_ykF6y.js → ErrorState-C2v8yoJp.js} +1 -1
- package/assets/{OnboardingWizard-CAXhAt96.js → OnboardingWizard-D2mMnbb0.js} +1 -1
- package/assets/{account-form-helpers-a_xge2ry.js → account-form-helpers-sCUQ_UAD.js} +1 -1
- package/assets/{accounts-Cy4UmdAf.js → accounts-BWdxNlDi.js} +1 -1
- package/assets/{advanced-C-NuXhwx.js → advanced-QPX5fVOq.js} +1 -1
- package/assets/{appearance-DzOHM19n.js → appearance-qXWR1QS1.js} +1 -1
- package/assets/{avatar-Cj0oqMTc.js → avatar-CG5Pc7a1.js} +1 -1
- package/assets/{browser-ponyfill-DMcihosO.js → browser-ponyfill-D4UsOpEg.js} +1 -1
- package/assets/{filter-status-hhxxZCHD.js → filter-status-v5X9jZaF.js} +1 -1
- package/assets/{filters-DDmNGV9n.js → filters-DzykyfiR.js} +1 -1
- package/assets/{flagged-TgI4TUpc.js → flagged-CvQ4o_87.js} +1 -1
- package/assets/{folders-Mg_9vARj.js → folders-ViaViajF.js} +1 -1
- package/assets/index-B4by91fD.js +1 -0
- package/assets/{index-CC1qp2Dq.js → index-BVKhoZzI.js} +1 -1
- package/assets/{index-DjAEGMKw.js → index-BuygbWIE.js} +13 -13
- package/assets/{kbd-BDO2pbIK.js → kbd-06NmYfQr.js} +1 -1
- package/assets/{mail-AVpn-u1X.js → mail-Dv2XG3cb.js} +3 -3
- package/assets/{onboarding-BNrlvOGa.js → onboarding-BGV6jksb.js} +1 -1
- package/assets/{select-DeJpKA42.js → select-DaeZJyvp.js} +1 -1
- package/assets/{send-DSbws47x.js → send-ZKJgkB_s.js} +1 -1
- package/assets/{senders-C2Aj1JuN.js → senders-4CHO98tp.js} +1 -1
- package/assets/settings-BuJZnqBj.js +1 -0
- package/assets/{settings-screen-Ck9KttTK.js → settings-screen-DliVqY8D.js} +1 -1
- package/assets/{star-CV2vqImk.js → star-B10UnFVc.js} +1 -1
- package/assets/{suggested-vips-CBu2znNy.js → suggested-vips-eZDJ2cni.js} +1 -1
- package/assets/{trash-2-DU2uSN4A.js → trash-2-DlrBh3cg.js} +1 -1
- package/assets/{useDebouncedValue-C8nRE7Ln.js → useDebouncedValue-BUjsMXUW.js} +1 -1
- package/assets/{useMutation-C1Fn6tC2.js → useMutation-5toMj9JW.js} +1 -1
- package/assets/{useSignature-DmY6Rwy-.js → useSignature-CjD7hQBM.js} +1 -1
- package/index.html +1 -1
- package/package.json +1 -1
- package/assets/index-CutN3f1u.js +0 -1
- package/assets/settings-t_C6gutx.js +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ComposeBody-
|
|
2
|
-
import{c as se,r as c,j as s,C as vt,X as De,a as $,B as X,b as Je,d as yt,e as Xl,f as Xr,p as Jr,I as Qn,i as Jl,g as Zr,D as eo,O as Zl,F as Wn,h as to,T as Vn,P as ec,k as so,l as tc,R as Yn,m as Gn,_ as it,n as no,o as sc,Q as Xn,q as nc,s as ac,S as rc,t as Tn,u as oc,v as ic,w as je,x as lc,y as cc,z as uc,A as dc,E as fc,G as mc,H as La,J as hc,K as gc,L as pc,M as ao,N as ro,U as oo,V as wt,W as Ce,Y as fe,Z as xs,$ as Jn,a0 as re,a1 as io,a2 as lo,a3 as xc,a4 as Js,a5 as co,a6 as Ze,a7 as ze,a8 as bc,a9 as $e,aa as uo,ab as fs,ac as Zs,ad as vc,ae as et,af as tt,ag as ut,ah as Vt,ai as en,aj as jt,ak as yc,al as wc,am as jc,an as fo,ao as z,ap as tn,aq as Ut,ar as Sc,as as Zn,at as Nc,au as kc,av as Ee,aw as mo,ax as ea,ay as sn,az as Dn,aA as Cc,aB as ho,aC as Xe,aD as ta,aE as sa,aF as na,aG as Ec,aH as Ic,aI as Rc,aJ as Mc,aK as aa,aL as Tc,aM as Dc,aN as Ac,aO as Oc,aP as Pc,aQ as Lc,aR as zc,aS as _c,aT as Fc,aU as rt,aV as Ye,aW as Bc}from"./index-DjAEGMKw.js";import{K as Kt}from"./kbd-BDO2pbIK.js";import{A as st,M as ra,C as $c}from"./avatar-Cj0oqMTc.js";import{S as dt}from"./star-CV2vqImk.js";import{T as qe}from"./trash-2-DU2uSN4A.js";import{L as St,M as go,a as Kc}from"./account-form-helpers-a_xge2ry.js";import{S as bs,F as qc,M as Uc,A as Hc,a as po}from"./send-DSbws47x.js";import{u as xe}from"./useMutation-C1Fn6tC2.js";import{R as Qc,u as Wc}from"./useSignature-DmY6Rwy-.js";import{S as vs,u as xo}from"./useDebouncedValue-C8nRE7Ln.js";import{E as ft,f as bo}from"./ErrorState-Cs_ykF6y.js";import{f as vo,a as mt,b as Ws,c as Vc,t as Yc}from"./format-BGdB831k.js";import{b as ys,R as An,g as Vs,l as Ht,s as Gc}from"./folder-roles-XnseeyyD.js";import{C as ws,S as Xc}from"./select-DeJpKA42.js";import{b as yo,h as Jc,p as Zc,u as eu}from"./filter-status-hhxxZCHD.js";const wo=se("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);const tu=se("ArrowRight",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]);const nn=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 su=se("Ban",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m4.9 4.9 14.2 14.2",key:"1m5liu"}]]);const jo=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 nu=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 za=se("Bug",[["path",{d:"m8 2 1.88 1.88",key:"fmnt4t"}],["path",{d:"M14.12 3.88 16 2",key:"qol33r"}],["path",{d:"M9 7.13v-1a3.003 3.003 0 1 1 6 0v1",key:"d7y7pr"}],["path",{d:"M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6",key:"xs1cw7"}],["path",{d:"M12 20v-9",key:"1qisl0"}],["path",{d:"M6.53 9C4.6 8.8 3 7.1 3 5",key:"32zzws"}],["path",{d:"M6 13H2",key:"82j7cp"}],["path",{d:"M3 21c0-2.1 1.7-3.9 3.8-4",key:"4p0ekp"}],["path",{d:"M20.97 5c0 2.1-1.6 3.8-3.5 4",key:"18gb23"}],["path",{d:"M22 13h-4",key:"1jl80f"}],["path",{d:"M17.2 17c2.1.1 3.8 1.9 3.8 4",key:"k3fwyw"}]]);const ms=se("ChevronRight",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]);const So=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 oa=se("CircleCheck",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const ia=se("Clock",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]]);const No=se("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]);const ko=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 au=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 Co=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 Eo=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 Io=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 ru=se("MailCheck",[["path",{d:"M22 13V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v12c0 1.1.9 2 2 2h8",key:"12jkf8"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}],["path",{d:"m16 19 2 2 4-4",key:"1b14m6"}]]);const js=se("MailOpen",[["path",{d:"M21.2 8.4c.5.38.8.97.8 1.6v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V10a2 2 0 0 1 .8-1.6l8-6a2 2 0 0 1 2.4 0l8 6Z",key:"1jhwl8"}],["path",{d:"m22 10-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 10",key:"1qfld7"}]]);const ou=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 iu=se("Minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);const an=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 lu=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 Ro=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 Mo=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 To=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 cu=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 Do=se("Settings",[["path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z",key:"1qme2f"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);const Ss=se("ShieldAlert",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M12 16h.01",key:"1drbdi"}]]);const rn=se("ShieldCheck",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const uu=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 du=se("ShieldX",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m14.5 9.5-5 5",key:"17q4r4"}],["path",{d:"m9.5 9.5 5 5",key:"18nt4w"}]]);const Ke=se("Sparkles",[["path",{d:"M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z",key:"4pj2yx"}],["path",{d:"M20 3v4",key:"1olli1"}],["path",{d:"M22 5h-4",key:"1gvqau"}],["path",{d:"M4 17v2",key:"vumght"}],["path",{d:"M5 18H3",key:"zchphs"}]]);const fu=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 mu=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"}]]),hu=({address:e,showTrustedBadge:t=!1})=>{const n=t?s.jsx(nn,{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]})},gu=({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(hu,{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(vt,{className:"h-4 w-4"}):s.jsx(ms,{className:"h-4 w-4"})})]})},pu=({email:e,displayName:t,onRemove:n,className:a})=>s.jsxs("span",{className:$("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(De,{className:"size-3"})})]}),xu={unknown:{label:"Unknown sender",tone:"neutral"},wellknown:{label:"Known sender",tone:"positive"},vip:{label:"VIP",tone:"accent"}};function At({label:e,children:t,className:n}){return s.jsxs("section",{className:$("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 bu({sender:e}){const t=xu[e.trust],n=e.inboundCount==null?null:(e.replyCount??0)>0?`${e.inboundCount} received · you replied ${e.replyCount}×`:`${e.inboundCount} received · you've never replied`;return s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx(st,{name:e.name,email:e.email,size:"md"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"truncate text-sm font-semibold text-fg",children:e.name}),s.jsx("div",{className:"truncate text-2xs text-fg-subtle",children:e.email})]})]}),s.jsx("div",{className:"mt-2 flex items-center gap-2",children:e.addressUnverified?s.jsx(Je,{tone:"danger",dot:!0,children:"Address couldn't be verified"}):s.jsx(Je,{tone:t.tone,dot:!0,children:t.label})}),s.jsxs("p",{className:"mt-2 text-xs text-fg-muted",children:["First seen ",e.firstSeenLabel,n?` · ${n}`:""]})]})}function vu({auth:e,onShowSimilar:t}){if(e.verdict==="aligned")return s.jsxs("div",{className:"flex items-start gap-2 text-xs text-fg-muted",children:[s.jsx(rn,{className:"mt-0.5 size-3.5 shrink-0 text-positive"}),s.jsx("span",{children:e.summary})]});if(e.verdict==="caution")return s.jsxs("div",{className:"flex items-start gap-2 rounded-md bg-warning/10 p-3 text-warning",children:[s.jsx(uu,{className:"mt-0.5 size-4 shrink-0"}),s.jsx("p",{className:"text-xs leading-relaxed",children:e.summary})]});const n=e.addressUnreadable?"This sender can't be verified":"This message may be impersonating someone";return s.jsxs("div",{className:"rounded-md bg-danger-soft p-3",children:[s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(Ss,{className:"mt-0.5 size-4 shrink-0 text-danger"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"text-sm font-semibold text-danger",children:n}),s.jsx("p",{className:"mt-1 text-xs leading-relaxed text-fg",children:e.summary}),!e.addressUnreadable&&e.dkimDomain&&s.jsxs("p",{className:"mt-1 text-2xs text-fg-muted",children:["Sent from"," ",s.jsx("code",{className:"rounded bg-surface px-1 py-0.5",children:e.dkimDomain}),", claims to be"," ",s.jsx("code",{className:"rounded bg-surface px-1 py-0.5",children:e.fromDomain})]})]})]}),e.similarCount!=null&&e.similarCount>0&&s.jsxs(X,{variant:"secondary",size:"sm",className:"mt-2 w-full border-danger/30 text-danger hover:bg-danger-soft",onClick:t,children:[e.similarCount," similar messages"]})]})}function Ot({icon:e,label:t,active:n,danger:a,onClick:r}){return s.jsxs("button",{type:"button",onClick:r,className:$("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"),children:[e,t]})}const yu={sender:"matched: sender",recipient:"matched: recipient",subject:"matched: subject",attachment:"matched: attachment",body:"matched: body",entities:"matched: entities"};function Ao({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:g}=e,x=d.verdict==="mismatch";return s.jsxs("aside",{className:$("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(X,{variant:"ghost",size:"sm",icon:s.jsx(De,{className:"size-3.5"}),onClick:t,"aria-label":"Collapse intelligence sidebar"})]}),s.jsx(At,{label:"Sender",children:s.jsx(bu,{sender:u})}),s.jsx(At,{label:"Authenticity",children:s.jsx(vu,{auth:d,onShowSimilar:n})}),s.jsx(At,{label:"Category",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Je,{tone:x?"danger":"neutral",children:f.value}),f.overridden&&s.jsx("span",{className:"text-2xs text-fg-subtle",children:"your override"}),s.jsx("button",{type:"button",className:"ml-auto text-2xs text-accent hover:underline",onClick:a?.onReclassify,children:"reclassify"})]})}),s.jsx(At,{label:"Quick actions",children:s.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[s.jsx(Ot,{icon:s.jsx(dt,{className:"size-3.5"}),label:"VIP",active:m.vip,onClick:a?.onToggleVip}),s.jsx(Ot,{icon:s.jsx(jo,{className:"size-3.5"}),label:"Mute",active:m.muted,onClick:a?.onToggleMute}),s.jsx(Ot,{icon:s.jsx(su,{className:"size-3.5"}),label:"Block",active:m.blocked,danger:!0,onClick:a?.onToggleBlock}),s.jsx(Ot,{icon:s.jsx(ou,{className:"size-3.5"}),label:"Unsubscribe",active:m.unsubscribed,onClick:a?.onToggleUnsubscribe}),a?.onNotSpam&&s.jsx(Ot,{icon:s.jsx(ru,{className:"size-3.5"}),label:"Not spam",onClick:a.onNotSpam}),a?.onMarkSpam&&s.jsx(Ot,{icon:s.jsx(du,{className:"size-3.5"}),label:"Mark spam",danger:!0,onClick:a.onMarkSpam})]})}),(r!=="ready"||g.length>0)&&s.jsx(At,{label:"Similar messages",children:r==="loading"?s.jsx("div",{className:"animate-pulse space-y-2",children:Array.from({length:3}).map((b,p)=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"h-3 w-3/4 rounded bg-surface-sunken"}),s.jsx("div",{className:"h-2.5 w-1/2 rounded bg-surface-sunken"})]},p))}):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:g.map(b=>{const p="block w-full rounded-md px-1 py-1 text-left hover:bg-surface-sunken",y=`Open message from ${b.fromName||"unknown sender"}: ${b.subject}`,h=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:yu[b.matched]})]});return s.jsx("li",{children:o?o({mailboxId:b.mailboxId,messageId:b.id,className:p,ariaLabel:y,children:h}):s.jsx("div",{className:p,children:h})},b.id)})})}),s.jsx(At,{label:"Coming soon",className:"border-b-0 opacity-70",children:s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed border-line p-2",children:[s.jsx(Ke,{className:"mt-0.5 size-3.5 shrink-0 text-fg-subtle"}),s.jsxs("div",{children:[s.jsx("div",{className:"text-xs font-medium text-fg-muted",children:"Suggested actions"}),s.jsx("div",{className:"text-2xs text-fg-subtle",children:'"Create a filter for messages like this" — on-device model'})]})]}),s.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed border-line p-2",children:[s.jsx(Ke,{className:"mt-0.5 size-3.5 shrink-0 text-fg-subtle"}),s.jsxs("div",{children:[s.jsx("div",{className:"text-xs font-medium text-fg-muted",children:"Thread summary"}),s.jsx("div",{className:"text-2xs text-fg-subtle",children:"One-paragraph digest — Bedrock"})]})]})]})})]})}const wu=[{keys:["j","k"],label:"navigate"},{keys:["m"],label:"mute"},{keys:["?"],label:"all shortcuts"}];function Oo({hints:e=wu,className:t}){return s.jsx("footer",{className:$("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(ju,{hint:n},n.label))})}function ju({hint:e}){return s.jsxs("span",{className:"flex items-center gap-1",children:[e.keys.map(t=>s.jsx(Kt,{children:t},t)),s.jsx("span",{children:e.label})]})}function Su(){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 Nu({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 ku({message:e="Something went wrong loading this mailbox.",onRetry:t,onReport:n}){return s.jsx("div",{className:"flex h-full flex-1 items-center justify-center p-4",children:s.jsxs("div",{role:"alert",className:"flex max-w-sm flex-col items-center justify-center gap-3 text-center",children:[s.jsx(yt,{className:"size-8 text-danger","aria-hidden":"true"}),s.jsxs("div",{children:[s.jsx("p",{className:"font-medium text-danger",children:"Couldn't load messages"}),s.jsx("p",{className:"mt-1 break-words text-sm text-fg-muted",children:e})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[t&&s.jsx(X,{variant:"secondary",size:"sm",onClick:t,children:"Retry"}),n&&s.jsx(X,{variant:"ghost",size:"sm",onClick:n,children:"Report a problem"})]})]})})}const Po=({active:e,focused:t})=>$("relative flex h-8 w-full items-center gap-2 px-row-inset text-left",e?"bg-accent-2-soft":t?"bg-surface-sunken":"hover:bg-surface-sunken",t&&!e&&"before:absolute before:inset-y-0 before:left-0 before:w-0.5 before:bg-accent-2"),Yt=({active:e,focused:t})=>$("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 Lo({thread:e}){const t=!e.isRead;return s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"flex w-4 shrink-0 items-center justify-center",children:e.suspicious?s.jsx(Ss,{className:"size-3.5 text-danger"}):e.starred?s.jsx(dt,{className:"size-3 fill-warning text-warning"}):t?s.jsx("span",{className:"size-1.5 rounded-full bg-accent"}):null}),s.jsx("span",{className:$("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:$(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(an,{className:"size-3 shrink-0 text-fg-subtle"}),s.jsx("span",{className:"w-11 shrink-0 text-right text-2xs text-fg-subtle tabular-nums",children:e.timeLabel})]})}function Gt({thread:e,badge:t}){const n=!e.isRead;return s.jsxs("span",{className:"min-w-0 flex-1",children:[s.jsxs("span",{className:"flex items-baseline justify-between gap-2",children:[s.jsxs("span",{className:$("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:$("truncate text-sm",n?"text-fg":"text-fg-muted"),children:e.subject}),e.suspicious&&s.jsx(Ss,{className:"size-3.5 shrink-0 text-danger"}),e.starred&&s.jsx(dt,{className:"size-3 shrink-0 fill-warning text-warning"}),e.hasAttachment&&s.jsx(an,{className:"size-3 shrink-0 text-fg-subtle"})]}),s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"line-clamp-1 min-w-0 flex-1 text-xs text-fg-subtle",children:e.snippet}),e.category&&e.category!=="personal"&&s.jsx(Je,{tone:Xl[e.category],className:"shrink-0",children:e.category}),t]})]})}function zo({thread:e}){const t=!e.isRead;return s.jsxs(s.Fragment,{children:[t&&s.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),s.jsx(st,{name:e.fromName,email:e.fromEmail,size:"sm"}),s.jsx(Gt,{thread:e})]})}function Cu({thread:e,active:t,onClick:n}){return s.jsx("button",{type:"button",onClick:n,className:Po({active:t}),children:s.jsx(Lo,{thread:e})})}function _o({thread:e,active:t,onClick:n}){return s.jsx("button",{type:"button",onClick:n,className:Yt({active:t}),children:s.jsx(zo,{thread:e})})}function Fo({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(X,{variant:"ghost",size:"sm",icon:s.jsx(De,{className:"size-4"}),onClick:t,"aria-label":"Cancel selection",className:"-ml-1 shrink-0"}),s.jsxs("span",{className:"min-w-0 flex-1 truncate text-sm font-medium text-fg",children:[e," ",e===1?"message":"messages"," selected"]}),n&&s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(js,{className:"size-4"}),onClick:i?void 0:n,"aria-label":"Mark as read","aria-busy":i||void 0,className:"shrink-0"}),r,s.jsx(X,{variant:"ghost",size:"sm",icon:i?s.jsx(St,{className:"size-4 animate-spin"}):s.jsx(qe,{className:"size-4 text-danger"}),onClick:i?void 0: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 Qt=72,_a=10;function Fa(e){return e==="leading"?Qt:e==="trailing"?-Qt:0}function Eu(e){return e>=Qt/2?"leading":e<=-Qt/2?"trailing":"none"}function Bo({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),g=c.useRef(null),[x,b]=c.useState(null),p=()=>clearTimeout(m.current),y=C=>{g.current={startX:C.clientX,startY:C.clientY,axis:"none",moved:!1},!t&&(m.current=setTimeout(()=>{g.current=null,b(null),l()},500))},h=C=>{if(t)return;const E=g.current;if(!E)return;const R=C.clientX-E.startX,M=C.clientY-E.startY;if(E.axis==="none"){if(Math.abs(M)>_a&&Math.abs(M)>Math.abs(R)){E.axis="vertical",p(),g.current=null;return}Math.abs(R)>_a&&(E.axis="horizontal",E.moved=!0,p(),C.currentTarget.setPointerCapture(C.pointerId))}if(E.axis!=="horizontal")return;const T=Fa(r),P=Math.max(-Qt,Math.min(Qt,T+R));b(P)},v=()=>{p();const C=g.current;g.current=null;const E=x;if(b(null),!!C){if(C.axis==="horizontal"&&E!==null){o(Eu(E));return}if(t){i();return}if(r!=="none"){o("none");return}f||u()}},j=C=>{r!=="none"&&C.preventDefault()},w=x??Fa(r),N=w>0?"leading":w<0?"trailing":"none",I=$("relative touch-pan-y bg-surface",Yt({active:n||a})),S={transform:w!==0?`translateX(${w}px)`:void 0,transition:x===null?"transform 150ms ease":"none",minHeight:44},k=t?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:$("inline-flex size-7 shrink-0 items-center justify-center rounded-full border",n?"border-accent bg-accent text-accent-fg":"border-line-strong bg-canvas"),children:n&&s.jsx(ws,{className:"size-3.5"})}),s.jsx(Gt,{thread:e})]}):s.jsx(zo,{thread:e});return s.jsxs("div",{className:"relative overflow-hidden",children:[N==="leading"&&s.jsx("button",{type:"button",onClick:()=>d("leading"),"aria-label":e.isRead?"Mark as unread":"Mark as read",className:"absolute inset-y-0 left-0 flex items-center justify-start bg-accent-2 px-6 text-accent-fg",children:e.isRead?s.jsx(go,{className:"size-6"}):s.jsx(js,{className:"size-6"})}),N==="trailing"&&s.jsx("button",{type:"button",onClick:()=>d("trailing"),"aria-label":"Delete message",className:"absolute inset-y-0 right-0 flex items-center justify-end bg-danger px-6 text-canvas",children:s.jsx(qe,{className:"size-6"})}),f&&!t?f({className:I,style:S,onPointerDown:y,onPointerMove:h,onPointerUp:v,onPointerCancel:v,onOpenClick:j,children:k}):s.jsx("button",{type:"button",onPointerDown:y,onPointerMove:h,onPointerUp:v,onPointerCancel:v,className:I,style:S,children:k})]})}function Iu({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(p=>p.threads)),[g,x]=c.useState(r&&r!=="none"&&f[1]?{id:f[1].id,side:r}:null),b=(p,y)=>{m(y==="trailing"?h=>h.filter(v=>v.id!==p):h=>h.map(v=>v.id===p?{...v,isRead:!v.isRead}:v)),x(null)};return s.jsxs("div",{className:"flex-1 overflow-y-auto",children:[d&&s.jsxs("div",{className:"flex items-center justify-center gap-2 border-b border-line py-3 text-fg-muted",children:[s.jsx(Ro,{className:"size-4 animate-spin"}),s.jsx("span",{className:"text-xs",children:"Checking for new mail…"})]}),s.jsx("div",{className:"divide-y divide-line",children:f.map(p=>s.jsx(Bo,{thread:p,selectionMode:n,checked:a.has(p.id),active:p.id===t,peek:g?.id===p.id?g.side:"none",onPeek:y=>x(y==="none"?null:{id:p.id,side:y}),onToggleCheck:()=>o(p.id),onLongPress:()=>i(p.id),onOpen:()=>l(p.id),onAct:y=>b(p.id,y)},p.id))}),!n&&!d&&s.jsx("button",{type:"button",onClick:u,className:"w-full border-t border-line py-2 text-center text-2xs text-fg-subtle transition-colors hover:bg-surface-sunken",children:"Pull to refresh"})]})}function $o({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:g="comfortable",onSelectThread:x,onSelectBriefCategory:b,onOpenNav:p,isDesktop:y,initialTouchState:h,selectionBar:v,listBody:j,hideHeader:w=!1}){const N=g==="compact"?Cu:_o,I=!y&&!a&&o==="ready",S=n.flatMap(q=>q.threads),[k,C]=c.useState(h==="selection"),[E,R]=c.useState(()=>h==="selection"?new Set(S.slice(0,2).map(q=>q.id)):new Set),[M,T]=c.useState(!1),P=h==="peek-trailing"?"trailing":h==="peek-leading"?"leading":void 0,Y=q=>{R(te=>{const U=new Set(te);return U.has(q)?U.delete(q):U.add(q),U.size===0&&C(!1),U})},K=q=>{C(!0),R(new Set([q]))},B=()=>{C(!1),R(new Set)},_=()=>{T(!0),setTimeout(()=>T(!1),1400)},F=!v&&I&&k&&E.size>0;return s.jsxs("section",{className:"flex h-full w-full flex-col bg-surface",children:[v??(F?s.jsx(Fo,{count:E.size,onCancel:B,onMarkRead:B,onDelete:B}):w?null:s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[p&&s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(ra,{className:"size-4"}),onClick:p,"aria-label":"Open folders",className:"-ml-1 shrink-0"}),s.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e}),t&&s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle",children:t})]})),o==="loading"?s.jsx("div",{className:"flex-1 overflow-y-auto",children:s.jsx(Su,{})}):o==="empty"?s.jsx(Nu,{searchQuery:i}):o==="error"?s.jsx(ku,{message:l,onRetry:u,onReport:d}):a?s.jsx(Xr,{sections:n,briefCategory:f,selectedThreadId:m,Row:N,onSelectThread:x,onSelectBriefCategory:b}):j??(I?s.jsx(Iu,{sections:n,selectedThreadId:m,selectionMode:k,checkedIds:E,initialPeek:P,onToggleCheck:Y,onEnterSelection:K,onOpenThread:q=>x?.(q),onRefresh:_,refreshing:M}):s.jsx("div",{className:"flex-1 overflow-y-auto",children:n.map(q=>s.jsxs("div",{children:[!r&&q.label&&s.jsxs("div",{className:"sticky top-0 flex h-section-row items-center justify-between border-b border-line bg-surface-sunken px-row-inset",children:[s.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:q.label}),s.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:q.threads.length})]}),s.jsx("div",{className:"divide-y divide-line",children:q.threads.map(te=>s.jsx(N,{thread:te,active:te.id===m,onClick:()=>x?.(te.id)},te.id))})]},q.id))})),y&&s.jsx(Oo,{})]})}function Ru({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:$("relative",o),children:[s.jsx(X,{variant:"ghost",size:"sm",icon:t??s.jsx(ko,{className:"size-5"}),onClick:()=>l(d=>!d),"aria-label":e,"aria-haspopup":"menu","aria-expanded":i,className:$(r&&"min-h-11 min-w-11 px-0")}),i&&s.jsx("div",{role:"menu",className:$("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 as="min-h-11 min-w-11 px-0";function Ko({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:g,className:x}){const b=(y,h)=>()=>{if(!e){m?.(y);return}h?.()},p=u?[{key:"toggle-read",label:l?"Mark as unread":"Mark as read",icon:l?s.jsx(go,{className:"size-4"}):s.jsx(js,{className:"size-4"}),onSelect:b("toggleRead",u)}]:[];return s.jsxs("div",{className:$("relative",x),children:[s.jsxs("div",{className:"flex h-12 shrink-0 items-center gap-0.5 border-y border-line bg-canvas px-1",children:[s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(To,{className:"size-5"}),onClick:b("reply",t),"aria-label":"Reply",title:"Reply",className:as}),s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(Mo,{className:"size-5"}),onClick:b("replyAll",n),"aria-label":"Reply all",title:"Reply all",className:as}),s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(Eo,{className:"size-5"}),onClick:b("forward",a),"aria-label":"Forward",title:"Forward",className:as}),s.jsx("div",{className:"flex-1"}),s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(dt,{className:$("size-5",r&&"fill-warning text-warning")}),onClick:b("star",o),"aria-label":r?"Remove flag":"Flag","aria-pressed":r,title:r?"Remove flag":"Flag",className:as}),d,s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(qe,{className:"size-5"}),onClick:b("delete",i),"aria-label":"Move to Trash",title:"Move to Trash",className:as}),s.jsx(Ru,{triggerLabel:"More actions",items:[...p,...f]})]}),!e&&g&&s.jsx("p",{role:"status",className:"border-b border-line bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:g})]})}function Mu({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:g="Reply (r)",replyAllTitle:x="Reply all (a)",forwardTitle:b="Forward (f)",deleteTitle:p="Move to Trash (#)",flagTitle:y="Flag (s)",children:h,className:v}){const j=(w,N)=>()=>{if(!e){t?.(w);return}N?.()};return s.jsxs("div",{className:"relative",children:[s.jsxs("header",{className:$("flex h-pane-header shrink-0 items-center gap-1 border-b border-line bg-surface px-3",v),children:[s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(To,{className:"size-4"}),title:g,"aria-label":"Reply",onClick:j("reply",o)}),s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(Mo,{className:"size-4"}),title:x,"aria-label":"Reply all",onClick:j("replyAll",i)}),s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(Eo,{className:"size-4"}),title:b,"aria-label":"Forward",onClick:j("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(X,{variant:"ghost",size:"sm",icon:s.jsx(qe,{className:"size-4"}),title:p,"aria-label":"Move to Trash",onClick:j("delete",u)}),f??s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(Co,{className:"size-4"}),title:"Move to mailbox","aria-label":"Move to mailbox",onClick:j("move",m)}),s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(dt,{className:$("size-4",a&&"fill-warning text-warning")}),title:y,"aria-label":"Flag",onClick:j("flag",d)})]}),s.jsx("div",{className:"flex-1"}),h]}),!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 Tu=(e,t)=>{const a=e==="newsletter"||e==="marketing"||t;return{framed:a,isPlain:!a}},Du=()=>`
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ComposeBody-CJCPS_su.js","assets/index-BuygbWIE.js","assets/index-DmHlZDE_.css","assets/kbd-06NmYfQr.js","assets/avatar-CG5Pc7a1.js","assets/star-B10UnFVc.js","assets/trash-2-DlrBh3cg.js","assets/account-form-helpers-sCUQ_UAD.js","assets/send-ZKJgkB_s.js","assets/useMutation-5toMj9JW.js","assets/useSignature-CjD7hQBM.js","assets/useDebouncedValue-BUjsMXUW.js","assets/ErrorState-C2v8yoJp.js","assets/format-BGdB831k.js","assets/folder-roles-XnseeyyD.js","assets/select-DaeZJyvp.js","assets/filter-status-v5X9jZaF.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{c as se,r as c,j as s,C as vt,X as De,a as $,B as X,b as Je,d as yt,e as Xl,f as Xr,p as Jr,I as Qn,i as Jl,g as Zr,D as eo,O as Zl,F as Wn,h as to,T as Vn,P as ec,k as so,l as tc,R as Yn,m as Gn,_ as it,n as no,o as sc,Q as Xn,q as nc,s as ac,S as rc,t as Tn,u as oc,v as ic,w as je,x as lc,y as cc,z as uc,A as dc,E as fc,G as mc,H as La,J as hc,K as gc,L as pc,M as ao,N as ro,U as oo,V as wt,W as Ce,Y as fe,Z as xs,$ as Jn,a0 as re,a1 as io,a2 as lo,a3 as xc,a4 as Js,a5 as co,a6 as Ze,a7 as ze,a8 as bc,a9 as $e,aa as uo,ab as fs,ac as Zs,ad as vc,ae as et,af as tt,ag as ut,ah as Vt,ai as en,aj as jt,ak as yc,al as wc,am as jc,an as fo,ao as z,ap as tn,aq as Ut,ar as Sc,as as Zn,at as Nc,au as kc,av as Ee,aw as mo,ax as ea,ay as sn,az as Dn,aA as Cc,aB as ho,aC as Xe,aD as ta,aE as sa,aF as na,aG as Ec,aH as Ic,aI as Rc,aJ as Mc,aK as aa,aL as Tc,aM as Dc,aN as Ac,aO as Oc,aP as Pc,aQ as Lc,aR as zc,aS as _c,aT as Fc,aU as rt,aV as Ye,aW as Bc}from"./index-BuygbWIE.js";import{K as Kt}from"./kbd-06NmYfQr.js";import{A as st,M as ra,C as $c}from"./avatar-CG5Pc7a1.js";import{S as dt}from"./star-B10UnFVc.js";import{T as qe}from"./trash-2-DlrBh3cg.js";import{L as St,M as go,a as Kc}from"./account-form-helpers-sCUQ_UAD.js";import{S as bs,F as qc,M as Uc,A as Hc,a as po}from"./send-ZKJgkB_s.js";import{u as xe}from"./useMutation-5toMj9JW.js";import{R as Qc,u as Wc}from"./useSignature-CjD7hQBM.js";import{S as vs,u as xo}from"./useDebouncedValue-BUjsMXUW.js";import{E as ft,f as bo}from"./ErrorState-C2v8yoJp.js";import{f as vo,a as mt,b as Ws,c as Vc,t as Yc}from"./format-BGdB831k.js";import{b as ys,R as An,g as Vs,l as Ht,s as Gc}from"./folder-roles-XnseeyyD.js";import{C as ws,S as Xc}from"./select-DaeZJyvp.js";import{b as yo,h as Jc,p as Zc,u as eu}from"./filter-status-v5X9jZaF.js";const wo=se("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);const tu=se("ArrowRight",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]);const nn=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 su=se("Ban",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m4.9 4.9 14.2 14.2",key:"1m5liu"}]]);const jo=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 nu=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 za=se("Bug",[["path",{d:"m8 2 1.88 1.88",key:"fmnt4t"}],["path",{d:"M14.12 3.88 16 2",key:"qol33r"}],["path",{d:"M9 7.13v-1a3.003 3.003 0 1 1 6 0v1",key:"d7y7pr"}],["path",{d:"M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6",key:"xs1cw7"}],["path",{d:"M12 20v-9",key:"1qisl0"}],["path",{d:"M6.53 9C4.6 8.8 3 7.1 3 5",key:"32zzws"}],["path",{d:"M6 13H2",key:"82j7cp"}],["path",{d:"M3 21c0-2.1 1.7-3.9 3.8-4",key:"4p0ekp"}],["path",{d:"M20.97 5c0 2.1-1.6 3.8-3.5 4",key:"18gb23"}],["path",{d:"M22 13h-4",key:"1jl80f"}],["path",{d:"M17.2 17c2.1.1 3.8 1.9 3.8 4",key:"k3fwyw"}]]);const ms=se("ChevronRight",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]);const So=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 oa=se("CircleCheck",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const ia=se("Clock",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]]);const No=se("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]);const ko=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 au=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 Co=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 Eo=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 Io=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 ru=se("MailCheck",[["path",{d:"M22 13V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v12c0 1.1.9 2 2 2h8",key:"12jkf8"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}],["path",{d:"m16 19 2 2 4-4",key:"1b14m6"}]]);const js=se("MailOpen",[["path",{d:"M21.2 8.4c.5.38.8.97.8 1.6v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V10a2 2 0 0 1 .8-1.6l8-6a2 2 0 0 1 2.4 0l8 6Z",key:"1jhwl8"}],["path",{d:"m22 10-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 10",key:"1qfld7"}]]);const ou=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 iu=se("Minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);const an=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 lu=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 Ro=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 Mo=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 To=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 cu=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 Do=se("Settings",[["path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z",key:"1qme2f"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);const Ss=se("ShieldAlert",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M12 16h.01",key:"1drbdi"}]]);const rn=se("ShieldCheck",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const uu=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 du=se("ShieldX",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m14.5 9.5-5 5",key:"17q4r4"}],["path",{d:"m9.5 9.5 5 5",key:"18nt4w"}]]);const Ke=se("Sparkles",[["path",{d:"M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z",key:"4pj2yx"}],["path",{d:"M20 3v4",key:"1olli1"}],["path",{d:"M22 5h-4",key:"1gvqau"}],["path",{d:"M4 17v2",key:"vumght"}],["path",{d:"M5 18H3",key:"zchphs"}]]);const fu=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 mu=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"}]]),hu=({address:e,showTrustedBadge:t=!1})=>{const n=t?s.jsx(nn,{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]})},gu=({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(hu,{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(vt,{className:"h-4 w-4"}):s.jsx(ms,{className:"h-4 w-4"})})]})},pu=({email:e,displayName:t,onRemove:n,className:a})=>s.jsxs("span",{className:$("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(De,{className:"size-3"})})]}),xu={unknown:{label:"Unknown sender",tone:"neutral"},wellknown:{label:"Known sender",tone:"positive"},vip:{label:"VIP",tone:"accent"}};function At({label:e,children:t,className:n}){return s.jsxs("section",{className:$("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 bu({sender:e}){const t=xu[e.trust],n=e.inboundCount==null?null:(e.replyCount??0)>0?`${e.inboundCount} received · you replied ${e.replyCount}×`:`${e.inboundCount} received · you've never replied`;return s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx(st,{name:e.name,email:e.email,size:"md"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"truncate text-sm font-semibold text-fg",children:e.name}),s.jsx("div",{className:"truncate text-2xs text-fg-subtle",children:e.email})]})]}),s.jsx("div",{className:"mt-2 flex items-center gap-2",children:e.addressUnverified?s.jsx(Je,{tone:"danger",dot:!0,children:"Address couldn't be verified"}):s.jsx(Je,{tone:t.tone,dot:!0,children:t.label})}),s.jsxs("p",{className:"mt-2 text-xs text-fg-muted",children:["First seen ",e.firstSeenLabel,n?` · ${n}`:""]})]})}function vu({auth:e,onShowSimilar:t}){if(e.verdict==="aligned")return s.jsxs("div",{className:"flex items-start gap-2 text-xs text-fg-muted",children:[s.jsx(rn,{className:"mt-0.5 size-3.5 shrink-0 text-positive"}),s.jsx("span",{children:e.summary})]});if(e.verdict==="caution")return s.jsxs("div",{className:"flex items-start gap-2 rounded-md bg-warning/10 p-3 text-warning",children:[s.jsx(uu,{className:"mt-0.5 size-4 shrink-0"}),s.jsx("p",{className:"text-xs leading-relaxed",children:e.summary})]});const n=e.addressUnreadable?"This sender can't be verified":"This message may be impersonating someone";return s.jsxs("div",{className:"rounded-md bg-danger-soft p-3",children:[s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(Ss,{className:"mt-0.5 size-4 shrink-0 text-danger"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"text-sm font-semibold text-danger",children:n}),s.jsx("p",{className:"mt-1 text-xs leading-relaxed text-fg",children:e.summary}),!e.addressUnreadable&&e.dkimDomain&&s.jsxs("p",{className:"mt-1 text-2xs text-fg-muted",children:["Sent from"," ",s.jsx("code",{className:"rounded bg-surface px-1 py-0.5",children:e.dkimDomain}),", claims to be"," ",s.jsx("code",{className:"rounded bg-surface px-1 py-0.5",children:e.fromDomain})]})]})]}),e.similarCount!=null&&e.similarCount>0&&s.jsxs(X,{variant:"secondary",size:"sm",className:"mt-2 w-full border-danger/30 text-danger hover:bg-danger-soft",onClick:t,children:[e.similarCount," similar messages"]})]})}function Ot({icon:e,label:t,active:n,danger:a,onClick:r}){return s.jsxs("button",{type:"button",onClick:r,className:$("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"),children:[e,t]})}const yu={sender:"matched: sender",recipient:"matched: recipient",subject:"matched: subject",attachment:"matched: attachment",body:"matched: body",entities:"matched: entities"};function Ao({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:g}=e,x=d.verdict==="mismatch";return s.jsxs("aside",{className:$("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(X,{variant:"ghost",size:"sm",icon:s.jsx(De,{className:"size-3.5"}),onClick:t,"aria-label":"Collapse intelligence sidebar"})]}),s.jsx(At,{label:"Sender",children:s.jsx(bu,{sender:u})}),s.jsx(At,{label:"Authenticity",children:s.jsx(vu,{auth:d,onShowSimilar:n})}),s.jsx(At,{label:"Category",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Je,{tone:x?"danger":"neutral",children:f.value}),f.overridden&&s.jsx("span",{className:"text-2xs text-fg-subtle",children:"your override"}),s.jsx("button",{type:"button",className:"ml-auto text-2xs text-accent hover:underline",onClick:a?.onReclassify,children:"reclassify"})]})}),s.jsx(At,{label:"Quick actions",children:s.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[s.jsx(Ot,{icon:s.jsx(dt,{className:"size-3.5"}),label:"VIP",active:m.vip,onClick:a?.onToggleVip}),s.jsx(Ot,{icon:s.jsx(jo,{className:"size-3.5"}),label:"Mute",active:m.muted,onClick:a?.onToggleMute}),s.jsx(Ot,{icon:s.jsx(su,{className:"size-3.5"}),label:"Block",active:m.blocked,danger:!0,onClick:a?.onToggleBlock}),s.jsx(Ot,{icon:s.jsx(ou,{className:"size-3.5"}),label:"Unsubscribe",active:m.unsubscribed,onClick:a?.onToggleUnsubscribe}),a?.onNotSpam&&s.jsx(Ot,{icon:s.jsx(ru,{className:"size-3.5"}),label:"Not spam",onClick:a.onNotSpam}),a?.onMarkSpam&&s.jsx(Ot,{icon:s.jsx(du,{className:"size-3.5"}),label:"Mark spam",danger:!0,onClick:a.onMarkSpam})]})}),(r!=="ready"||g.length>0)&&s.jsx(At,{label:"Similar messages",children:r==="loading"?s.jsx("div",{className:"animate-pulse space-y-2",children:Array.from({length:3}).map((b,p)=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"h-3 w-3/4 rounded bg-surface-sunken"}),s.jsx("div",{className:"h-2.5 w-1/2 rounded bg-surface-sunken"})]},p))}):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:g.map(b=>{const p="block w-full rounded-md px-1 py-1 text-left hover:bg-surface-sunken",y=`Open message from ${b.fromName||"unknown sender"}: ${b.subject}`,h=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:yu[b.matched]})]});return s.jsx("li",{children:o?o({mailboxId:b.mailboxId,messageId:b.id,className:p,ariaLabel:y,children:h}):s.jsx("div",{className:p,children:h})},b.id)})})}),s.jsx(At,{label:"Coming soon",className:"border-b-0 opacity-70",children:s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed border-line p-2",children:[s.jsx(Ke,{className:"mt-0.5 size-3.5 shrink-0 text-fg-subtle"}),s.jsxs("div",{children:[s.jsx("div",{className:"text-xs font-medium text-fg-muted",children:"Suggested actions"}),s.jsx("div",{className:"text-2xs text-fg-subtle",children:'"Create a filter for messages like this" — on-device model'})]})]}),s.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed border-line p-2",children:[s.jsx(Ke,{className:"mt-0.5 size-3.5 shrink-0 text-fg-subtle"}),s.jsxs("div",{children:[s.jsx("div",{className:"text-xs font-medium text-fg-muted",children:"Thread summary"}),s.jsx("div",{className:"text-2xs text-fg-subtle",children:"One-paragraph digest — Bedrock"})]})]})]})})]})}const wu=[{keys:["j","k"],label:"navigate"},{keys:["m"],label:"mute"},{keys:["?"],label:"all shortcuts"}];function Oo({hints:e=wu,className:t}){return s.jsx("footer",{className:$("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(ju,{hint:n},n.label))})}function ju({hint:e}){return s.jsxs("span",{className:"flex items-center gap-1",children:[e.keys.map(t=>s.jsx(Kt,{children:t},t)),s.jsx("span",{children:e.label})]})}function Su(){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 Nu({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 ku({message:e="Something went wrong loading this mailbox.",onRetry:t,onReport:n}){return s.jsx("div",{className:"flex h-full flex-1 items-center justify-center p-4",children:s.jsxs("div",{role:"alert",className:"flex max-w-sm flex-col items-center justify-center gap-3 text-center",children:[s.jsx(yt,{className:"size-8 text-danger","aria-hidden":"true"}),s.jsxs("div",{children:[s.jsx("p",{className:"font-medium text-danger",children:"Couldn't load messages"}),s.jsx("p",{className:"mt-1 break-words text-sm text-fg-muted",children:e})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[t&&s.jsx(X,{variant:"secondary",size:"sm",onClick:t,children:"Retry"}),n&&s.jsx(X,{variant:"ghost",size:"sm",onClick:n,children:"Report a problem"})]})]})})}const Po=({active:e,focused:t})=>$("relative flex h-8 w-full items-center gap-2 px-row-inset text-left",e?"bg-accent-2-soft":t?"bg-surface-sunken":"hover:bg-surface-sunken",t&&!e&&"before:absolute before:inset-y-0 before:left-0 before:w-0.5 before:bg-accent-2"),Yt=({active:e,focused:t})=>$("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 Lo({thread:e}){const t=!e.isRead;return s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"flex w-4 shrink-0 items-center justify-center",children:e.suspicious?s.jsx(Ss,{className:"size-3.5 text-danger"}):e.starred?s.jsx(dt,{className:"size-3 fill-warning text-warning"}):t?s.jsx("span",{className:"size-1.5 rounded-full bg-accent"}):null}),s.jsx("span",{className:$("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:$(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(an,{className:"size-3 shrink-0 text-fg-subtle"}),s.jsx("span",{className:"w-11 shrink-0 text-right text-2xs text-fg-subtle tabular-nums",children:e.timeLabel})]})}function Gt({thread:e,badge:t}){const n=!e.isRead;return s.jsxs("span",{className:"min-w-0 flex-1",children:[s.jsxs("span",{className:"flex items-baseline justify-between gap-2",children:[s.jsxs("span",{className:$("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:$("truncate text-sm",n?"text-fg":"text-fg-muted"),children:e.subject}),e.suspicious&&s.jsx(Ss,{className:"size-3.5 shrink-0 text-danger"}),e.starred&&s.jsx(dt,{className:"size-3 shrink-0 fill-warning text-warning"}),e.hasAttachment&&s.jsx(an,{className:"size-3 shrink-0 text-fg-subtle"})]}),s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"line-clamp-1 min-w-0 flex-1 text-xs text-fg-subtle",children:e.snippet}),e.category&&e.category!=="personal"&&s.jsx(Je,{tone:Xl[e.category],className:"shrink-0",children:e.category}),t]})]})}function zo({thread:e}){const t=!e.isRead;return s.jsxs(s.Fragment,{children:[t&&s.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),s.jsx(st,{name:e.fromName,email:e.fromEmail,size:"sm"}),s.jsx(Gt,{thread:e})]})}function Cu({thread:e,active:t,onClick:n}){return s.jsx("button",{type:"button",onClick:n,className:Po({active:t}),children:s.jsx(Lo,{thread:e})})}function _o({thread:e,active:t,onClick:n}){return s.jsx("button",{type:"button",onClick:n,className:Yt({active:t}),children:s.jsx(zo,{thread:e})})}function Fo({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(X,{variant:"ghost",size:"sm",icon:s.jsx(De,{className:"size-4"}),onClick:t,"aria-label":"Cancel selection",className:"-ml-1 shrink-0"}),s.jsxs("span",{className:"min-w-0 flex-1 truncate text-sm font-medium text-fg",children:[e," ",e===1?"message":"messages"," selected"]}),n&&s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(js,{className:"size-4"}),onClick:i?void 0:n,"aria-label":"Mark as read","aria-busy":i||void 0,className:"shrink-0"}),r,s.jsx(X,{variant:"ghost",size:"sm",icon:i?s.jsx(St,{className:"size-4 animate-spin"}):s.jsx(qe,{className:"size-4 text-danger"}),onClick:i?void 0: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 Qt=72,_a=10;function Fa(e){return e==="leading"?Qt:e==="trailing"?-Qt:0}function Eu(e){return e>=Qt/2?"leading":e<=-Qt/2?"trailing":"none"}function Bo({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),g=c.useRef(null),[x,b]=c.useState(null),p=()=>clearTimeout(m.current),y=C=>{g.current={startX:C.clientX,startY:C.clientY,axis:"none",moved:!1},!t&&(m.current=setTimeout(()=>{g.current=null,b(null),l()},500))},h=C=>{if(t)return;const E=g.current;if(!E)return;const R=C.clientX-E.startX,M=C.clientY-E.startY;if(E.axis==="none"){if(Math.abs(M)>_a&&Math.abs(M)>Math.abs(R)){E.axis="vertical",p(),g.current=null;return}Math.abs(R)>_a&&(E.axis="horizontal",E.moved=!0,p(),C.currentTarget.setPointerCapture(C.pointerId))}if(E.axis!=="horizontal")return;const T=Fa(r),P=Math.max(-Qt,Math.min(Qt,T+R));b(P)},v=()=>{p();const C=g.current;g.current=null;const E=x;if(b(null),!!C){if(C.axis==="horizontal"&&E!==null){o(Eu(E));return}if(t){i();return}if(r!=="none"){o("none");return}f||u()}},j=C=>{r!=="none"&&C.preventDefault()},w=x??Fa(r),N=w>0?"leading":w<0?"trailing":"none",I=$("relative touch-pan-y bg-surface",Yt({active:n||a})),S={transform:w!==0?`translateX(${w}px)`:void 0,transition:x===null?"transform 150ms ease":"none",minHeight:44},k=t?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:$("inline-flex size-7 shrink-0 items-center justify-center rounded-full border",n?"border-accent bg-accent text-accent-fg":"border-line-strong bg-canvas"),children:n&&s.jsx(ws,{className:"size-3.5"})}),s.jsx(Gt,{thread:e})]}):s.jsx(zo,{thread:e});return s.jsxs("div",{className:"relative overflow-hidden",children:[N==="leading"&&s.jsx("button",{type:"button",onClick:()=>d("leading"),"aria-label":e.isRead?"Mark as unread":"Mark as read",className:"absolute inset-y-0 left-0 flex items-center justify-start bg-accent-2 px-6 text-accent-fg",children:e.isRead?s.jsx(go,{className:"size-6"}):s.jsx(js,{className:"size-6"})}),N==="trailing"&&s.jsx("button",{type:"button",onClick:()=>d("trailing"),"aria-label":"Delete message",className:"absolute inset-y-0 right-0 flex items-center justify-end bg-danger px-6 text-canvas",children:s.jsx(qe,{className:"size-6"})}),f&&!t?f({className:I,style:S,onPointerDown:y,onPointerMove:h,onPointerUp:v,onPointerCancel:v,onOpenClick:j,children:k}):s.jsx("button",{type:"button",onPointerDown:y,onPointerMove:h,onPointerUp:v,onPointerCancel:v,className:I,style:S,children:k})]})}function Iu({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(p=>p.threads)),[g,x]=c.useState(r&&r!=="none"&&f[1]?{id:f[1].id,side:r}:null),b=(p,y)=>{m(y==="trailing"?h=>h.filter(v=>v.id!==p):h=>h.map(v=>v.id===p?{...v,isRead:!v.isRead}:v)),x(null)};return s.jsxs("div",{className:"flex-1 overflow-y-auto",children:[d&&s.jsxs("div",{className:"flex items-center justify-center gap-2 border-b border-line py-3 text-fg-muted",children:[s.jsx(Ro,{className:"size-4 animate-spin"}),s.jsx("span",{className:"text-xs",children:"Checking for new mail…"})]}),s.jsx("div",{className:"divide-y divide-line",children:f.map(p=>s.jsx(Bo,{thread:p,selectionMode:n,checked:a.has(p.id),active:p.id===t,peek:g?.id===p.id?g.side:"none",onPeek:y=>x(y==="none"?null:{id:p.id,side:y}),onToggleCheck:()=>o(p.id),onLongPress:()=>i(p.id),onOpen:()=>l(p.id),onAct:y=>b(p.id,y)},p.id))}),!n&&!d&&s.jsx("button",{type:"button",onClick:u,className:"w-full border-t border-line py-2 text-center text-2xs text-fg-subtle transition-colors hover:bg-surface-sunken",children:"Pull to refresh"})]})}function $o({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:g="comfortable",onSelectThread:x,onSelectBriefCategory:b,onOpenNav:p,isDesktop:y,initialTouchState:h,selectionBar:v,listBody:j,hideHeader:w=!1}){const N=g==="compact"?Cu:_o,I=!y&&!a&&o==="ready",S=n.flatMap(q=>q.threads),[k,C]=c.useState(h==="selection"),[E,R]=c.useState(()=>h==="selection"?new Set(S.slice(0,2).map(q=>q.id)):new Set),[M,T]=c.useState(!1),P=h==="peek-trailing"?"trailing":h==="peek-leading"?"leading":void 0,Y=q=>{R(te=>{const U=new Set(te);return U.has(q)?U.delete(q):U.add(q),U.size===0&&C(!1),U})},K=q=>{C(!0),R(new Set([q]))},B=()=>{C(!1),R(new Set)},_=()=>{T(!0),setTimeout(()=>T(!1),1400)},F=!v&&I&&k&&E.size>0;return s.jsxs("section",{className:"flex h-full w-full flex-col bg-surface",children:[v??(F?s.jsx(Fo,{count:E.size,onCancel:B,onMarkRead:B,onDelete:B}):w?null:s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[p&&s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(ra,{className:"size-4"}),onClick:p,"aria-label":"Open folders",className:"-ml-1 shrink-0"}),s.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e}),t&&s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle",children:t})]})),o==="loading"?s.jsx("div",{className:"flex-1 overflow-y-auto",children:s.jsx(Su,{})}):o==="empty"?s.jsx(Nu,{searchQuery:i}):o==="error"?s.jsx(ku,{message:l,onRetry:u,onReport:d}):a?s.jsx(Xr,{sections:n,briefCategory:f,selectedThreadId:m,Row:N,onSelectThread:x,onSelectBriefCategory:b}):j??(I?s.jsx(Iu,{sections:n,selectedThreadId:m,selectionMode:k,checkedIds:E,initialPeek:P,onToggleCheck:Y,onEnterSelection:K,onOpenThread:q=>x?.(q),onRefresh:_,refreshing:M}):s.jsx("div",{className:"flex-1 overflow-y-auto",children:n.map(q=>s.jsxs("div",{children:[!r&&q.label&&s.jsxs("div",{className:"sticky top-0 flex h-section-row items-center justify-between border-b border-line bg-surface-sunken px-row-inset",children:[s.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:q.label}),s.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:q.threads.length})]}),s.jsx("div",{className:"divide-y divide-line",children:q.threads.map(te=>s.jsx(N,{thread:te,active:te.id===m,onClick:()=>x?.(te.id)},te.id))})]},q.id))})),y&&s.jsx(Oo,{})]})}function Ru({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:$("relative",o),children:[s.jsx(X,{variant:"ghost",size:"sm",icon:t??s.jsx(ko,{className:"size-5"}),onClick:()=>l(d=>!d),"aria-label":e,"aria-haspopup":"menu","aria-expanded":i,className:$(r&&"min-h-11 min-w-11 px-0")}),i&&s.jsx("div",{role:"menu",className:$("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 as="min-h-11 min-w-11 px-0";function Ko({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:g,className:x}){const b=(y,h)=>()=>{if(!e){m?.(y);return}h?.()},p=u?[{key:"toggle-read",label:l?"Mark as unread":"Mark as read",icon:l?s.jsx(go,{className:"size-4"}):s.jsx(js,{className:"size-4"}),onSelect:b("toggleRead",u)}]:[];return s.jsxs("div",{className:$("relative",x),children:[s.jsxs("div",{className:"flex h-12 shrink-0 items-center gap-0.5 border-y border-line bg-canvas px-1",children:[s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(To,{className:"size-5"}),onClick:b("reply",t),"aria-label":"Reply",title:"Reply",className:as}),s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(Mo,{className:"size-5"}),onClick:b("replyAll",n),"aria-label":"Reply all",title:"Reply all",className:as}),s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(Eo,{className:"size-5"}),onClick:b("forward",a),"aria-label":"Forward",title:"Forward",className:as}),s.jsx("div",{className:"flex-1"}),s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(dt,{className:$("size-5",r&&"fill-warning text-warning")}),onClick:b("star",o),"aria-label":r?"Remove flag":"Flag","aria-pressed":r,title:r?"Remove flag":"Flag",className:as}),d,s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(qe,{className:"size-5"}),onClick:b("delete",i),"aria-label":"Move to Trash",title:"Move to Trash",className:as}),s.jsx(Ru,{triggerLabel:"More actions",items:[...p,...f]})]}),!e&&g&&s.jsx("p",{role:"status",className:"border-b border-line bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:g})]})}function Mu({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:g="Reply (r)",replyAllTitle:x="Reply all (a)",forwardTitle:b="Forward (f)",deleteTitle:p="Move to Trash (#)",flagTitle:y="Flag (s)",children:h,className:v}){const j=(w,N)=>()=>{if(!e){t?.(w);return}N?.()};return s.jsxs("div",{className:"relative",children:[s.jsxs("header",{className:$("flex h-pane-header shrink-0 items-center gap-1 border-b border-line bg-surface px-3",v),children:[s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(To,{className:"size-4"}),title:g,"aria-label":"Reply",onClick:j("reply",o)}),s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(Mo,{className:"size-4"}),title:x,"aria-label":"Reply all",onClick:j("replyAll",i)}),s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(Eo,{className:"size-4"}),title:b,"aria-label":"Forward",onClick:j("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(X,{variant:"ghost",size:"sm",icon:s.jsx(qe,{className:"size-4"}),title:p,"aria-label":"Move to Trash",onClick:j("delete",u)}),f??s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(Co,{className:"size-4"}),title:"Move to mailbox","aria-label":"Move to mailbox",onClick:j("move",m)}),s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(dt,{className:$("size-4",a&&"fill-warning text-warning")}),title:y,"aria-label":"Flag",onClick:j("flag",d)})]}),s.jsx("div",{className:"flex-1"}),h]}),!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 Tu=(e,t)=>{const a=e==="newsletter"||e==="marketing"||t;return{framed:a,isPlain:!a}},Du=()=>`
|
|
3
3
|
/* Zero the UA default body margin and clamp the document to the iframe width so
|
|
4
4
|
wide author markup can't push the body (and the page) past the viewport. */
|
|
5
5
|
html, body {
|
|
@@ -107,6 +107,6 @@ a, a:visited {
|
|
|
107
107
|
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
108
108
|
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
109
109
|
`)},km=0,_t=[];function Cm(e){var t=c.useRef([]),n=c.useRef([0,0]),a=c.useRef(),r=c.useState(km++)[0],o=c.useState(ai)[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 p=sc([e.lockRef.current],(e.shards||[]).map(xr),!0).filter(Boolean);return p.forEach(function(y){return y.classList.add("allow-interactivity-".concat(r))}),function(){document.body.classList.remove("block-interactivity-".concat(r)),p.forEach(function(y){return y.classList.remove("allow-interactivity-".concat(r))})}}},[e.inert,e.lockRef.current,e.shards]);var l=c.useCallback(function(p,y){if("touches"in p&&p.touches.length===2||p.type==="wheel"&&p.ctrlKey)return!i.current.allowPinchZoom;var h=Ps(p),v=n.current,j="deltaX"in p?p.deltaX:v[0]-h[0],w="deltaY"in p?p.deltaY:v[1]-h[1],N,I=p.target,S=Math.abs(j)>Math.abs(w)?"h":"v";if("touches"in p&&S==="h"&&I.type==="range")return!1;var k=window.getSelection(),C=k&&k.anchorNode,E=C?C===I||C.contains(I):!1;if(E)return!1;var R=gr(S,I);if(!R)return!0;if(R?N=S:(N=S==="v"?"h":"v",R=gr(S,I)),!R)return!1;if(!a.current&&"changedTouches"in p&&(j||w)&&(a.current=N),!N)return!0;var M=a.current||N;return jm(M,y,p,M==="h"?j:w)},[]),u=c.useCallback(function(p){var y=p;if(!(!_t.length||_t[_t.length-1]!==o)){var h="deltaY"in y?pr(y):Ps(y),v=t.current.filter(function(N){return N.name===y.type&&(N.target===y.target||y.target===N.shadowParent)&&Sm(N.delta,h)})[0];if(v&&v.should){y.cancelable&&y.preventDefault();return}if(!v){var j=(i.current.shards||[]).map(xr).filter(Boolean).filter(function(N){return N.contains(y.target)}),w=j.length>0?l(y,j[0]):!i.current.noIsolation;w&&y.cancelable&&y.preventDefault()}}},[]),d=c.useCallback(function(p,y,h,v){var j={name:p,delta:y,target:h,should:v,shadowParent:Em(h)};t.current.push(j),setTimeout(function(){t.current=t.current.filter(function(w){return w!==j})},1)},[]),f=c.useCallback(function(p){n.current=Ps(p),a.current=void 0},[]),m=c.useCallback(function(p){d(p.type,pr(p),p.target,l(p,e.lockRef.current))},[]),g=c.useCallback(function(p){d(p.type,Ps(p),p.target,l(p,e.lockRef.current))},[]);c.useEffect(function(){return _t.push(o),e.setCallbacks({onScrollCapture:m,onWheelCapture:m,onTouchMoveCapture:g}),document.addEventListener("wheel",u,zt),document.addEventListener("touchmove",u,zt),document.addEventListener("touchstart",f,zt),function(){_t=_t.filter(function(p){return p!==o}),document.removeEventListener("wheel",u,zt),document.removeEventListener("touchmove",u,zt),document.removeEventListener("touchstart",f,zt)}},[]);var x=e.removeScrollBar,b=e.inert;return c.createElement(c.Fragment,null,b?c.createElement(o,{styles:Nm(r)}):null,x?c.createElement(gm,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Em(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const Im=sm(ni,Cm);var li=c.forwardRef(function(e,t){return c.createElement(ln,it({},e,{ref:t,sideCar:Im}))});li.classNames=ln.classNames;var Rm=class extends Xn{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",g=r&&u==="backward";return{...a,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:ac(t,n.data),hasPreviousPage:nc(t,n.data),isFetchNextPageError:d,isFetchingNextPage:f,isFetchPreviousPageError:m,isFetchingPreviousPage:g,isRefetchError:l&&!d&&!m,isRefetching:o&&!f&&!g}}};function br(e,t){const n=new Set(t);return e.filter(a=>!n.has(a))}function Mm(e,t,n){const a=e.slice(0);return a[t]=n,a}var Tm=class extends rc{#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,Tn.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 g=this.#e[m];return!g||!oc(f,g)});!u&&!d||(u&&(this.#c=a,this.#t=r),this.#e=o,this.hasListeners()&&(u&&(br(n,r).forEach(f=>{f.destroy()}),br(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=ic(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 Xn(this.#a,r);n.push({defaultedQueryOptions:r,observer:i})}),n}#m(e,t){const n=this.#t.indexOf(e);n!==-1&&(this.#e=Mm(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)&&Tn.batch(()=>{this.listeners.forEach(r=>{r(this.#e)})})}}};function Jt({queries:e,...t},n){const a=je(),r=lc(),o=cc(),i=c.useMemo(()=>e.map(p=>{const y=a.defaultQueryOptions(p);return y._optimisticResults=r?"isRestoring":"optimistic",y}),[e,a,r]);i.forEach(p=>{uc(p);const y=a.getQueryCache().get(p.queryHash);dc(p,o,y)}),fc(o);const[l]=c.useState(()=>new Tm(a,i,t)),[u,d,f]=l.getOptimisticResult(i,t.combine),m=!r&&t.subscribed!==!1;c.useSyncExternalStore(c.useCallback(p=>m?l.subscribe(Tn.batchCalls(p)):mc,[l,m]),()=>l.getCurrentResult(),()=>l.getCurrentResult()),c.useEffect(()=>{l.setQueries(i,t)},[i,t,l]);const x=u.some((p,y)=>La(i[y],p))?u.flatMap((p,y)=>{const h=i[y];if(h&&La(h,p)){const v=new Xn(a,h);return hc(h,v,o)}return[]}):[];if(x.length>0)throw Promise.all(x);const b=u.find((p,y)=>{const h=i[y];return h&&gc({result:p,errorResetBoundary:o,throwOnError:h.throwOnError,query:a.getQueryCache().get(h.queryHash),suspense:h.suspense})});if(b?.error)throw b.error;return d(f())}function Dm(e,t){return pc(e,Rm)}function Ls(e){const t=ao({warn:e?.router===void 0}),n=e?.router||t;return ro(n.stores.__store,oo(e,n))}function ma(e){const t=ao();return ro(t.stores.location,oo(e,t))}const Am=e=>/^\/mail\/(?!outbox)[^/?]+/.test(e),Om=e=>e.startsWith("/mail")||e.startsWith("/settings"),Pm=()=>{const{state:e,openCompose:t}=wt(),n=ma(),a=Ce(),r=n.search,o=typeof r?.selectedMessageId=="string"&&r.selectedMessageId.length>0;if(!Om(n.pathname)||e.isOpen||o)return null;const i=()=>{c.startTransition(()=>{t({mode:"new"})}),!Am(n.pathname)&&a({to:"/mail"})};return s.jsx("button",{type:"button",onClick:i,"aria-label":"Compose new message",className:"lg:hidden fixed right-4 z-30 h-14 w-14 rounded-full bg-accent text-accent-fg shadow-lg flex items-center justify-center hover:opacity-90 active:scale-95 transition-all",style:{bottom:"calc(env(safe-area-inset-bottom, 0) + 1rem)"},children:s.jsx(lu,{className:"size-6"})})},ha=({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=g=>{g.key==="Escape"&&(g.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(De,{className:"size-5"})})}),s.jsx("div",{className:"flex-1 overflow-y-auto",children:n})]})]})},Lm=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},zn={all:["messages"],detail:e=>[...zn.all,"detail",e],body:e=>[...zn.detail(e),"body"]};class bt 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 zm=e=>{const t=Number.parseInt(e??"",10);return!Number.isFinite(t)||t<=0?1:Math.min(t,30)},_m=8,Fm="x-remit-403-reason",Bm=(e,t)=>{const n=t?.trim()??"";return e===401?"auth":e===403?n.length>0?"auth":"body-missing":e===404?"body-missing":"generic"},$m=(e,t)=>(t??"").toLowerCase().startsWith("text/html")?/<div\s+id=["']root["']/i.test(e):!1,Km=(e,t)=>{const n=(t??"").toLowerCase();return!!(e==="text"&&n.startsWith("text/html"))},qm=async(e,t,n=async()=>null)=>{const a={},r=await n();r&&(a.Authorization=`Bearer ${r}`);const o=await fetch(e,{headers:a});if(o.status===202)throw new bt("not-ready","Message body is still syncing",202,zm(o.headers.get("Retry-After")));if(!o.ok){const u=o.headers.get(Fm),d=Bm(o.status,u);throw new bt(d,`Failed to load message body (${o.status} ${o.statusText})`,o.status)}const i=o.headers.get("content-type");if(Km(t,i))throw new bt("content-type-mismatch",`Refusing to render message body — expected ${t}, got Content-Type ${i}`);const l=await o.text();if($m(l,i))throw new bt("spa-shell-leak","Refusing to render message body — response looks like the SPA shell (CloudFront 403/404 fallback leaked through to /content/*)");return l},Um=async(e,t)=>(t.isRetryAfterNotReady&&await e.refetchDescribeMessage(),e.fetchContent(t.contentUrl,t.kind)),ci=({messageId:e,bodyParts:t,enabled:n=!0})=>{const a=t?Lm(t):null,r=xs(),{getToken:o}=Jn(),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=re({queryKey:e?[...zn.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,Um({fetchContent:(p,y)=>qm(p,y,o),refetchDescribeMessage:()=>l.refetchQueries({queryKey:io({path:{messageId:e}})})},{contentUrl:a.contentUrl,kind:a.kind,isRetryAfterNotReady:b})},enabled:n&&!!e&&!!a,staleTime:300*1e3,gcTime:1800*1e3,retry:(b,p)=>p instanceof bt&&p.reason==="not-ready"?b<_m:b<1,retryDelay:(b,p)=>p instanceof bt&&p.reason==="not-ready"?(u.current=!0,(p.retryAfterSeconds??1)*1e3):1e3,meta:{softError:!0}}),g=m.isLoading&&!!a;c.useEffect(()=>{g&&(i.current=performance.now())},[g]),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 x=m.data&&a?{kind:a.kind,body:m.data}:void 0;return{picked:a,data:x,isLoading:g,isError:m.isError,error:m.error,refetch:m.refetch}},Hm=({outboxMessageId:e,onDraftCreated:t})=>{const[n,a]=c.useState("idle"),[r,o]=c.useState(null),i=c.useRef(void 0),l=je(),u=xe(lo()),d=xe(xc()),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 p=await u.mutateAsync({body:{...b,sendImmediately:!1}});return t(p.outboxMessageId),a("saved"),l.invalidateQueries({queryKey:Js().queryKey}),p},[e,u,d,t,l]),m=c.useCallback(b=>{i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{f(b).catch(p=>{o(p),a("error")})},2e3)},[f]),g=c.useCallback(b=>(i.current&&clearTimeout(i.current),f(b)),[f]),x=c.useCallback(()=>{i.current&&clearTimeout(i.current)},[]);return{saveStatus:n,saveError:r,saveDraft:m,saveImmediately:g,cancelAutoSave:x}},ui=e=>"text"in e&&!("children"in e),di=e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),Qm=e=>{let t=di(e.text);return e.bold&&(t=`<strong>${t}</strong>`),e.italic&&(t=`<em>${t}</em>`),t},fi=e=>{const t=e.children.map(n=>ui(n)?Qm(n):fi(n)).join("");switch(e.type){case"blockquote":return`<blockquote>${t}</blockquote>`;case"a":{const n=e.url??"";return`<a href="${di(n)}">${t}</a>`}default:return`<p>${t}</p>`}},vr=e=>e.map(fi).join(""),mi=e=>ui(e)?e.text:e.children.map(mi).join(""),_n=e=>e.map(mi).join(`
|
|
110
|
-
`),Wm=e=>e.displayName?`${e.displayName} <${e.normalizedEmail}>`:e.normalizedEmail,yr=e=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.trim()),Vm=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(yr(r))return{email:r,displayName:a}}if(yr(t))return{email:t}},Sn=({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),g=xo(r,200),{data:x}=re({...co({query:{q:g,limit:8}}),enabled:g.length>=2}),b=x?.items??[],p=new Set(t.map(S=>S.email.toLowerCase())),y=b.filter(S=>!p.has(S.normalizedEmail.toLowerCase()));c.useEffect(()=>{l(-1),d(y.length>0&&r.length>=2)},[y.length,r.length]);const h=c.useCallback(S=>{p.has(S.email.toLowerCase())||(n([...t,S]),o(""),d(!1))},[t,p,n]),v=c.useCallback(S=>{n(t.filter((k,C)=>C!==S))},[t,n]),j=c.useCallback(S=>{h({email:S.normalizedEmail,displayName:S.displayName}),f.current?.focus()},[h]),w=c.useCallback(()=>{const S=Vm(r);S&&h(S)},[r,h]),N=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(),j(y[i]);return}r.trim()&&(S.preventDefault(),w());return}if(S.key==="ArrowDown"&&u){S.preventDefault(),l(k=>k<y.length-1?k+1:0);return}if(S.key==="ArrowUp"&&u){S.preventDefault(),l(k=>k>0?k-1:y.length-1);return}S.key==="Escape"&&(d(!1),l(-1))},[r,t.length,i,y,u,v,j,w]),I=c.useCallback(()=>{setTimeout(()=>{w(),d(!1)},150)},[w]);return s.jsxs("div",{className:"relative",children:[s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("label",{htmlFor:`address-field-${e}`,className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:[e,":"]}),s.jsxs("div",{className:"flex-1 flex flex-wrap items-center gap-1 min-h-[36px] px-2 py-1 border rounded-md bg-canvas cursor-text",onClick:()=>f.current?.focus(),onKeyDown:S=>{(S.key==="Enter"||S.key===" ")&&f.current?.focus()},children:[t.map((S,k)=>s.jsx(pu,{email:S.email,displayName:S.displayName,onRemove:()=>v(k)},S.email)),s.jsx("input",{ref:f,id:`address-field-${e}`,type:"text",value:r,onChange:S=>o(S.target.value),onKeyDown:N,onBlur:I,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,k)=>s.jsx("li",{className:fe("px-3 py-2 text-sm cursor-pointer transition-colors",k===i&&"bg-accent-2-soft"),onMouseDown:C=>{C.preventDefault(),j(S)},onMouseEnter:()=>l(k),children:Wm(S)},S.addressId))})]})},Ym=({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(Vn,{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(tu,{className:"size-3","aria-hidden":"true"})]})]})]})},Fn=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},kt=()=>Fn("(min-width: 1024px)"),wr=150,Gm=()=>{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>wr}});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>wr})};return a(),n.addEventListener("resize",a),()=>n.removeEventListener("resize",a)},[]),e},Xm=({selectedAccountId:e,onSelect:t})=>{const{data:n}=re({...Ze(),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))})]})},Jm=({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})]}),Zm=["p","br","strong","b","em","i","a","blockquote","ul","ol","li"],eh=["href"],th=e=>Jr.sanitize(e,{ALLOWED_TAGS:Zm,ALLOWED_ATTR:eh}),sh=c.lazy(()=>vc(()=>import("./ComposeBody-Bv4ZgOEg.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}))),nh=()=>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"})]}),hi=[{type:"p",children:[{text:""}]}],ah=[{type:"p",children:[{text:""}]},{type:"p",children:[{text:"-- "}]}],rh=e=>e?[...ah,{type:"p",children:[{text:e}]}]:hi,oh=e=>e?/^re:\s/i.test(e)?e:`Re: ${e}`:"Re: ",ih=e=>e?/^fwd?:\s/i.test(e)?e:`Fwd: ${e}`:"Fwd: ",lh=(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}},ch=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}},uh=(e,t,n,a,r)=>e.length===0&&t.length===0&&n.length===0&&a.trim()===""&&_n(r).trim()==="",dh=({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:g,setSubject:x})=>{const b=kt(),{isKeyboardOpen:p}=Gm();if(!b&&p){const h=[];return n.length>0&&h.push(`To: ${n.map(v=>v.displayName??v.email).join(", ")}`),r.length>0&&h.push(`Cc: ${r.length}`),i.length>0&&h.push(`Bcc: ${i.length}`),g&&h.push(g),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:h.length>0?h.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(Xm,{selectedAccountId:e,onSelect:t}),s.jsx(Sn,{label:"To",addresses:n,onChange:a,placeholder:"Recipients"}),u?s.jsx(Sn,{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(Sn,{label:"Bcc",addresses:i,onChange:l}),s.jsx(Jm,{value:g,onChange:x})]})},ga=({mode:e,account:t,sourceMessage:n,onClose:a,onAccountChange:r})=>{const{state:o,setOutboxMessageId:i,startSendPolling:l}=wt(),{pushError:u}=ze(),{outboxMessageId:d}=o,[f,m]=c.useState([]),[g,x]=c.useState([]),[b,p]=c.useState([]),[y,h]=c.useState(""),[v,j]=c.useState(!1),[w,N]=c.useState(!1),[I,S]=c.useState(t?.accountId),[k,C]=c.useState(!1),E=c.useRef(d);c.useEffect(()=>{E.current!==d&&(E.current=d,d&&(m([]),x([]),p([]),h(""),j(!1),N(!1),T(hi),C(!1)))},[d]);const{signature:R}=Wc(I),[M,T]=c.useState(()=>rh(R.plainText)),{data:P}=re({...bc({path:{outboxMessageId:d??""}}),enabled:!!d&&!k});c.useEffect(()=>{!P||k||(m(P.toAddresses.map(Q=>({email:Q,displayName:void 0}))),P.ccAddresses&&P.ccAddresses.length>0&&(x(P.ccAddresses.map(Q=>({email:Q,displayName:void 0}))),j(!0)),P.bccAddresses&&P.bccAddresses.length>0&&(p(P.bccAddresses.map(Q=>({email:Q,displayName:void 0}))),N(!0)),P.subject&&h(P.subject),P.textBody&&T([{type:"p",children:[{text:P.textBody}]}]),S(P.accountId),C(!0))},[P,k]),c.useEffect(()=>{if(n){if(e==="reply"||e==="reply_all"){const{to:Q,cc:ee}=lh(n,e,t?.email);m(Q),x(ee),ee.length>0&&j(!0),h(oh(n.envelope.subject))}e==="forward"&&h(ih(n.envelope.subject))}},[e,n,t?.email]);const Y=e==="reply"||e==="reply_all"||e==="forward",{data:K}=ci({messageId:n?.message.messageId,bodyParts:n?.bodyParts,enabled:Y&&!!n}),B=K?.kind==="text"?K.body:"",_=K?.kind==="html"?th(K.body):void 0,F=n?.envelope.from[0]?.displayName??n?.envelope.from[0]?.normalizedEmail,{saveStatus:q,saveError:te,saveDraft:U,cancelAutoSave:O}=Hm({outboxMessageId:d,onDraftCreated:i});c.useEffect(()=>{te&&u({title:"Couldn't save draft",detail:$e(te)??"Saving the draft failed."})},[te,u]);const D=xe(lo()),V=xe(uo()),le=xe({...Zs(),onError:Q=>{u(fs("Couldn't discard draft","The draft wasn't discarded.",Q))}}),{data:ve}=re({...Ze(),staleTime:1/0}),ce=ve?.accounts.find(Q=>Q.accountId===I),ye=ce?Kc(ce):!1,Se=D.isPending||V.isPending,G=f.length>0&&!!I&&!ye;c.useEffect(()=>{if(!I||d&&!k||uh(f,g,b,y,M))return;const Q=_n(M),ee=vr(M);U({accountId:I,toAddresses:f.map(ne=>ne.email),ccAddresses:g.length>0?g.map(ne=>ne.email):void 0,bccAddresses:b.length>0?b.map(ne=>ne.email):void 0,subject:y||void 0,textBody:Q||void 0,htmlBody:ee||void 0})},[I,d,k,f,g,b,y,M,U]);const ge=c.useCallback(async()=>{if(!I||f.length===0)return;O();const Q=n&&(e==="reply"||e==="reply_all")?ch(n):{};let ee=d,ne=!1;if(!ee){const oe=_n(M),Ne=vr(M),Fe=await D.mutateAsync({body:{accountId:I,toAddresses:f.map(Ae=>Ae.email),ccAddresses:g.length>0?g.map(Ae=>Ae.email):void 0,bccAddresses:b.length>0?b.map(Ae=>Ae.email):void 0,subject:y||void 0,textBody:oe||void 0,htmlBody:Ne||void 0,sendImmediately:!0,...Q}}).catch(Ae=>(u({title:"Couldn't send message",detail:$e(Ae)??"Saving the draft failed."}),null));if(Fe===null)return;ee=Fe.outboxMessageId,ne=!0,i(ee)}await V.mutateAsync({path:{outboxMessageId:ee}}).catch(oe=>(u({title:"Couldn't send message",detail:$e(oe)??(ne?"The draft was saved but the send request failed. Try again from the Outbox.":"The send request failed. Try again.")}),null))!==null&&(l(ee),a())},[I,f,g,b,y,M,e,n,d,D,V,O,l,i,u,a]),Ie=c.useCallback(()=>{O(),d&&le.mutate({path:{outboxMessageId:d}}),a()},[O,d,le,a]),H=c.useCallback(Q=>{S(Q.accountId),r?.(Q)},[r]);return s.jsx(jd,{banner:ce&&ye?s.jsx(Ym,{accountId:ce.accountId}):void 0,header:s.jsx(dh,{selectedAccountId:I,onAccountChange:H,toAddresses:f,setToAddresses:m,ccAddresses:g,setCcAddresses:x,bccAddresses:b,setBccAddresses:p,showCc:v,setShowCc:j,showBcc:w,setShowBcc:N,subject:y,setSubject:h}),quoted:B||_?s.jsx(Bd,{text:B,html:_,senderName:F}):void 0,actionBar:s.jsx(wd,{onSend:ge,onDiscard:Ie,sending:Se,canSend:G,saveStatus:q,unavailableReason:ye?"SMTP not configured":void 0,onUnavailable:Q=>u({title:"Can't send yet",detail:Q})}),children:s.jsx(c.Suspense,{fallback:s.jsx(nh,{}),children:s.jsx(sh,{value:M,onChange:T,onSubmit:ge,autoFocus:e==="new"})})})},jr=({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(ga,{mode:e,account:t,sourceMessage:n,onClose:a})}),gi=({message:e,icon:t})=>s.jsxs("div",{className:"flex flex-col items-center justify-center p-8 text-center",children:[t&&s.jsx("div",{className:"mb-4 text-fg-muted",children:t}),s.jsx("p",{className:"text-fg-muted",children:e})]}),ps=({enabled:e=!0,bindings:t,capture:n=!1})=>{const 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])},pi=e=>{const{data:t,isLoading:n}=re({...Ze(),staleTime:1/0}),a=c.useMemo(()=>(t?.accounts??[]).map(l=>l.accountId),[t?.accounts]),r=Jt({queries:a.map(l=>({...et({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}},Sr=(e,t,n)=>e.map(a=>t.has(a.messageId)?{...a,isRead:n}:a),fh=(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),mh=({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}=xe({...en(),onMutate:async g=>{const x=new Set(g.body.messageIds??[]),b=g.body.isRead??!0,p=jt({path:{threadId:n}}),y=tt({path:{mailboxId:a}}),h=ut({path:{mailboxId:a}});await Promise.all([o.cancelQueries({queryKey:p}),o.cancelQueries({queryKey:y}),o.cancelQueries({queryKey:h})]);const v=o.getQueriesData({queryKey:p}).filter(N=>N[1]!==void 0).map(([N,I])=>({queryKey:N,data:I})),j=o.getQueriesData({queryKey:y}).concat(o.getQueriesData({queryKey:h})).filter(N=>N[1]!==void 0).map(([N,I])=>({queryKey:N,data:I}));o.setQueriesData({queryKey:p},N=>N&&{...N,items:Sr(N.items,x,b)});const w=N=>N&&{...N,pages:N.pages.map(I=>({...I,items:Sr(I.items,x,b)}))};return o.setQueriesData({queryKey:y},w),o.setQueriesData({queryKey:h},w),{threadMessagesPrefix:p,threadsListPrefix:y,threadsSearchPrefix:h,previousThreadMessages:v,previousThreadsList:j}},onSuccess:(g,x)=>{const b=x.body.messageIds??[];for(const p of b)l.current.add(p),u.current.delete(p)},onError:(g,x,b)=>{const p=x.body.messageIds??[];for(const h of p)u.current.delete(h);if(b){for(const h of b.previousThreadMessages)o.setQueryData(h.queryKey,h.data);for(const h of b.previousThreadsList)o.setQueryData(h.queryKey,h.data)}const y=x.body.isRead??!0;i({title:y?"Couldn't mark as read":"Couldn't mark as unread",detail:$e(g)})},onSettled:(g,x,b,p)=>{p&&(o.invalidateQueries({queryKey:p.threadMessagesPrefix}),o.invalidateQueries({queryKey:p.threadsListPrefix}),o.invalidateQueries({queryKey:p.threadsSearchPrefix}),r&&o.invalidateQueries({queryKey:Vt({path:{accountId:r}})}))}}),f=c.useCallback(g=>{const x=g.filter(b=>!l.current.has(b)&&!u.current.has(b));if(x.length!==0){for(const b of x)u.current.add(b);d({body:{messageIds:x,isRead:!0}})}},[d]),m=c.useMemo(()=>fh(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])},xi=e=>{const{mailboxId:t,accountId:n}=e,a=je(),{pushError:r}=ze(),{mutate:o,isPending:i}=xe({...en(),onError:(u,d)=>{const f=d.body.isRead??!0;r({title:f?"Couldn't mark as read":"Couldn't mark as unread",detail:$e(u)})},onSettled:()=>{a.invalidateQueries({queryKey:tt({path:{mailboxId:t}})}),a.invalidateQueries({queryKey:ut({path:{mailboxId:t}})}),n&&a.invalidateQueries({queryKey:Vt({path:{accountId:n}})})}});return{toggleReadFor:c.useCallback((u,d)=>{u.length!==0&&o({body:{messageIds:u,isRead:d}})},[o]),isPending:i}},hh=60,gh=1.5,ph=(e,t,n)=>{const a=Math.abs(e),r=Math.abs(t);return a<n?{direction:null}:a<r*gh?{direction:null}:{direction:e<0?"left":"right"}},xh=({onSwipeLeft:e,onSwipeRight:t,thresholdPx:n=hh})=>{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}=ph(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}}},Nr=(e,t,n)=>e.map(a=>a.messageId===t?{...a,hasStars:n}:a),Bn=({threadId:e,mailboxId:t})=>{const n=je(),{pushError:a}=ze(),{mutate:r,isPending:o,variables:i}=xe({...yc(),onMutate:async u=>{const d=u.path.messageId,f=u.body.isStarred??!1,m=jt({path:{threadId:e}}),g=tt({path:{mailboxId:t}}),x=ut({path:{mailboxId:t}});await Promise.all([n.cancelQueries({queryKey:m}),n.cancelQueries({queryKey:g}),n.cancelQueries({queryKey:x})]);const b=n.getQueriesData({queryKey:m}).filter(h=>h[1]!==void 0).map(([h,v])=>({queryKey:h,data:v})),p=n.getQueriesData({queryKey:g}).concat(n.getQueriesData({queryKey:x})).filter(h=>h[1]!==void 0).map(([h,v])=>({queryKey:h,data:v}));n.setQueriesData({queryKey:m},h=>h&&{...h,items:Nr(h.items,d,f)});const y=h=>h&&{...h,pages:h.pages.map(v=>({...v,items:Nr(v.items,d,f)}))};return n.setQueriesData({queryKey:g},y),n.setQueriesData({queryKey:x},y),{threadMessagesPrefix:m,threadsListPrefix:g,threadsSearchPrefix:x,previousThreadMessages:b,previousThreadsList:p}},onError:(u,d,f)=>{if(f){for(const g of f.previousThreadMessages)n.setQueryData(g.queryKey,g.data);for(const g of f.previousThreadsList)n.setQueryData(g.queryKey,g.data)}const m=d.body.isStarred??!1;a({title:m?"Couldn't star message":"Couldn't unstar message",detail:$e(u)})},onSettled:(u,d,f,m)=>{m&&(n.invalidateQueries({queryKey:m.threadMessagesPrefix}),n.invalidateQueries({queryKey:m.threadsListPrefix}),n.invalidateQueries({queryKey:m.threadsSearchPrefix}))}});return{toggleStar:(u,d)=>{r({path:{messageId:u},body:{isStarred:!d}})},isPending:o,pendingMessageId:o?i?.path.messageId:void 0}};function cn(e){return e===void 0||e==="uncategorized"?"personal":e}const Ge={uncategorized:"uncategorized",personal:"personal",newsletter:"newsletter",marketing:"marketing",automated:"automated",transactional:"transactional",social:"social"},kr={MoveToInbox:"MoveToInbox",MoveToJunk:"MoveToJunk"},bh={inbox:"Inbox",junk:"Junk"},vh=e=>`Moved from ${bh[e]??"another folder"} by Remit`,yh=(e,t)=>{if(e===kr.MoveToInbox)return t.inboxMailboxId;if(e===kr.MoveToJunk)return t.junkMailboxId},wh=(e,t,n)=>{if(!e||!t)return!1;const a=yh(e.action,n);return a!==void 0&&a===t},jh=(e,t)=>{if(e==="inbox")return t.inboxMailboxId;if(e==="junk")return t.junkMailboxId},un=(e,t)=>{const{data:n,isLoading:a}=re({...Ze(),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}},Sh=e=>{const{mailboxId:t,isLoading:n}=un(e,"Archive");return{archiveMailboxId:t,isLoading:n}},Nh=e=>{const{mailboxId:t,isLoading:n}=un(e,"Drafts");return{draftsMailboxId:t,isLoading:n}},pa=e=>{const{mailboxId:t,isLoading:n}=un(e,"Inbox");return{inboxMailboxId:t,isLoading:n}},xa=e=>{const{mailboxId:t,isLoading:n}=un(e,"Junk");return{junkMailboxId:t,isLoading:n}},bi=e=>{const{data:t}=re({...Ze(),staleTime:1/0,enabled:!!e});return c.useMemo(()=>t?.accounts.find(n=>n.accountId===e)?.folderAppointments??[],[t,e])},Cr=(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}=xe({...wc(),onMutate:async d=>{const f=new Set(d.body.messageIds??[]),m=t?jt({path:{threadId:t}}):[],g=tt({path:{mailboxId:e}}),x=ut({path:{mailboxId:e}});await Promise.all([...t?[r.cancelQueries({queryKey:m})]:[],r.cancelQueries({queryKey:g}),r.cancelQueries({queryKey:x})]);const b=t?r.getQueriesData({queryKey:m}).filter(h=>h[1]!==void 0).map(([h,v])=>({queryKey:h,data:v})):[],p=r.getQueriesData({queryKey:g}).concat(r.getQueriesData({queryKey:x})).filter(h=>h[1]!==void 0).map(([h,v])=>({queryKey:h,data:v}));t&&r.setQueriesData({queryKey:m},h=>h&&{...h,items:Cr(h.items,f)});const y=h=>h&&{...h,pages:h.pages.map(v=>({...v,items:Cr(v.items,f)}))};return r.setQueriesData({queryKey:g},y),r.setQueriesData({queryKey:x},y),a?.(Array.from(f)),{threadMessagesPrefix:m,threadsListPrefix:g,threadsSearchPrefix:x,previousThreadMessages:b,previousThreadsList:p}},onError:(d,f,m)=>{if(m){for(const x of m.previousThreadMessages)r.setQueryData(x.queryKey,x.data);for(const x of m.previousThreadsList)r.setQueryData(x.queryKey,x.data)}const g=f.body.messageIds?.length??0;o({title:g>1?`Couldn't move ${g} messages`:"Couldn't move this message",detail:$e(d)})},onSettled:(d,f,m,g)=>{g&&(t&&r.invalidateQueries({queryKey:g.threadMessagesPrefix}),r.invalidateQueries({queryKey:g.threadsListPrefix}),r.invalidateQueries({queryKey:g.threadsSearchPrefix}),n&&r.invalidateQueries({queryKey:Vt({path:{accountId:n}})}))}});return{moveMessages:c.useCallback((d,f)=>{d.length!==0&&i({body:{messageIds:d,destinationMailboxId:f}})},[i]),isPending:l}},kh=({accountId:e,messageId:t,threadId:n,mailboxId:a,autoMoved:r})=>{const{inboxMailboxId:o}=pa(e),{junkMailboxId:i}=xa(e),{moveMessages:l,isPending:u}=ct({mailboxId:a,threadId:n,accountId:e}),d={inboxMailboxId:o,junkMailboxId:i},f=wh(r,a,d),m=r?jh(r.fromPlacement,d):void 0,g=c.useCallback(()=>{m&&l([t],m)},[l,t,m]);return!f||!r?{show:!1,label:"",isUndoing:!1}:{show:!0,label:vh(r.fromPlacement),onUndo:m?g:void 0,isUndoing:u}};function vi({accountId:e,messageId:t,threadId:n,mailboxId:a,autoMoved:r,size:o="sm"}){const i=kh({accountId:e,messageId:t,threadId:n,mailboxId:a,autoMoved:r});return i.show?s.jsx(ud,{label:i.label,size:o,onUndo:i.onUndo,undoLabel:i.isUndoing?"Undoing…":"Undo"}):null}const yi=({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})]})},$t=({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"}),Er=(e,t)=>e.filter(n=>!t.has(n.messageId)),Ch=e=>e.filter(t=>t.isDeleted!==!0),ds=({mailboxId:e,threadId:t,accountId:n,onAfterOptimisticRemove:a})=>{const r=je(),{pushError:o}=ze(),{mutate:i,isPending:l}=xe({...jc(),onMutate:async d=>{const f=new Set(d.body.messageIds??[]),m=t?jt({path:{threadId:t}}):[],g=tt({path:{mailboxId:e}}),x=ut({path:{mailboxId:e}});await Promise.all([r.cancelQueries({queryKey:m}),r.cancelQueries({queryKey:g}),r.cancelQueries({queryKey:x})]);const b=t?r.getQueriesData({queryKey:m}).filter(h=>h[1]!==void 0).map(([h,v])=>({queryKey:h,data:v})):[],p=r.getQueriesData({queryKey:g}).concat(r.getQueriesData({queryKey:x})).filter(h=>h[1]!==void 0).map(([h,v])=>({queryKey:h,data:v}));t&&r.setQueriesData({queryKey:m},h=>h&&{...h,items:Er(h.items,f)});const y=h=>h&&{...h,pages:h.pages.map(v=>({...v,items:Er(v.items,f)}))};return r.setQueriesData({queryKey:g},y),r.setQueriesData({queryKey:x},y),a?.(Array.from(f)),{threadMessagesPrefix:m,threadsListPrefix:g,threadsSearchPrefix:x,previousThreadMessages:b,previousThreadsList:p}},onError:(d,f,m)=>{if(m){for(const x of m.previousThreadMessages)r.setQueryData(x.queryKey,x.data);for(const x of m.previousThreadsList)r.setQueryData(x.queryKey,x.data)}const g=f.body.messageIds?.length??0;o({title:g>1?`Couldn't delete ${g} messages`:"Couldn't delete this message",detail:$e(d)})},onSettled:(d,f,m,g)=>{g&&(t&&r.invalidateQueries({queryKey:g.threadMessagesPrefix}),r.invalidateQueries({queryKey:g.threadsListPrefix}),r.invalidateQueries({queryKey:g.threadsSearchPrefix}),n&&r.invalidateQueries({queryKey:Vt({path:{accountId:n}})}))}});return{deleteMessages:c.useCallback(d=>{d.length!==0&&i({body:{messageIds:d}})},[i]),isPending:l}},wi=(e,t=Date.now())=>({value:e,setAt:t}),Eh=(e,t,n,a)=>{if(e.addressId!==t)return e;const r={...e.flags??{}};return n?r.trusted=wi(!0,a):delete r.trusted,{...e,flags:r}},Ih=(e,t,n,a)=>{const r=o=>o.map(i=>Eh(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)}}},ba=({messageId:e})=>{const t=je(),{pushError:n}=ze(),{mutate:a,isPending:r,error:o,reset:i}=xe({...fo(),onMutate:async u=>{const d=u.path.addressId,m=u.body.flags?.trusted?.value===!0,g=io({path:{messageId:e}});await t.cancelQueries({queryKey:g});const x=t.getQueriesData({queryKey:g}).filter(b=>b[1]!==void 0).map(([b,p])=>({queryKey:b,data:p}));return t.setQueriesData({queryKey:g},b=>b&&Ih(b,d,m)),{describePrefix:g,previous:x}},onError:(u,d,f)=>{if(f)for(const m of f.previous)t.setQueryData(m.queryKey,m.data);n(fs("Couldn't trust sender","The change wasn't saved.",u))},onSettled:(u,d,f,m)=>{m&&t.invalidateQueries({queryKey:m.describePrefix})}});return{toggleTrusted:(u,d)=>{a({path:{addressId:u},body:{flags:{trusted:wi(!d)}}})},isPending:r,error:o,reset:i}};var dn="Dialog",[ji]=sf(dn),[Rh,_e]=ji(dn),Si=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]=rf({prop:a,defaultProp:r??!1,onChange:o,caller:dn});return s.jsx(Rh,{scope:t,triggerRef:l,contentRef:u,contentId:bn(),titleId:bn(),descriptionId:bn(),open:d,onOpenChange:f,onOpenToggle:c.useCallback(()=>f(m=>!m),[f]),modal:i,children:n})};Si.displayName=dn;var Ni="DialogTrigger",Mh=c.forwardRef((e,t)=>{const{__scopeDialog:n,...a}=e,r=_e(Ni,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":ya(r.open),...a,ref:o,onClick:lt(e.onClick,r.onOpenToggle)})});Mh.displayName=Ni;var va="DialogPortal",[Th,ki]=ji(va,{forceMount:void 0}),Ci=e=>{const{__scopeDialog:t,forceMount:n,children:a,container:r}=e,o=_e(va,t);return s.jsx(Th,{scope:t,forceMount:n,children:c.Children.map(a,i=>s.jsx(on,{present:n||o.open,children:s.jsx(ei,{asChild:!0,container:r,children:i})}))})};Ci.displayName=va;var Ys="DialogOverlay",Ei=c.forwardRef((e,t)=>{const n=ki(Ys,e.__scopeDialog),{forceMount:a=n.forceMount,...r}=e,o=_e(Ys,e.__scopeDialog);return o.modal?s.jsx(on,{present:a||o.open,children:s.jsx(Ah,{...r,ref:t})}):null});Ei.displayName=Ys;var Dh=da("DialogOverlay.RemoveScroll"),Ah=c.forwardRef((e,t)=>{const{__scopeDialog:n,...a}=e,r=_e(Ys,n),o=kf(),i=Nt(t,o);return s.jsx(li,{as:Dh,allowPinchZoom:!0,shards:[r.contentRef],children:s.jsx(nt.div,{"data-state":ya(r.open),...a,ref:i,style:{pointerEvents:"auto",...a.style}})})}),Wt="DialogContent",Ii=c.forwardRef((e,t)=>{const n=ki(Wt,e.__scopeDialog),{forceMount:a=n.forceMount,...r}=e,o=_e(Wt,e.__scopeDialog);return s.jsx(on,{present:a||o.open,children:o.modal?s.jsx(Oh,{...r,ref:t}):s.jsx(Ph,{...r,ref:t})})});Ii.displayName=Wt;var Oh=c.forwardRef((e,t)=>{const n=_e(Wt,e.__scopeDialog),a=c.useRef(null),r=Nt(t,n.contentRef,a);return c.useEffect(()=>{const o=a.current;if(o)return Wf(o)},[]),s.jsx(Ri,{...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())})}),Ph=c.forwardRef((e,t)=>{const n=_e(Wt,e.__scopeDialog),a=c.useRef(!1),r=c.useRef(!1);return s.jsx(Ri,{...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()}})}),Ri=c.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:a,onOpenAutoFocus:r,onCloseAutoFocus:o,...i}=e,l=_e(Wt,n);return Rf(),s.jsx(s.Fragment,{children:s.jsx(Jo,{asChild:!0,loop:!0,trapped:a,onMountAutoFocus:r,onUnmountAutoFocus:o,children:s.jsx(Go,{role:"dialog",id:l.contentId,"aria-describedby":l.descriptionId,"aria-labelledby":l.titleId,"data-state":ya(l.open),...i,ref:t,deferPointerDownOutside:!0,onDismiss:()=>l.onOpenChange(!1)})})})}),Mi="DialogTitle",Ti=c.forwardRef((e,t)=>{const{__scopeDialog:n,...a}=e,r=_e(Mi,n);return s.jsx(nt.h2,{id:r.titleId,...a,ref:t})});Ti.displayName=Mi;var Di="DialogDescription",Lh=c.forwardRef((e,t)=>{const{__scopeDialog:n,...a}=e,r=_e(Di,n);return s.jsx(nt.p,{id:r.descriptionId,...a,ref:t})});Lh.displayName=Di;var Ai="DialogClose",zh=c.forwardRef((e,t)=>{const{__scopeDialog:n,...a}=e,r=_e(Ai,n);return s.jsx(nt.button,{type:"button",...a,ref:t,onClick:lt(e.onClick,()=>r.onOpenChange(!1))})});zh.displayName=Ai;function ya(e){return e?"open":"closed"}function _h(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 Oi=z.createContext({drawerRef:{current:null},overlayRef:{current:null},onPress:()=>{},onRelease:()=>{},onDrag:()=>{},onNestedDrag:()=>{},onNestedOpenChange:()=>{},onNestedRelease:()=>{},openProp:void 0,dismissible:!1,isOpen:!1,isDragging:!1,keyboardIsOpen:{current:!1},snapPointsOffset:null,snapPoints:null,handleOnly:!1,modal:!1,shouldFade:!1,activeSnapPoint:null,onOpenChange:()=>{},setActiveSnapPoint:()=>{},closeDrawer:()=>{},direction:"bottom",shouldAnimate:{current:!0},shouldScaleBackground:!1,setBackgroundColorOnScale:!0,noBodyStyles:!1,container:null,autoFocus:!1}),Ns=()=>{const e=z.useContext(Oi);if(!e)throw new Error("useDrawerContext must be used within a Drawer.Root");return e};_h(`[data-vaul-drawer]{touch-action:none;will-change:transform;transition:transform .5s cubic-bezier(.32, .72, 0, 1);animation-duration:.5s;animation-timing-function:cubic-bezier(0.32,0.72,0,1)}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=bottom][data-state=open]{animation-name:slideFromBottom}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=bottom][data-state=closed]{animation-name:slideToBottom}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=top][data-state=open]{animation-name:slideFromTop}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=top][data-state=closed]{animation-name:slideToTop}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=left][data-state=open]{animation-name:slideFromLeft}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=left][data-state=closed]{animation-name:slideToLeft}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=right][data-state=open]{animation-name:slideFromRight}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=right][data-state=closed]{animation-name:slideToRight}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=bottom]{transform:translate3d(0,var(--initial-transform,100%),0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=top]{transform:translate3d(0,calc(var(--initial-transform,100%) * -1),0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=left]{transform:translate3d(calc(var(--initial-transform,100%) * -1),0,0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=right]{transform:translate3d(var(--initial-transform,100%),0,0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=top]{transform:translate3d(0,var(--snap-point-height,0),0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=bottom]{transform:translate3d(0,var(--snap-point-height,0),0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=left]{transform:translate3d(var(--snap-point-height,0),0,0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=right]{transform:translate3d(var(--snap-point-height,0),0,0)}[data-vaul-overlay][data-vaul-snap-points=false]{animation-duration:.5s;animation-timing-function:cubic-bezier(0.32,0.72,0,1)}[data-vaul-overlay][data-vaul-snap-points=false][data-state=open]{animation-name:fadeIn}[data-vaul-overlay][data-state=closed]{animation-name:fadeOut}[data-vaul-animate=false]{animation:none!important}[data-vaul-overlay][data-vaul-snap-points=true]{opacity:0;transition:opacity .5s cubic-bezier(.32, .72, 0, 1)}[data-vaul-overlay][data-vaul-snap-points=true]{opacity:1}[data-vaul-drawer]:not([data-vaul-custom-container=true])::after{content:'';position:absolute;background:inherit;background-color:inherit}[data-vaul-drawer][data-vaul-drawer-direction=top]::after{top:initial;bottom:100%;left:0;right:0;height:200%}[data-vaul-drawer][data-vaul-drawer-direction=bottom]::after{top:100%;bottom:initial;left:0;right:0;height:200%}[data-vaul-drawer][data-vaul-drawer-direction=left]::after{left:initial;right:100%;top:0;bottom:0;width:200%}[data-vaul-drawer][data-vaul-drawer-direction=right]::after{left:100%;right:initial;top:0;bottom:0;width:200%}[data-vaul-overlay][data-vaul-snap-points=true]:not([data-vaul-snap-points-overlay=true]):not(
|
|
110
|
+
`),Wm=e=>e.displayName?`${e.displayName} <${e.normalizedEmail}>`:e.normalizedEmail,yr=e=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.trim()),Vm=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(yr(r))return{email:r,displayName:a}}if(yr(t))return{email:t}},Sn=({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),g=xo(r,200),{data:x}=re({...co({query:{q:g,limit:8}}),enabled:g.length>=2}),b=x?.items??[],p=new Set(t.map(S=>S.email.toLowerCase())),y=b.filter(S=>!p.has(S.normalizedEmail.toLowerCase()));c.useEffect(()=>{l(-1),d(y.length>0&&r.length>=2)},[y.length,r.length]);const h=c.useCallback(S=>{p.has(S.email.toLowerCase())||(n([...t,S]),o(""),d(!1))},[t,p,n]),v=c.useCallback(S=>{n(t.filter((k,C)=>C!==S))},[t,n]),j=c.useCallback(S=>{h({email:S.normalizedEmail,displayName:S.displayName}),f.current?.focus()},[h]),w=c.useCallback(()=>{const S=Vm(r);S&&h(S)},[r,h]),N=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(),j(y[i]);return}r.trim()&&(S.preventDefault(),w());return}if(S.key==="ArrowDown"&&u){S.preventDefault(),l(k=>k<y.length-1?k+1:0);return}if(S.key==="ArrowUp"&&u){S.preventDefault(),l(k=>k>0?k-1:y.length-1);return}S.key==="Escape"&&(d(!1),l(-1))},[r,t.length,i,y,u,v,j,w]),I=c.useCallback(()=>{setTimeout(()=>{w(),d(!1)},150)},[w]);return s.jsxs("div",{className:"relative",children:[s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("label",{htmlFor:`address-field-${e}`,className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:[e,":"]}),s.jsxs("div",{className:"flex-1 flex flex-wrap items-center gap-1 min-h-[36px] px-2 py-1 border rounded-md bg-canvas cursor-text",onClick:()=>f.current?.focus(),onKeyDown:S=>{(S.key==="Enter"||S.key===" ")&&f.current?.focus()},children:[t.map((S,k)=>s.jsx(pu,{email:S.email,displayName:S.displayName,onRemove:()=>v(k)},S.email)),s.jsx("input",{ref:f,id:`address-field-${e}`,type:"text",value:r,onChange:S=>o(S.target.value),onKeyDown:N,onBlur:I,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,k)=>s.jsx("li",{className:fe("px-3 py-2 text-sm cursor-pointer transition-colors",k===i&&"bg-accent-2-soft"),onMouseDown:C=>{C.preventDefault(),j(S)},onMouseEnter:()=>l(k),children:Wm(S)},S.addressId))})]})},Ym=({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(Vn,{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(tu,{className:"size-3","aria-hidden":"true"})]})]})]})},Fn=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},kt=()=>Fn("(min-width: 1024px)"),wr=150,Gm=()=>{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>wr}});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>wr})};return a(),n.addEventListener("resize",a),()=>n.removeEventListener("resize",a)},[]),e},Xm=({selectedAccountId:e,onSelect:t})=>{const{data:n}=re({...Ze(),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))})]})},Jm=({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})]}),Zm=["p","br","strong","b","em","i","a","blockquote","ul","ol","li"],eh=["href"],th=e=>Jr.sanitize(e,{ALLOWED_TAGS:Zm,ALLOWED_ATTR:eh}),sh=c.lazy(()=>vc(()=>import("./ComposeBody-CJCPS_su.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}))),nh=()=>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"})]}),hi=[{type:"p",children:[{text:""}]}],ah=[{type:"p",children:[{text:""}]},{type:"p",children:[{text:"-- "}]}],rh=e=>e?[...ah,{type:"p",children:[{text:e}]}]:hi,oh=e=>e?/^re:\s/i.test(e)?e:`Re: ${e}`:"Re: ",ih=e=>e?/^fwd?:\s/i.test(e)?e:`Fwd: ${e}`:"Fwd: ",lh=(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}},ch=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}},uh=(e,t,n,a,r)=>e.length===0&&t.length===0&&n.length===0&&a.trim()===""&&_n(r).trim()==="",dh=({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:g,setSubject:x})=>{const b=kt(),{isKeyboardOpen:p}=Gm();if(!b&&p){const h=[];return n.length>0&&h.push(`To: ${n.map(v=>v.displayName??v.email).join(", ")}`),r.length>0&&h.push(`Cc: ${r.length}`),i.length>0&&h.push(`Bcc: ${i.length}`),g&&h.push(g),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:h.length>0?h.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(Xm,{selectedAccountId:e,onSelect:t}),s.jsx(Sn,{label:"To",addresses:n,onChange:a,placeholder:"Recipients"}),u?s.jsx(Sn,{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(Sn,{label:"Bcc",addresses:i,onChange:l}),s.jsx(Jm,{value:g,onChange:x})]})},ga=({mode:e,account:t,sourceMessage:n,onClose:a,onAccountChange:r})=>{const{state:o,setOutboxMessageId:i,startSendPolling:l}=wt(),{pushError:u}=ze(),{outboxMessageId:d}=o,[f,m]=c.useState([]),[g,x]=c.useState([]),[b,p]=c.useState([]),[y,h]=c.useState(""),[v,j]=c.useState(!1),[w,N]=c.useState(!1),[I,S]=c.useState(t?.accountId),[k,C]=c.useState(!1),E=c.useRef(d);c.useEffect(()=>{E.current!==d&&(E.current=d,d&&(m([]),x([]),p([]),h(""),j(!1),N(!1),T(hi),C(!1)))},[d]);const{signature:R}=Wc(I),[M,T]=c.useState(()=>rh(R.plainText)),{data:P}=re({...bc({path:{outboxMessageId:d??""}}),enabled:!!d&&!k});c.useEffect(()=>{!P||k||(m(P.toAddresses.map(Q=>({email:Q,displayName:void 0}))),P.ccAddresses&&P.ccAddresses.length>0&&(x(P.ccAddresses.map(Q=>({email:Q,displayName:void 0}))),j(!0)),P.bccAddresses&&P.bccAddresses.length>0&&(p(P.bccAddresses.map(Q=>({email:Q,displayName:void 0}))),N(!0)),P.subject&&h(P.subject),P.textBody&&T([{type:"p",children:[{text:P.textBody}]}]),S(P.accountId),C(!0))},[P,k]),c.useEffect(()=>{if(n){if(e==="reply"||e==="reply_all"){const{to:Q,cc:ee}=lh(n,e,t?.email);m(Q),x(ee),ee.length>0&&j(!0),h(oh(n.envelope.subject))}e==="forward"&&h(ih(n.envelope.subject))}},[e,n,t?.email]);const Y=e==="reply"||e==="reply_all"||e==="forward",{data:K}=ci({messageId:n?.message.messageId,bodyParts:n?.bodyParts,enabled:Y&&!!n}),B=K?.kind==="text"?K.body:"",_=K?.kind==="html"?th(K.body):void 0,F=n?.envelope.from[0]?.displayName??n?.envelope.from[0]?.normalizedEmail,{saveStatus:q,saveError:te,saveDraft:U,cancelAutoSave:O}=Hm({outboxMessageId:d,onDraftCreated:i});c.useEffect(()=>{te&&u({title:"Couldn't save draft",detail:$e(te)??"Saving the draft failed."})},[te,u]);const D=xe(lo()),V=xe(uo()),le=xe({...Zs(),onError:Q=>{u(fs("Couldn't discard draft","The draft wasn't discarded.",Q))}}),{data:ve}=re({...Ze(),staleTime:1/0}),ce=ve?.accounts.find(Q=>Q.accountId===I),ye=ce?Kc(ce):!1,Se=D.isPending||V.isPending,G=f.length>0&&!!I&&!ye;c.useEffect(()=>{if(!I||d&&!k||uh(f,g,b,y,M))return;const Q=_n(M),ee=vr(M);U({accountId:I,toAddresses:f.map(ne=>ne.email),ccAddresses:g.length>0?g.map(ne=>ne.email):void 0,bccAddresses:b.length>0?b.map(ne=>ne.email):void 0,subject:y||void 0,textBody:Q||void 0,htmlBody:ee||void 0})},[I,d,k,f,g,b,y,M,U]);const ge=c.useCallback(async()=>{if(!I||f.length===0)return;O();const Q=n&&(e==="reply"||e==="reply_all")?ch(n):{};let ee=d,ne=!1;if(!ee){const oe=_n(M),Ne=vr(M),Fe=await D.mutateAsync({body:{accountId:I,toAddresses:f.map(Ae=>Ae.email),ccAddresses:g.length>0?g.map(Ae=>Ae.email):void 0,bccAddresses:b.length>0?b.map(Ae=>Ae.email):void 0,subject:y||void 0,textBody:oe||void 0,htmlBody:Ne||void 0,sendImmediately:!0,...Q}}).catch(Ae=>(u({title:"Couldn't send message",detail:$e(Ae)??"Saving the draft failed."}),null));if(Fe===null)return;ee=Fe.outboxMessageId,ne=!0,i(ee)}await V.mutateAsync({path:{outboxMessageId:ee}}).catch(oe=>(u({title:"Couldn't send message",detail:$e(oe)??(ne?"The draft was saved but the send request failed. Try again from the Outbox.":"The send request failed. Try again.")}),null))!==null&&(l(ee),a())},[I,f,g,b,y,M,e,n,d,D,V,O,l,i,u,a]),Ie=c.useCallback(()=>{O(),d&&le.mutate({path:{outboxMessageId:d}}),a()},[O,d,le,a]),H=c.useCallback(Q=>{S(Q.accountId),r?.(Q)},[r]);return s.jsx(jd,{banner:ce&&ye?s.jsx(Ym,{accountId:ce.accountId}):void 0,header:s.jsx(dh,{selectedAccountId:I,onAccountChange:H,toAddresses:f,setToAddresses:m,ccAddresses:g,setCcAddresses:x,bccAddresses:b,setBccAddresses:p,showCc:v,setShowCc:j,showBcc:w,setShowBcc:N,subject:y,setSubject:h}),quoted:B||_?s.jsx(Bd,{text:B,html:_,senderName:F}):void 0,actionBar:s.jsx(wd,{onSend:ge,onDiscard:Ie,sending:Se,canSend:G,saveStatus:q,unavailableReason:ye?"SMTP not configured":void 0,onUnavailable:Q=>u({title:"Can't send yet",detail:Q})}),children:s.jsx(c.Suspense,{fallback:s.jsx(nh,{}),children:s.jsx(sh,{value:M,onChange:T,onSubmit:ge,autoFocus:e==="new"})})})},jr=({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(ga,{mode:e,account:t,sourceMessage:n,onClose:a})}),gi=({message:e,icon:t})=>s.jsxs("div",{className:"flex flex-col items-center justify-center p-8 text-center",children:[t&&s.jsx("div",{className:"mb-4 text-fg-muted",children:t}),s.jsx("p",{className:"text-fg-muted",children:e})]}),ps=({enabled:e=!0,bindings:t,capture:n=!1})=>{const 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])},pi=e=>{const{data:t,isLoading:n}=re({...Ze(),staleTime:1/0}),a=c.useMemo(()=>(t?.accounts??[]).map(l=>l.accountId),[t?.accounts]),r=Jt({queries:a.map(l=>({...et({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}},Sr=(e,t,n)=>e.map(a=>t.has(a.messageId)?{...a,isRead:n}:a),fh=(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),mh=({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}=xe({...en(),onMutate:async g=>{const x=new Set(g.body.messageIds??[]),b=g.body.isRead??!0,p=jt({path:{threadId:n}}),y=tt({path:{mailboxId:a}}),h=ut({path:{mailboxId:a}});await Promise.all([o.cancelQueries({queryKey:p}),o.cancelQueries({queryKey:y}),o.cancelQueries({queryKey:h})]);const v=o.getQueriesData({queryKey:p}).filter(N=>N[1]!==void 0).map(([N,I])=>({queryKey:N,data:I})),j=o.getQueriesData({queryKey:y}).concat(o.getQueriesData({queryKey:h})).filter(N=>N[1]!==void 0).map(([N,I])=>({queryKey:N,data:I}));o.setQueriesData({queryKey:p},N=>N&&{...N,items:Sr(N.items,x,b)});const w=N=>N&&{...N,pages:N.pages.map(I=>({...I,items:Sr(I.items,x,b)}))};return o.setQueriesData({queryKey:y},w),o.setQueriesData({queryKey:h},w),{threadMessagesPrefix:p,threadsListPrefix:y,threadsSearchPrefix:h,previousThreadMessages:v,previousThreadsList:j}},onSuccess:(g,x)=>{const b=x.body.messageIds??[];for(const p of b)l.current.add(p),u.current.delete(p)},onError:(g,x,b)=>{const p=x.body.messageIds??[];for(const h of p)u.current.delete(h);if(b){for(const h of b.previousThreadMessages)o.setQueryData(h.queryKey,h.data);for(const h of b.previousThreadsList)o.setQueryData(h.queryKey,h.data)}const y=x.body.isRead??!0;i({title:y?"Couldn't mark as read":"Couldn't mark as unread",detail:$e(g)})},onSettled:(g,x,b,p)=>{p&&(o.invalidateQueries({queryKey:p.threadMessagesPrefix}),o.invalidateQueries({queryKey:p.threadsListPrefix}),o.invalidateQueries({queryKey:p.threadsSearchPrefix}),r&&o.invalidateQueries({queryKey:Vt({path:{accountId:r}})}))}}),f=c.useCallback(g=>{const x=g.filter(b=>!l.current.has(b)&&!u.current.has(b));if(x.length!==0){for(const b of x)u.current.add(b);d({body:{messageIds:x,isRead:!0}})}},[d]),m=c.useMemo(()=>fh(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])},xi=e=>{const{mailboxId:t,accountId:n}=e,a=je(),{pushError:r}=ze(),{mutate:o,isPending:i}=xe({...en(),onError:(u,d)=>{const f=d.body.isRead??!0;r({title:f?"Couldn't mark as read":"Couldn't mark as unread",detail:$e(u)})},onSettled:()=>{a.invalidateQueries({queryKey:tt({path:{mailboxId:t}})}),a.invalidateQueries({queryKey:ut({path:{mailboxId:t}})}),n&&a.invalidateQueries({queryKey:Vt({path:{accountId:n}})})}});return{toggleReadFor:c.useCallback((u,d)=>{u.length!==0&&o({body:{messageIds:u,isRead:d}})},[o]),isPending:i}},hh=60,gh=1.5,ph=(e,t,n)=>{const a=Math.abs(e),r=Math.abs(t);return a<n?{direction:null}:a<r*gh?{direction:null}:{direction:e<0?"left":"right"}},xh=({onSwipeLeft:e,onSwipeRight:t,thresholdPx:n=hh})=>{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}=ph(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}}},Nr=(e,t,n)=>e.map(a=>a.messageId===t?{...a,hasStars:n}:a),Bn=({threadId:e,mailboxId:t})=>{const n=je(),{pushError:a}=ze(),{mutate:r,isPending:o,variables:i}=xe({...yc(),onMutate:async u=>{const d=u.path.messageId,f=u.body.isStarred??!1,m=jt({path:{threadId:e}}),g=tt({path:{mailboxId:t}}),x=ut({path:{mailboxId:t}});await Promise.all([n.cancelQueries({queryKey:m}),n.cancelQueries({queryKey:g}),n.cancelQueries({queryKey:x})]);const b=n.getQueriesData({queryKey:m}).filter(h=>h[1]!==void 0).map(([h,v])=>({queryKey:h,data:v})),p=n.getQueriesData({queryKey:g}).concat(n.getQueriesData({queryKey:x})).filter(h=>h[1]!==void 0).map(([h,v])=>({queryKey:h,data:v}));n.setQueriesData({queryKey:m},h=>h&&{...h,items:Nr(h.items,d,f)});const y=h=>h&&{...h,pages:h.pages.map(v=>({...v,items:Nr(v.items,d,f)}))};return n.setQueriesData({queryKey:g},y),n.setQueriesData({queryKey:x},y),{threadMessagesPrefix:m,threadsListPrefix:g,threadsSearchPrefix:x,previousThreadMessages:b,previousThreadsList:p}},onError:(u,d,f)=>{if(f){for(const g of f.previousThreadMessages)n.setQueryData(g.queryKey,g.data);for(const g of f.previousThreadsList)n.setQueryData(g.queryKey,g.data)}const m=d.body.isStarred??!1;a({title:m?"Couldn't star message":"Couldn't unstar message",detail:$e(u)})},onSettled:(u,d,f,m)=>{m&&(n.invalidateQueries({queryKey:m.threadMessagesPrefix}),n.invalidateQueries({queryKey:m.threadsListPrefix}),n.invalidateQueries({queryKey:m.threadsSearchPrefix}))}});return{toggleStar:(u,d)=>{r({path:{messageId:u},body:{isStarred:!d}})},isPending:o,pendingMessageId:o?i?.path.messageId:void 0}};function cn(e){return e===void 0||e==="uncategorized"?"personal":e}const Ge={uncategorized:"uncategorized",personal:"personal",newsletter:"newsletter",marketing:"marketing",automated:"automated",transactional:"transactional",social:"social"},kr={MoveToInbox:"MoveToInbox",MoveToJunk:"MoveToJunk"},bh={inbox:"Inbox",junk:"Junk"},vh=e=>`Moved from ${bh[e]??"another folder"} by Remit`,yh=(e,t)=>{if(e===kr.MoveToInbox)return t.inboxMailboxId;if(e===kr.MoveToJunk)return t.junkMailboxId},wh=(e,t,n)=>{if(!e||!t)return!1;const a=yh(e.action,n);return a!==void 0&&a===t},jh=(e,t)=>{if(e==="inbox")return t.inboxMailboxId;if(e==="junk")return t.junkMailboxId},un=(e,t)=>{const{data:n,isLoading:a}=re({...Ze(),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}},Sh=e=>{const{mailboxId:t,isLoading:n}=un(e,"Archive");return{archiveMailboxId:t,isLoading:n}},Nh=e=>{const{mailboxId:t,isLoading:n}=un(e,"Drafts");return{draftsMailboxId:t,isLoading:n}},pa=e=>{const{mailboxId:t,isLoading:n}=un(e,"Inbox");return{inboxMailboxId:t,isLoading:n}},xa=e=>{const{mailboxId:t,isLoading:n}=un(e,"Junk");return{junkMailboxId:t,isLoading:n}},bi=e=>{const{data:t}=re({...Ze(),staleTime:1/0,enabled:!!e});return c.useMemo(()=>t?.accounts.find(n=>n.accountId===e)?.folderAppointments??[],[t,e])},Cr=(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}=xe({...wc(),onMutate:async d=>{const f=new Set(d.body.messageIds??[]),m=t?jt({path:{threadId:t}}):[],g=tt({path:{mailboxId:e}}),x=ut({path:{mailboxId:e}});await Promise.all([...t?[r.cancelQueries({queryKey:m})]:[],r.cancelQueries({queryKey:g}),r.cancelQueries({queryKey:x})]);const b=t?r.getQueriesData({queryKey:m}).filter(h=>h[1]!==void 0).map(([h,v])=>({queryKey:h,data:v})):[],p=r.getQueriesData({queryKey:g}).concat(r.getQueriesData({queryKey:x})).filter(h=>h[1]!==void 0).map(([h,v])=>({queryKey:h,data:v}));t&&r.setQueriesData({queryKey:m},h=>h&&{...h,items:Cr(h.items,f)});const y=h=>h&&{...h,pages:h.pages.map(v=>({...v,items:Cr(v.items,f)}))};return r.setQueriesData({queryKey:g},y),r.setQueriesData({queryKey:x},y),a?.(Array.from(f)),{threadMessagesPrefix:m,threadsListPrefix:g,threadsSearchPrefix:x,previousThreadMessages:b,previousThreadsList:p}},onError:(d,f,m)=>{if(m){for(const x of m.previousThreadMessages)r.setQueryData(x.queryKey,x.data);for(const x of m.previousThreadsList)r.setQueryData(x.queryKey,x.data)}const g=f.body.messageIds?.length??0;o({title:g>1?`Couldn't move ${g} messages`:"Couldn't move this message",detail:$e(d)})},onSettled:(d,f,m,g)=>{g&&(t&&r.invalidateQueries({queryKey:g.threadMessagesPrefix}),r.invalidateQueries({queryKey:g.threadsListPrefix}),r.invalidateQueries({queryKey:g.threadsSearchPrefix}),n&&r.invalidateQueries({queryKey:Vt({path:{accountId:n}})}))}});return{moveMessages:c.useCallback((d,f)=>{d.length!==0&&i({body:{messageIds:d,destinationMailboxId:f}})},[i]),isPending:l}},kh=({accountId:e,messageId:t,threadId:n,mailboxId:a,autoMoved:r})=>{const{inboxMailboxId:o}=pa(e),{junkMailboxId:i}=xa(e),{moveMessages:l,isPending:u}=ct({mailboxId:a,threadId:n,accountId:e}),d={inboxMailboxId:o,junkMailboxId:i},f=wh(r,a,d),m=r?jh(r.fromPlacement,d):void 0,g=c.useCallback(()=>{m&&l([t],m)},[l,t,m]);return!f||!r?{show:!1,label:"",isUndoing:!1}:{show:!0,label:vh(r.fromPlacement),onUndo:m?g:void 0,isUndoing:u}};function vi({accountId:e,messageId:t,threadId:n,mailboxId:a,autoMoved:r,size:o="sm"}){const i=kh({accountId:e,messageId:t,threadId:n,mailboxId:a,autoMoved:r});return i.show?s.jsx(ud,{label:i.label,size:o,onUndo:i.onUndo,undoLabel:i.isUndoing?"Undoing…":"Undo"}):null}const yi=({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})]})},$t=({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"}),Er=(e,t)=>e.filter(n=>!t.has(n.messageId)),Ch=e=>e.filter(t=>t.isDeleted!==!0),ds=({mailboxId:e,threadId:t,accountId:n,onAfterOptimisticRemove:a})=>{const r=je(),{pushError:o}=ze(),{mutate:i,isPending:l}=xe({...jc(),onMutate:async d=>{const f=new Set(d.body.messageIds??[]),m=t?jt({path:{threadId:t}}):[],g=tt({path:{mailboxId:e}}),x=ut({path:{mailboxId:e}});await Promise.all([r.cancelQueries({queryKey:m}),r.cancelQueries({queryKey:g}),r.cancelQueries({queryKey:x})]);const b=t?r.getQueriesData({queryKey:m}).filter(h=>h[1]!==void 0).map(([h,v])=>({queryKey:h,data:v})):[],p=r.getQueriesData({queryKey:g}).concat(r.getQueriesData({queryKey:x})).filter(h=>h[1]!==void 0).map(([h,v])=>({queryKey:h,data:v}));t&&r.setQueriesData({queryKey:m},h=>h&&{...h,items:Er(h.items,f)});const y=h=>h&&{...h,pages:h.pages.map(v=>({...v,items:Er(v.items,f)}))};return r.setQueriesData({queryKey:g},y),r.setQueriesData({queryKey:x},y),a?.(Array.from(f)),{threadMessagesPrefix:m,threadsListPrefix:g,threadsSearchPrefix:x,previousThreadMessages:b,previousThreadsList:p}},onError:(d,f,m)=>{if(m){for(const x of m.previousThreadMessages)r.setQueryData(x.queryKey,x.data);for(const x of m.previousThreadsList)r.setQueryData(x.queryKey,x.data)}const g=f.body.messageIds?.length??0;o({title:g>1?`Couldn't delete ${g} messages`:"Couldn't delete this message",detail:$e(d)})},onSettled:(d,f,m,g)=>{g&&(t&&r.invalidateQueries({queryKey:g.threadMessagesPrefix}),r.invalidateQueries({queryKey:g.threadsListPrefix}),r.invalidateQueries({queryKey:g.threadsSearchPrefix}),n&&r.invalidateQueries({queryKey:Vt({path:{accountId:n}})}))}});return{deleteMessages:c.useCallback(d=>{d.length!==0&&i({body:{messageIds:d}})},[i]),isPending:l}},wi=(e,t=Date.now())=>({value:e,setAt:t}),Eh=(e,t,n,a)=>{if(e.addressId!==t)return e;const r={...e.flags??{}};return n?r.trusted=wi(!0,a):delete r.trusted,{...e,flags:r}},Ih=(e,t,n,a)=>{const r=o=>o.map(i=>Eh(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)}}},ba=({messageId:e})=>{const t=je(),{pushError:n}=ze(),{mutate:a,isPending:r,error:o,reset:i}=xe({...fo(),onMutate:async u=>{const d=u.path.addressId,m=u.body.flags?.trusted?.value===!0,g=io({path:{messageId:e}});await t.cancelQueries({queryKey:g});const x=t.getQueriesData({queryKey:g}).filter(b=>b[1]!==void 0).map(([b,p])=>({queryKey:b,data:p}));return t.setQueriesData({queryKey:g},b=>b&&Ih(b,d,m)),{describePrefix:g,previous:x}},onError:(u,d,f)=>{if(f)for(const m of f.previous)t.setQueryData(m.queryKey,m.data);n(fs("Couldn't trust sender","The change wasn't saved.",u))},onSettled:(u,d,f,m)=>{m&&t.invalidateQueries({queryKey:m.describePrefix})}});return{toggleTrusted:(u,d)=>{a({path:{addressId:u},body:{flags:{trusted:wi(!d)}}})},isPending:r,error:o,reset:i}};var dn="Dialog",[ji]=sf(dn),[Rh,_e]=ji(dn),Si=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]=rf({prop:a,defaultProp:r??!1,onChange:o,caller:dn});return s.jsx(Rh,{scope:t,triggerRef:l,contentRef:u,contentId:bn(),titleId:bn(),descriptionId:bn(),open:d,onOpenChange:f,onOpenToggle:c.useCallback(()=>f(m=>!m),[f]),modal:i,children:n})};Si.displayName=dn;var Ni="DialogTrigger",Mh=c.forwardRef((e,t)=>{const{__scopeDialog:n,...a}=e,r=_e(Ni,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":ya(r.open),...a,ref:o,onClick:lt(e.onClick,r.onOpenToggle)})});Mh.displayName=Ni;var va="DialogPortal",[Th,ki]=ji(va,{forceMount:void 0}),Ci=e=>{const{__scopeDialog:t,forceMount:n,children:a,container:r}=e,o=_e(va,t);return s.jsx(Th,{scope:t,forceMount:n,children:c.Children.map(a,i=>s.jsx(on,{present:n||o.open,children:s.jsx(ei,{asChild:!0,container:r,children:i})}))})};Ci.displayName=va;var Ys="DialogOverlay",Ei=c.forwardRef((e,t)=>{const n=ki(Ys,e.__scopeDialog),{forceMount:a=n.forceMount,...r}=e,o=_e(Ys,e.__scopeDialog);return o.modal?s.jsx(on,{present:a||o.open,children:s.jsx(Ah,{...r,ref:t})}):null});Ei.displayName=Ys;var Dh=da("DialogOverlay.RemoveScroll"),Ah=c.forwardRef((e,t)=>{const{__scopeDialog:n,...a}=e,r=_e(Ys,n),o=kf(),i=Nt(t,o);return s.jsx(li,{as:Dh,allowPinchZoom:!0,shards:[r.contentRef],children:s.jsx(nt.div,{"data-state":ya(r.open),...a,ref:i,style:{pointerEvents:"auto",...a.style}})})}),Wt="DialogContent",Ii=c.forwardRef((e,t)=>{const n=ki(Wt,e.__scopeDialog),{forceMount:a=n.forceMount,...r}=e,o=_e(Wt,e.__scopeDialog);return s.jsx(on,{present:a||o.open,children:o.modal?s.jsx(Oh,{...r,ref:t}):s.jsx(Ph,{...r,ref:t})})});Ii.displayName=Wt;var Oh=c.forwardRef((e,t)=>{const n=_e(Wt,e.__scopeDialog),a=c.useRef(null),r=Nt(t,n.contentRef,a);return c.useEffect(()=>{const o=a.current;if(o)return Wf(o)},[]),s.jsx(Ri,{...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())})}),Ph=c.forwardRef((e,t)=>{const n=_e(Wt,e.__scopeDialog),a=c.useRef(!1),r=c.useRef(!1);return s.jsx(Ri,{...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()}})}),Ri=c.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:a,onOpenAutoFocus:r,onCloseAutoFocus:o,...i}=e,l=_e(Wt,n);return Rf(),s.jsx(s.Fragment,{children:s.jsx(Jo,{asChild:!0,loop:!0,trapped:a,onMountAutoFocus:r,onUnmountAutoFocus:o,children:s.jsx(Go,{role:"dialog",id:l.contentId,"aria-describedby":l.descriptionId,"aria-labelledby":l.titleId,"data-state":ya(l.open),...i,ref:t,deferPointerDownOutside:!0,onDismiss:()=>l.onOpenChange(!1)})})})}),Mi="DialogTitle",Ti=c.forwardRef((e,t)=>{const{__scopeDialog:n,...a}=e,r=_e(Mi,n);return s.jsx(nt.h2,{id:r.titleId,...a,ref:t})});Ti.displayName=Mi;var Di="DialogDescription",Lh=c.forwardRef((e,t)=>{const{__scopeDialog:n,...a}=e,r=_e(Di,n);return s.jsx(nt.p,{id:r.descriptionId,...a,ref:t})});Lh.displayName=Di;var Ai="DialogClose",zh=c.forwardRef((e,t)=>{const{__scopeDialog:n,...a}=e,r=_e(Ai,n);return s.jsx(nt.button,{type:"button",...a,ref:t,onClick:lt(e.onClick,()=>r.onOpenChange(!1))})});zh.displayName=Ai;function ya(e){return e?"open":"closed"}function _h(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 Oi=z.createContext({drawerRef:{current:null},overlayRef:{current:null},onPress:()=>{},onRelease:()=>{},onDrag:()=>{},onNestedDrag:()=>{},onNestedOpenChange:()=>{},onNestedRelease:()=>{},openProp:void 0,dismissible:!1,isOpen:!1,isDragging:!1,keyboardIsOpen:{current:!1},snapPointsOffset:null,snapPoints:null,handleOnly:!1,modal:!1,shouldFade:!1,activeSnapPoint:null,onOpenChange:()=>{},setActiveSnapPoint:()=>{},closeDrawer:()=>{},direction:"bottom",shouldAnimate:{current:!0},shouldScaleBackground:!1,setBackgroundColorOnScale:!0,noBodyStyles:!1,container:null,autoFocus:!1}),Ns=()=>{const e=z.useContext(Oi);if(!e)throw new Error("useDrawerContext must be used within a Drawer.Root");return e};_h(`[data-vaul-drawer]{touch-action:none;will-change:transform;transition:transform .5s cubic-bezier(.32, .72, 0, 1);animation-duration:.5s;animation-timing-function:cubic-bezier(0.32,0.72,0,1)}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=bottom][data-state=open]{animation-name:slideFromBottom}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=bottom][data-state=closed]{animation-name:slideToBottom}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=top][data-state=open]{animation-name:slideFromTop}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=top][data-state=closed]{animation-name:slideToTop}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=left][data-state=open]{animation-name:slideFromLeft}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=left][data-state=closed]{animation-name:slideToLeft}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=right][data-state=open]{animation-name:slideFromRight}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=right][data-state=closed]{animation-name:slideToRight}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=bottom]{transform:translate3d(0,var(--initial-transform,100%),0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=top]{transform:translate3d(0,calc(var(--initial-transform,100%) * -1),0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=left]{transform:translate3d(calc(var(--initial-transform,100%) * -1),0,0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=right]{transform:translate3d(var(--initial-transform,100%),0,0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=top]{transform:translate3d(0,var(--snap-point-height,0),0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=bottom]{transform:translate3d(0,var(--snap-point-height,0),0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=left]{transform:translate3d(var(--snap-point-height,0),0,0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=right]{transform:translate3d(var(--snap-point-height,0),0,0)}[data-vaul-overlay][data-vaul-snap-points=false]{animation-duration:.5s;animation-timing-function:cubic-bezier(0.32,0.72,0,1)}[data-vaul-overlay][data-vaul-snap-points=false][data-state=open]{animation-name:fadeIn}[data-vaul-overlay][data-state=closed]{animation-name:fadeOut}[data-vaul-animate=false]{animation:none!important}[data-vaul-overlay][data-vaul-snap-points=true]{opacity:0;transition:opacity .5s cubic-bezier(.32, .72, 0, 1)}[data-vaul-overlay][data-vaul-snap-points=true]{opacity:1}[data-vaul-drawer]:not([data-vaul-custom-container=true])::after{content:'';position:absolute;background:inherit;background-color:inherit}[data-vaul-drawer][data-vaul-drawer-direction=top]::after{top:initial;bottom:100%;left:0;right:0;height:200%}[data-vaul-drawer][data-vaul-drawer-direction=bottom]::after{top:100%;bottom:initial;left:0;right:0;height:200%}[data-vaul-drawer][data-vaul-drawer-direction=left]::after{left:initial;right:100%;top:0;bottom:0;width:200%}[data-vaul-drawer][data-vaul-drawer-direction=right]::after{left:100%;right:initial;top:0;bottom:0;width:200%}[data-vaul-overlay][data-vaul-snap-points=true]:not([data-vaul-snap-points-overlay=true]):not(
|
|
111
111
|
[data-state=closed]
|
|
112
112
|
){opacity:0}[data-vaul-overlay][data-vaul-snap-points-overlay=true]{opacity:1}[data-vaul-handle]{display:block;position:relative;opacity:.7;background:#e2e2e4;margin-left:auto;margin-right:auto;height:5px;width:32px;border-radius:1rem;touch-action:pan-y}[data-vaul-handle]:active,[data-vaul-handle]:hover{opacity:1}[data-vaul-handle-hitarea]{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);width:max(100%,2.75rem);height:max(100%,2.75rem);touch-action:inherit}@media (hover:hover) and (pointer:fine){[data-vaul-drawer]{user-select:none}}@media (pointer:fine){[data-vaul-handle-hitarea]:{width:100%;height:100%}}@keyframes fadeIn{from{opacity:0}to{opacity:1}}@keyframes fadeOut{to{opacity:0}}@keyframes slideFromBottom{from{transform:translate3d(0,var(--initial-transform,100%),0)}to{transform:translate3d(0,0,0)}}@keyframes slideToBottom{to{transform:translate3d(0,var(--initial-transform,100%),0)}}@keyframes slideFromTop{from{transform:translate3d(0,calc(var(--initial-transform,100%) * -1),0)}to{transform:translate3d(0,0,0)}}@keyframes slideToTop{to{transform:translate3d(0,calc(var(--initial-transform,100%) * -1),0)}}@keyframes slideFromLeft{from{transform:translate3d(calc(var(--initial-transform,100%) * -1),0,0)}to{transform:translate3d(0,0,0)}}@keyframes slideToLeft{to{transform:translate3d(calc(var(--initial-transform,100%) * -1),0,0)}}@keyframes slideFromRight{from{transform:translate3d(var(--initial-transform,100%),0,0)}to{transform:translate3d(0,0,0)}}@keyframes slideToRight{to{transform:translate3d(var(--initial-transform,100%),0,0)}}`);function Fh(){const e=navigator.userAgent;return typeof window<"u"&&(/Firefox/.test(e)&&/Mobile/.test(e)||/FxiOS/.test(e))}function Bh(){return wa(/^Mac/)}function $h(){return wa(/^iPhone/)}function Ir(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function Kh(){return wa(/^iPad/)||Bh()&&navigator.maxTouchPoints>1}function Pi(){return $h()||Kh()}function wa(e){return typeof window<"u"&&window.navigator!=null?e.test(window.navigator.platform):void 0}const qh=24,Uh=typeof window<"u"?c.useLayoutEffect:c.useEffect;function Rr(...e){return(...t)=>{for(let n of e)typeof n=="function"&&n(...t)}}const Nn=typeof document<"u"&&window.visualViewport;function Mr(e){let t=window.getComputedStyle(e);return/(auto|scroll)/.test(t.overflow+t.overflowX+t.overflowY)}function Li(e){for(Mr(e)&&(e=e.parentElement);e&&!Mr(e);)e=e.parentElement;return e||document.scrollingElement||document.documentElement}const Hh=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);let zs=0,kn;function Qh(e={}){let{isDisabled:t}=e;Uh(()=>{if(!t)return zs++,zs===1&&Pi()&&(kn=Wh()),()=>{zs--,zs===0&&kn?.()}},[t])}function Wh(){let e,t=0,n=m=>{e=Li(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 g=m.changedTouches[0].pageY,x=e.scrollTop,b=e.scrollHeight-e.clientHeight;b!==0&&((x<=0&&g>t||x>=b&&g<t)&&m.preventDefault(),t=g)},r=m=>{let g=m.target;Kn(g)&&g!==document.activeElement&&(m.preventDefault(),g.style.transform="translateY(-2000px)",g.focus(),requestAnimationFrame(()=>{g.style.transform=""}))},o=m=>{let g=m.target;Kn(g)&&(g.style.transform="translateY(-2000px)",requestAnimationFrame(()=>{g.style.transform="",Nn&&(Nn.height<window.innerHeight?requestAnimationFrame(()=>{Tr(g)}):Nn.addEventListener("resize",()=>Tr(g),{once:!0}))}))},i=()=>{window.scrollTo(0,0)},l=window.pageXOffset,u=window.pageYOffset,d=Rr(Vh(document.documentElement,"paddingRight",`${window.innerWidth-document.documentElement.clientWidth}px`));window.scrollTo(0,0);let f=Rr(os(document,"touchstart",n,{passive:!1,capture:!0}),os(document,"touchmove",a,{passive:!1,capture:!0}),os(document,"touchend",r,{passive:!1,capture:!0}),os(document,"focus",o,!0),os(window,"scroll",i));return()=>{d(),f(),window.scrollTo(l,u)}}function Vh(e,t,n){let a=e.style[t];return e.style[t]=n,()=>{e.style[t]=a}}function os(e,t,n,a){return e.addEventListener(t,n,a),()=>{e.removeEventListener(t,n,a)}}function Tr(e){let t=document.scrollingElement||document.documentElement;for(;e&&e!==t;){let n=Li(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+qh;o>i&&(n.scrollTop+=r-a)}e=n.parentElement}}function Kn(e){return e instanceof HTMLInputElement&&!Hh.has(e.type)||e instanceof HTMLTextAreaElement||e instanceof HTMLElement&&e.isContentEditable}function Yh(e,t){typeof e=="function"?e(t):e!=null&&(e.current=t)}function Gh(...e){return t=>e.forEach(n=>Yh(n,t))}function zi(...e){return c.useCallback(Gh(...e),e)}const _i=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&&_i.set(e,a)}function Xh(e,t){if(!e||!(e instanceof HTMLElement))return;let n=_i.get(e);n&&(e.style[t]=n[t])}const be=e=>{switch(e){case"top":case"bottom":return!0;case"left":case"right":return!1;default:return e}};function _s(e,t){if(!e)return null;const n=window.getComputedStyle(e),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 Jh(e){return 8*(Math.log(e+1)-2)}function Cn(e,t){if(!e)return()=>{};const n=e.style.cssText;return Object.assign(e.style,t),()=>{e.style.cssText=n}}function Zh(...e){return(...t)=>{for(const n of e)typeof n=="function"&&n(...t)}}const he={DURATION:.5,EASE:[.32,.72,0,1]},Fi=.4,eg=.25,tg=100,Bi=8,xt=16,qn=26,En="vaul-dragging";function $i(e){const t=z.useRef(e);return z.useEffect(()=>{t.current=e}),z.useMemo(()=>(...n)=>t.current==null?void 0:t.current.call(t,...n),[])}function sg({defaultProp:e,onChange:t}){const n=z.useState(e),[a]=n,r=z.useRef(a),o=$i(t);return z.useEffect(()=>{r.current!==a&&(o(a),r.current=a)},[a,r,o]),n}function Ki({prop:e,defaultProp:t,onChange:n=()=>{}}){const[a,r]=sg({defaultProp:t,onChange:n}),o=e!==void 0,i=o?e:a,l=$i(n),u=z.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 ng({activeSnapPointProp:e,setActiveSnapPointProp:t,snapPoints:n,drawerRef:a,overlayRef:r,fadeFromIndex:o,onSnapPointChange:i,direction:l="bottom",container:u,snapToSequentialPoint:d}){const[f,m]=Ki({prop:e,defaultProp:n?.[0],onChange:t}),[g,x]=z.useState(typeof window<"u"?{innerWidth:window.innerWidth,innerHeight:window.innerHeight}:void 0);z.useEffect(()=>{function S(){x({innerWidth:window.innerWidth,innerHeight:window.innerHeight})}return window.addEventListener("resize",S),()=>window.removeEventListener("resize",S)},[]);const b=z.useMemo(()=>f===n?.[n.length-1]||null,[n,f]),p=z.useMemo(()=>{var S;return(S=n?.findIndex(k=>k===f))!=null?S:null},[n,f]),y=n&&n.length>0&&(o||o===0)&&!Number.isNaN(o)&&n[o]===f||!n,h=z.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 k;return(k=n?.map(C=>{const E=typeof C=="string";let R=0;if(E&&(R=parseInt(C,10)),be(l)){const T=E?R:g?C*S.height:0;return g?l==="bottom"?S.height-T:-S.height+T:T}const M=E?R:g?C*S.width:0;return g?l==="right"?S.width-M:-S.width+M:M}))!=null?k:[]},[n,g,u]),v=z.useMemo(()=>p!==null?h?.[p]:null,[h,p]),j=z.useCallback(S=>{var k;const C=(k=h?.findIndex(E=>E===S))!=null?k:null;i(C),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)`}),h&&C!==h.length-1&&o!==void 0&&C!==o&&C<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(C,0)])},[a.current,n,h,o,r,m]);z.useEffect(()=>{if(f||e){var S;const k=(S=n?.findIndex(C=>C===e||C===f))!=null?S:-1;h&&k!==-1&&typeof h[k]=="number"&&j(h[k])}},[f,e,n,h,j]);function w({draggedDistance:S,closeDrawer:k,velocity:C,dismissible:E}){if(o===void 0)return;const R=l==="bottom"||l==="right"?(v??0)-S:(v??0)+S,M=p===o-1,T=p===0,P=S>0;if(M&&we(r.current,{transition:`opacity ${he.DURATION}s cubic-bezier(${he.EASE.join(",")})`}),!d&&C>2&&!P){E?k():j(h[0]);return}if(!d&&C>2&&P&&h&&n){j(h[n.length-1]);return}const Y=h?.reduce((B,_)=>typeof B!="number"||typeof _!="number"?B:Math.abs(_-R)<Math.abs(B-R)?_:B),K=be(l)?window.innerHeight:window.innerWidth;if(C>Fi&&Math.abs(S)<K*.4){const B=P?1:-1;if(B>0&&b&&n){j(h[n.length-1]);return}if(T&&B<0&&E&&k(),p===null)return;j(h[p+B]);return}j(Y)}function N({draggedDistance:S}){if(v===null)return;const k=l==="bottom"||l==="right"?v-S:v+S;(l==="bottom"||l==="right")&&k<h[h.length-1]||(l==="top"||l==="left")&&k>h[h.length-1]||we(a.current,{transform:be(l)?`translate3d(0, ${k}px, 0)`:`translate3d(${k}px, 0, 0)`})}function I(S,k){if(!n||typeof p!="number"||!h||o===void 0)return null;const C=p===o-1;if(p>=o&&k)return 0;if(C&&!k)return 1;if(!y&&!C)return null;const R=C?p+1:p-1,M=C?h[R]-h[R-1]:h[R+1]-h[R],T=S/Math.abs(M);return C?1-T:T}return{isLastSnapPoint:b,activeSnapPoint:f,shouldFade:y,getPercentageDragged:I,setActiveSnapPoint:m,activeSnapPointIndex:p,onRelease:w,onDrag:N,snapPointsOffset:h}}const ag=()=>()=>{};function rg(){const{direction:e,isOpen:t,shouldScaleBackground:n,setBackgroundColorOnScale:a,noBodyStyles:r}=Ns(),o=z.useRef(null),i=c.useMemo(()=>document.body.style.backgroundColor,[]);function l(){return(window.innerWidth-qn)/window.innerWidth}z.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;Zh(a&&!r?Cn(document.body,{background:"black"}):ag,Cn(u,{transformOrigin:be(e)?"top":"left",transitionProperty:"transform, border-radius",transitionDuration:`${he.DURATION}s`,transitionTimingFunction:`cubic-bezier(${he.EASE.join(",")})`}));const d=Cn(u,{borderRadius:`${Bi}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 is=null;function og({isOpen:e,modal:t,nested:n,hasBeenOpened:a,preventScrollRestoration:r,noBodyStyles:o}){const[i,l]=z.useState(()=>typeof window<"u"?window.location.href:""),u=z.useRef(0),d=z.useCallback(()=>{if(Ir()&&is===null&&e&&!o){is={position:document.body.style.position,top:document.body.style.top,left:document.body.style.left,height:document.body.style.height,right:"unset"};const{scrollX:m,innerHeight:g}=window;document.body.style.setProperty("position","fixed","important"),Object.assign(document.body.style,{top:`${-u.current}px`,left:`${-m}px`,right:"0px",height:"auto"}),window.setTimeout(()=>window.requestAnimationFrame(()=>{const x=g-window.innerHeight;x&&u.current>=g&&(document.body.style.top=`${-(u.current+x)}px`)}),300)}},[e]),f=z.useCallback(()=>{if(Ir()&&is!==null&&!o){const m=-parseInt(document.body.style.top,10),g=-parseInt(document.body.style.left,10);Object.assign(document.body.style,is),window.requestAnimationFrame(()=>{if(r&&i!==window.location.href){l(window.location.href);return}window.scrollTo(g,m)}),is=null}},[i]);return z.useEffect(()=>{function m(){u.current=window.scrollY}return m(),window.addEventListener("scroll",m),()=>{window.removeEventListener("scroll",m)}},[]),z.useEffect(()=>{if(t)return()=>{typeof document>"u"||document.querySelector("[data-vaul-drawer]")||f()}},[t,f]),z.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 ig({open:e,onOpenChange:t,children:n,onDrag:a,onRelease:r,snapPoints:o,shouldScaleBackground:i=!1,setBackgroundColorOnScale:l=!0,closeThreshold:u=eg,scrollLockTimeout:d=tg,dismissible:f=!0,handleOnly:m=!1,fadeFromIndex:g=o&&o.length-1,activeSnapPoint:x,setActiveSnapPoint:b,fixed:p,modal:y=!0,onClose:h,nested:v,noBodyStyles:j=!1,direction:w="bottom",defaultOpen:N=!1,disablePreventScroll:I=!0,snapToSequentialPoint:S=!1,preventScrollRestoration:k=!1,repositionInputs:C=!0,onAnimationEnd:E,container:R,autoFocus:M=!1}){var T,P;const[Y=!1,K]=Ki({defaultProp:N,prop:e,onChange:W=>{t?.(W),!W&&!v&&Et(),setTimeout(()=>{E?.(W)},he.DURATION*1e3),W&&!y&&typeof window<"u"&&window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"}),W||(document.body.style.pointerEvents="auto")}}),[B,_]=z.useState(!1),[F,q]=z.useState(!1),[te,U]=z.useState(!1),O=z.useRef(null),D=z.useRef(null),V=z.useRef(null),le=z.useRef(null),ve=z.useRef(null),ce=z.useRef(!1),ye=z.useRef(null),Se=z.useRef(0),G=z.useRef(!1),ge=z.useRef(!N),Ie=z.useRef(0),H=z.useRef(null),Q=z.useRef(((T=H.current)==null?void 0:T.getBoundingClientRect().height)||0),ee=z.useRef(((P=H.current)==null?void 0:P.getBoundingClientRect().width)||0),ne=z.useRef(0),Ue=z.useCallback(W=>{o&&W===He.length-1&&(D.current=new Date)},[]),{activeSnapPoint:oe,activeSnapPointIndex:Ne,setActiveSnapPoint:Fe,onRelease:Ae,snapPointsOffset:He,onDrag:Qe,shouldFade:Ct,getPercentageDragged:ht}=ng({snapPoints:o,activeSnapPointProp:x,setActiveSnapPointProp:b,drawerRef:H,fadeFromIndex:g,overlayRef:O,onSnapPointChange:Ue,direction:w,container:R,snapToSequentialPoint:S});Qh({isDisabled:!Y||F||!y||te||!B||!C||!I});const{restorePositionSetting:Et}=og({isOpen:Y,modal:y,nested:v??!1,hasBeenOpened:B,preventScrollRestoration:k,noBodyStyles:j});function We(){return(window.innerWidth-qn)/window.innerWidth}function at(W){var ae,ie;!f&&!o||H.current&&!H.current.contains(W.target)||(Q.current=((ae=H.current)==null?void 0:ae.getBoundingClientRect().height)||0,ee.current=((ie=H.current)==null?void 0:ie.getBoundingClientRect().width)||0,q(!0),V.current=new Date,Pi()&&window.addEventListener("touchend",()=>ce.current=!1,{once:!0}),W.target.setPointerCapture(W.pointerId),Se.current=be(w)?W.pageY:W.pageX)}function gt(W,ae){var ie;let Z=W;const ue=(ie=window.getSelection())==null?void 0:ie.toString(),pe=H.current?_s(H.current,w):null,A=new Date;if(Z.tagName==="SELECT"||Z.hasAttribute("data-vaul-no-drag")||Z.closest("[data-vaul-no-drag]"))return!1;if(w==="right"||w==="left")return!0;if(D.current&&A.getTime()-D.current.getTime()<500)return!1;if(pe!==null&&(w==="bottom"?pe>0:pe<0))return!0;if(ue&&ue.length>0)return!1;if(ve.current&&A.getTime()-ve.current.getTime()<d&&pe===0||ae)return ve.current=A,!1;for(;Z;){if(Z.scrollHeight>Z.clientHeight){if(Z.scrollTop!==0)return ve.current=new Date,!1;if(Z.getAttribute("role")==="dialog")return!0}Z=Z.parentNode}return!0}function Re(W){if(H.current&&F){const ae=w==="bottom"||w==="right"?1:-1,ie=(Se.current-(be(w)?W.pageY:W.pageX))*ae,Z=ie>0,ue=o&&!f&&!Z;if(ue&&Ne===0)return;const pe=Math.abs(ie),A=document.querySelector("[data-vaul-drawer-wrapper]"),J=w==="bottom"||w==="top"?Q.current:ee.current;let me=pe/J;const de=ht(pe,Z);if(de!==null&&(me=de),ue&&me>=1||!ce.current&&!gt(W.target,Z))return;if(H.current.classList.add(En),ce.current=!0,we(H.current,{transition:"none"}),we(O.current,{transition:"none"}),o&&Qe({draggedDistance:ie}),Z&&!o){const ke=Jh(ie),pt=Math.min(ke*-1,0)*ae;we(H.current,{transform:be(w)?`translate3d(0, ${pt}px, 0)`:`translate3d(${pt}px, 0, 0)`});return}const Me=1-me;if((Ct||g&&Ne===g-1)&&(a?.(W,me),we(O.current,{opacity:`${Me}`,transition:"none"},!0)),A&&O.current&&i){const ke=Math.min(We()+me*(1-We()),1),pt=8-me*8,Be=Math.max(0,14-me*14);we(A,{borderRadius:`${pt}px`,transform:be(w)?`scale(${ke}) translate3d(0, ${Be}px, 0)`:`scale(${ke}) translate3d(${Be}px, 0, 0)`,transition:"none"},!0)}if(!o){const ke=pe*ae;we(H.current,{transform:be(w)?`translate3d(0, ${ke}px, 0)`:`translate3d(${ke}px, 0, 0)`})}}}z.useEffect(()=>{window.requestAnimationFrame(()=>{ge.current=!0})},[]),z.useEffect(()=>{var W;function ae(){if(!H.current||!C)return;const ie=document.activeElement;if(Kn(ie)||G.current){var Z;const ue=((Z=window.visualViewport)==null?void 0:Z.height)||0,pe=window.innerHeight;let A=pe-ue;const J=H.current.getBoundingClientRect().height||0,me=J>pe*.8;ne.current||(ne.current=J);const de=H.current.getBoundingClientRect().top;if(Math.abs(Ie.current-A)>60&&(G.current=!G.current),o&&o.length>0&&He&&Ne){const Me=He[Ne]||0;A+=Me}if(Ie.current=A,J>ue||G.current){const Me=H.current.getBoundingClientRect().height;let ke=Me;Me>ue&&(ke=ue-(me?de:qn)),p?H.current.style.height=`${Me-Math.max(A,0)}px`:H.current.style.height=`${Math.max(ke,ue-de)}px`}else Fh()||(H.current.style.height=`${ne.current}px`);o&&o.length>0&&!G.current?H.current.style.bottom="0px":H.current.style.bottom=`${Math.max(A,0)}px`}}return(W=window.visualViewport)==null||W.addEventListener("resize",ae),()=>{var ie;return(ie=window.visualViewport)==null?void 0:ie.removeEventListener("resize",ae)}},[Ne,o,He]);function Ve(W){Rt(),h?.(),W||K(!1),setTimeout(()=>{o&&Fe(o[0])},he.DURATION*1e3)}function It(){if(!H.current)return;const W=document.querySelector("[data-vaul-drawer-wrapper]"),ae=_s(H.current,w);we(H.current,{transform:"translate3d(0, 0, 0)",transition:`transform ${he.DURATION}s cubic-bezier(${he.EASE.join(",")})`}),we(O.current,{transition:`opacity ${he.DURATION}s cubic-bezier(${he.EASE.join(",")})`,opacity:"1"}),i&&ae&&ae>0&&Y&&we(W,{borderRadius:`${Bi}px`,overflow:"hidden",...be(w)?{transform:`scale(${We()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`,transformOrigin:"top"}:{transform:`scale(${We()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)`,transformOrigin:"left"},transitionProperty:"transform, border-radius",transitionDuration:`${he.DURATION}s`,transitionTimingFunction:`cubic-bezier(${he.EASE.join(",")})`},!0)}function Rt(){!F||!H.current||(H.current.classList.remove(En),ce.current=!1,q(!1),le.current=new Date)}function es(W){if(!F||!H.current)return;H.current.classList.remove(En),ce.current=!1,q(!1),le.current=new Date;const ae=_s(H.current,w);if(!W||!gt(W.target,!1)||!ae||Number.isNaN(ae)||V.current===null)return;const ie=le.current.getTime()-V.current.getTime(),Z=Se.current-(be(w)?W.pageY:W.pageX),ue=Math.abs(Z)/ie;if(ue>.05&&(U(!0),setTimeout(()=>{U(!1)},200)),o){Ae({draggedDistance:Z*(w==="bottom"||w==="right"?1:-1),closeDrawer:Ve,velocity:ue,dismissible:f}),r?.(W,!0);return}if(w==="bottom"||w==="right"?Z>0:Z<0){It(),r?.(W,!0);return}if(ue>Fi){Ve(),r?.(W,!1);return}var pe;const A=Math.min((pe=H.current.getBoundingClientRect().height)!=null?pe:0,window.innerHeight);var J;const me=Math.min((J=H.current.getBoundingClientRect().width)!=null?J:0,window.innerWidth),de=w==="left"||w==="right";if(Math.abs(ae)>=(de?me:A)*u){Ve(),r?.(W,!1);return}r?.(W,!0),It()}z.useEffect(()=>(Y&&(we(document.documentElement,{scrollBehavior:"auto"}),D.current=new Date),()=>{Xh(document.documentElement,"scrollBehavior")}),[Y]);function Mt(W){const ae=W?(window.innerWidth-xt)/window.innerWidth:1,ie=W?-xt:0;ye.current&&window.clearTimeout(ye.current),we(H.current,{transition:`transform ${he.DURATION}s cubic-bezier(${he.EASE.join(",")})`,transform:be(w)?`scale(${ae}) translate3d(0, ${ie}px, 0)`:`scale(${ae}) translate3d(${ie}px, 0, 0)`}),!W&&H.current&&(ye.current=setTimeout(()=>{const Z=_s(H.current,w);we(H.current,{transition:"none",transform:be(w)?`translate3d(0, ${Z}px, 0)`:`translate3d(${Z}px, 0, 0)`})},500))}function Le(W,ae){if(ae<0)return;const ie=(window.innerWidth-xt)/window.innerWidth,Z=ie+ae*(1-ie),ue=-xt+ae*xt;we(H.current,{transform:be(w)?`scale(${Z}) translate3d(0, ${ue}px, 0)`:`scale(${Z}) translate3d(${ue}px, 0, 0)`,transition:"none"})}function ts(W,ae){const ie=be(w)?window.innerHeight:window.innerWidth,Z=ae?(ie-xt)/ie:1,ue=ae?-xt:0;ae&&we(H.current,{transition:`transform ${he.DURATION}s cubic-bezier(${he.EASE.join(",")})`,transform:be(w)?`scale(${Z}) translate3d(0, ${ue}px, 0)`:`scale(${Z}) translate3d(${ue}px, 0, 0)`})}return z.useEffect(()=>{y||window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"})},[y]),z.createElement(Si,{defaultOpen:N,onOpenChange:W=>{!f&&!W||(W?_(!0):Ve(!0),K(W))},open:Y},z.createElement(Oi.Provider,{value:{activeSnapPoint:oe,snapPoints:o,setActiveSnapPoint:Fe,drawerRef:H,overlayRef:O,onOpenChange:t,onPress:at,onRelease:es,onDrag:Re,dismissible:f,shouldAnimate:ge,handleOnly:m,isOpen:Y,isDragging:F,shouldFade:Ct,closeDrawer:Ve,onNestedDrag:Le,onNestedOpenChange:Mt,onNestedRelease:ts,keyboardIsOpen:G,modal:y,snapPointsOffset:He,activeSnapPointIndex:Ne,direction:w,shouldScaleBackground:i,setBackgroundColorOnScale:l,noBodyStyles:j,container:R,autoFocus:M}},n))}const qi=z.forwardRef(function({...e},t){const{overlayRef:n,snapPoints:a,onRelease:r,shouldFade:o,isOpen:i,modal:l,shouldAnimate:u}=Ns(),d=zi(t,n),f=a&&a.length>0;if(!l)return null;const m=z.useCallback(g=>r(g),[r]);return z.createElement(Ei,{onMouseUp:m,ref:d,"data-vaul-overlay":"","data-vaul-snap-points":i&&f?"true":"false","data-vaul-snap-points-overlay":i&&o?"true":"false","data-vaul-animate":u?.current?"true":"false",...e})});qi.displayName="Drawer.Overlay";const Ui=z.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:g,isOpen:x,direction:b,snapPoints:p,container:y,handleOnly:h,shouldAnimate:v,autoFocus:j}=Ns(),[w,N]=z.useState(!1),I=zi(r,o),S=z.useRef(null),k=z.useRef(null),C=z.useRef(!1),E=p&&p.length>0;rg();const R=(T,P,Y=0)=>{if(C.current)return!0;const K=Math.abs(T.y),B=Math.abs(T.x),_=B>K,F=["bottom","right"].includes(P)?1:-1;if(P==="left"||P==="right"){if(!(T.x*F<0)&&B>=0&&B<=Y)return _}else if(!(T.y*F<0)&&K>=0&&K<=Y)return!_;return C.current=!0,!0};z.useEffect(()=>{E&&window.requestAnimationFrame(()=>{N(!0)})},[]);function M(T){S.current=null,C.current=!1,l(T)}return z.createElement(Ii,{"data-vaul-drawer-direction":b,"data-vaul-drawer":"","data-vaul-delayed-snap-points":w?"true":"false","data-vaul-snap-points":x&&E?"true":"false","data-vaul-custom-container":y?"true":"false","data-vaul-animate":v?.current?"true":"false",...a,ref:I,style:f&&f.length>0?{"--snap-point-height":`${f[m??0]}px`,...t}:t,onPointerDown:T=>{h||(a.onPointerDown==null||a.onPointerDown.call(a,T),S.current={x:T.pageX,y:T.pageY},i(T))},onOpenAutoFocus:T=>{n?.(T),j||T.preventDefault()},onPointerDownOutside:T=>{if(e?.(T),!g||T.defaultPrevented){T.preventDefault();return}d.current&&(d.current=!1)},onFocusOutside:T=>{if(!g){T.preventDefault();return}},onPointerMove:T=>{if(k.current=T,h||(a.onPointerMove==null||a.onPointerMove.call(a,T),!S.current))return;const P=T.pageY-S.current.y,Y=T.pageX-S.current.x,K=T.pointerType==="touch"?10:2;R({x:Y,y:P},b,K)?u(T):(Math.abs(Y)>K||Math.abs(P)>K)&&(S.current=null)},onPointerUp:T=>{a.onPointerUp==null||a.onPointerUp.call(a,T),S.current=null,C.current=!1,l(T)},onPointerOut:T=>{a.onPointerOut==null||a.onPointerOut.call(a,T),M(k.current)},onContextMenu:T=>{a.onContextMenu==null||a.onContextMenu.call(a,T),k.current&&M(k.current)}})});Ui.displayName="Drawer.Content";const lg=250,cg=120,Hi=z.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:g,onDrag:x}=Ns(),b=z.useRef(null),p=z.useRef(!1);function y(){if(p.current){j();return}window.setTimeout(()=>{h()},cg)}function h(){if(o||e||p.current){j();return}if(j(),!i||i.length===0){d||r();return}if(l===i[i.length-1]&&d){r();return}const N=i.findIndex(S=>S===l);if(N===-1)return;const I=i[N+1];u(I)}function v(){b.current=window.setTimeout(()=>{p.current=!0},lg)}function j(){b.current&&window.clearTimeout(b.current),p.current=!1}return z.createElement("div",{onClick:y,onPointerCancel:j,onPointerDown:w=>{f&&g(w),v()},onPointerMove:w=>{f&&x(w)},ref:a,"data-vaul-drawer-visible":m?"true":"false","data-vaul-handle":"","aria-hidden":"true",...n},z.createElement("span",{"data-vaul-handle-hitarea":"","aria-hidden":"true"},t))});Hi.displayName="Drawer.Handle";function ug(e){const t=Ns(),{container:n=t.container,...a}=e;return z.createElement(Ci,{container:n,...a})}const Pe={Root:ig,Content:Ui,Overlay:qi,Portal:ug,Handle:Hi,Title:Ti},dg=new Set(["outbox","postvak uit","boîte d'envoi","postausgang","buzón de salida","posta in uscita","送信トレイ","送件匣","发件箱","skrzynka nadawcza"]),fg=e=>{const t=Vs(e.fullPath).trim().toLowerCase();return dg.has(t)},Dr=An.length,ja=(e,t=[])=>{const n=ys(t);return[...e.filter(r=>{const o=n.get(r.mailboxId);return o==="drafts"||o==="sent"?!1:!fg(r)})].sort((r,o)=>{const i=n.has(r.mailboxId)?An.indexOf(n.get(r.mailboxId)??"inbox"):Dr,l=n.has(o.mailboxId)?An.indexOf(n.get(o.mailboxId)??"inbox"):Dr;return i!==l?i-l:Vs(r.fullPath).localeCompare(Vs(o.fullPath),void 0,{sensitivity:"base",numeric:!0})})},Qi="inline-flex items-center justify-center transition-colors",mg=fe(Qi,"min-h-11 min-w-11 rounded hover:bg-surface-raised"),hg=fe(Qi,"min-h-11 gap-1.5 px-3 rounded text-sm font-medium hover:bg-surface-raised"),ks=({accountId:e,currentMailboxId:t,onMove:n,disabled:a=!1,disabledHint:r,variant:o="icon-only",label:i})=>{const[l,u]=c.useState(!1),d=kt(),f=c.useRef(null),m=i??"Move to folder",g=c.useId(),{t:x}=tn("mail",{useSuspense:!1}),b=c.useCallback((E,R)=>x(E,{defaultValue:R}),[x]),{data:p,isLoading:y,isError:h,error:v,refetch:j}=re({...et({path:{accountId:e}}),staleTime:1/0,enabled:l}),w=bi(e),N=c.useMemo(()=>{const E=ja(p?.items??[],w),R=ys(w);return E.map(M=>({id:M.mailboxId,label:Ht(M,R.get(M.mailboxId),b),searchValue:M.fullPath,isCurrent:M.mailboxId===t}))},[p?.items,w,t,b]),I=c.useCallback(E=>{u(!1),n(E)},[n]);c.useEffect(()=>{if(!l||!d)return;const E=M=>{f.current&&!f.current.contains(M.target)&&u(!1)},R=M=>{M.key==="Escape"&&u(!1)};return document.addEventListener("mousedown",E),document.addEventListener("keydown",R),()=>{document.removeEventListener("mousedown",E),document.removeEventListener("keydown",R)}},[l,d]);const S=a||!!r,k=s.jsxs("button",{type:"button",onClick:E=>{E.stopPropagation(),!S&&u(R=>!R)},"aria-label":m,"aria-haspopup":d?"listbox":"dialog","aria-expanded":l,"aria-controls":l?g:void 0,title:r,className:o==="icon-only"?mg:hg,children:[s.jsx(Co,{className:"size-4"}),o==="compact"&&s.jsx("span",{className:"hidden sm:inline",children:"Move"})]}),C=y?s.jsx("div",{className:"px-3 py-5 text-sm text-fg-muted",children:"Loading folders…"}):h?s.jsx("div",{className:"p-3",children:s.jsx(ft,{variant:"inline",title:"Couldn't load folders",error:v,onRetry:()=>j()})}):s.jsx(Wo,{mailboxes:N,onSelect:I,onCancel:()=>u(!1),autoFocus:!d,labels:{searchPlaceholder:x("move_picker_placeholder",{defaultValue:"Move to…"}),searchAriaLabel:x("move_picker_filter_label",{defaultValue:"Filter folders"}),optionLabel:E=>`Move to ${E}`,currentSuffix:"(current folder)",currentTag:"current",emptyMessage:E=>`No folders match "${E}"`}});return d?s.jsxs("div",{ref:f,className:"relative inline-block",children:[k,l&&s.jsx("div",{id:g,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:C})]}):s.jsxs(s.Fragment,{children:[k,s.jsx(Pe.Root,{open:l,onOpenChange:u,children:s.jsxs(Pe.Portal,{children:[s.jsx(Pe.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),s.jsxs(Pe.Content,{className:"fixed inset-x-0 bottom-0 z-50 flex flex-col bg-canvas rounded-t-lg",style:{maxHeight:"85dvh"},id:g,children:[s.jsx(Pe.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-subtle/30"}),s.jsx(Pe.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:C})]})]})})]})},gg=({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:g}=Ut({strict:!1}),{mutate:x,isPending:b}=xe({...en(),onMutate:async Y=>{const K=Y.body.isRead??!0,B=new Set(Y.body.messageIds??[]),_=jt({path:{threadId:t}}),F=tt({path:{mailboxId:n}}),q=ut({path:{mailboxId:n}});await Promise.all([d.cancelQueries({queryKey:_}),d.cancelQueries({queryKey:F}),d.cancelQueries({queryKey:q})]);const te=d.getQueriesData({queryKey:_}).filter(D=>D[1]!==void 0).map(([D,V])=>({queryKey:D,data:V})),U=d.getQueriesData({queryKey:F}).concat(d.getQueriesData({queryKey:q})).filter(D=>D[1]!==void 0).map(([D,V])=>({queryKey:D,data:V}));d.setQueriesData({queryKey:_},D=>D&&{...D,items:D.items.map(V=>B.has(V.messageId)?{...V,isRead:K}:V)});const O=D=>D&&{...D,pages:D.pages.map(V=>({...V,items:V.items.map(le=>B.has(le.messageId)?{...le,isRead:K}:le)}))};return d.setQueriesData({queryKey:F},O),d.setQueriesData({queryKey:q},O),{threadMessagesPrefix:_,threadsListPrefix:F,threadsSearchPrefix:q,previousThreadMessages:te,previousThreadsList:U}},onError:(Y,K,B)=>{if(B){for(const F of B.previousThreadMessages)d.setQueryData(F.queryKey,F.data);for(const F of B.previousThreadsList)d.setQueryData(F.queryKey,F.data)}const _=K.body.isRead??!0;m({title:_?"Couldn't mark as read":"Couldn't mark as unread",detail:$e(Y)})},onSettled:(Y,K,B,_)=>{_&&(d.invalidateQueries({queryKey:_.threadMessagesPrefix}),d.invalidateQueries({queryKey:_.threadsListPrefix}),d.invalidateQueries({queryKey:_.threadsSearchPrefix}))}}),p=c.useCallback(Y=>{g&&Y.includes(g)&&f({to:"/mail/$mailboxId",params:{mailboxId:n},search:K=>({...K,selectedMessageId:void 0})})},[g,n,f]),{deleteMessages:y,isPending:h}=ds({mailboxId:n,threadId:t,onAfterOptimisticRemove:p}),{moveMessages:v,isPending:j}=ct({mailboxId:n,threadId:t,accountId:r,onAfterOptimisticRemove:p}),{toggleTrusted:w,isPending:N,error:I,reset:S}=ba({messageId:e}),k=()=>{x({body:{messageIds:[e],isRead:!1}})},C=()=>{y([e])},E=()=>{o&&w(o,i)},R=b||h||j||N,M=R||!o,T=c.useCallback(Y=>{v([e],Y)},[v,e]),P=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(ks,{accountId:r,currentMailboxId:n,onMove:T,disabled:R,label:"Move this message"}),s.jsxs(yi,{trigger:s.jsx(ko,{className:"size-4"}),children:[s.jsxs($t,{onClick:E,disabled:M,children:[i?s.jsx(nn,{className:"size-4 text-positive"}):s.jsx(ws,{className:"size-4 opacity-0"}),s.jsx("span",{title:P,children:"Trusted sender"})]}),a&&s.jsxs($t,{onClick:k,disabled:R,children:[s.jsx(js,{className:"size-4"}),"Mark as unread"]}),u&&s.jsxs($t,{onClick:u,children:[s.jsx(No,{className:"size-4"}),l?"Show formatted":"Show raw email"]}),s.jsx($n,{}),s.jsxs($t,{onClick:C,disabled:R,destructive:!0,children:[s.jsx(qe,{className:"size-4"}),"Delete"]})]})]}),I&&s.jsx("div",{className:"w-64",children:s.jsx(ft,{variant:"inline",title:"Couldn't update trust",error:I,onRetry:()=>{S(),E()}})})]})},pg=()=>{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},xg=({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"})]})]}),bg=(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}}},vg=e=>e instanceof bt?e.reason:"generic",yg=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=vg(e),a=yg(e),{title:r,detail:o}=bg(n,a),[i,l]=c.useState(!1),{Account:u}=Jn();return i?null:s.jsxs("div",{role:"alert","data-testid":"message-body-error-banner","data-reason":n,className:"flex items-start gap-2 rounded-md border border-danger/40 bg-danger-soft px-3 py-2 text-sm",children:[s.jsx(yt,{className:"size-4 shrink-0 text-danger mt-0.5","aria-hidden":"true"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"font-medium text-danger",children: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(De,{className:"size-4","aria-hidden":"true"})})]})]})},jg=()=>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"})]}),Ar=()=>s.jsx("p",{className:"text-fg-muted text-sm italic",children:"This message has no body content."}),Wi=({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=pg(),{toggleTrusted:g,isPending:x}=ba({messageId:r??""}),b=!!e&&e.length>0,{picked:p,data:y,isLoading:h,isError:v,error:j,refetch:w}=ci({messageId:r,bodyParts:e,enabled:b}),N=c.useMemo(()=>Au(e??[]),[e]),I=b&&y?.kind==="html"?y.body:t,S=b&&y?.kind==="text"?y.body:n;if(b){if(h)return s.jsx("div",{className:fe("message-body",l),children:s.jsx(jg,{})});if(v)return s.jsx("div",{className:fe("message-body",l),children:s.jsx(wg,{error:j,onRetry:()=>w()})});if(!p)return s.jsx("div",{className:fe("message-body",l),children:s.jsx(Ar,{})})}else if(!t&&!n)return s.jsx("div",{className:fe("message-body",l),children:s.jsx(Ar,{})});const k=!!(o&&r),C=()=>{!o||x||(d(!0),g(o,!1))};return s.jsx(qo,{className:l,html:I,text:S,isDark:m,category:i,allowImages:f,resolveCid:N,renderBlockedNotice:E=>s.jsx(xg,{blockedImageCount:E,canAlwaysTrust:k,isTrustPending:x,onLoadOnce:()=>d(!0),onAlwaysTrust:C})})},Sg=({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:g,onForward:x})=>{const b=je(),{deleteMessages:p}=ds({mailboxId:n,threadId:t}),{moveMessages:y}=ct({mailboxId:n,threadId:t,accountId:a}),{toggleTrusted:h}=ba({messageId:e}),{mutate:v}=xe({...en(),onSettled:()=>{b.invalidateQueries({queryKey:jt({path:{threadId:t}})}),b.invalidateQueries({queryKey:tt({path:{mailboxId:n}})}),b.invalidateQueries({queryKey:ut({path:{mailboxId:n}})})}}),j=c.useCallback(S=>{y([e],S)},[y,e]),w=c.useCallback(()=>{p([e])},[p,e]),N=c.useCallback(()=>{v({body:{messageIds:[e],isRead:!r}})},[v,e,r]),I=[];return l&&I.push({key:"trusted",label:u?"Trusted sender":"Mark sender trusted",icon:u?s.jsx(nn,{className:"size-4 text-positive"}):s.jsx(ws,{className:"size-4"}),onSelect:()=>h(l,u)}),f&&I.push({key:"raw",label:d?"Show formatted":"Show raw email",icon:s.jsx(No,{className:"size-4"}),onSelect:f}),s.jsx(Ko,{hasThread:!0,onReply:m,onReplyAll:g,onForward:x,isStarred:o,onToggleStar:i,onDelete:w,isRead:r,onToggleRead:N,overflowItems:I,moveSlot:a?s.jsx(ks,{accountId:a,currentMailboxId:n,onMove:j,label:"Move this message"}):void 0})},Ng=()=>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"})]}),kg=({messageId:e,enabled:t=!0})=>{const{data:n,isLoading:a,isError:r,error:o,refetch:i}=re({...Sc({path:{messageId:e}}),enabled:t});if(a)return s.jsx("div",{className:"message-body",children:s.jsx(Ng,{})});if(r)return s.jsx("div",{className:"message-body",children:s.jsx(ft,{variant:"inline",title:"Couldn't load the raw email",error:o,onRetry:()=>i()})});const 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})})},Cg=()=>s.jsx(nn,{className:"inline-block size-4 ml-1 -mt-0.5 text-positive align-middle","aria-label":"Trusted sender","data-testid":"trusted-sender-badge"}),Vi=(e,t)=>({id:e.messageId,fromName:e.fromName??e.fromEmail??"?",fromEmail:e.fromEmail??"",toLabel:"",dateLabel:t,snippet:e.snippet||"",bodyHtml:""}),Yi=({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(dt,{className:fe("size-3.5",e&&"fill-current")})}),Eg=({threadMessage:e,isFocused:t,onToggle:n,onToggleStar:a,isStarPending:r})=>{const o=vo(e.sentDate,"datetime"),i=Vi(e,o);return s.jsx(Uo,{message:i,onClick:n,isFocused:t,isUnread:!e.isRead,trailing:s.jsxs(s.Fragment,{children:[e.hasAttachment&&s.jsx(an,{className:"size-3 shrink-0 text-fg-subtle"}),s.jsx(Yi,{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})]})})},Ig=({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:g,mobile:x,onReply:b,onReplyAll:p,onForward:y})=>{const h=vo(e.sentDate,"long"),v=!e.isRead,j=t?.envelope.from[0]?.flags?.trusted?.value===!0,w=t?.envelope.from[0]?.addressId,N=Vi(e,h),I=e.autoMoved?s.jsx(vi,{accountId:f,messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,autoMoved:e.autoMoved,size:"md"}):null;return s.jsx(Ho,{message:N,isFocused:i,onHeaderClick:l,senderBadge:j?s.jsx(Cg,{}):void 0,trailing:s.jsx("span",{"data-testid":"message-date",className:"text-2xs text-fg-subtle",children:h}),to:t?s.jsx(gu,{label:"To",addresses:t.envelope.to}):null,indicators:I||!x?s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mt-0.5",children:[I,!x&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex items-center justify-end gap-1",children:[s.jsx(Yi,{isStarred:e.hasStars,onToggleStar:u,isStarPending:d}),e.hasAttachment&&s.jsx("span",{className:"text-fg-subtle p-0.5",children:s.jsx(an,{className:"size-3.5"})})]}),v&&s.jsx("span",{className:"size-1.5 rounded-full bg-accent","aria-label":"Unread"})]})]}):void 0,actionMenu:x?void 0:s.jsx(gg,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,isRead:e.isRead,accountId:f,fromAddressId:w,isTrusted:j,showRaw:m,onToggleRaw:g}),actionBar:x?s.jsx(Sg,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,accountId:f,isRead:e.isRead,isStarred:e.hasStars,onToggleStar:u,fromAddressId:w,isTrusted:j,showRaw:m,onToggleRaw:g,onReply:b,onReplyAll:p,onForward:y}):void 0,body:n?s.jsxs("div",{className:"mt-3 animate-pulse space-y-2",children:[s.jsx("div",{className:"h-4 bg-surface-sunken rounded w-full"}),s.jsx("div",{className:"h-4 bg-surface-sunken rounded w-3/4"}),s.jsx("div",{className:"h-4 bg-surface-sunken rounded w-1/2"})]}):a&&Nc(r)?s.jsx("div",{className:"mt-3",children:s.jsx(gi,{message:"This message has been deleted"})}):a?s.jsx("div",{className:"mt-3",children:s.jsx(ft,{variant:"inline",title:"Couldn't load this message",error:r,onRetry:o})}):m?s.jsx("div",{className:"mt-3",children:s.jsx(kg,{messageId:e.messageId})}):s.jsx("div",{className:"mt-3",children:s.jsx(Wi,{bodyParts:t?.bodyParts,messageId:e.messageId,fromAddressId:t?.envelope.from[0]?.addressId,isTrusted:j,category:cn(e.category)})})})},Rg=({threadMessage:e,isExpanded:t,isFocused:n,onToggle:a,onToggleStar:r,isStarPending:o,accountId:i,mobile:l,onReply:u,onReplyAll:d,onForward:f})=>{const[m,g]=c.useState(!1),{data:x,isLoading:b,isError:p,error:y,refetch:h}=re({...Zn({path:{messageId:e.messageId}}),enabled:t,meta:{softError:!0}});return t?s.jsx(Ig,{threadMessage:e,messageData:x,isLoading:b,isError:p,error:y,onRetry:()=>h(),isFocused:n,onToggle:a,onToggleStar:r,isStarPending:o,accountId:i,showRaw:m,onToggleRaw:()=>g(v=>!v),mobile:l,onReply:u,onReplyAll:d,onForward:f}):s.jsx(Eg,{threadMessage:e,isFocused:n,onToggle:a,onToggleStar:r,isStarPending:o})},Mg=()=>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 Or({authenticity:e,onOpenIntelligence:t}){return e.dkimMismatch?s.jsxs("div",{className:"flex items-start gap-2 rounded-none border-b border-danger/20 bg-danger-soft px-5 py-2.5 text-sm",children:[s.jsx(Ss,{className:"mt-0.5 size-4 shrink-0 text-danger"}),s.jsxs("p",{className:"flex-1 leading-snug text-fg",children:["This message claims to be from"," ",s.jsx("span",{className:"font-semibold",children:e.fromDomain})," but was sent",e.dkimDomain?` via ${e.dkimDomain}`:" from a different domain","."]}),t&&s.jsx("button",{type:"button",onClick:t,className:"shrink-0 text-2xs font-medium text-danger hover:underline",children:"Why?"})]}):null}const Zt=({threadId:e,mailboxId:t,subject:n,selectedMessageId:a,authenticity:r,onOpenIntelligence:o,onBack:i,composeRequest:l,onComposeClose:u,onSwipeNext:d,onSwipePrevious:f,mobileIntelligenceOpen:m})=>{const g=kt(),{handlers:x}=xh({onSwipeLeft:d,onSwipeRight:f}),{accountId:b}=pi(t),{data:p,isLoading:y,isError:h,error:v,refetch:j}=re({...kc({path:{threadId:e},query:{order:"desc",mailboxId:t}})}),w=c.useMemo(()=>p?.items??[],[p?.items]),N=c.useRef(new Map),[I,S]=c.useState(new Set),[k,C]=c.useState(null),[E,R]=c.useState(0);c.useEffect(()=>{if(w.length>0&&e!==k){C(e);const Q=new Set([w[0].threadMessageId]);if(a){const ee=w.find(ne=>ne.messageId===a);ee&&Q.add(ee.threadMessageId)}S(Q),R(0)}},[e,w,k,a]);const M=c.useCallback(Q=>{S(ee=>{const ne=new Set(ee);return ne.has(Q)?ne.delete(Q):ne.add(Q),ne})},[]),T=c.useCallback(Q=>{const ee=w[Q];if(!ee)return;N.current.get(ee.threadMessageId)?.scrollIntoView({behavior:"smooth",block:"nearest"})},[w]),P=c.useCallback(()=>{if(w.length===0)return;const Q=Math.min(E+1,w.length-1);R(Q),T(Q)},[w.length,E,T]),Y=c.useCallback(()=>{if(w.length===0)return;const Q=Math.max(E-1,0);R(Q),T(Q)},[w.length,E,T]),K=c.useCallback(()=>{const Q=w[E];Q&&M(Q.threadMessageId)},[w,E,M]),{data:B}=re({...Ze(),staleTime:1/0}),_=B?.accounts?.[0],F=!!_?.smtpHost;mh({messages:w,expandedIds:I,threadId:e,mailboxId:t,accountId:_?.accountId});const{toggleStar:q,isPending:te,pendingMessageId:U}=Bn({threadId:e,mailboxId:t}),[O,D]=c.useState(null);c.useEffect(()=>{l&&l!=="new"&&(D(l),u?.())},[l,u]);const V=w[0],{data:le}=re({...Zn({path:{messageId:V?.messageId??""}}),enabled:!!V&&O!==null}),ve=c.useCallback(()=>{D("reply")},[]),ce=c.useCallback(()=>{D("reply_all")},[]),ye=c.useCallback(()=>{D("forward")},[]),Se=c.useCallback(()=>{D(null),u?.()},[u]);if(ps({enabled:!y&&w.length>0&&O===null,bindings:[{key:"j",handler:P,preventDefault:!0},{key:"ArrowDown",handler:P,preventDefault:!0},{key:"k",handler:Y,preventDefault:!0},{key:"ArrowUp",handler:Y,preventDefault:!0},{key:"Enter",handler:K,preventDefault:!0},{key:"o",handler:K,preventDefault:!0},...F?[{key:"r",handler:ve,preventDefault:!0},{key:"R",handler:ce,noModifiers:!1,preventDefault:!0},{key:"f",handler:ye,preventDefault:!0}]:[]]}),y)return s.jsx(Mg,{});if(h)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsx(ft,{title:"Couldn't load this conversation",error:v,onRetry:()=>j()})});if(w.length===0)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsx(gi,{message:"No messages in this thread"})});const G=n||w[0]?.subject||"(No subject)",ge=w.length,Ie=Q=>s.jsx("div",{children:w.map((ee,ne)=>s.jsx("div",{ref:Ue=>{Ue&&N.current.set(ee.threadMessageId,Ue)},children:s.jsx(Rg,{threadMessage:ee,isExpanded:I.has(ee.threadMessageId),isFocused:ne===E,onToggle:()=>M(ee.threadMessageId),onToggleStar:()=>q(ee.messageId,ee.hasStars),isStarPending:te&&U===ee.messageId,accountId:b,mobile:Q,onReply:Q&&F?ve:void 0,onReplyAll:Q&&F?ce:void 0,onForward:Q&&F?ye:void 0})},ee.threadMessageId))}),H=s.jsxs("header",{className:"border-b border-line px-5 pt-5 pb-3",children:[s.jsx("h1",{className:"max-w-2xl text-lg font-semibold leading-snug text-fg",children:G}),s.jsxs("p",{className:"mt-1 text-2xs text-fg-subtle",children:[ge," ",ge===1?"message":"messages"]})]});return g?s.jsxs("article",{className:"h-full flex flex-col",children:[H,r?.dkimMismatch&&s.jsx(Or,{authenticity:r,onOpenIntelligence:o}),s.jsx("div",{className:"flex-1 overflow-auto",children:Ie(!1)}),O!==null&&s.jsx(jr,{mode:O,account:_,sourceMessage:le,onClose:Se})]}):s.jsxs(sd,{thread:{subject:G,messages:[]},onBack:i??(()=>{}),intelligenceOpen:m,onToggleIntelligence:o,touchHandlers:x,children:[r?.dkimMismatch&&s.jsx(Or,{authenticity:r,onOpenIntelligence:o}),Ie(!0),O!==null&&s.jsx(jr,{mode:O,account:_,sourceMessage:le,onClose:Se})]})},Gi=e=>e.trim().toLocaleLowerCase(),Tg=/^\d{4}-\d{2}-\d{2}$/;function Pr(e,t,n){if(!Tg.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 Dg(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 Pr("before",e,e.slice(7));if(n.startsWith("after:")&&e.length>6)return Pr("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 Cs(e,t={}){const n=e.split(/\s+/).filter(o=>o.length>0),a=[],r=[];for(const o of n){const i=Dg(o,t);i?a.push(i):r.push(o)}return{freeText:r.join(" "),tokens:a}}function Ag(e,t){return e.split(/\s+/).filter(n=>n.length>0&&n!==t.raw).join(" ")}function Og(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 Pg=20,Lg=new Set(Object.values(Ge)),zg=e=>e!==void 0&&Lg.has(e)?e:void 0;function Xi({mailboxId:e,filterCategory:t}={}){const{searchQuery:n,mailboxNameIndex:a,accountNameIndex:r}=Ee(),o=Gi(n),{freeText:i,tokens:l}=Cs(o,{mailboxesByName:a,accountsByName:r}),u=o.length>0,d=zg(t),f=l.some(v=>v.type==="hasAttachment")?!0:void 0,m=l.some(v=>v.type==="isUnread")?!1:void 0,g=l.find(v=>v.type==="after"),x=l.find(v=>v.type==="before"),p=l.find(v=>v.type==="in")?.mailboxId??e,{data:y,isLoading:h}=re({...mo({query:{query:i,mailboxId:p,limit:Pg,...d!==void 0?{category:d}:{},...f!==void 0?{hasAttachment:f}:{},...m!==void 0?{isRead:m}:{},...g?{sentDateFrom:g.epochSeconds}:{},...x?{sentDateTo:x.epochSeconds}:{}}}),enabled:u,staleTime:6e4});return{hits:y?.items??[],isLoading:u&&h}}const _g=(e,t)=>e.createdAt!==t.createdAt?e.createdAt-t.createdAt:e.accountId.localeCompare(t.accountId),Fg=e=>[...e].sort(_g);function Ji(e){const t=e.authenticity?.dkimMismatch===!0;return{id:e.messageId,accountId:e.accountId??e.accountConfigId,mailboxId:e.mailboxId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:mt(e.sentDate),sentDate:e.sentDate,isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.star!=null&&e.star!=="none"&&e.hasStars===!0,trust:e.senderTrust,category:cn(e.category),suspicious:t}}const Lr=[{id:"personal",label:"Personal",category:Ge.personal},{id:"transactional",label:"Transactional",category:Ge.transactional},{id:"newsletter",label:"Newsletter",category:Ge.newsletter},{id:"marketing",label:"Marketing",category:Ge.marketing},{id:"social",label:"Social",category:Ge.social},{id:"automated",label:"Automated",category:Ge.automated}];function Bg(e){const t=new Map(Lr.map(a=>[a.category,[]]));for(const a of e){const r=a.category??Ge.personal;(t.get(r)??t.get(Ge.personal))?.push(a)}const n=[];for(const a of Lr){const r=t.get(a.category);r&&r.length>0&&n.push({id:a.id,label:a.label,threads:r})}return n}function Zi(e,t){return e.fromName.toLowerCase().includes(t)||e.fromEmail.toLowerCase().includes(t)||e.subject.toLowerCase().includes(t)||e.snippet.toLowerCase().includes(t)}function el(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 $g={sender:"sender",recipient:"recipient",subject:"subject",attachment:"attachment",body:"body",entities:"entities"};function Kg(e){return $g[e]??e}function qg(e){return{id:e.messageId,sender:e.fromName??e.fromEmail??"Unknown",subject:e.subject??"(No subject)",snippet:e.snippet??"",date:mt(e.sentDate),unread:!e.isRead,flagged:e.hasStars===!0,threadId:e.threadId,mailboxId:e.mailboxId}}function tl(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 Ug(e){return{id:e.messageId,sender:e.fromName??"Unknown",subject:e.subject??"(No subject)",snippet:"",date:e.sentDate!=null?mt(e.sentDate*1e3):"",threadId:e.threadId,matchedChunkLabel:Kg(e.matchedChunkType),score:e.score,...e.mailboxIds[0]!=null?{mailboxId:e.mailboxIds[0]}:{}}}function sl(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(Ug(r)));return a}const Hg=768,Qg=1024,Wg=e=>e!=="desktop",Es=()=>{const e=Fn(`(min-width: ${Hg}px)`);return Fn(`(min-width: ${Qg}px)`)?"desktop":e?"tablet":"phone"},nl="remit.recentSearches",Vg=5;function Un(){try{const e=localStorage.getItem(nl);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(n=>typeof n=="string"):[]}catch{return[]}}function zr(e){const t=e.trim();if(!t)return Un();const n=[t,...Un().filter(a=>a!==t)].slice(0,Vg);try{localStorage.setItem(nl,JSON.stringify(n))}catch{return n}return n}function al({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:g,mailboxNameIndex:x,accountNameIndex:b}=Ee(),p=ea(),y=Es(),[h,v]=c.useState(!1),[j,w]=c.useState(Un),N=f.trim().length>0,I=Cs(f,{mailboxesByName:x,accountsByName:b}).tokens.map(K=>({label:Og(K),onRemove:()=>m(Ag(f,K))})),S=o??[],k=l??[],C=N?[{id:"top",label:"Top matches",results:S},{id:"related",label:"Related",results:k}]:[],R=!(S.length+k.length>0)&&(i===!0||u===!0);if(y==="phone"&&h){const K=B=>{w(zr(f)),v(!1),d?.(B)};return s.jsx(Td,{value:f,onChange:m,onClear:g,onCancel:()=>{v(!1),g()},filter:r,recentSearches:j,onPickRecent:m,sections:C,loading:R,onSelectResult:K,tokens:I})}const M=y!=="phone"&&N,T=K=>{w(zr(f)),d?.(K)},P=s.jsx(Qo,{value:f,sections:C,loading:R,onSelectResult:T,tokens:I}),Y=M?r?s.jsx(Wn,{...r,children:P}):s.jsx("div",{className:"h-full overflow-y-auto",children:P}):n;return s.jsxs("section",{className:"flex h-full w-full flex-col bg-surface",children:[s.jsx(Nd,{title:e,unreadCount:t,isDesktop:!1,onMenuClick:()=>p?.openNav(),searchValue:f,onSearchChange:m,onSearchClear:g,searchOpen:h,onSearchOpenChange:v}),s.jsx("div",{className:"min-h-0 flex-1",children:Y}),a]})}const Yg={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))}),Gg=({accountEmail:e})=>{const t=Ce();return s.jsxs("div",{className:"flex items-center gap-2 px-row-inset py-2 border-b border-line bg-danger-soft/40 text-xs text-danger",children:[s.jsx(yt,{className:"size-3.5 shrink-0"}),s.jsxs("span",{className:"flex-1 truncate",children:[e," can't connect"]}),s.jsx("button",{type:"button",onClick:()=>t({to:"/settings/accounts"}),className:"shrink-0 underline text-danger hover:opacity-80",children:"Reconnect"})]})},Xg=({thread:e,active:t,onClick:n})=>{const a=!e.isRead;return s.jsxs("button",{type:"button",onClick:n,className:$("group w-full",Yt({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(st,{name:e.fromName,email:e.fromEmail,size:"sm"}),s.jsx(Gt,{thread:e})]})};function rl({accounts:e,selectedMessageId:t,onSelectMessage:n,onSelectSearchResult:a}){const{searchQuery:r,mailboxNameIndex:o,accountNameIndex:i}=Ee(),l=kt(),u=c.useMemo(()=>Fg(e.filter(O=>!O.muted?.value)),[e]),[d,f]=c.useState("all"),[m,g]=c.useState("all"),[x,b]=c.useState(new Set),[p,y]=c.useState(!1),h=c.useCallback(O=>{b(D=>{const V=new Set(D);return V.has(O)?V.delete(O):V.add(O),V})},[]),{data:v,isLoading:j,isError:w,refetch:N}=re({...sn(),staleTime:6e4}),I=Jt({queries:u.map(O=>({...et({path:{accountId:O.accountId}}),staleTime:1/0,meta:{softError:!0}}))}),S=c.useMemo(()=>{const O=new Map;for(let D=0;D<u.length;D++){const V=u[D].accountId,ve=(I[D]?.data?.items??[]).reduce((ce,ye)=>ce+(ye.unseenCount??0),0);O.set(V,ve)}return O},[u,I]),k=c.useMemo(()=>u.filter((O,D)=>{const V=I[D];return V?.isError?!Dn(V.error):!1}),[u,I]),{freeText:C,tokens:E}=Cs(r.trim().toLowerCase(),{mailboxesByName:o,accountsByName:i}),R=c.useMemo(()=>(v?.items??[]).filter(D=>d==="all"||(D.accountId??D.accountConfigId)===d).map(Ji).filter(D=>(!C||Zi(D,C))&&el(D,E)),[v,d,C,E]),M=c.useMemo(()=>Bg(R),[R]),T=c.useMemo(()=>u.length<=1?[]:[{id:"all",label:"All",active:d==="all"},...u.map(O=>({id:O.accountId,label:O.email.split("@")[0]??O.email,count:S.get(O.accountId),active:d===O.accountId}))],[u,S,d]),P=c.useMemo(()=>e.filter(O=>O.muted?.value).length,[e]),Y=c.useMemo(()=>Array.from(S.values()).reduce((O,D)=>O+D,0),[S]),K=c.useMemo(()=>{const O=Array.from(x).map(D=>Yg[D]).filter(D=>D!=null);return R.filter(D=>(m==="all"||D.category===m)&&O.every(V=>V(D))).map(tl)},[R,m,x]),{hits:B,isLoading:_}=Xi(),F=c.useMemo(()=>{const O=new Map;for(const V of v?.items??[])O.set(V.messageId,V.threadId);const D=K.map(V=>O.get(V.id)).filter(V=>V!=null);return sl(B,D)},[B,K,v]),q=c.useMemo(()=>{const O=Jd(T.map(D=>({id:D.id,label:D.label,count:D.count,active:D.active})));return{categories:O.categories,filters:O.filters,sources:O.sources,sourcesNote:P>0?`+${P} muted`:void 0,selectedCategory:m,activeFilters:x,expanded:p,onExpandedChange:y,onSelectCategory:D=>g(D),onSelectSource:f,onToggleFilter:h,onClear:()=>{g("all"),f("all"),b(new Set)}}},[T,P,m,x,p,h]),te=M.length===0&&d==="all"&&C.length===0,U=j?s.jsxs("div",{className:"h-full overflow-y-auto",children:[s.jsx(_r,{}),s.jsx(_r,{})]}):w?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 py-12 text-sm text-fg-muted",children:[s.jsx(yt,{className:"size-8 text-danger"}),s.jsx("p",{children:"Couldn't load your messages"}),s.jsxs("button",{type:"button",onClick:()=>N(),className:"flex items-center gap-1 text-accent underline text-xs",children:[s.jsx(Ro,{className:"size-3.5"}),"Try again"]})]}):te?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 py-12 text-center px-4",children:[s.jsx(Ke,{className:"size-8 text-fg-subtle"}),s.jsx("p",{className:"text-sm font-medium text-fg",children:"You're caught up"}),s.jsx("p",{className:"text-xs text-fg-subtle",children:"Nothing needs attention."})]}):s.jsx(Xr,{sections:M,Row:Xg,briefCategory:m,onSelectBriefCategory:g,sources:T,sourcesNote:P>0?`+${P} muted`:void 0,onSelectSource:f,selectedThreadId:t,onSelectThread:n});return s.jsx(al,{title:"Daily brief",unreadCount:Y,footer:l?s.jsx(Oo,{}):void 0,searchFilter:q,searchResults:K,searchLoading:j,relatedResults:F,relatedLoading:_,onSelectSearchResult:a,children:s.jsxs("div",{className:"flex h-full flex-col",children:[k.map(O=>s.jsx(Gg,{accountEmail:O.email,accountId:O.accountId},O.accountId)),s.jsx("div",{className:"min-h-0 flex-1",children:U})]})})}const ol=({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};function Jg(e){const t=new Date(e),n=new Date;return t.toDateString()===n.toDateString()?"today":Ws(t,{month:"short",year:"numeric"})}function il(e){if(!e)return!0;const[,t]=e.split("@");return t?!t.includes("."):!0}const Zg="We can't verify the sender of this email, which could mean it's from an insecure source.",ep="We couldn't read this sender's address, so we can't confirm who really sent this message.";function tp(e,t){return{name:e.fromName??e.fromEmail??"Unknown",email:e.fromEmail??"",trust:e.senderTrust,firstSeenLabel:t?Jg(t.createdAt):"unknown",inboundCount:t?.inboundCount,replyCount:t?.replyCount,addressUnverified:il(e.fromEmail)}}function sp(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 np(e,t){const n=t>0?t:void 0;if(il(e.fromEmail))return{verdict:"mismatch",fromDomain:"",addressUnreadable:!0,summary:ep,similarCount:n};const a=e.authenticity;if(!a)return{verdict:"caution",fromDomain:e.fromEmail?.split("@")[1]??"",summary:Zg};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 ll(e,t){const n=e?.fromEmail??null,a=e?.subject??"",{data:r,error:o}=re({...co({query:{q:n??"",limit:1}}),enabled:!!n,staleTime:3e4}),i=r?.items?.[0],l=[a,n].filter(Boolean).join(" "),{data:u,isLoading:d,error:f}=re({...mo({query:{query:l,limit:5}}),enabled:!!(e&&l.length>3),staleTime:6e4,retry:1});return{data:c.useMemo(()=>{if(!e)return null;const g=(u?.items??[]).filter(h=>h.messageId!==e.messageId).map(h=>({id:h.messageId,mailboxId:t!=null&&h.mailboxIds.includes(t)?t:h.mailboxIds[0]??"",fromName:h.fromName??"",subject:h.subject??"(No subject)",timeLabel:h.sentDate!=null?mt(h.sentDate*1e3):"",matched:h.matchedChunkType})),x=tp(e,i),b=np(e,g.length),p={value:e.category??"personal",overridden:i?.flags?.category?.value!=null&&i.flags.category.value!==e.category},y=sp(i);return{sender:x,authenticity:b,category:p,flags:y,similar:g}},[e,i,u,t]),isSimilarLoading:d,similarError:f,similarErrorIsFatal:Dn(f),addressErrorIsFatal:Dn(o),addressId:i?.addressId,address:i}}function ap(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 cl({addressId:e,senderEmail:t}){const n=je(),{pushError:a}=ze(),r=Cc({query:{q:t??"",limit:1}}),{mutate:o,isPending:i}=xe({...fo(),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(g=>g.addressId===u.path.addressId?{...g,flags:ap(g.flags,d)}:g)}),{previous:f}},onError:(u,d,f)=>{f?.previous!==void 0&&n.setQueryData(r,f.previous),a({title:"Couldn't update sender preference",detail:$e(u)})},onSettled:()=>{n.invalidateQueries({queryKey:r})}});return{updateFlags:c.useCallback(u=>{if(!e){ho(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 rp=e=>e==="vip"?"A sender you know":e==="wellknown"?"You've emailed them before":"Passed authentication",ul=e=>e.senderTrust!=="vip"&&e.senderTrust!=="wellknown"?!1:e.authenticity?.dkimMismatch!==!0;function op(e,t){e.recordEvent("rescue.candidates_surfaced",{count:String(t)})}function ip(e,t){e.recordEvent("rescue.flow_opened",{count:String(t)})}function lp(e,t){e.recordEvent("rescue.committed",{selected:String(t.selected),total:String(t.total),destination:t.toInbox?"inbox":"other"})}function dl(e,t){e.recordEvent("rescue.sent_to_junk",{count:String(t.count),senderTrust:t.senderTrust,wasRescuable:String(t.wasRescuable)})}const cp=["personal","newsletter","marketing","automated","transactional","social"],up=e=>{const{mailboxId:t,junkMailboxId:n,inboxMailboxId:a}=e;return t?n&&t===n?a?"notSpam":null:n?"markSpam":null:null},dp=e=>{const{similarError:t,similarErrorIsFatal:n,isSimilarLoading:a}=e;return t&&!n?"error":a?"loading":"ready"};function fp(){return s.jsxs("aside",{className:"flex h-full w-full flex-col bg-surface-sunken",children:[s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-1.5 border-b border-line px-row-inset",children:[s.jsx(Ke,{className:"size-3.5 text-fg-subtle"}),s.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"})]}),s.jsxs("div",{className:"flex-1 animate-pulse space-y-4 p-4",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"h-2.5 rounded bg-surface w-1/4"}),s.jsxs("div",{className:"flex gap-3",children:[s.jsx("div",{className:"size-10 rounded-full bg-surface shrink-0"}),s.jsxs("div",{className:"flex-1 space-y-1.5",children:[s.jsx("div",{className:"h-3 rounded bg-surface w-3/4"}),s.jsx("div",{className:"h-2.5 rounded bg-surface w-1/2"})]})]})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"h-2.5 rounded bg-surface w-1/4"}),s.jsx("div",{className:"h-8 rounded bg-surface"})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"h-2.5 rounded bg-surface w-1/4"}),s.jsx("div",{className:"flex gap-1.5 flex-wrap",children:Array.from({length:5}).map((e,t)=>s.jsx("div",{className:"h-6 w-16 rounded bg-surface"},t))})]})]})]})}function mp({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:cp.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 hp({thread:e,onClose:t,mailboxId:n,accountId:a,hideCloseButton:r}){const{data:o,addressId:i,isSimilarLoading:l,similarError:u,similarErrorIsFatal:d}=ll(e,n),[f,m]=c.useState(!1),[g,x]=c.useState(!1),b=e.fromEmail??void 0,{updateFlags:p,isPending:y}=cl({addressId:i,senderEmail:b}),{junkMailboxId:h}=xa(a),{inboxMailboxId:v}=pa(a),{moveMessages:j}=ct({mailboxId:n??"",threadId:e.threadId,accountId:a}),w=xs(),N=up({mailboxId:n,junkMailboxId:h,inboxMailboxId:v}),I=c.useCallback(()=>{v&&j([e.messageId],v)},[v,j,e.messageId]),S=c.useCallback(()=>{h&&(dl(w,{count:1,senderTrust:e.senderTrust,wasRescuable:ul(e)}),j([e.messageId],h))},[h,j,e,w]),k=c.useCallback(()=>{},[]),C=c.useCallback(()=>{const _=o?.flags?.vip!==!0;p({vip:{value:_}})},[o?.flags?.vip,p]),E=c.useCallback(()=>{const _=o?.flags?.muted!==!0;p({muted:{value:_}})},[o?.flags?.muted,p]),R=c.useCallback(()=>{o?.flags?.blocked===!0?p({blocked:{value:!1}}):m(!0)},[o?.flags?.blocked,p]),M=c.useCallback(()=>{m(!1),p({blocked:{value:!0}})},[p]),T=c.useCallback(()=>{const _=o?.flags?.unsubscribed!==!0;p({unsubscribed:{value:_}})},[o?.flags?.unsubscribed,p]),P=c.useCallback(_=>{x(!1),p({category:{value:_}})},[p]),Y={onToggleVip:C,onToggleMute:E,onToggleBlock:R,onToggleUnsubscribe:T,onReclassify:()=>x(!0),onNotSpam:N==="notSpam"?I:void 0,onMarkSpam:N==="markSpam"?S:void 0},K=({mailboxId:_,messageId:F,className:q,ariaLabel:te,children:U})=>s.jsx(Xe,{to:"/mail/$mailboxId",params:{mailboxId:_},search:O=>({...O,selectedMessageId:F}),className:q,"aria-label":te,children:U});if(!o)return s.jsx(fp,{});const B=dp({similarError:u,similarErrorIsFatal:d,isSimilarLoading:l});return s.jsxs(s.Fragment,{children:[s.jsx(Ao,{data:o,onClose:t,hideCloseButton:r,onShowSimilar:k,actions:Y,similarState:B,similarLinkComponent:K,className:"border-l-0 h-full w-full"}),s.jsx(ol,{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:M,onCancel:()=>m(!1)}),s.jsx(mp,{isOpen:g,current:o.category.value,onSelect:P,onCancel:()=>x(!1)})]})}const fn=({onClose:e,thread:t,mailboxId:n,accountId:a,hideCloseButton:r})=>t?s.jsx(hp,{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(Ke,{className:"size-3.5 text-fg-subtle"}),s.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"})]}),s.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center px-row-inset text-center",children:[s.jsx(Ke,{className:"size-8 text-fg-subtle"}),s.jsx("p",{className:"mt-3 text-sm text-fg-muted",children:"Intelligence"}),s.jsx("p",{className:"mt-1 text-2xs text-fg-subtle",children:"Sender trust, authenticity and similar messages will appear here."})]})]}),fl=({children:e})=>{const{Account:t}=Jn();return s.jsx(t,{children:e})},gp=({email:e,onSignOut:t})=>{const n=Ce(),a=e??"Account";return s.jsxs(yi,{trigger:s.jsx(st,{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($t,{onClick:()=>n({to:"/settings/accounts"}),children:[s.jsx(Do,{className:"size-4"}),"Settings"]}),s.jsx($n,{}),s.jsxs($t,{onClick:t,children:[s.jsx(Io,{className:"size-4"}),"Sign out"]})]})},pp=()=>s.jsx(fl,{children:({email:e,signOut:t})=>s.jsx(gp,{email:e,onSignOut:t})}),Fr=()=>{const e=ta(),t=sa(e);window.open(t,"_blank","noopener,noreferrer")};function ml({variant:e="icon"}){return e==="drawer"?s.jsxs("button",{type:"button",onClick:Fr,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(za,{className:"size-4 shrink-0"}),s.jsx("span",{className:"flex-1 truncate text-left",children:"Report a bug"})]}):s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(za,{className:"size-4"}),title:"Report a bug","aria-label":"Report a bug",onClick:Fr})}const hl=[{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:"Flagged"},{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 xp(e){for(const t of hl){const n=t.hints.find(a=>a.action===e);if(n)return n.keys}}function Ft(e){const t=xp(e);return!t||t.length===0?"":t.length===1?`(${t[0]})`:t[0]==="g"?`(${t.join(" then ")})`:`(${t.join("")})`}const In="Open a message first",Sa=({hasThread:e,onCompose:t,intelligenceOpen:n,showIntelligenceToggle:a,onToggleIntelligence:r,searchValue:o,onSearchChange:i,onSearchClear:l,onSearchClearQuery:u,onReply:d,onReplyAll:f,onForward:m,onDelete:g,canDelete:x,onToggleStar:b,isStarred:p,moveContext:y})=>{const[h,v]=c.useState(null),j=x??e,w=N=>()=>v(N);return s.jsxs(Mu,{hasThread:e,isStarred:p,onUnavailable:N=>v(In),unavailableHint:h,replyTitle:`Reply ${Ft("reply")}`,replyAllTitle:`Reply all ${Ft("replyAll")}`,forwardTitle:`Forward ${Ft("forward")}`,deleteTitle:`Move to Trash ${Ft("delete")}`,flagTitle:`Flag ${Ft("toggleStar")}`,onReply:d,onReplyAll:f,onForward:m,onDelete:j?g:w(In),onToggleStar:b,onMove:w(In),moveSlot:y?s.jsx(ks,{accountId:y.accountId,currentMailboxId:y.currentMailboxId,onMove:y.onMove,label:"Move to mailbox"}):void 0,children:[s.jsx("div",{className:"w-64 min-w-40 shrink",children:s.jsx(la,{value:o,onChange:i,onClear:l,onClearQuery:u,placeholder:"Search mail"})}),s.jsx("span",{className:"mx-1 h-4 w-px bg-line","aria-hidden":!0}),s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(fu,{className:"size-4"}),title:`Compose ${Ft("compose")}`,"aria-label":"Compose",onClick:t}),a&&s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(Zr,{className:"size-4"}),title:"Intelligence","aria-label":n?"Hide intelligence sidebar":"Show intelligence sidebar","aria-pressed":n,onClick:r,className:n?"bg-accent-2-soft text-accent-2":void 0}),s.jsx(ml,{}),s.jsx(pp,{})]})};function bp(e){return{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,messageId:e.messageId,authenticity:e.authenticity}}function gl(e,t){if(e)return bp(e);if(t.messageId&&t.threadId&&t.mailboxId)return{threadId:t.threadId,mailboxId:t.mailboxId,messageId:t.messageId}}const pl=c.createContext(null);function Na(){const e=c.useContext(pl);if(!e)throw new Error("BriefPane.* must be used inside <BriefPane>");return e}function vp({selectedMessageId:e,children:t}){const n=Ce(),{searchInput:a}=Ee(),{selectedThreadId:r,selectedMailboxId:o}=Ut({strict:!1}),{data:i}=re({...sn(),staleTime:6e4}),l=c.useMemo(()=>{if(e)return i?.items.find(x=>x.messageId===e)},[i,e]),u=c.useMemo(()=>gl(l,{messageId:e,threadId:r,mailboxId:o}),[l,e,r,o]),d=c.useCallback(x=>{n({to:"/mail",search:b=>({...b,selectedMessageId:x,selectedThreadId:void 0,selectedMailboxId:void 0})})},[n]),f=c.useCallback(x=>{n({to:"/mail",search:b=>({...b,q:a||void 0,selectedMessageId:x.id,selectedThreadId:x.threadId,selectedMailboxId:x.mailboxId})})},[n,a]),m=c.useCallback(()=>{n({to:"/mail",search:x=>({...x,selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0})})},[n]),g={selectedMessageId:e,selectedThread:l,conversation:u,onSelectMessage:d,onSelectSearchResult:f,onCloseThread:m};return s.jsx(pl.Provider,{value:g,children:t})}function yp(){const{selectedMessageId:e,onSelectMessage:t,onSelectSearchResult:n}=Na(),{accounts:a}=Ee();return s.jsx(rl,{accounts:a,selectedMessageId:e,onSelectMessage:t,onSelectSearchResult:n})}function wp(){const{conversation:e}=Na(),{onToggleIntelligence:t,searchInput:n,onSearchChange:a,onSearchClear:r,onSearchClearQuery:o}=Ee();return s.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[s.jsx(Sa,{hasThread:!!e,onCompose:()=>{},intelligenceOpen:!1,showIntelligenceToggle:!1,onToggleIntelligence:t,searchValue:n,onSearchChange:a,onSearchClear:r,onSearchClearQuery:o}),s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?s.jsx(Zt,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,selectedMessageId:e.messageId,authenticity:e.authenticity}):s.jsx(Xt,{})})]})}function jp(){const{selectedThread:e,conversation:t,selectedMessageId:n,onSelectMessage:a,onSelectSearchResult:r,onCloseThread:o}=Na(),{accounts:i,intelligenceOpen:l,onToggleIntelligence:u}=Ee();return t?s.jsxs(s.Fragment,{children:[s.jsx(Zt,{threadId:t.threadId,mailboxId:t.mailboxId,subject:t.subject,selectedMessageId:t.messageId,authenticity:t.authenticity,onBack:o,onOpenIntelligence:u}),s.jsx(ha,{isOpen:l,onClose:u,ariaLabel:"Message details",side:"right",children:s.jsx(fn,{onClose:u,thread:e,hideCloseButton:!0})})]}):s.jsx("div",{className:"h-full",children:s.jsx(rl,{accounts:i,selectedMessageId:n,onSelectMessage:a,onSelectSearchResult:r})})}const Fs=Object.assign(vp,{List:yp,Reading:wp,Phone:jp});function xl({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:g,relatedResults:x,relatedLoading:b,onSelectSearchResult:p}){const[y,h]=c.useState(!1),v={categories:n.categories,filters:n.filters,sources:n.sources,selectedCategory:a,activeFilters:r,expanded:y,onExpandedChange:h,onSelectCategory:o,onSelectSource:l,onToggleFilter:i,onClear:u};return s.jsx(al,{title:e,unreadCount:t,footer:f,searchFilter:v,searchResults:m,searchLoading:g,relatedResults:x,relatedLoading:b,onSelectSearchResult:p,children:s.jsx(Wn,{...v,children:d})})}const Sp={unread:e=>!e.isRead,attachment:e=>e.hasAttachment===!0};function Np({selectedMessageId:e,onSelectMessage:t}){const{searchQuery:n,mailboxNameIndex:a,accountNameIndex:r}=Ee(),o=kt(),[i,l]=c.useState("all"),[u,d]=c.useState(new Set),f=c.useCallback(E=>{d(R=>{const M=new Set(R);return M.has(E)?M.delete(E):M.add(E),M})},[]),m=c.useCallback(()=>{l("all"),d(new Set)},[]),{data:g,isLoading:x,isError:b,error:p,refetch:y}=re({...sn(),staleTime:6e4}),{freeText:h,tokens:v}=Cs(n.trim().toLowerCase(),{mailboxesByName:a,accountsByName:r}),j=c.useMemo(()=>{const E=Array.from(u).map(R=>Sp[R]).filter(R=>R!=null);return(g?.items??[]).map(Ji).filter(R=>R.starred===!0).filter(R=>(i==="all"||R.category===i)&&E.every(M=>M(R))&&(!h||Zi(R,h))&&el(R,v))},[g,i,u,h,v]),w=c.useMemo(()=>ef(),[]),N=c.useMemo(()=>j.map(tl),[j]),I=c.useMemo(()=>j.filter(E=>!E.isRead).length,[j]),S=x?"loading":b?"error":j.length===0?"empty":"ready",k=c.useCallback(()=>{const E=sa(ta());window.open(E,"_blank","noopener,noreferrer")},[]),C=s.jsx("div",{className:"flex-1 overflow-y-auto",children:s.jsx("div",{className:"divide-y divide-line",children:j.map(E=>s.jsx(_o,{thread:E,active:E.id===e,onClick:()=>t?.(E.id)},E.id))})});return s.jsx(xl,{title:"Flagged",unreadCount:I,preset:w,selectedCategory:i,activeFilters:u,onSelectCategory:l,onToggleFilter:f,onClearFilters:m,searchResults:N,searchLoading:x,onSelectSearchResult:E=>t?.(E.id),children:s.jsx($o,{listTitle:"Flagged",sections:[{id:"flagged",threads:j}],flatList:!0,hideHeader:!0,listState:S,searchQuery:h?n:void 0,errorMessage:b?bo(p):void 0,onRetry:()=>y(),onReportError:k,selectedThreadId:e,onSelectThread:t,onSelectBriefCategory:()=>{},isDesktop:o,listBody:S==="ready"?C:void 0})})}const bl=c.createContext(null);function ka(){const e=c.useContext(bl);if(!e)throw new Error("FlaggedPane.* must be used inside <FlaggedPane>");return e}function kp({selectedMessageId:e,children:t}){const n=Ce(),{data:a}=re({...sn(),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(bl.Provider,{value:l,children:t})}function vl(){const{selectedMessageId:e,onSelectMessage:t}=ka();return s.jsx(Np,{selectedMessageId:e,onSelectMessage:t})}function Cp(){const{selectedThread:e}=ka(),{onToggleIntelligence:t,searchInput:n,onSearchChange:a,onSearchClear:r,onSearchClearQuery:o}=Ee();return s.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[s.jsx(Sa,{hasThread:!!e,onCompose:()=>{},intelligenceOpen:!1,showIntelligenceToggle:!1,onToggleIntelligence:t,searchValue:n,onSearchChange:a,onSearchClear:r,onSearchClearQuery:o}),s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?s.jsx(Zt,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,authenticity:e.authenticity}):s.jsx(Xt,{})})]})}function Ep(){const{selectedThread:e,onCloseThread:t}=ka(),{intelligenceOpen:n,onToggleIntelligence:a}=Ee();return e?s.jsxs(s.Fragment,{children:[s.jsx(Zt,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,authenticity:e.authenticity,onBack:t,onOpenIntelligence:a}),s.jsx(ha,{isOpen:n,onClose:a,ariaLabel:"Message details",side:"right",children:s.jsx(fn,{onClose:a,thread:e,hideCloseButton:!0})})]}):s.jsx("div",{className:"h-full",children:s.jsx(vl,{})})}const Bs=Object.assign(kp,{List:vl,Reading:Cp,Phone:Ep}),Ip={reply:"Reply",reply_all:"Reply All",forward:"Forward",new:"New Message"},Rp=()=>{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},[])},Mp=()=>{const{state:e,closeCompose:t}=wt(),n=Rp(),[a,r]=c.useState(!1),{isError:o,error:i,refetch:l}=re({...Ze(),staleTime:1/0}),u=c.useCallback(g=>{g||(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=Ip[e.mode]??"New Message";return s.jsxs(Pe.Root,{open:e.isOpen,onOpenChange:u,children:[s.jsxs(Pe.Portal,{children:[s.jsx(Pe.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),s.jsxs(Pe.Content,{className:"fixed inset-x-0 bottom-0 z-50 flex flex-col bg-canvas rounded-t-lg",style:{height:"95dvh"},children:[s.jsx(Pe.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-muted/30"}),s.jsx(Pe.Title,{className:"px-4 py-2 text-base font-semibold border-b border-line",children:m}),o?s.jsx("div",{className:"flex-1 flex items-center justify-center p-4",children:s.jsx(ft,{title:"Couldn't load compose",error:i,onRetry:()=>{l()}})}):s.jsx("div",{className:"flex-1 overflow-hidden",children:s.jsx(ga,{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"})]})]})})]})},Tp={reply:"Reply",reply_all:"Reply All",forward:"Forward",new:"New Message"},yl=()=>{const{state:e,closeCompose:t}=wt(),n=kt(),{isError:a,error:r,refetch:o}=re({...Ze(),staleTime:1/0});if(!n)return s.jsx(Mp,{});if(!e.isOpen)return null;const i=Tp[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(De,{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(ft,{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(ga,{mode:e.mode,account:e.account,sourceMessage:e.sourceMessage,onClose:t},e.outboxMessageId??"new")})]})};function Dp(e){const t=e.toAddresses.join(", ");return{id:e.outboxMessageId,accountId:e.accountId,fromName:e.fromName??e.fromAddress??"Me",fromEmail:e.fromAddress??"",subject:e.subject??"(No subject)",snippet:t?`To: ${t}`:"(No recipients)",timeLabel:mt(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:mt(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.star!=null&&e.star!=="none"&&e.hasStars===!0}}function Op({outboxMessages:e,accountId:t,imapThreads:n}){const a=e.filter(i=>i.status==="draft"&&i.accountId===t).map(Dp),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 Ca(){const e=ea();return!e||e.showNavPane?null:s.jsx(X,{variant:"ghost",size:"sm",icon:s.jsx(ra,{className:"size-4"}),onClick:e.openNav,"aria-label":"Open folders",className:"-ml-1 shrink-0"})}const Pp=({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})]}),Lp=({row:e,isSelected:t,onOpen:n,onDelete:a,isDeleting:r})=>s.jsxs("button",{type:"button",onClick:()=>n(e.id),className:$("group",Yt({active:t})),children:[s.jsx(po,{className:"size-7 shrink-0 text-fg-muted mt-0.5"}),s.jsx(Gt,{thread:e}),s.jsx("div",{className:"flex items-center gap-1 shrink-0",children:s.jsx("button",{type:"button",onClick:o=>{o.stopPropagation(),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(qe,{className:"size-3.5"})})})]}),zp=({row:e,isSelected:t,onOpen:n})=>{const a=!e.isRead;return s.jsxs("button",{type:"button",onClick:()=>n(e.id),className:$("group",Yt({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(st,{name:e.fromName,email:e.fromEmail,size:"sm"}),s.jsx(Gt,{thread:e})]})};function _p({mailboxId:e,accountId:t,selectedMessageId:n,imapThreads:a,title:r,unreadCount:o}){const{openCompose:i,state:l}=wt(),u=Ce(),d=je(),{data:f}=re(Js()),m=c.useMemo(()=>Op({outboxMessages:f?.items??[],accountId:t,imapThreads:a}),[f?.items,t,a]),g=xe({...Zs(),onSuccess:()=>{d.invalidateQueries({queryKey:na()})}}),x=h=>{g.mutate({path:{outboxMessageId:h}})},b=h=>{n&&u({to:"/mail/$mailboxId",params:{mailboxId:e},search:{selectedMessageId:void 0}}),i({mode:"new",outboxMessageId:h})},p=h=>{u({to:"/mail/$mailboxId",params:{mailboxId:e},search:{selectedMessageId:h}})},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(Ca,{}),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(Qn,{className:"size-8 text-fg-subtle"}),s.jsx("p",{className:"text-sm font-medium text-fg",children:"No drafts"}),s.jsx("p",{className:"text-xs text-fg-subtle",children:"Messages you start composing will appear here."})]}):m.map(h=>s.jsxs("div",{children:[h.label&&s.jsx(Pp,{label:h.label,count:h.threads.length}),s.jsx("div",{className:"divide-y divide-line",children:h.threads.map(v=>h.id==="remit-drafts"?s.jsx(Lp,{row:v,isSelected:l.isOpen&&v.id===l.outboxMessageId,onOpen:b,onDelete:x,isDeleting:g.isPending},v.id):s.jsx(zp,{row:v,isSelected:v.id===n,onOpen:p},v.id))})]},h.id))})]})}function Fp(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 Br(e,t){if(e===void 0)throw new Error("Unexpected undefined");return e}const Bp=(e,t)=>Math.abs(e-t)<1.01,$p=(e,t,n)=>{let a;return function(...r){e.clearTimeout(a),a=e.setTimeout(()=>t.apply(this,r),n)}};let ls;const Rn=()=>{if(ls!==void 0)return ls;if(typeof navigator>"u")return ls=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return ls=!0;const e=navigator.maxTouchPoints;return ls=navigator.platform==="MacIntel"&&e!==void 0&&e>0},$r=e=>{const{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},Kp=e=>e,qp=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},Up=(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($r(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($r(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(l):l()});return o.observe(n,{box:"border-box"}),()=>{o.unobserve(n)}},Gs={passive:!0},Hp=typeof window>"u"?!0:"onscrollend"in window,Qp=(e,t,n)=>{const a=e.scrollElement;if(!a)return;const r=e.targetWindow;if(!r)return;const o=e.options.useScrollendEvent&&Hp;let i=0;const l=o?null:$p(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,Gs),o&&a.addEventListener("scrollend",f,Gs),()=>{a.removeEventListener("scroll",d),o&&a.removeEventListener("scrollend",f)}},Wp=(e,t)=>Qp(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})},Gp=Yp;class Xp{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:Kp,rangeExtractor:qp,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 g in n){const x=n[g];x!==void 0&&(o[g]=x)}const i=this.options;let l=null,u=null,d=!1;if(i!==void 0&&i.enabled&&o.enabled&&o.anchorTo==="end"&&this.scrollElement!==null){const g=i.count,x=o.count,b=this.getMeasurements(),p=g>0?((a=b[0])==null?void 0:a.key)??i.getItemKey(0):null,y=g>0?((r=b[g-1])==null?void 0:r.key)??i.getItemKey(g-1):null;if(x!==g||g>0&&x>0&&(o.getItemKey(0)!==p||o.getItemKey(x-1)!==y)){d=!0;const j=g>0?this.getVirtualItemForOffset(this.getScrollOffset())??b[0]:null;j&&(l=[j.key,this.getScrollOffset()-j.start]);const w=o.followOnAppend===!0?"auto":o.followOnAppend||null;w&&x>g&&this.isAtEnd(i.scrollEndThreshold)&&(g===0||o.getItemKey(x-1)!==y)&&(u=w)}}this.options=o,d&&(this.pendingMin=0,this.itemSizeCacheVersion++);let f=!1,m=0;if(l&&this.scrollOffset!==null){const[g,x]=l,b=this.getMeasurements(),{count:p,getItemKey:y}=this.options;let h=0;for(;h<p&&y(h)!==g;)h++;if(h<p){const v=b[h];if(v){const j=v.start+x;j!==this.scrollOffset&&(m=j-this.scrollOffset,this.scrollOffset=j,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,!(!Rn()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};o.addEventListener("touchstart",i,Gs),o.addEventListener("touchend",l,Gs),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&&(Rn()&&(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 h of this.laneAssignments.keys())h>=n&&this.laneAssignments.delete(h);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(h=>{this.itemSizeCache.set(h.key,h.size)}));const g=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===n&&(this.lanesSettling=!1),l===1){const h=n*2;let v=this._flatMeasurements;if(!v||v.length<h){const N=new Float64Array(h);v&&g>0&&N.set(v.subarray(0,g*2)),v=N,this._flatMeasurements=v}let j;if(g===0)j=a+r;else{const N=g-1;j=v[N*2]+v[N*2+1]+d}for(let N=g;N<n;N++){const I=o(N),S=m.get(I),k=typeof S=="number"?S:this.options.estimateSize(N);v[N*2]=j,v[N*2+1]=k,j+=k+d}const w=Fp(n,v,o);return this.measurementsCache=w,w}const x=this.measurementsCache.slice(0,g),b=new Array(l).fill(void 0),p=new Float64Array(l);let y=0;for(let h=0;h<g;h++){const v=x[h];v&&(b[v.lane]===void 0&&y++,b[v.lane]=h,p[v.lane]=v.end)}for(let h=g;h<n;h++){const v=o(h),j=this.laneAssignments.get(h);let w,N;const I=u==="estimate"||m.has(v);if(j!==void 0&&this.options.lanes>1){w=j;const E=b[w],R=E!==void 0?x[E]:void 0;N=R?R.end+d:a+r}else if(y===l){let E=0,R=p[0],M=b[0];for(let T=1;T<l;T++){const P=p[T];(P<R||P===R&&b[T]<M)&&(E=T,R=P,M=b[T])}w=E,N=R+d,I&&this.laneAssignments.set(h,w)}else w=h%this.options.lanes,N=a+r,I&&this.laneAssignments.set(h,w);const S=m.get(v),k=typeof S=="number"?S:this.options.estimateSize(h),C=N+k;x[h]={index:h,start:N,size:k,end:C,key:v,lane:w},b[w]===void 0&&y++,b[w]=h,p[w]=C}return this.measurementsCache=x,x},{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=Zp(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 g=this.measurementsCache[n];if(!g)return;u=g.key,l=g.start,i=g.size}const f=this.itemSizeCache.get(u)??i,m=a-f;if(m!==0){const g=this.options.anchorTo==="end"&&((r=this.scrollState)==null?void 0:r.behavior)!=="smooth"&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,x=g?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++,g?this.applyScrollAdjustment(this.getTotalSize()-x):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=wl(0,a.length-1,o?l=>r[l*2]:l=>Br(a[l]).start,n);return Br(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&&(Rn()&&(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&&Bp(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 wl=(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 Jp(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 Zp(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=Jp(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=wl(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 Mn=typeof document<"u"?c.useLayoutEffect:c.useEffect;function ex({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 h=d.options.horizontal?"width":"height";f.container.style[h]=`${m}px`}const g=!!d.options.horizontal,x=f.mode==="transform",b=g?"left":"top",p=d.options.scrollMargin,y=d.getVirtualItems();for(const h of y){const v=h.start-p,j=d.elementsCache.get(h.key);j&&f.lastPositions.get(j)!==v&&(f.lastPositions.set(j,v),x?j.style.transform=g?`translate3d(${v}px, 0, 0)`:`translate3d(0, ${v}px, 0)`:j.style[b]=`${v}px`)}},l={...a,onChange:(d,f)=>{var m;const g=o.current;let x=!0;if(g.enabled){i(d);const b=d.range,p=g.prevRange;x=!p||p.isScrolling!==d.isScrolling||p.startIndex!==b?.startIndex||p.endIndex!==b?.endIndex,x&&(g.prevRange=b?{startIndex:b.startIndex,endIndex:b.endIndex,isScrolling:d.isScrolling}:null)}x&&(e&&f?Gn.flushSync(r):r()),(m=a.onChange)==null||m.call(a,d,f)}},[u]=c.useState(()=>{const d=new Xp(l);return Object.assign(d,{containerRef:f=>{const m=o.current;if(m.container=f,m.lastSize=null,f&&m.enabled){const g=d.getTotalSize();m.lastSize=g;const x=d.options.horizontal?"width":"height";f.style[x]=`${g}px`}}})});return u.setOptions(l),Mn(()=>u._didMount(),[]),Mn(()=>u._willUpdate()),Mn(()=>{i(u)}),u}function tx(e){return ex({observeElementRect:Up,observeElementOffset:Wp,scrollToFn:Gp,...e})}const sx=(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)},nx=(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]},ax=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(p=>{const y=new Set(p);return y.has(b)?y.delete(b):y.add(b),y})},[]),l=c.useCallback(b=>{r(b),n(p=>{if(p.has(b))return p;const y=new Set(p);return y.add(b),y})},[]),u=c.useCallback(b=>{n(p=>{if(!p.has(b))return p;const y=new Set(p);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(p=>b.every(h=>p.has(h))?new Set:new Set(b))},[]),g=c.useCallback(b=>{r(b)},[]),x=c.useCallback((b,p)=>{n(y=>{const h=sx(b,a,p);if(h.length===0)return y;const v=new Set(y);for(const j of h)v.add(j);return v}),r(y=>y??p)},[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:x,setAnchor:g,anchorId:a}},rx=e=>{const t=xe(Ec()),{mutate:n}=t;return{preview:c.useCallback(r=>{e&&n({path:{accountId:e},body:yo(r)})},[e,n]),reset:t.reset,matchedCount:t.data?.matchedCount,messageIds:t.data?.messageIds,isPending:t.isPending,isError:t.isError,error:t.error}},ox=new Set(["Complete","Failed"]),Kr=e=>e!==void 0&&ox.has(e),ix=1e3,lx=15e3,cx=e=>{const t=Math.max(0,e),n=ix*2**t;return Math.min(n,lx)},ux=e=>{const[t,n]=c.useState(),a=xe({...Ic(),onSuccess:m=>n(m.organizeJobId)}),{mutate:r}=a,o=re({...Rc({path:{accountId:e??"",organizeJobId:t??""}}),enabled:!!e&&!!t,refetchInterval:m=>{const g=m.state.data?.state;return Kr(g)?!1:cx(m.state.dataUpdateCount)}}),i=c.useCallback(m=>{e&&(n(void 0),r({path:{accountId:e},body:yo(m)}))},[e,r]),l=o.data,u=l?.state??a.data?.state,d=Kr(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}},dx=({draft:e,scope:t,name:n,pickedDate:a})=>{if(!Jc(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."},fx=(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"}},mx=(e,t,n)=>e==="just-these"?t:n,hx=[{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 gx({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(""),[g,x]=c.useState(""),{data:b}=re({...et({path:{accountId:e}}),staleTime:1/0}),p=c.useMemo(()=>ja(b?.items??[]).map(E=>({id:E.mailboxId,label:Vs(E.fullPath)})),[b?.items]),y=c.useMemo(()=>({anchorMessageId:a,matchOperator:"And",literalClauses:[],moveMailboxId:u||void 0,expiresAt:i==="temporary"?Zc(g):void 0}),[a,u,i,g]),{moveMessages:h}=ct({mailboxId:t,accountId:e}),v=ux(e),j=eu(e),w=n.length,N=mx(i,w,r),I=dx({draft:y,scope:i,name:f,pickedDate:g}),S=()=>{if(!I)switch(i){case"just-these":u&&h(n,u),o();return;case"all-like-these":v.start(y);return;case"standing":j.createFilter(y,"standing",f.trim());return;case"temporary":j.createFilter(y,"temporary",f.trim());return}};if(v.isRunning||v.isDone)return s.jsx(px,{progress:v.progress,isDone:v.isDone,onClose:o});if(j.isSuccess)return s.jsxs("div",{className:"flex flex-col items-center gap-3 px-5 py-8 text-center",children:[s.jsx(oa,{className:"size-8 text-positive"}),s.jsx("p",{className:"text-sm font-medium text-fg",children:"Filter saved"}),s.jsx("p",{className:"max-w-xs text-xs text-fg-muted",children:"You can see it, and when it expires, under Settings › Filters."}),s.jsx(X,{variant:"primary",onClick:o,className:"mt-2",children:"Done"})]});const k=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",w>0?` from ${w} selected`:"","."]})]}),s.jsxs("div",{className:"min-h-0 flex-1 space-y-5 overflow-y-auto px-5 py-4",children:[s.jsxs("section",{className:"space-y-2 rounded-lg border border-line bg-surface-sunken p-3",children:[s.jsxs("p",{className:"text-sm leading-relaxed text-fg-muted",children:[i==="standing"&&s.jsx("span",{className:"font-semibold text-fg",children:"Always keep "}),i==="standing"?"":"Keep ",i==="just-these"?"these":"emails like these"," in"]}),s.jsxs(Xc,{"aria-label":"Destination folder",value:u,onChange:C=>d(C.target.value),children:[s.jsx("option",{value:"",children:"Choose a folder…"}),p.map(C=>s.jsx("option",{value:C.id,children:C.label},C.id))]}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx(Je,{tone:"neutral",children:"label them…"}),s.jsx("span",{className:"text-2xs text-fg-subtle",children:"Labeling isn't available yet — arrives with mail-labeling (RFC 031)."})]})]}),s.jsx("section",{className:"space-y-1.5",children:hx.map(C=>{const E=i===C.id;return s.jsxs("button",{type:"button",onClick:()=>l(C.id),className:`flex w-full items-start gap-3 rounded-lg border px-3 py-2.5 text-left transition-colors ${E?"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 ${E?"border-accent-2 bg-accent-2":"border-line bg-surface"}`,children:E&&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 ${E?"text-accent-2":"text-fg"}`,children:C.label}),s.jsx("span",{className:"block text-xs text-fg-subtle",children:C.caption})]})]},C.id)})}),k&&s.jsxs("section",{className:"space-y-2",children:[s.jsx(to,{value:f,onChange:C=>m(C.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:g,onChange:C=>x(C.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:[I&&s.jsx("p",{className:"text-xs text-fg-subtle",role:"status",children:I}),j.isError&&s.jsx("p",{className:"text-xs text-danger",role:"alert",children:"Couldn't save the filter. Please try again."}),s.jsx(X,{variant:"primary",onClick:S,disabled:!!I||j.isPending||v.isStarting,className:"w-full",children:j.isPending?"Saving…":fx(i,N)}),s.jsx(X,{variant:"ghost",onClick:o,className:"w-full",children:"Not now"})]})]})}function px({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(oa,{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(X,{variant:"primary",onClick:n,className:"mt-2",children:"Done"})]})}function xx({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}=rx(t);c.useEffect(()=>{!e||!o||i({anchorMessageId:o,matchOperator:"And",literalClauses:[]})},[e,o,i]);const g=()=>{l(),r()};return e?s.jsx(eo,{open:e,onClose:g,title:"Organize similar mail",children:d||u===void 0?f?s.jsxs("div",{className:"flex flex-col items-center gap-3 px-5 py-8 text-center",children:[s.jsx("p",{className:"text-sm font-medium text-danger",children:"Couldn't find similar messages"}),s.jsx("p",{className:"max-w-xs text-xs text-fg-muted",children:m instanceof Error?m.message:"Please try again."}),s.jsx(X,{variant:"ghost",onClick:g,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(gx,{accountId:t,mailboxId:n,selectedMessageIds:a,anchorMessageId:o,matchedCount:u,onClose:g})}):null}const bx=({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 g=!!r&&!!u&&!!d,x=!!o&&!!u&&!!d&&!f;return s.jsxs("div",{className:"sticky top-0 z-10 flex items-center justify-between px-3 py-2 bg-surface-sunken border-b border-line",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("button",{type:"button",onClick:n,className:"min-h-11 min-w-11 inline-flex items-center justify-center rounded hover:bg-surface-raised transition-colors","aria-label":"Clear selection",children:s.jsx(De,{className:"size-4 text-fg-muted"})}),s.jsxs("span",{className:"text-sm font-medium",children:[e," ",e===1?"message":"messages"," ","selected"]}),f&&s.jsx("span",{className:"text-xs text-fg-muted",role:"status","aria-live":"polite",children:f})]}),s.jsxs("div",{className:"flex items-center gap-1",children:[x&&o&&s.jsxs("button",{type:"button",onClick:m?void 0:o,className:"min-h-11 inline-flex items-center justify-center gap-1.5 px-3 rounded text-sm font-medium transition-colors hover:bg-surface-raised","aria-label":"Organize similar messages",children:[s.jsx(Ke,{className:"size-4"}),s.jsx("span",{className:"hidden sm:inline",children:"Organize"})]}),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(js,{className:"size-4"})}),g&&r&&u&&d&&s.jsx(ks,{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(qe,{className:"size-4"}),s.jsx("span",{className:"hidden sm:inline",children:i?"Deleting...":"Delete"})]})]})]})},vx=8,yx=({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)>vx&&r()},[r]),l=c.useCallback(()=>{r()},[r]),u=c.useCallback(()=>{r()},[r]);return{handlers:{onPointerDown:o,onPointerMove:i,onPointerUp:l,onPointerCancel:u}}},wx=(e,t)=>{const n=e.authenticity?.dkimMismatch===!0;return{id:e.messageId,accountId:e.accountConfigId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:mt(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.star!=null&&e.star!=="none"&&e.hasStars===!0,trust:e.senderTrust,category:cn(e.category),messageCount:t,suspicious:n}},jx=({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:g="comfortable"})=>{const x=je(),b=e.messageId,p=wx(e,u),y=I=>{I.preventDefault(),I.stopPropagation(),i(e.messageId)},h=c.useCallback(I=>{if(!m)return;l(b,{shiftKey:I.shiftKey,metaKey:I.metaKey,ctrlKey:I.ctrlKey})&&(I.preventDefault(),I.stopPropagation())},[m,l,b]),v=c.useCallback(()=>{f?.(b)},[f,b]),j=yx({onLongPress:v,delayMs:500}),w=c.useCallback(()=>{x.prefetchQuery(Zn({path:{messageId:e.messageId}}))},[x,e.messageId]),N=!e.isRead;return g==="compact"?s.jsx(Xe,{to:"/mail/$mailboxId",params:{mailboxId:t},search:I=>({...I,selectedMessageId:e.messageId}),"data-message-row":!0,onClick:h,onMouseEnter:w,onFocus:w,...!m&&j.handlers,className:fe(Po({active:a,focused:r}),o&&"bg-accent-soft",!m&&"min-h-11"),children:s.jsx(Lo,{thread:p})}):s.jsxs(Xe,{to:"/mail/$mailboxId",params:{mailboxId:t},search:I=>({...I,selectedMessageId:e.messageId}),"data-message-row":!0,onClick:h,onMouseEnter:w,onFocus:w,...!m&&j.handlers,className:fe("group",Yt({active:a,focused:r}),o&&"bg-accent-soft",!m&&"min-h-11"),children:[N&&s.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),s.jsxs("div",{className:"relative size-7 shrink-0",children:[s.jsx(st,{name:e.fromName??e.fromEmail??"?",email:e.fromEmail??void 0,size:"sm",className:fe("absolute inset-0","sm:group-hover:opacity-0 transition-opacity",(o||d)&&"opacity-0")}),s.jsx("button",{type:"button",onClick:y,className:fe("absolute inset-0 size-7 rounded-full border items-center justify-center transition-opacity",d?"flex":"hidden sm:flex",o?"bg-accent border-accent text-accent-fg opacity-100":d?"border-fg-subtle/40 opacity-100 bg-canvas":"border-fg-subtle/40 opacity-0 group-hover:opacity-100 bg-canvas"),"aria-label":o?"Deselect message":"Select message",children:o&&s.jsx(ws,{className:"size-3"})})]}),s.jsx(Gt,{thread:p,badge:e.autoMoved&&s.jsx(vi,{accountId:n,messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,autoMoved:e.autoMoved,size:"sm"})})]})},Sx=c.memo(jx),Nx=e=>{const t=e.authenticity?.dkimMismatch===!0;return{id:e.messageId,accountId:e.accountConfigId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:mt(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.star!=null&&e.star!=="none"&&e.hasStars===!0,trust:e.senderTrust,category:cn(e.category),suspicious:t}},kx=({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:g,density:x})=>{const[b,p]=c.useState("none"),y=c.useCallback(j=>{navigator.vibrate?.(10),j==="trailing"?m(e.messageId):g(e.messageId,e.isRead),p("none")},[m,g,e.messageId,e.isRead]),h=c.useCallback(()=>{d(e.messageId)},[d,e.messageId]),v=c.useCallback(()=>{i(e.messageId)},[i,e.messageId]);return f||u?s.jsx(Sx,{thread:e,mailboxId:t,accountId:n,isSelected:a,isFocused:r,isChecked:o,onToggleCheck:i,onRowSelect:l,isMultiSelectMode:u,onLongPress:d,isDesktop:f,density:x}):s.jsx(Bo,{thread:Nx(e),selectionMode:!1,checked:!1,active:a,peek:b,onPeek:p,onToggleCheck:v,onLongPress:h,onOpen:()=>{},onAct:y,linkComponent:({onOpenClick:j,children:w,...N})=>s.jsx(Xe,{...N,to:"/mail/$mailboxId",params:{mailboxId:t},search:I=>({...I,selectedMessageId:e.messageId}),"data-message-row":!0,onClick:j,children:w})})},Cx=72,Ex=32,Ix=5,jl="remit:list-density",Rx=()=>{try{const e=localStorage.getItem(jl);if(e==="compact"||e==="comfortable")return e}catch{}return"comfortable"},Mx=({query:e,count:t})=>s.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-line bg-surface-sunken/30",children:[s.jsx(vs,{className:"size-4 text-fg-muted"}),s.jsxs("span",{className:"text-sm text-fg-muted",children:[t," ",t===1?"result":"results"," for “",e,"”"]})]}),Tx=({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:g=!1,onLoadMore:x,hasMore:b=!1,isLoadingMore:p=!1,accountId:y,listTitle:h,listMeta:v,onTriageContextChange:j,hideHeader:w=!1})=>{const N=c.useRef(null),I=Ce(),S=kt(),[k,C]=c.useState(!1),[E,R]=c.useState(!1),[M,T]=c.useState(n),[P,Y]=c.useState(Rx),K=c.useCallback(()=>{Y(A=>{const J=A==="comfortable"?"compact":"comfortable";try{localStorage.setItem(jl,J)}catch{}return J})},[]),{toggleReadFor:B}=xi({mailboxId:e}),{selectedIds:_,selectedCount:F,hasSelection:q,isSelected:te,toggle:U,select:O,clearSelection:D,selectRange:V,setAnchor:le,selectAll:ve}=ax(),[ce,ye]=c.useState(null);c.useEffect(()=>{k&&F===0&&C(!1)},[k,F]);const Se=tx({count:t.length,getScrollElement:()=>N.current,estimateSize:()=>P==="compact"?Ex:Cx,overscan:Ix}),G=n?t.findIndex(A=>A.messageId===n):-1,ge=M?t.findIndex(A=>A.messageId===M):-1,Ie=c.useCallback(A=>{if(A<0||A>=t.length)return;const J=t[A];if(k){U(J.messageId);return}T(J.messageId)},[t,k,U]),H=c.useCallback(()=>{if(t.length===0)return;const A=ge<0?0:Math.min(ge+1,t.length-1);Ie(A)},[t.length,ge,Ie]),Q=c.useCallback(()=>{if(t.length===0)return;const A=ge<=0?0:ge-1;Ie(A)},[t.length,ge,Ie]),ee=c.useCallback(()=>{M&&U(M)},[M,U]),ne=c.useMemo(()=>t.map(A=>A.messageId),[t]),Ue=c.useCallback((A,J)=>J.shiftKey?(V(ne,A),!0):J.metaKey||J.ctrlKey?(U(A),!0):(D(),le(A),!1),[ne,V,U,D,le]),oe=c.useCallback(A=>{!u||A.length===0||ye(A)},[u]),Ne=c.useCallback(A=>{const J=nx(ne,M,A);J!==void 0&&(V(ne,J),T(J))},[ne,M,V]),Fe=c.useCallback(()=>Ne(-1),[Ne]),Ae=c.useCallback(()=>Ne(1),[Ne]),He=c.useCallback(()=>{ne.length>0&&ve(ne)},[ne,ve]),Qe=c.useCallback(()=>{F>0?oe(Array.from(_)):M&&oe([M])},[F,_,M,oe]),Ct=c.useCallback(()=>{M&&I({to:"/mail/$mailboxId",params:{mailboxId:e},search:A=>({...A,selectedMessageId:M})})},[M,I,e]),ht=c.useCallback(()=>{F>0&&oe(Array.from(_))},[oe,F,_]),Et=c.useCallback(()=>{if(!ce||ce.length===0){ye(null);return}const A=new Set(ce),J=t.findIndex(de=>A.has(de.messageId));let me;for(let de=J+1;de<t.length;de++)if(!A.has(t[de].messageId)){me=t[de].messageId;break}if(me===void 0){for(let de=J-1;de>=0;de--)if(!A.has(t[de].messageId)){me=t[de].messageId;break}}u?.(ce),D(),ye(null),me!==void 0&&I({to:"/mail/$mailboxId",params:{mailboxId:e},search:de=>({...de,selectedMessageId:me}),replace:!0})},[ce,t,u,D,I,e]),We=c.useCallback(()=>{ye(null)},[]),at=c.useCallback(()=>{d&&F>0&&d(Array.from(_))},[d,F,_]),gt=c.useCallback(A=>{!f||F===0||(f(Array.from(_),A),D())},[f,F,_,D]),Re=c.useMemo(()=>{if(F===0)return;const A=new Set;for(const J of t)_.has(J.messageId)&&A.add(J.accountConfigId);if(A.size>1)return"Move only works within one account — clear selection or pick messages from a single account"},[F,_,t]),Ve=c.useCallback(A=>{u?.([A])},[u]),It=c.useCallback((A,J)=>{B([A],!J)},[B]),Rt=c.useCallback(A=>{S||(C(!0),O(A))},[S,O]),es=c.useCallback(()=>{C(!1),D()},[D]);c.useEffect(()=>{if(!S&&n)return;const A=ge>=0?ge:G;A>=0&&Se.scrollToIndex(A,{align:"auto"})},[ge,G,Se,S,n]),c.useEffect(()=>{n&&T(n)},[n]),c.useEffect(()=>{M&&(t.some(A=>A.messageId===M)||T(t[0]?.messageId))},[t,M]),c.useEffect(()=>{j?.({focusedMessageId:M,selectedIds:Array.from(_)})},[M,_,j]),c.useEffect(()=>{const A=new Set(t.map(me=>me.messageId));Array.from(_).some(me=>!A.has(me))&&D()},[t,_,D]),c.useEffect(()=>{const A=N.current;if(!A||!b||!x)return;const J=()=>{if(p)return;const{scrollTop:me,scrollHeight:de,clientHeight:Me}=A;me+Me>=de-200&&x()};return A.addEventListener("scroll",J,{passive:!0}),J(),()=>A.removeEventListener("scroll",J)},[b,p,x]),ps({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:Q,preventDefault:!0},{key:"ArrowUp",handler:Q,preventDefault:!0,requireShift:!1},{key:"ArrowDown",handler:Ae,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:He,preventDefault:!0,requireMeta:!0},{key:"Enter",handler:Ct,preventDefault:!0},{key:"Delete",handler:Qe,preventDefault:!0},{key:"Backspace",handler:Qe,preventDefault:!0},{key:"d",handler:K,preventDefault:!0}]}),ps({enabled:q&&ce===null,capture:!0,bindings:[{key:"Escape",handler:D,preventDefault:!0,stopPropagation:!0}]});const Mt=a?"loading":r?"error":t.length===0?"empty":"ready",Le=r?bo(o):void 0,ts=c.useCallback(()=>{const A=sa(ta());window.open(A,"_blank","noopener,noreferrer")},[]),W=[{id:"inbox",threads:[]}],ae=q&&S?s.jsx(bx,{selectedCount:F,onDelete:ht,onClearSelection:D,onMarkAsRead:d?at:void 0,onMove:f?gt:void 0,onOrganize:()=>R(!0),isDeleting:m,isMoving:g,accountId:y,currentMailboxId:e,moveDisabledHint:Re}):void 0,ie=k&&!S?s.jsx(Fo,{count:F,onCancel:es,onDelete:ht,onMarkRead:d?at:void 0,isBusy:m||g,moveDisabledHint:Re,moveSlot:f&&y&&e?s.jsxs(s.Fragment,{children:[!Re&&s.jsx("button",{type:"button",onClick:()=>R(!0),className:"min-h-11 min-w-11 inline-flex shrink-0 items-center justify-center rounded text-fg-muted hover:bg-surface-raised","aria-label":"Organize similar messages",children:s.jsx(Ke,{className:"size-4"})}),s.jsx(ks,{accountId:y,currentMailboxId:e,onMove:m||g?()=>{}:gt,disabledHint:Re,label:"Move selected messages"})]}):void 0}):void 0,Z=ae??ie,ue=!!l?.trim(),pe=s.jsxs(s.Fragment,{children:[ue&&l&&s.jsx(Mx,{query:l,count:t.length}),s.jsxs("div",{ref:N,className:"flex-1 overflow-y-auto",children:[s.jsx("div",{className:"relative w-full",style:{height:`${Se.getTotalSize()}px`},children:Se.getVirtualItems().map(A=>{const J=t[A.index];return s.jsx("div",{"data-index":A.index,ref:Se.measureElement,className:"absolute left-0 top-0 w-full border-b border-line",style:{transform:`translateY(${A.start}px)`},children:s.jsx(kx,{thread:J,mailboxId:e,accountId:y,isSelected:n===J.messageId,isFocused:M===J.messageId,isChecked:te(J.messageId),onToggleCheck:U,onRowSelect:Ue,isMultiSelectMode:k,onLongPress:Rt,isDesktop:S,onDelete:Ve,onToggleRead:It,density:P})},A.key)})}),p&&s.jsx("div",{className:"flex justify-center py-4",children:s.jsx("div",{className:"h-5 w-5 animate-spin rounded-full border-2 border-fg-muted border-t-transparent"})})]})]});return s.jsxs(s.Fragment,{children:[s.jsx($o,{listTitle:h,listMeta:v,sections:W,flatList:!0,listState:Mt,searchQuery:ue?l:void 0,errorMessage:Le,onRetry:i,onReportError:ts,density:P,selectedThreadId:n,onSelectThread:A=>I({to:"/mail/$mailboxId",params:{mailboxId:e},search:J=>({...J,selectedMessageId:A})}),onSelectBriefCategory:()=>{},isDesktop:S,hideHeader:w,selectionBar:Z,listBody:Mt==="ready"?pe:void 0}),s.jsx(ol,{isOpen:ce!==null,title:Vc(ce?.length??0),description:"You can restore them from Trash later.",confirmLabel:"Move to Trash",destructive:!0,isBusy:m,onConfirm:Et,onCancel:We}),E&&y&&s.jsx(xx,{open:E,accountId:y,mailboxId:e,selectedMessageIds:Array.from(_),onClose:()=>R(!1)})]})},Dx=e=>Vt({path:{accountId:e}}),Ax=e=>{const t=je(),n=xs(),a=xe({...Mc(),onSuccess:()=>{n.recordEvent("sync.triggered"),t.invalidateQueries({queryKey:Dx(e)})}});return{trigger:()=>{a.mutate({path:{accountId:e}})},triggerAsync:()=>a.mutateAsync({path:{accountId:e}}),isPending:a.isPending,error:a.error,reset:a.reset}},Ox=({accountId:e,children:t})=>{const{triggerAsync:n,isPending:a}=Ax(e);return s.jsx(Fd,{onRefresh:n,isRefreshing:a,children:t})};function Px({accountId:e,currentMailboxId:t,candidates:n,onMove:a,children:r}){const[o,i]=c.useState(!1),l=xs(),{t:u}=tn("mail",{useSuspense:!1}),d=c.useCallback((v,j)=>u(v,{defaultValue:j}),[u]),{inboxMailboxId:f}=pa(e),m=bi(e),{data:g}=re({...et({path:{accountId:e}}),staleTime:1/0}),x=c.useMemo(()=>{const v=ja(g?.items??[],m),j=ys(m);return v.map(w=>({id:w.mailboxId,label:Ht(w,j.get(w.mailboxId),d),searchValue:w.fullPath,isCurrent:w.mailboxId===t}))},[g?.items,m,t,d]),b=c.useMemo(()=>f||(x.find(j=>j.label.toLowerCase()==="inbox")?.id??x.find(j=>!j.isCurrent)?.id??""),[f,x]),p=c.useRef(!1);c.useEffect(()=>{p.current||(p.current=!0,op(l,n.length))},[l,n.length]);const y=c.useCallback(()=>{ip(l,n.length),i(!0)},[l,n.length]),h=c.useCallback((v,j)=>{lp(l,{selected:v.length,total:n.length,toInbox:j===f}),a(v,j)},[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(Kd,{count:n.length,onReview:y})}),s.jsx("div",{className:"min-h-0 flex-1",children:r}),s.jsx(Yd,{open:o,candidates:n,defaultDestinationId:b,availableFolders:x,onConfirmMove:h,onCancel:()=>i(!1)})]})}const Lx=({accounts:e})=>{const t=aa({strict:!1}),n=ma(),a=t.mailboxId,{t:r}=tn("mail",{useSuspense:!1}),o=c.useCallback((l,u)=>r(l,{defaultValue:u}),[r]),i=Jt({queries:e.map(l=>({...et({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=ys(e[l].folderAppointments);return Ht(d,f.get(a),o)}return null},zx=({accounts:e})=>{const n=aa({strict:!1}).mailboxId,a=Jt({queries:e.map(r=>({...et({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},_x="We can verify this sender";function Fx(e){const{data:t}=re({...Tc({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:_x,trustSubReason:rp(a.senderTrust),senderTrust:a.senderTrust}))}}const $s={action:null,nextPrefix:null,preventDefault:!1},Bx={b:"goBrief",i:"goInbox",s:"goSent",f:"goFlagged",",":"goSettings"},$x={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 Kx(e,t){const n=e.key.toLowerCase(),a=e.metaKey||e.ctrlKey;if(e.inEditable)return{...$s,nextPrefix:t==="g"?null:t};if(a&&n==="n")return{action:"compose",nextPrefix:null,preventDefault:!0};if(a)return{...$s,nextPrefix:t==="g"?null:t};if(n==="escape")return{action:"back",nextPrefix:null,preventDefault:!1};if(t==="g"){const i=Bx[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=$x[n];if(r){const o=r.requireShift===!0,i=n.length===1&&!/[a-z0-9]/.test(n);return!o&&e.shiftKey&&!i?$s:{action:r.action,nextPrefix:null,preventDefault:!0}}return $s}function qx(e){if(!(e instanceof HTMLElement))return!1;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"||e.isContentEditable}function Ux({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=Kx({key:u.key,shiftKey:u.shiftKey,metaKey:u.metaKey,ctrlKey:u.ctrlKey,altKey:u.altKey,inEditable:qx(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 qr=(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]},Sl="remit:intelligence-open";function Hx(){try{return localStorage.getItem(Sl)!=="closed"}catch{return!0}}function Ur(e){try{localStorage.setItem(Sl,e?"open":"closed")}catch{}}const Qx=(e,t)=>e!==t,Wx=(e,t,n)=>{if(!(n||!t))return e.find(a=>a.messageId===t)},Vx={unread:e=>!e.isRead,flagged:e=>e.star!=null&&e.star!=="none"&&e.hasStars===!0,attachment:e=>!!e.hasAttachment};function Yx(e,t,n){const a=Array.from(n).map(r=>Vx[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 Nl=c.createContext(null);function mn(){const e=c.useContext(Nl);if(!e)throw new Error("MailboxPane.* must be used inside <MailboxPane>");return e}function Gx({mailboxId:e,selectedMessageId:t,children:n}){const a=Ce(),o=Es()==="desktop",i=xs(),{accounts:l,mailboxNameIndex:u,accountNameIndex:d,searchQuery:f,searchInput:m,intelligenceOpen:g,onToggleIntelligence:x,onSetIntelligenceOpen:b}=Ee(),p=Gi(f),y=p.length>0,{freeText:h,tokens:v}=Cs(p,{mailboxesByName:u,accountsByName:d}),j=v.find(L=>L.type==="from"),w={order:"desc",...h?{query:h}:{},...j?{from:j.value}:{},...v.some(L=>L.type==="hasAttachment")?{attachments:!0}:{},...v.some(L=>L.type==="isUnread")?{unread:!0}:{}},N=y?ut({path:{mailboxId:e},query:w}):tt({path:{mailboxId:e},query:{order:"desc"}}),{data:I,isLoading:S,isError:k,error:C,refetch:E,fetchNextPage:R,hasNextPage:M,isFetchingNextPage:T}=Dm({queryKey:N,queryFn:async({pageParam:L})=>{if(y){const{data:Oe}=await Ac({path:{mailboxId:e},query:{...w,continuationToken:L},throwOnError:!0});return Oe}const{data:Te}=await Oc({path:{mailboxId:e},query:{order:"desc",continuationToken:L},throwOnError:!0});return Te},initialPageParam:void 0,getNextPageParam:L=>L.continuationToken,enabled:y?p.length>0:!0,placeholderData:Dc}),P=c.useCallback(L=>{t&&L.includes(t)&&a({to:"/mail/$mailboxId",params:{mailboxId:e},search:Te=>({...Te,selectedMessageId:void 0,selectedThreadId:void 0})})},[t,e,a]),{deleteMessages:Y,isPending:K}=ds({mailboxId:e,onAfterOptimisticRemove:P}),{accountId:B}=pi(e),_=Lx({accounts:l}),{moveMessages:F,isPending:q}=ct({mailboxId:e,accountId:B,onAfterOptimisticRemove:P}),te=Ch(I?.pages.flatMap(L=>L.items??[])??[]),[U,O]=c.useState("all"),[D,V]=c.useState(new Set),le=c.useMemo(()=>Yx(te,U,D),[te,U,D]),ve=c.useCallback(L=>{O(L)},[]),ce=c.useCallback(L=>{V(Te=>{const Oe=new Set(Te);return Oe.has(L)?Oe.delete(L):Oe.add(L),Oe})},[]),ye=c.useCallback(()=>{O("all"),V(new Set)},[]),Se=Qx(m,f),G=Wx(te,t,Se),{selectedThreadId:ge}=Ut({strict:!1}),Ie=c.useMemo(()=>gl(G,{messageId:t,threadId:Se?void 0:ge,mailboxId:e}),[G,t,ge,Se,e]),[H,Q]=c.useState(void 0),[ee,ne]=c.useState([]),Ue=c.useCallback(L=>{Q(L.focusedMessageId),ne(L.selectedIds)},[]),oe=le.find(L=>L.messageId===H)??G,Ne=c.useRef(null);c.useEffect(()=>{const L=G?.messageId??null;L&&Ne.current!==L&&G?.authenticity?.dkimMismatch&&(Ne.current=L,g||x())},[G?.messageId,G?.authenticity?.dkimMismatch,g,x]);const Fe=c.useRef(!1);c.useEffect(()=>{Fe.current||o&&G?.messageId&&(Fe.current=!0,Hx()&&!g&&b(!0))},[o,G?.messageId,g,b]);const He=zx({accounts:l})??te.filter(L=>!L.isRead).length,Qe=je(),{pushError:Ct}=ze(),{deleteMessages:ht}=ds({mailboxId:e,threadId:G?.threadId,onAfterOptimisticRemove:P}),{moveMessages:Et}=ct({mailboxId:e,threadId:G?.threadId,accountId:B,onAfterOptimisticRemove:P}),{draftsMailboxId:We}=Nh(B),at=We!==void 0&&We===e,{archiveMailboxId:gt}=Sh(B),Re=c.useCallback(L=>{const Te=jt({path:{threadId:L.threadId}}),Pa=Qe.getQueriesData({queryKey:Te}).flatMap(([,Yl])=>Yl?.items.map(Gl=>Gl.messageId)??[]);return Pa.length>0?Pa:[L.messageId]},[Qe]),Ve=c.useCallback(()=>{if(!G)return;const L=Re(G);ht(L)},[G,Re,ht]),It=c.useCallback(L=>{if(!G)return;const Te=Re(G);Et(Te,L)},[G,Re,Et]),{toggleStar:Rt}=Bn({threadId:G?.threadId??"",mailboxId:e}),es=c.useCallback(()=>{G&&Rt(G.messageId,G.hasStars)},[G,Rt]),[Mt,Le]=c.useState(null),ts=c.useCallback(()=>{Le("reply")},[]),W=c.useCallback(()=>{Le("reply_all")},[]),ae=c.useCallback(()=>{Le("forward")},[]),ie=c.useCallback(()=>{Le(null)},[]),{state:Z,openCompose:ue,closeCompose:pe}=wt(),A=c.useCallback(()=>{ue({mode:"new"})},[ue]),J=xe({...Zs(),onError:L=>{Ct(fs("Couldn't discard draft","The draft wasn't deleted.",L))}}),me=c.useCallback(()=>{const L=Z.outboxMessageId;L&&(J.mutate({path:{outboxMessageId:L}}),Qe.invalidateQueries({queryKey:na()}),pe())},[Z.outboxMessageId,J,Qe,pe]),de=c.useCallback(()=>{t&&a({to:"/mail/$mailboxId",params:{mailboxId:e},search:L=>({...L,selectedMessageId:void 0,selectedThreadId:void 0})})},[t,e,a]),Me=c.useCallback(L=>L?Re(L):[],[Re]),{toggleStar:ke}=Bn({threadId:oe?.threadId??"",mailboxId:e}),{toggleReadFor:pt}=xi({mailboxId:e,accountId:B}),{junkMailboxId:Be}=xa(B),Ra=Be!=null&&Be===e,{candidates:Dl}=Fx(Ra?Be:void 0),{moveMessages:Ma}=ct({mailboxId:e,threadId:oe?.threadId,accountId:B,onAfterOptimisticRemove:P}),{deleteMessages:Ta}=ds({mailboxId:e,threadId:oe?.threadId,onAfterOptimisticRemove:P}),{addressId:ss,address:Is}=ll(oe),{updateFlags:Rs}=cl({addressId:ss,senderEmail:oe?.fromEmail??void 0}),Tt=c.useCallback(()=>t||!H?!1:(a({to:"/mail/$mailboxId",params:{mailboxId:e},search:L=>({...L,selectedMessageId:H})}),!0),[t,H,e,a]),Al=c.useCallback(()=>{Tt()||G&&Le("reply")},[Tt,G]),Ol=c.useCallback(()=>{Tt()||G&&Le("reply_all")},[Tt,G]),Pl=c.useCallback(()=>{Tt()||G&&Le("forward")},[Tt,G]),Dt=c.useCallback(()=>ee.length>0?ee:Me(oe),[ee,Me,oe]),Ll=c.useCallback(()=>{const L=Dt();L.length>0&&Ta(L)},[Dt,Ta]),zl=c.useCallback(()=>{if(!Be)return;const L=Dt();L.length!==0&&(dl(i,{count:L.length,senderTrust:oe?.senderTrust??"unknown",wasRescuable:oe?ul(oe):!1}),Ma(L,Be))},[Be,Dt,Ma,i,oe]),_l=c.useCallback(()=>{if(ee.length>0){const L=!(oe?.hasStars??!1),Te=new Set(ee);for(const Oe of le)Te.has(Oe.messageId)&&Oe.hasStars!==L&&ke(Oe.messageId,Oe.hasStars);return}oe&&ke(oe.messageId,oe.hasStars)},[ee,le,oe,ke]),Fl=c.useCallback(()=>{const L=Dt();if(L.length===0)return;const Te=!(oe?.isRead??!1);pt(L,Te)},[Dt,oe,pt]),Bl=c.useCallback(()=>{if(!ss)return;const L=Is?.flags?.muted?.value!==!0;Rs({muted:{value:L}})},[ss,Is,Rs]),$l=c.useCallback(()=>{if(!ss)return;const L=Is?.flags?.vip?.value!==!0;Rs({vip:{value:L}})},[ss,Is,Rs]),Kl=c.useCallback(()=>{g||x()},[g,x]),ns=c.useCallback(L=>{a({to:L})},[a]),Da=at?"drafts":gt===e?"archive":Be===e?"junk":"inbox",Aa=c.useRef("");c.useEffect(()=>{const L=Aa.current;Aa.current=p,p.length>0&&L.length===0&&i.recordEvent("search.submitted",{mailboxType:Da})},[p,Da,i]);const ql=!!G,Ul=at&&Z.isOpen&&!!Z.outboxMessageId&&!G,Hl=o&&g&&ql;Ux({enabled:!Z.isOpen,handlers:{back:de,reply:Al,replyAll:Ol,forward:Pl,delete:Ll,toggleStar:_l,toggleRead:Fl,muteSender:Bl,blockSender:Kl,vipSender:$l,markJunk:zl,toggleIntelligence:G?x:void 0,compose:A,goBrief:()=>ns("/mail"),goInbox:()=>ns("/mail"),goSent:()=>ns("/mail"),goFlagged:()=>ns("/mail/flagged"),goSettings:()=>ns("/settings")}}),ps({enabled:Z.isOpen,bindings:[{key:"Escape",handler:pe,preventDefault:!0}]});const Oa=le.map(L=>L.messageId),Ql=qr(Oa,t,"next")??void 0,Wl=qr(Oa,t,"previous")??void 0,Vl={mailboxId:e,selectedMessageId:t,selectedThread:G,conversation:Ie,threads:le,isLoading:S,isError:k,error:C,mailboxAccountId:B,mailboxName:_,unreadCount:He,isDraftsMailbox:at,isSpamFolder:Ra,rescueCandidates:Dl,filterCategory:U,filterAttributes:D,onSelectFilterCategory:ve,onToggleFilterAttribute:ce,onClearFilters:ye,showIntelligence:Hl,intelligenceOpen:g,onToggleIntelligence:x,onDeleteMessages:Y,onMoveMessages:F,isDeleting:K,isMoving:q,onLoadMore:R,hasMore:M,isLoadingMore:T,onTriageContextChange:Ue,onRetry:()=>E(),toolbarComposeRequest:Mt,onToolbarReply:ts,onToolbarReplyAll:W,onToolbarForward:ae,onClearComposeRequest:ie,onToolbarDelete:Ve,onToolbarStar:es,onToolbarDiscardDraft:me,onToolbarMove:It,composeState:Z,openCompose:A,closeCompose:pe,hasRemitDraftOpen:Ul,onBack:de,nextMessageId:Ql,previousMessageId:Wl};return s.jsx(Nl.Provider,{value:Vl,children:n})}function kl(){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:g,mailboxAccountId:x,mailboxName:b,unreadCount:p,isDraftsMailbox:y,isSpamFolder:h,rescueCandidates:v,onTriageContextChange:j,onRetry:w,filterCategory:N,filterAttributes:I,onSelectFilterCategory:S,onToggleFilterAttribute:k,onClearFilters:C}=mn(),{searchQuery:E,searchInput:R,accounts:M}=Ee(),T=Es(),P=Ce(),Y=b??"Inbox",K=c.useMemo(()=>Zd(),[]),B=c.useMemo(()=>n.map(qg),[n]),{hits:_,isLoading:F}=Xi({mailboxId:e,filterCategory:N}),q=c.useMemo(()=>sl(_,n.map(le=>le.threadId)),[_,n]),te=c.useCallback(le=>P({to:"/mail/$mailboxId",params:{mailboxId:e},search:ve=>({...ve,q:R||void 0,selectedMessageId:le.id,selectedThreadId:le.threadId})}),[e,P,R]);if(y&&x)return s.jsx(_p,{mailboxId:e,accountId:x,selectedMessageId:t,imapThreads:n,title:b??"Drafts",unreadCount:p??void 0});const U=s.jsx(Tx,{mailboxId:e,threads:n,selectedMessageId:t,isLoading:a,isError:r,error:o,onRetry:w,searchQuery:E,onDeleteMessages:i,onMoveMessages:l,isDeleting:u,isMoving:d,onLoadMore:f,hasMore:m,isLoadingMore:g,accountId:x,listTitle:Y,hideHeader:!0,onTriageContextChange:j}),O=M[0]?.accountId,D=T==="phone"&&O?s.jsx(Ox,{accountId:O,children:U}):U,V=h&&v.length>0&&x?s.jsx(Px,{accountId:x,currentMailboxId:e,candidates:v,onMove:l,children:D}):D;return s.jsx(xl,{title:Y,unreadCount:p,preset:K,selectedCategory:N,activeFilters:I,onSelectCategory:S,onToggleFilter:k,onClearFilters:C,searchResults:B,searchLoading:a,relatedResults:q,relatedLoading:F,onSelectSearchResult:te,children:V})}function Xx(){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:g,onToolbarStar:x,onToolbarDiscardDraft:b,onToolbarMove:p,composeState:y,openCompose:h}=mn(),{searchInput:v,onSearchChange:j,onSearchClear:w,onSearchClearQuery:N}=Ee(),S=Es()==="desktop",k=!!a,C=y.isOpen&&!a?s.jsx(yl,{}):a?s.jsx(Zt,{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(Xt,{});return s.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[s.jsx(Sa,{hasThread:k,onCompose:h,intelligenceOpen:o,showIntelligenceToggle:S&&k,onToggleIntelligence:i,searchValue:v,onSearchChange:j,onSearchClear:w,onSearchClearQuery:N,onReply:k?u:void 0,onReplyAll:k?d:void 0,onForward:k?f:void 0,canDelete:k||r,onDelete:k?g:r?b:void 0,onToggleStar:k?x:void 0,isStarred:n?.hasStars,moveContext:k&&t?{accountId:t,currentMailboxId:e,onMove:p}:void 0}),s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:C})]})}function Jx(){const{mailboxId:e,mailboxAccountId:t,selectedThread:n,onToggleIntelligence:a}=mn();return s.jsx(fn,{onClose:a,thread:n,mailboxId:e,accountId:t})}function Zx(){const{mailboxId:e,selectedThread:t,conversation:n,intelligenceOpen:a,onToggleIntelligence:r,onBack:o,nextMessageId:i,previousMessageId:l,composeState:u}=mn(),d=Ce();if(n){const f=m=>d({to:"/mail/$mailboxId",params:{mailboxId:e},search:g=>({...g,selectedMessageId:m,selectedThreadId:void 0})});return s.jsxs(s.Fragment,{children:[s.jsx(Zt,{threadId:n.threadId,mailboxId:n.mailboxId,subject:n.subject,selectedMessageId:n.messageId,authenticity:n.authenticity,onBack:o,onOpenIntelligence:r,onSwipeNext:i?()=>f(i):void 0,onSwipePrevious:l?()=>f(l):void 0,mobileIntelligenceOpen:a}),s.jsx(ha,{isOpen:a,onClose:r,ariaLabel:"Message details",side:"right",children:s.jsx(fn,{onClose:r,thread:t,hideCloseButton:!0})})]})}return u.isOpen?s.jsx("div",{className:"h-full",children:s.jsx(yl,{})}):s.jsx(kl,{})}const cs=Object.assign(Gx,{List:kl,Reading:Xx,Intelligence:Jx,Phone:Zx}),Cl=e=>e==="failed"||e==="blocked",El=e=>e!=="draft"&&e!=="sent",Ea="remit.savedSearches",eb=25;function Xs(){try{const e=localStorage.getItem(Ea);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(n=>typeof n=="string"):[]}catch{return[]}}function tb(e){const t=e.trim();if(!t)return Xs();const n=[t,...Xs().filter(a=>a!==t)].slice(0,eb);try{localStorage.setItem(Ea,JSON.stringify(n))}catch{return n}return n}function sb(e){const t=Xs().filter(n=>n!==e);try{localStorage.setItem(Ea,JSON.stringify(t))}catch{return t}return t}const Hr=e=>/^\d/.test(e),nb=(e,t)=>{const n=Hr(e),a=Hr(t);return n&&!a?-1:!n&&a?1:e.localeCompare(t,void 0,{sensitivity:"base",numeric:!0})};function ab(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)=>nb(Ht(o,void 0,n),Ht(i,void 0,n))),{system:a,labels:r}}function rb(e,t,n){const a=Gc(t)&&e.unseenCount>0;return{id:e.mailboxId,name:Ht(e,t,n),unseen:a?e.unseenCount:void 0,role:t,fullPath:e.fullPath}}function ob(){const e=ma(),t=aa({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 Qr({accounts:e,onMailboxSelect:t,variant:n="desktop"}){const a=je(),r=Ce(),o=ob(),{searchInput:i,onSearchChange:l}=Ee(),[u,d]=c.useState(Xs),{t:f}=tn("mail",{useSuspense:!1}),m=c.useCallback((k,C)=>f(k,{defaultValue:C}),[f]),g=Jt({queries:e.map(k=>({...et({path:{accountId:k.accountId}}),staleTime:1/0}))}),{data:x}=re(Js()),b=c.useMemo(()=>(x?.items??[]).filter(k=>El(k.status)).length,[x?.items]),p=c.useMemo(()=>e.map((k,C)=>{const E=g[C],R=E?.data?.items??[],M=ys(k.folderAppointments),{system:T,labels:P}=ab(R,M,m),Y=E?.isError?"error":E?.isLoading?"loading":"ready";return{id:k.accountId,label:k.email,email:k.email,muted:!!k.muted,outboxPending:b,status:Y,onRetry:()=>E?.refetch(),mailboxes:[...T,...P].map(K=>rb(K,M.get(K.mailboxId),m))}}),[e,g,b,m]),y=k=>{a.invalidateQueries({queryKey:tt({path:{mailboxId:k},query:{order:"desc"}})})},h=({navId:k,className:C,ariaLabel:E,title:R,children:M,onClick:T})=>k==="brief"?s.jsx(Xe,{to:"/mail",search:{q:void 0,selectedMessageId:void 0},onClick:()=>T?.(),className:C,"aria-label":E,title:R,children:M}):k==="outbox"?s.jsx(Xe,{to:"/mail/outbox",search:{q:void 0,selectedOutboxMessageId:void 0},onClick:()=>T?.(),className:C,"aria-label":E,title:R,children:M}):k==="flagged"?s.jsx(Xe,{to:"/mail/flagged",search:{q:void 0,selectedMessageId:void 0},onClick:()=>T?.(),className:C,"aria-label":E,title:R,children:M}):s.jsx(Xe,{to:"/mail/$mailboxId",params:{mailboxId:k},search:{q:void 0,selectedMessageId:void 0},onClick:()=>{y(k),T?.()},className:C,"aria-label":E,title:R,children:M}),v=()=>{t?.()},j=i.trim(),w=j.length>0&&!u.includes(j)?j:void 0,N=c.useCallback(()=>{w&&d(tb(w))},[w]),I=c.useCallback(k=>{d(sb(k))},[]),S=c.useCallback(k=>{l(k),r({to:"/mail",search:{q:k,selectedMessageId:void 0}}),t?.()},[l,r,t]);return s.jsx(cd,{accounts:p,selectedNavId:o,onSelectNav:v,linkComponent:h,variant:n,savedSearches:u,saveableQuery:w,onSaveCurrentSearch:N,onSelectSavedSearch:S,onRemoveSavedSearch:I})}function ib({accounts:e,onMailboxSelect:t}){return ea()?.showNavPane??!0?s.jsx(Qr,{accounts:e}):s.jsxs("div",{className:"flex h-full flex-col",children:[s.jsx("div",{className:"flex-1 overflow-y-auto",children:s.jsx(Qr,{accounts:e,onMailboxSelect:t,variant:"drawer"})}),s.jsxs("div",{className:"border-t border-line px-2 py-2",children:[s.jsxs(Xe,{to:"/settings/accounts",onClick:t,className:"flex w-full items-center gap-2 rounded-md px-2 py-1 text-sm text-fg-muted transition-colors hover:bg-surface hover:text-fg",children:[s.jsx(Do,{className:"size-4 shrink-0"}),s.jsx("span",{className:"flex-1 truncate text-left",children:"Settings"})]}),s.jsx(ml,{variant:"drawer"}),s.jsx(fl,{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(Io,{className:"size-4 shrink-0"}),s.jsx("span",{className:"flex-1 truncate text-left",children:"Sign out"})]})})]})]})}const Il={queued:{icon:ia,label:"Queued",className:"text-warning"},sending:{icon:St,label:"Sending…",className:"text-accent-2"},sent:{icon:So,label:"Sent",className:"text-positive"},failed:{icon:yt,label:"Failed",className:"text-danger"},blocked:{icon:Vn,label:"Blocked",className:"text-warning"}},lb=e=>Yc(e).toDateString()===new Date().toDateString()?Ws(e,{hour:"numeric",minute:"2-digit"}):Ws(e,{month:"short",day:"numeric"}),Wr=e=>Ws(e,{dateStyle:"medium",timeStyle:"short"}),cb=e=>{const t=e.toAddresses??[];return t.length===0?"No recipients":t.length===1?t[0]:`${t[0]} +${t.length-1}`},Rl=c.createContext(null);function Ia(){const e=c.useContext(Rl);if(!e)throw new Error("OutboxPane.* must be used inside <OutboxPane>");return e}function ub({children:e}){const t=Ce(),{selectedOutboxMessageId:n}=Ut({strict:!1}),{data:a,isLoading:r}=re(Js()),o=c.useMemo(()=>(a?.items??[]).filter(d=>El(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(Rl.Provider,{value:u,children:e})}function Ml({message:e,isSelected:t,onSelect:n}){const a=je(),{openCompose:r}=wt(),{pushError:o}=ze(),i=c.useCallback(()=>{a.invalidateQueries({queryKey:na()})},[a]),l=xe({...uo(),onSuccess:i,onError:m=>{o(fs("Couldn't resend message","The message wasn't sent.",m))}}),u=xe({...Zs(),onSuccess:i,onError:m=>{o(fs("Couldn't delete message","The message wasn't deleted.",m))}}),d=e.status;if(!Il[d])return null;const f=Cl(e.status);return s.jsx(zd,{recipients:cb(e),subject:e.subject||"",time:lb(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 Tl({message:e,onBack:t}){const n=e.status,a=Il[n],r=a?.icon??bs,o=e.sentAt?Wr(e.sentAt):Wr(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(wo,{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}),Cl(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(Wi,{html:e.htmlBody,text:e.textBody})})]})}function db(){const{messages:e,isLoading:t,selectedMessageId:n,onSelectMessage:a}=Ia();return t?s.jsx("div",{className:"flex h-full items-center justify-center bg-canvas",children:s.jsx("span",{className:"text-fg-muted",children:"Loading..."})}):e.length===0?s.jsx("div",{className:"flex h-full bg-surface",children:s.jsx(Xt,{message:"No outbox messages",showHints:!1})}):s.jsxs("div",{className:"h-full flex flex-col bg-canvas",children:[s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[s.jsx(Ca,{}),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(Ml,{message:r,isSelected:n===r.outboxMessageId,onSelect:()=>a(r.outboxMessageId)},r.outboxMessageId))})]})}function fb(){const{selectedMessage:e}=Ia();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(Tl,{message:e}):s.jsx(Xt,{message:"Select a message to read",showHints:!1})})]})}function mb(){const{messages:e,isLoading:t,selectedMessageId:n,selectedMessage:a,onSelectMessage:r}=Ia();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(Tl,{message:a,onBack:()=>r(void 0)}):e.length===0?s.jsx("div",{className:"flex h-full bg-surface",children:s.jsx(Xt,{message:"No outbox messages",showHints:!1})}):s.jsxs("div",{className:"h-full flex flex-col bg-canvas",children:[s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[s.jsx(Ca,{}),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(Ml,{message:o,isSelected:n===o.outboxMessageId,onSelect:()=>r(o.outboxMessageId)},o.outboxMessageId))})]})}const Ks=Object.assign(ub,{List:db,Reading:fb,Phone:mb}),hb=({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(De,{className:"size-5"})})]}),s.jsx("div",{className:"grid gap-x-8 gap-y-6 sm:grid-cols-2",children:hl.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(Kt,{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(Kt,{children:"Esc"})," to close"]})})]})]}):null};function gb(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 pb(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 xb(e){const t=Jt({queries:e.map(n=>({...et({path:{accountId:n.accountId}}),staleTime:1/0}))});return c.useMemo(()=>pb(t.map(n=>n.data?.items??[])),[t])}var qs={exports:{}},Vr;function bb(){if(Vr)return qs.exports;Vr=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,g=0;const x=()=>{if(d)return;const b=u.next(),p=g;if(g++,b.done){f=!0,m===0&&r(l);return}m++,Promise.resolve(b.value).then(y=>n(y,p)).then(y=>{l[p]=y,m--,x()},y=>{d=!0,o(y)})};for(let b=0;b<i&&(x(),!f);b++);});return qs.exports=e,qs.exports.default=e,qs.exports}var vb=bb();const yb=Pc(vb),wb=900*1e3,jb=300,Sb=(e,t)=>{if(!e)return t;const n=Number.parseInt(e,10);return Number.isFinite(n)&&n>0?n:t},Qs=Sb(_c().mailboxPollIntervalSeconds,jb)*1e3,Nb=5,Hn=new Set,kb=(e,t,n=wb)=>e.filter(a=>{const r=a.lastSyncAt;return r==null?!0:t-r>n}).map(a=>a.accountId),Cb=(e,t,n=Qs)=>e-t>=n,Eb=(e,t)=>e.filter(n=>!t.has(n)),Yr=(e,t)=>{if(Hn.delete(e),zc(t,{softError:!0})){ho(t);return}console.warn("[remit] background mailbox sync failed",{accountId:e,error:t})},Gr=(e,t)=>Lc({path:{accountId:e},throwOnError:!0}).then(()=>{t.invalidateQueries({queryKey:Vt({path:{accountId:e}})})}),Ib=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=kb(n.current,r).filter(l=>!Hn.has(l));if(i.length!==0)for(const l of i)Hn.add(l),Gr(l,t).catch(u=>{Yr(l,u)})},[a,t]),c.useEffect(()=>{let r=Date.now(),o;const i=new Set,l=()=>{r=Date.now();const f=Eb(n.current.map(m=>m.accountId),i);for(const m of f)i.add(m);yb(f,m=>Gr(m,t).catch(g=>{Yr(m,g)}).finally(()=>{i.delete(m)}),{concurrency:Nb})},u=()=>{if(document.visibilityState==="visible"){l(),o=setTimeout(u,Qs);return}},d=()=>{document.visibilityState==="visible"&&Cb(Date.now(),r)&&(o!==void 0&&clearTimeout(o),l(),o=setTimeout(u,Qs))};return o=setTimeout(u,Qs),document.addEventListener("visibilitychange",d),()=>{o!==void 0&&clearTimeout(o),document.removeEventListener("visibilitychange",d)}},[a,t])},Rb="/mail/",Mb="/mail/outbox",Tb="/mail/flagged";function Db(e){return e.some(t=>t.routeId===Rb)}function Ab(e){return e.some(t=>t.routeId===Tb)}function Ob(e){return e.some(t=>t.routeId===Mb)}function Pb(){const{q:e=""}=Ut({from:"/mail"}),t=Ce(),n=Es(),a=Wg(n),[r,o]=c.useState(!1),[i,l]=c.useState(!1),[u,d]=c.useState(!1),f=c.useCallback(U=>{d(U),Ur(U)},[]),[m,g]=c.useState(e),x=xo(m,200),b=c.useRef(e);b.current=e,c.useEffect(()=>{x!==b.current&&t({to:".",search:U=>{const O=U.q===x;return{...U,q:x||void 0,...x&&!O?{selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0}:{}}},replace:!0})},[x,t]);const{data:p,isLoading:y,isError:h,error:v,refetch:j}=re({...Ze(),staleTime:1/0}),w=!!(p&&(p.accounts?.length??0)===0);c.useEffect(()=>{w&&t({to:"/onboarding",replace:!0})},[w,t]),ps({enabled:!r,bindings:[{key:"?",handler:()=>o(!0),noModifiers:!1,preventDefault:!0}]});const N=c.useCallback(U=>{g(U)},[]),I=c.useCallback(()=>{g("")},[]),S=c.useCallback(()=>{g("")},[]),k=c.useCallback(()=>{d(U=>{const O=!U;return Ur(O),O})},[]),C=p?.accounts??[],E=xb(C),R=c.useMemo(()=>gb(C),[C]),M=Ls({select:U=>U.matches.find(D=>"mailboxId"in D.params)?.params.mailboxId}),{selectedMessageId:T}=Ut({strict:!1}),P=Ls({select:U=>Db(U.matches)}),Y=Ls({select:U=>Ab(U.matches)}),K=Ls({select:U=>Ob(U.matches)});Ib(C);const B=c.useCallback(()=>{l(!1)},[]),_={accounts:C,mailboxNameIndex:E,accountNameIndex:R,searchQuery:x,searchInput:m,onSearchChange:N,onSearchClear:I,onSearchClearQuery:S,intelligenceOpen:u,onToggleIntelligence:k,onSetIntelligenceOpen:f},F=s.jsx(ib,{accounts:C,onMailboxSelect:B}),q=s.jsx(Pm,{}),te={navOpen:i,onOpenNav:()=>l(!0),onCloseNav:()=>l(!1)};return s.jsxs(Fc.Provider,{value:_,children:[h?s.jsx("div",{className:"flex h-full items-center justify-center bg-canvas p-4",children:s.jsx(ft,{title:"Couldn't load your account",error:v,onRetry:()=>{j()}})}):P?s.jsx(Fs,{selectedMessageId:T,children:a?s.jsx(rt,{nav:F,list:s.jsx(Fs.Phone,{}),intelligenceOpen:u,overlay:q,skeleton:s.jsx(Ye,{}),isLoading:y||w,...te}):s.jsx(rt,{nav:F,list:s.jsx(Fs.List,{}),reading:s.jsx(Fs.Reading,{}),intelligenceOpen:u,overlay:q,skeleton:s.jsx(Ye,{}),isLoading:y||w,...te})}):Y?s.jsx(Bs,{selectedMessageId:T,children:a?s.jsx(rt,{nav:F,list:s.jsx(Bs.Phone,{}),intelligenceOpen:u,overlay:q,skeleton:s.jsx(Ye,{}),isLoading:y||w,...te}):s.jsx(rt,{nav:F,list:s.jsx(Bs.List,{}),reading:s.jsx(Bs.Reading,{}),intelligenceOpen:u,overlay:q,skeleton:s.jsx(Ye,{}),isLoading:y||w,...te})}):M?s.jsx(cs,{mailboxId:M,selectedMessageId:T,children:a?s.jsx(rt,{nav:F,list:s.jsx(cs.Phone,{}),intelligenceOpen:u,overlay:q,skeleton:s.jsx(Ye,{}),isLoading:y||w,...te}):s.jsx(rt,{nav:F,list:s.jsx(cs.List,{}),reading:s.jsx(cs.Reading,{}),intelligence:s.jsx(cs.Intelligence,{}),intelligenceOpen:u,overlay:q,skeleton:s.jsx(Ye,{}),isLoading:y||w,...te})}):K?s.jsx(Ks,{children:a?s.jsx(rt,{nav:F,list:s.jsx(Ks.Phone,{}),intelligenceOpen:!1,overlay:q,skeleton:s.jsx(Ye,{}),isLoading:y||w,...te}):s.jsx(rt,{nav:F,list:s.jsx(Ks.List,{}),reading:s.jsx(Ks.Reading,{}),intelligenceOpen:!1,overlay:q,skeleton:s.jsx(Ye,{}),isLoading:y||w,...te})}):s.jsx(Ye,{}),s.jsx(hb,{isOpen:r,onClose:()=>o(!1)}),s.jsx(Bc,{})]})}const Jb=Object.freeze(Object.defineProperty({__proto__:null,component:Pb,useMailContext:Ee},Symbol.toStringTag,{value:"Module"}));export{Xb as S,mu as U,Jb as m};
|