@remit/web-client-dist 0.0.42 → 0.0.44
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-B4ijJFEZ.js → ComposeBody-ByyX2-iG.js} +1 -1
- package/assets/{ErrorState-Bswph0oy.js → ErrorState-BaDfyuf_.js} +1 -1
- package/assets/{OnboardingWizard-Y1hEXYuY.js → OnboardingWizard-D_dyPcK8.js} +1 -1
- package/assets/{account-form-helpers-CcY6x2eu.js → account-form-helpers-h-cr5HUp.js} +1 -1
- package/assets/{accounts-CPMJ-6AS.js → accounts-C5iQ5yGC.js} +1 -1
- package/assets/{advanced-qNrA0Yb1.js → advanced-DZEiKlOp.js} +1 -1
- package/assets/{appearance-CwIJ3qum.js → appearance-DMfof84n.js} +1 -1
- package/assets/{avatar-BYadYgTE.js → avatar-DEojoTYb.js} +1 -1
- package/assets/{browser-ponyfill-DhG_01Ti.js → browser-ponyfill-Bvxu0dic.js} +2 -2
- package/assets/{filter-status-B_VZy2Lu.js → filter-status-g_ItY2BY.js} +1 -1
- package/assets/{filters-I_X0htZY.js → filters-DHFo0JM2.js} +1 -1
- package/assets/{flagged-CQYWUb5R.js → flagged-Lbi7gDRN.js} +1 -1
- package/assets/{folder-role-GVbvlBu2.js → folder-role-Xb44YpPb.js} +1 -1
- package/assets/{folders-CNfWOcYJ.js → folders-D7ikz9Na.js} +1 -1
- package/assets/format-QyUYNmWo.js +1 -0
- package/assets/index-C7hS9hA9.js +1 -0
- package/assets/{index-_JZwCKCZ.js → index-CzrTPifm.js} +4 -4
- package/assets/{index-BSGiGMLi.css → index-aToiseR7.css} +1 -1
- package/assets/{index-BWrmdjib.js → index-eWx4BglZ.js} +1 -1
- package/assets/{kbd-DSga2bAX.js → kbd-CZYCgnXf.js} +1 -1
- package/assets/mail-CTP-NI56.js +112 -0
- package/assets/{onboarding-CK-CG1BV.js → onboarding-Dcmuk5-F.js} +1 -1
- package/assets/{select-Dyme2JFG.js → select-ByKtppny.js} +1 -1
- package/assets/{senders-DEznZN3v.js → senders-BjLD175U.js} +1 -1
- package/assets/settings-Dt0kLYES.js +1 -0
- package/assets/{settings-screen-BWdBP4d_.js → settings-screen-CR6tRiuq.js} +1 -1
- package/assets/{star-BWyt8JPD.js → star-CLsQD1JN.js} +1 -1
- package/assets/{suggested-vips-BLcWm76x.js → suggested-vips-Dg4AyT-l.js} +1 -1
- package/assets/{trash-2-Ch5qvKPw.js → trash-2-DidEGdqy.js} +1 -1
- package/assets/{useDebouncedValue-DLV19KTk.js → useDebouncedValue-M0w63M0E.js} +1 -1
- package/assets/{useMutation-B8_-fD6v.js → useMutation-Dxhol3zw.js} +1 -1
- package/assets/{useSignature-CvVm-cWN.js → useSignature-lyiy8Q1F.js} +1 -1
- package/index.html +2 -2
- package/package.json +1 -1
- package/assets/format-BGdB831k.js +0 -1
- package/assets/index-CZmMgKDv.js +0 -1
- package/assets/mail-BOirpjKk.js +0 -112
- package/assets/settings-DsfuQf4M.js +0 -1
package/assets/mail-BOirpjKk.js
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ComposeBody-B4ijJFEZ.js","assets/index-_JZwCKCZ.js","assets/index-BSGiGMLi.css","assets/folder-roles-XnseeyyD.js","assets/useDebouncedValue-DLV19KTk.js","assets/avatar-BYadYgTE.js","assets/kbd-DSga2bAX.js","assets/star-BWyt8JPD.js","assets/trash-2-Ch5qvKPw.js","assets/account-form-helpers-CcY6x2eu.js","assets/folder-role-GVbvlBu2.js","assets/useMutation-B8_-fD6v.js","assets/useSignature-CvVm-cWN.js","assets/ErrorState-Bswph0oy.js","assets/format-BGdB831k.js","assets/select-Dyme2JFG.js","assets/filter-status-B_VZy2Lu.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{c as re,r as c,j as s,C as pt,X as Ke,a as K,B as V,b as Ue,d as Rt,e as Sc,f as dn,g as xo,I as bo,p as vo,h as ur,i as Nc,D as yo,O as kc,S as Cc,k as Ec,F as dr,l as wo,T as fr,P as Ic,m as Rc,R as mr,n as hr,_ as ft,o as jo,q as Mc,Q as gr,s as Tc,t as Ac,u as Dc,v as Wn,w as Oc,x as Pc,y as je,z as Lc,A as zc,E as Fc,G as _c,H as Bc,J as $c,K as Jr,L as Kc,M as qc,N as Uc,U as So,V as No,W as ko,Y as xt,Z as Me,$ as Ze,a0 as fe,a1 as pr,a2 as xr,a3 as br,a4 as vr,a5 as fn,a6 as ve,a7 as Ms,a8 as ie,a9 as Co,aa as Qc,ab as Eo,ac as Hc,ad as mn,ae as Io,af as at,ag as Qe,ah as Wc,ai as Xe,aj as Ro,ak as Es,al as hn,am as Vc,an as ot,ao as bt,ap as as,aq as gn,ar as Mt,as as Mo,at as Yc,au as Gc,av as Xc,aw as To,ax as B,ay as Zt,az as Jc,aA as yr,aB as Zc,aC as eu,aD as Ao,aE as os,aF as Vn,aG as Yn,aH as tu,aI as Do,aJ as rt,aK as su,aL as wr,aM as nu,aN as ru,aO as au,aP as ou,aQ as iu,aR as lu,aS as cu,aT as uu,aU as du,aV as fu,aW as mu,aX as hu,aY as gu,aZ as ut,a_ as nt,a$ as pu}from"./index-_JZwCKCZ.js";import{b as is,l as es,R as Gn,g as an,s as xu}from"./folder-roles-XnseeyyD.js";import{S as Ts,u as Oo}from"./useDebouncedValue-DLV19KTk.js";import{A as He,M as jr,C as bu}from"./avatar-BYadYgTE.js";import{K as Xt}from"./kbd-DSga2bAX.js";import{S as vt}from"./star-BWyt8JPD.js";import{T as et}from"./trash-2-Ch5qvKPw.js";import{L as Tt,M as Po,a as vu}from"./account-form-helpers-CcY6x2eu.js";import{S as As,F as yu,M as wu,A as ju,a as Lo,p as Su}from"./folder-role-GVbvlBu2.js";import{u as pe}from"./useMutation-B8_-fD6v.js";import{R as Nu,u as ku}from"./useSignature-CvVm-cWN.js";import{E as yt,f as zo}from"./ErrorState-Bswph0oy.js";import{f as Fo,a as wt,b as on,c as Cu,t as Eu}from"./format-BGdB831k.js";import{C as Ds,S as Iu}from"./select-Dyme2JFG.js";import{b as _o,h as Ru,p as Mu,u as Tu}from"./filter-status-B_VZy2Lu.js";const Bo=re("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);const Au=re("ArrowRight",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]);const pn=re("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 Du=re("Ban",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m4.9 4.9 14.2 14.2",key:"1m5liu"}]]);const $o=re("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 Ou=re("BookmarkPlus",[["path",{d:"m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z",key:"1fy3hk"}],["line",{x1:"12",x2:"12",y1:"7",y2:"13",key:"1cppfj"}],["line",{x1:"15",x2:"9",y1:"10",y2:"10",key:"1gty7f"}]]);const Zr=re("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 ts=re("ChevronRight",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]);const Ko=re("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 Sr=re("CircleCheck",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const Nr=re("Clock",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]]);const qo=re("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]);const Uo=re("EllipsisVertical",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]]);const Pu=re("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 Qo=re("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 Ho=re("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 Wo=re("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 Lu=re("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 Os=re("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 zu=re("MailX",[["path",{d:"M22 13V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v12c0 1.1.9 2 2 2h9",key:"1j9vog"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}],["path",{d:"m17 17 4 4",key:"1b3523"}],["path",{d:"m21 17-4 4",key:"uinynz"}]]);const Fu=re("Minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);const xn=re("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 _u=re("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 Vo=re("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 Yo=re("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 Go=re("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 Bu=re("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 Xo=re("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 Ps=re("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 Ls=re("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 $u=re("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 Ku=re("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 Je=re("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 qu=re("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 Uu=re("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"}]]),Qu=({address:e,showTrustedBadge:t=!1})=>{const n=t?s.jsx(pn,{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]})},Hu=({label:e,addresses:t,showTrustedBadge:n=!1})=>{const[r,a]=c.useState(!1);if(t.length===0)return null;const o=t.length>3,i=l=>{const u=n&&l.flags?.trusted?.value===!0;return s.jsx(Qu,{address:l,showTrustedBadge:u})};return s.jsxs("div",{className:"flex gap-2 text-sm",children:[s.jsxs("span",{className:"text-fg-muted shrink-0 w-12",children:[e,":"]}),s.jsx("div",{className:"flex-1 min-w-0",children:r?s.jsx("div",{className:"flex flex-wrap gap-1",children:t.map((l,u)=>s.jsxs("span",{children:[i(l),u<t.length-1&&", "]},u))}):s.jsx("div",{className:"truncate",children:t.map((l,u)=>s.jsxs("span",{children:[i(l),u<t.length-1&&", "]},u))})}),o&&s.jsx("button",{type:"button",onClick:l=>{l.stopPropagation(),a(!r)},className:"shrink-0 text-fg-muted hover:text-fg transition-colors","aria-label":r?"Collapse":"Expand",children:r?s.jsx(pt,{className:"h-4 w-4"}):s.jsx(ts,{className:"h-4 w-4"})})]})},Wu=({email:e,displayName:t,onRemove:n,className:r})=>s.jsxs("span",{className:K("inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-accent-2-soft text-sm max-w-[200px]",r),children:[s.jsx("span",{className:"truncate",children:t||e}),s.jsx("button",{type:"button",onClick:n,className:"shrink-0 p-0.5 rounded-full hover:bg-fg-muted/20 transition-colors","aria-label":`Remove ${e}`,children:s.jsx(Ke,{className:"size-3"})})]}),Vu={unknown:{label:"Unknown sender",tone:"neutral"},wellknown:{label:"Known sender",tone:"positive"},vip:{label:"VIP",tone:"accent"}};function Kt({label:e,children:t,className:n}){return s.jsxs("section",{className:K("border-b border-line px-row-inset py-3",n),children:[s.jsx("h3",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e}),s.jsx("div",{className:"mt-2",children:t})]})}function Yu({sender:e}){const t=Vu[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(He,{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(Ue,{tone:"danger",dot:!0,children:"Address couldn't be verified"}):s.jsx(Ue,{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 Gu({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(Ls,{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($u,{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(Ps,{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(V,{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 qt({icon:e,label:t,active:n,danger:r,onClick:a}){const o=a===void 0;return s.jsxs("button",{type:"button",onClick:a,disabled:o,className:K("flex items-center gap-2 rounded-md border px-2 py-1 text-xs transition-colors",n?"border-accent-2 bg-accent-2-soft text-accent-2":"border-line text-fg-muted hover:border-line-strong hover:text-fg",r&&!n&&"text-danger hover:bg-danger-soft",o&&"cursor-not-allowed opacity-50 hover:border-line"),children:[e,t]})}const Xu={sender:"matched: sender",recipient:"matched: recipient",subject:"matched: subject",attachment:"matched: attachment",body:"matched: body",entities:"matched: entities"};function Jo({data:e,onClose:t,onShowSimilar:n,actions:r,similarState:a="ready",similarLinkComponent:o,className:i,hideCloseButton:l=!1}){const{sender:u,authenticity:d,category:m,flags:f={},similar:h}=e,x=d.verdict==="mismatch";return s.jsxs("aside",{className:K("flex w-76 shrink-0 flex-col overflow-y-auto border-l border-line bg-surface",i),children:[s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center justify-between border-b border-line px-row-inset",children:[s.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"}),!l&&s.jsx(V,{variant:"ghost",size:"sm",icon:s.jsx(Ke,{className:"size-3.5"}),onClick:t,"aria-label":"Collapse intelligence sidebar"})]}),s.jsx(Kt,{label:"Sender",children:s.jsx(Yu,{sender:u})}),s.jsx(Kt,{label:"Authenticity",children:s.jsx(Gu,{auth:d,onShowSimilar:n})}),s.jsx(Kt,{label:"Category",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Ue,{tone:x?"danger":"neutral",children:m.value}),m.overridden&&s.jsx("span",{className:"text-2xs text-fg-subtle",children:"your override"}),s.jsx("button",{type:"button",className:K("ml-auto text-2xs text-accent hover:underline",!r?.onReclassify&&"cursor-not-allowed opacity-50 hover:no-underline"),disabled:!r?.onReclassify,onClick:r?.onReclassify,children:"reclassify"})]})}),s.jsx(Kt,{label:"Quick actions",children:s.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[s.jsx(qt,{icon:s.jsx(vt,{className:"size-3.5"}),label:"VIP",active:f.vip,onClick:r?.onToggleVip}),s.jsx(qt,{icon:s.jsx($o,{className:"size-3.5"}),label:"Mute",active:f.muted,onClick:r?.onToggleMute}),s.jsx(qt,{icon:s.jsx(Du,{className:"size-3.5"}),label:"Block",active:f.blocked,danger:!0,onClick:r?.onToggleBlock}),s.jsx(qt,{icon:s.jsx(zu,{className:"size-3.5"}),label:"Unsubscribe",active:f.unsubscribed,onClick:r?.onToggleUnsubscribe}),r?.onNotSpam&&s.jsx(qt,{icon:s.jsx(Lu,{className:"size-3.5"}),label:"Not spam",onClick:r.onNotSpam}),r?.onMarkSpam&&s.jsx(qt,{icon:s.jsx(Ku,{className:"size-3.5"}),label:"Mark spam",danger:!0,onClick:r.onMarkSpam})]})}),(a!=="ready"||h.length>0)&&s.jsx(Kt,{label:"Similar messages",children:a==="loading"?s.jsx("div",{className:"animate-pulse space-y-2",children:Array.from({length:3}).map((b,p)=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"h-3 w-3/4 rounded bg-surface-sunken"}),s.jsx("div",{className:"h-2.5 w-1/2 rounded bg-surface-sunken"})]},p))}):a==="error"?s.jsx("p",{className:"text-xs text-fg-subtle",children:"Similarity search unavailable"}):s.jsx("ul",{className:"-mx-1 space-y-1",children:h.map(b=>{const p="block w-full rounded-md px-1 py-1 text-left hover:bg-surface-sunken",v=`Open message from ${b.fromName||"unknown sender"}: ${b.subject}`,g=s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[s.jsx("span",{className:"truncate text-xs font-medium text-fg",children:b.fromName}),s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:b.timeLabel})]}),s.jsx("div",{className:"truncate text-xs text-fg-muted",children:b.subject}),s.jsx("span",{className:"mt-1 inline-block rounded-full bg-surface-sunken px-1.5 py-px text-2xs text-fg-subtle",children:Xu[b.matched]})]});return s.jsx("li",{children:o?o({mailboxId:b.mailboxId,messageId:b.id,className:p,ariaLabel:v,children:g}):s.jsx("div",{className:p,children:g})},b.id)})})}),s.jsx(Kt,{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(Je,{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(Je,{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 Ju=[{keys:["j","k"],label:"navigate"},{keys:["m"],label:"mute"},{keys:["?"],label:"all shortcuts"}];function Zo({hints:e=Ju,className:t}){return s.jsx("footer",{className:K("flex items-center gap-2 border-t border-line px-row-inset py-1 text-2xs text-fg-subtle",t),children:e.map(n=>s.jsx(Zu,{hint:n},n.label))})}function Zu({hint:e}){return s.jsxs("span",{className:"flex items-center gap-1",children:[e.keys.map(t=>s.jsx(Xt,{children:t},t)),s.jsx("span",{children:e.label})]})}function ed(){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 td({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 sd({message:e="Something went wrong loading this mailbox.",onRetry:t,onReport:n}){return s.jsx("div",{className:"flex h-full flex-1 items-center justify-center p-4",children:s.jsxs("div",{role:"alert",className:"flex max-w-sm flex-col items-center justify-center gap-3 text-center",children:[s.jsx(Rt,{className:"size-8 text-danger","aria-hidden":"true"}),s.jsxs("div",{children:[s.jsx("p",{className:"font-medium text-danger",children:"Couldn't load messages"}),s.jsx("p",{className:"mt-1 break-words text-sm text-fg-muted",children:e})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[t&&s.jsx(V,{variant:"secondary",size:"sm",onClick:t,children:"Retry"}),n&&s.jsx(V,{variant:"ghost",size:"sm",onClick:n,children:"Report a problem"})]})]})})}const ei=({active:e,focused:t})=>K("relative flex h-8 w-full items-center gap-2 px-row-inset text-left",e?"bg-accent-2-soft":t?"bg-surface-sunken":"hover:bg-surface-sunken",t&&!e&&"before:absolute before:inset-y-0 before:left-0 before:w-0.5 before:bg-accent-2"),ls=({active:e,focused:t})=>K("relative flex w-full items-start gap-3 py-2 pl-5 pr-row-inset text-left transition-colors",e?"bg-accent-2-soft":t?"bg-surface-sunken":"hover:bg-surface-sunken",t&&!e&&"before:absolute before:inset-y-0 before:left-0 before:w-0.5 before:bg-accent-2");function ti({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(Ps,{className:"size-3.5 text-danger"}):e.starred?s.jsx(vt,{className:"size-3 fill-warning text-warning"}):t?s.jsx("span",{className:"size-1.5 rounded-full bg-accent"}):null}),s.jsx("span",{className:K("w-36 shrink-0 truncate text-xs",t?"font-semibold text-fg":"text-fg-muted"),children:e.fromName}),s.jsxs("span",{className:"min-w-0 flex-1 truncate text-xs",children:[s.jsx("span",{className:K(t?"font-medium text-fg":"text-fg-muted"),children:e.subject}),s.jsxs("span",{className:"text-fg-subtle",children:[" — ",e.snippet]})]}),e.hasAttachment&&s.jsx(xn,{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 It({thread:e,badge:t}){const n=!e.isRead;return s.jsxs("span",{className:"min-w-0 flex-1",children:[s.jsxs("span",{className:"flex items-baseline justify-between gap-2",children:[s.jsxs("span",{className:K("flex min-w-0 items-center gap-1.5 truncate text-sm",n?"font-semibold text-fg":"font-medium text-fg-muted"),children:[e.trust==="vip"&&s.jsx("span",{className:"size-1.5 shrink-0 rounded-full bg-accent-2"}),s.jsx("span",{className:"truncate",children:e.fromName}),e.messageCount!=null&&e.messageCount>1&&s.jsx("span",{className:"shrink-0 text-2xs font-normal text-fg-subtle",children:e.messageCount})]}),s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.timeLabel})]}),s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:K("truncate text-sm",n?"text-fg":"text-fg-muted"),children:e.subject}),e.suspicious&&s.jsx(Ps,{className:"size-3.5 shrink-0 text-danger"}),e.starred&&s.jsx(vt,{className:"size-3 shrink-0 fill-warning text-warning"}),e.hasAttachment&&s.jsx(xn,{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(Ue,{tone:Sc[e.category],className:"shrink-0",children:e.category}),t]})]})}function nd({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(He,{name:e.fromName,email:e.fromEmail,size:"sm"}),s.jsx(It,{thread:e})]})}function rd({thread:e,active:t,onClick:n}){return s.jsx("button",{type:"button",onClick:n,className:ei({active:t}),children:s.jsx(ti,{thread:e})})}function si({thread:e,active:t,onClick:n}){return s.jsx("button",{type:"button",onClick:n,className:ls({active:t}),children:s.jsx(nd,{thread:e})})}const ad="peer relative size-5 shrink-0 cursor-pointer appearance-none rounded-md border border-line-strong bg-surface outline-none transition-colors checked:border-positive checked:bg-positive indeterminate:border-positive indeterminate:bg-positive focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-surface",ea="pointer-events-none absolute inset-0 m-auto size-3.5 text-accent-fg";function kr({label:e,description:t,indeterminate:n=!1,checked:r,onChange:a,className:o,...i}){const l=c.useRef(null);c.useEffect(()=>{l.current&&(l.current.indeterminate=n)},[n]);const u=s.jsxs("span",{className:"relative inline-flex",children:[s.jsx("input",{ref:l,type:"checkbox",checked:r,onChange:a,className:ad,...i}),s.jsx(Ds,{className:K(ea,"hidden peer-checked:block"),"aria-hidden":!0}),s.jsx(Fu,{className:K(ea,"hidden peer-indeterminate:block"),"aria-hidden":!0})]});return e===void 0&&t===void 0?s.jsx("span",{className:o,children:u}):s.jsxs("label",{className:K("flex min-h-11 cursor-pointer items-center gap-3 text-left",o),children:[u,s.jsxs("span",{className:"flex min-w-0 flex-col",children:[e!==void 0&&s.jsx("span",{className:"text-sm text-fg",children:e}),t!==void 0&&s.jsx("span",{className:"text-xs text-fg-subtle",children:t})]})]})}const od={info:"bg-accent-2",success:"bg-positive",warning:"bg-warning",danger:"bg-danger"};function id({value:e,max:t,tone:n="info",indeterminate:r=!1,className:a}){const o=r?100:t<=0?0:Math.min(100,Math.max(0,e/t*100));return s.jsx("div",{role:"progressbar","aria-valuenow":r?void 0:e,"aria-valuemin":r?void 0:0,"aria-valuemax":r?void 0:t,className:K("h-1.5 w-full overflow-hidden rounded-full bg-surface-sunken",a),children:s.jsx("div",{className:K("h-full rounded-full transition-[width] duration-300 ease-out",od[n],r&&"w-1/3 animate-pulse"),style:r?void 0:{width:`${o}%`}})})}const ta=e=>e.toLocaleString();function ni({count:e,onCancel:t,onMarkRead:n,onDelete:r,moveSlot:a,isBusy:o=!1,isCounting:i=!1,selectAll:l,statusLabel:u,progress:d,notice:m}){const f=l?.checked?`All ${ta(e)} loaded selected`:`${ta(e)} ${e===1?"message":"messages"} selected`;return s.jsxs("header",{className:"flex shrink-0 flex-col border-b border-line bg-surface-sunken",children:[s.jsxs("div",{className:"flex h-pane-header items-center gap-2 px-row-inset",children:[s.jsx(V,{variant:"ghost",size:"touch",icon:s.jsx(Ke,{className:"size-4"}),onClick:t,"aria-label":"Cancel selection",className:"-ml-2 shrink-0"}),l&&s.jsx("label",{className:"-ml-1.5 flex size-11 shrink-0 cursor-pointer items-center justify-center",children:s.jsx(kr,{"aria-label":"Select all",checked:l.checked,indeterminate:l.indeterminate,onChange:l.onChange})}),s.jsx("span",{className:"min-w-0 flex-1 truncate text-sm font-medium text-fg",role:"status","aria-live":"polite",children:u??f}),n&&!o&&s.jsx(V,{variant:"ghost",size:"touch",icon:s.jsx(Os,{className:"size-4"}),onClick:n,"aria-label":"Mark as read",className:"shrink-0"}),a,!i&&s.jsx(V,{variant:"ghost",size:"touch",icon:o?s.jsx(Tt,{className:"size-4 animate-spin"}):s.jsx(et,{className:"size-4 text-danger"}),onClick:o?void 0:r,"aria-label":"Move selected messages to Trash","aria-busy":o||void 0,className:"ml-4 shrink-0"})]}),d&&s.jsx("div",{className:"px-row-inset pb-2",children:s.jsx(id,{value:d.value,max:d.max,tone:d.tone})}),m&&s.jsx(dn,{tone:m.tone,variant:"soft",role:"status","aria-live":"polite",className:"mx-row-inset mb-2",children:s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[m.text&&s.jsx("span",{children:m.text}),m.action&&s.jsx(V,{variant:"ghost",size:"md",onClick:m.action.onClick,className:"-my-1 min-h-11 shrink-0",children:m.action.label})]})})]})}const ss=72,sa=10;function na(e){return e==="leading"?ss:e==="trailing"?-ss:0}function ld(e){return e>=ss/2?"leading":e<=-ss/2?"trailing":"none"}function ri({thread:e,selectionMode:t,checked:n,active:r,peek:a,onPeek:o,onToggleCheck:i,onLongPress:l,onOpen:u,onAct:d,linkComponent:m}){const f=c.useRef(void 0),h=c.useRef(null),[x,b]=c.useState(null),p=()=>clearTimeout(f.current),v=E=>{h.current={startX:E.clientX,startY:E.clientY,axis:"none",moved:!1},!t&&(f.current=setTimeout(()=>{h.current=null,b(null),l()},500))},g=E=>{if(t)return;const M=h.current;if(!M)return;const I=E.clientX-M.startX,T=E.clientY-M.startY;if(M.axis==="none"){if(Math.abs(T)>sa&&Math.abs(T)>Math.abs(I)){M.axis="vertical",p(),h.current=null;return}Math.abs(I)>sa&&(M.axis="horizontal",M.moved=!0,p(),E.currentTarget.setPointerCapture(E.pointerId))}if(M.axis!=="horizontal")return;const O=na(a),_=Math.max(-ss,Math.min(ss,O+I));b(_)},y=()=>{p();const E=h.current;h.current=null;const M=x;if(b(null),!!E){if(E.axis==="horizontal"&&M!==null){o(ld(M));return}if(t){i();return}if(a!=="none"){o("none");return}m||u()}},j=E=>{a!=="none"&&E.preventDefault()},w=x??na(a),C=w>0?"leading":w<0?"trailing":"none",k=K("relative touch-pan-y bg-surface",ls({active:n||r})),S={transform:w!==0?`translateX(${w}px)`:void 0,transition:x===null?"transform 150ms ease":"none",minHeight:44},N=!e.isRead,R=E=>E.stopPropagation(),A=t?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:K("inline-flex size-7 shrink-0 items-center justify-center rounded-full border",n?"border-accent bg-accent text-accent-fg":"border-line-strong bg-canvas"),children:n&&s.jsx(Ds,{className:"size-3.5"})}),s.jsx(It,{thread:e})]}):s.jsxs(s.Fragment,{children:[N&&s.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),s.jsx("button",{type:"button",role:"checkbox","aria-checked":n,"aria-label":`Select message from ${e.fromName}`,onPointerDown:R,onPointerMove:R,onPointerUp:R,onClick:E=>{E.preventDefault(),E.stopPropagation(),l()},className:"inline-flex size-7 shrink-0 items-center justify-center rounded-full",children:s.jsx(He,{name:e.fromName,email:e.fromEmail,size:"sm"})}),s.jsx(It,{thread:e})]});return s.jsxs("div",{className:"relative overflow-hidden",children:[C==="leading"&&s.jsx("button",{type:"button",onClick:()=>d("leading"),"aria-label":e.isRead?"Mark as unread":"Mark as read",className:"absolute inset-y-0 left-0 flex items-center justify-start bg-accent-2 px-6 text-accent-fg",children:e.isRead?s.jsx(Po,{className:"size-6"}):s.jsx(Os,{className:"size-6"})}),C==="trailing"&&s.jsx("button",{type:"button",onClick:()=>d("trailing"),"aria-label":"Delete message",className:"absolute inset-y-0 right-0 flex items-center justify-end bg-danger px-6 text-canvas",children:s.jsx(et,{className:"size-6"})}),m&&!t?m({className:k,style:S,onPointerDown:v,onPointerMove:g,onPointerUp:y,onPointerCancel:y,onOpenClick:j,children:A}):s.jsx("button",{type:"button",role:t?"checkbox":void 0,"aria-checked":t?n:void 0,onPointerDown:v,onPointerMove:g,onPointerUp:y,onPointerCancel:y,className:k,style:S,children:A})]})}function cd({sections:e,selectedThreadId:t,selectionMode:n,checkedIds:r,initialPeek:a,onToggleCheck:o,onEnterSelection:i,onOpenThread:l,onRefresh:u,refreshing:d,busy:m=!1}){const[f,h]=c.useState(()=>e.flatMap(v=>v.threads)),[x,b]=c.useState(a&&a!=="none"&&f[1]?{id:f[1].id,side:a}:null),p=(v,g)=>{h(g==="trailing"?y=>y.filter(j=>j.id!==v):y=>y.map(j=>j.id===v?{...j,isRead:!j.isRead}:j)),b(null)};return s.jsxs("div",{className:"flex-1 overflow-y-auto",children:[d&&s.jsxs("div",{className:"flex items-center justify-center gap-2 border-b border-line py-3 text-fg-muted",children:[s.jsx(Vo,{className:"size-4 animate-spin"}),s.jsx("span",{className:"text-xs",children:"Checking for new mail…"})]}),s.jsx("div",{className:"divide-y divide-line",children:f.map(v=>s.jsx("div",{className:m?"pointer-events-none opacity-50":void 0,children:s.jsx(ri,{thread:v,selectionMode:n,checked:r.has(v.id),active:v.id===t,peek:x?.id===v.id?x.side:"none",onPeek:g=>b(g==="none"?null:{id:v.id,side:g}),onToggleCheck:()=>o(v.id),onLongPress:()=>i(v.id),onOpen:()=>l(v.id),onAct:g=>p(v.id,g)})},v.id))}),!n&&!d&&!m&&s.jsx("button",{type:"button",onClick:u,className:"w-full border-t border-line py-2 text-center text-2xs text-fg-subtle transition-colors hover:bg-surface-sunken",children:"Pull to refresh"})]})}function ai({listTitle:e,listMeta:t,sections:n,briefFilters:r,flatList:a,listState:o="ready",searchQuery:i,errorMessage:l,onRetry:u,onReportError:d,briefCategory:m,selectedThreadId:f,density:h="comfortable",onSelectThread:x,onSelectBriefCategory:b,onOpenNav:p,isDesktop:v,initialTouchState:g,selectionBar:y,listBody:j,hideHeader:w=!1}){const C=h==="compact"?rd:si,k=!v&&!r&&o==="ready",S=n.flatMap($=>$.threads),[N,R]=c.useState(g==="selection"),[A,E]=c.useState(()=>g==="selection"?new Set(S.slice(0,2).map($=>$.id)):new Set),[M,I]=c.useState(!1),T=g==="peek-trailing"?"trailing":g==="peek-leading"?"leading":void 0,O=$=>{E(ae=>{const ce=new Set(ae);return ce.has($)?ce.delete($):ce.add($),ce.size===0&&R(!1),ce})},_=$=>{R(!0),E(new Set([$]))},q=()=>{R(!1),E(new Set)},X=()=>{I(!0),setTimeout(()=>I(!1),1400)},F=!y&&k&&N&&A.size>0;return s.jsxs("section",{className:"flex h-full w-full flex-col bg-surface",children:[y??(F?s.jsx(ni,{count:A.size,onCancel:q,onMarkRead:q,onDelete:q}):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(V,{variant:"ghost",size:"sm",icon:s.jsx(jr,{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(ed,{})}):o==="empty"?s.jsx(td,{searchQuery:i}):o==="error"?s.jsx(sd,{message:l,onRetry:u,onReport:d}):r?s.jsx(xo,{sections:n,briefCategory:m,selectedThreadId:f,Row:C,onSelectThread:x,onSelectBriefCategory:b}):j??(k?s.jsx(cd,{sections:n,selectedThreadId:f,selectionMode:N,checkedIds:A,initialPeek:T,onToggleCheck:O,onEnterSelection:_,onOpenThread:$=>x?.($),onRefresh:X,refreshing:M}):s.jsx("div",{className:"flex-1 overflow-y-auto",children:n.map($=>s.jsxs("div",{children:[!a&&$.label&&s.jsxs("div",{className:"sticky top-0 flex h-section-row items-center justify-between border-b border-line bg-surface-sunken px-row-inset",children:[s.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:$.label}),s.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:$.threads.length})]}),s.jsx("div",{className:"divide-y divide-line",children:$.threads.map(ae=>s.jsx(C,{thread:ae,active:ae.id===f,onClick:()=>x?.(ae.id)},ae.id))})]},$.id))})),v&&s.jsx(Zo,{})]})}function ud({triggerLabel:e,triggerIcon:t,items:n,align:r="end",touch:a=!0,className:o}){const[i,l]=c.useState(!1),u=c.useRef(null);return c.useEffect(()=>{if(!i)return;const d=f=>{u.current&&!u.current.contains(f.target)&&l(!1)},m=f=>{f.key==="Escape"&&l(!1)};return document.addEventListener("mousedown",d),document.addEventListener("keydown",m),()=>{document.removeEventListener("mousedown",d),document.removeEventListener("keydown",m)}},[i]),n.length===0?null:s.jsxs("div",{ref:u,className:K("relative",o),children:[s.jsx(V,{variant:"ghost",size:"sm",icon:t??s.jsx(Uo,{className:"size-5"}),onClick:()=>l(d=>!d),"aria-label":e,"aria-haspopup":"menu","aria-expanded":i,className:K(a&&"min-h-11 min-w-11 px-0")}),i&&s.jsx("div",{role:"menu",className:K("absolute top-full z-50 mt-1 flex min-w-44 flex-col rounded-md border border-line bg-surface py-1 shadow-lg",r==="end"?"right-0":"left-0"),children:n.map(d=>s.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{l(!1),d.onSelect()},className:"flex min-h-11 items-center gap-3 px-4 py-2.5 text-left text-sm text-fg transition-colors hover:bg-surface-sunken",children:[d.icon&&s.jsx("span",{className:"shrink-0 text-fg-subtle",children:d.icon}),d.label]},d.key))})]})}const ps="min-h-11 min-w-11 px-0";function oi({hasThread:e,onReply:t,onReplyAll:n,onForward:r,isStarred:a,onToggleStar:o,onDelete:i,isRead:l,onToggleRead:u,moveSlot:d,overflowItems:m=[],onUnavailable:f,unavailableHint:h,className:x}){const b=(v,g)=>()=>{if(!e){f?.(v);return}g?.()},p=u?[{key:"toggle-read",label:l?"Mark as unread":"Mark as read",icon:l?s.jsx(Po,{className:"size-4"}):s.jsx(Os,{className:"size-4"}),onSelect:b("toggleRead",u)}]:[];return s.jsxs("div",{className:K("relative",x),children:[s.jsxs("div",{className:"flex h-12 shrink-0 items-center gap-0.5 border-y border-line bg-canvas px-1",children:[s.jsx(V,{variant:"ghost",size:"sm",icon:s.jsx(Go,{className:"size-5"}),onClick:b("reply",t),"aria-label":"Reply",title:"Reply",className:ps}),s.jsx(V,{variant:"ghost",size:"sm",icon:s.jsx(Yo,{className:"size-5"}),onClick:b("replyAll",n),"aria-label":"Reply all",title:"Reply all",className:ps}),s.jsx(V,{variant:"ghost",size:"sm",icon:s.jsx(Ho,{className:"size-5"}),onClick:b("forward",r),"aria-label":"Forward",title:"Forward",className:ps}),s.jsx("div",{className:"flex-1"}),s.jsx(V,{variant:"ghost",size:"sm",icon:s.jsx(vt,{className:K("size-5",a&&"fill-warning text-warning")}),onClick:b("star",o),"aria-label":a?"Unstar":"Star","aria-pressed":a,title:a?"Unstar":"Star",className:ps}),d,s.jsx(V,{variant:"ghost",size:"sm",icon:s.jsx(et,{className:"size-5"}),onClick:b("delete",i),"aria-label":"Move to Trash",title:"Move to Trash",className:ps}),s.jsx(ud,{triggerLabel:"More actions",items:[...p,...m]})]}),!e&&h&&s.jsx("p",{role:"status",className:"border-b border-line bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:h})]})}function dd({open:e=!1,enabled:t=!0,onToggle:n,className:r}){return s.jsx(V,{variant:"ghost",size:"sm",icon:s.jsx(bo,{className:"size-4"}),title:"Intelligence","aria-label":e?"Hide intelligence sidebar":"Show intelligence sidebar","aria-pressed":e,disabled:!t,onClick:n,className:K(e&&"bg-accent-2-soft text-accent-2",r)})}function fd({hasThread:e,onUnavailable:t,unavailableHint:n,isStarred:r,showTriage:a=!0,onReply:o,onReplyAll:i,onForward:l,onDelete:u,onToggleStar:d,moveSlot:m,onMove:f,replyTitle:h="Reply (r)",replyAllTitle:x="Reply all (a)",forwardTitle:b="Forward (f)",deleteTitle:p="Move to Trash (#)",flagTitle:v="Star (s)",children:g,className:y}){const j=(w,C)=>()=>{if(!e){t?.(w);return}C?.()};return s.jsxs("div",{className:"relative",children:[s.jsxs("header",{className:K("flex h-pane-header shrink-0 items-center gap-1 border-b border-line bg-surface px-3",y),children:[s.jsx(V,{variant:"ghost",size:"sm",icon:s.jsx(Go,{className:"size-4"}),title:h,"aria-label":"Reply",onClick:j("reply",o)}),s.jsx(V,{variant:"ghost",size:"sm",icon:s.jsx(Yo,{className:"size-4"}),title:x,"aria-label":"Reply all",onClick:j("replyAll",i)}),s.jsx(V,{variant:"ghost",size:"sm",icon:s.jsx(Ho,{className:"size-4"}),title:b,"aria-label":"Forward",onClick:j("forward",l)}),a&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"mx-1 h-4 w-px bg-line","aria-hidden":!0}),s.jsx(V,{variant:"ghost",size:"sm",icon:s.jsx(et,{className:"size-4"}),title:p,"aria-label":"Move to Trash",onClick:j("delete",u)}),m??s.jsx(V,{variant:"ghost",size:"sm",icon:s.jsx(Qo,{className:"size-4"}),title:"Move to mailbox","aria-label":"Move to mailbox",onClick:j("move",f)}),s.jsx(V,{variant:"ghost",size:"sm",icon:s.jsx(vt,{className:K("size-4",r&&"fill-warning text-warning")}),title:v,"aria-label":"Star",onClick:j("flag",d)})]}),s.jsx("div",{className:"flex-1"}),g]}),!e&&n&&s.jsx("p",{role:"status",className:"border-b border-line bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:n})]})}const md=(e,t)=>{const r=e==="newsletter"||e==="marketing"||t;return{framed:r,isPlain:!r}},hd=()=>`
|
|
3
|
-
/* Zero the UA default body margin and clamp the document to the iframe width so
|
|
4
|
-
wide author markup can't push the body (and the page) past the viewport. */
|
|
5
|
-
html, body {
|
|
6
|
-
margin: 0;
|
|
7
|
-
padding: 0;
|
|
8
|
-
max-width: 100%;
|
|
9
|
-
}
|
|
10
|
-
body {
|
|
11
|
-
overflow-wrap: anywhere;
|
|
12
|
-
word-break: break-word;
|
|
13
|
-
}
|
|
14
|
-
/* Media never wider than the frame; keep aspect ratio when width is capped. */
|
|
15
|
-
img, video, iframe, svg, canvas {
|
|
16
|
-
max-width: 100% !important;
|
|
17
|
-
height: auto;
|
|
18
|
-
}
|
|
19
|
-
/* Fixed-width author tables (\`<table width="600">\`) collapse to fit. */
|
|
20
|
-
table {
|
|
21
|
-
max-width: 100% !important;
|
|
22
|
-
table-layout: auto;
|
|
23
|
-
}
|
|
24
|
-
/* Cells carry the fixed widths in real newsletters (\`<td width="600">\`);
|
|
25
|
-
cap them too or the table can't actually shrink. */
|
|
26
|
-
td, th {
|
|
27
|
-
max-width: 100% !important;
|
|
28
|
-
}
|
|
29
|
-
/* \`max-width\` alone can't beat an inline \`min-width\`; zeroing the min lets
|
|
30
|
-
flex / grid / table children actually collapse to the clamped width. */
|
|
31
|
-
* {
|
|
32
|
-
min-width: 0;
|
|
33
|
-
}
|
|
34
|
-
/* Long unbroken strings (URLs, tokens) wrap instead of forcing a wide line. */
|
|
35
|
-
pre, code {
|
|
36
|
-
white-space: pre-wrap;
|
|
37
|
-
overflow-wrap: anywhere;
|
|
38
|
-
word-break: break-word;
|
|
39
|
-
}
|
|
40
|
-
`,gd=e=>{const t=new Map;for(const n of e){if(!n.contentId||n.contentUrl.length===0)continue;const r=n.contentId.replace(/^<|>$/g,"");t.set(r,n.contentUrl)}return n=>t.get(n.replace(/^<|>$/g,""))},pd=/^(none|transparent|inherit|initial|unset)\s*$/i,xd=e=>{const t=[],n=/<style[^>]*>([\s\S]*?)<\/style>/gi;let r;for(r=n.exec(e);r!==null;)t.push(r[1]),r=n.exec(e);return t},bd=e=>{const t=/background(?:-color)?\s*:\s*([^;}\n]+)/gi;let n;for(n=t.exec(e);n!==null;){const r=n[1].trim();if(!pd.test(r))return!0;n=t.exec(e)}return!1},vd=e=>{if(/\bstyle\s*=\s*["'][^"']*background/i.test(e)||/\bbgcolor\s*=/i.test(e))return!0;for(const t of xd(e))if(bd(t))return!0;return!1},yd=["script","iframe","object","embed","form","input","button","textarea","select","meta","link","base"],wd=["onerror","onload","onclick","onmouseover","onmouseout","onfocus","onblur","onsubmit","onkeydown","onkeyup","formaction","xlink:href","data-bind"],jd="data:image/svg+xml,"+encodeURIComponent(`
|
|
41
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100">
|
|
42
|
-
<rect fill="#f0f0f0" width="100" height="100"/>
|
|
43
|
-
<text x="50" y="50" text-anchor="middle" dy=".3em" fill="#999" font-size="12">
|
|
44
|
-
Image blocked
|
|
45
|
-
</text>
|
|
46
|
-
</svg>
|
|
47
|
-
`),Sd=e=>e.replace(/url\s*\([^)]*\)/gi,"none").replace(/expression\s*\([^)]*\)/gi,"").replace(/-moz-binding\s*:[^;]*/gi,""),Nd=e=>e.replace(/@import[^;]*;/gi,"/* @import blocked */").replace(/url\s*\([^)]*\)/gi,"none").replace(/expression\s*\([^)]*\)/gi,"").replace(/-moz-binding\s*:[^;]*/gi,""),kd=(e={})=>{const t=vo(),n={FORBID_TAGS:yd,FORBID_ATTR:wd,ALLOW_DATA_ATTR:!1,ALLOW_UNKNOWN_PROTOCOLS:!1};return t.addHook("afterSanitizeAttributes",r=>{if(r.tagName==="IMG"){const a=r.getAttribute("src")||"";if(a.startsWith("data:"))return;if(a.startsWith("cid:")){const i=a.slice(4).replace(/^<|>$/g,""),l=e.resolveCid?.(i);l&&(r.setAttribute("src",l),r.classList.add("inline-content"));return}e.allowExternalImages||(r.setAttribute("data-blocked-src",a),r.setAttribute("src",jd),r.setAttribute("alt","[Blocked image]"),r.classList.add("blocked-image"))}if(r.tagName==="A"){const a=r.getAttribute("href")||"";if(/^(javascript|data):/i.test(a)){r.removeAttribute("href");return}r.setAttribute("target","_blank"),r.setAttribute("rel","noopener noreferrer nofollow"),r.classList.add("external-link")}if(r.hasAttribute("style")){const a=r.getAttribute("style")||"";r.setAttribute("style",Sd(a))}}),t.addHook("uponSanitizeElement",(r,a)=>{if(a.tagName==="style"){const o=r.textContent||"";r.textContent=Nd(o)}}),r=>{const a=vd(r),o=t.sanitize(r,n);return{html:`<style>${hd()}</style>${o}`,hasAuthorBackground:a}}},Cd='"Geist Variable", "Geist", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',ra={light:{fg:"oklch(0.3 0.025 235)",surface:"oklch(0.975 0.012 90)",accent:"oklch(0.55 0.14 150)"},dark:{fg:"oklch(0.88 0.02 90)",surface:"oklch(0.25 0.025 220)",accent:"oklch(0.78 0.16 150)"}},Ed=/prefers-color-scheme\s*:\s*dark|color-scheme\s*:\s*[^;}"']*\bdark\b/i,aa='<meta name="viewport" content="width=device-width, initial-scale=1">',Id=e=>{const t=e?ra.dark:ra.light;return`
|
|
48
|
-
/* Plain-email base: UI font-stack + theme-aware colors (#424) */
|
|
49
|
-
html, body {
|
|
50
|
-
font-family: ${Cd};
|
|
51
|
-
font-size: 14px;
|
|
52
|
-
line-height: 1.6;
|
|
53
|
-
color: ${t.fg};
|
|
54
|
-
background-color: ${t.surface};
|
|
55
|
-
margin: 0;
|
|
56
|
-
padding: 0;
|
|
57
|
-
}
|
|
58
|
-
/* Strip author unreadable text colors and element backgrounds, scoped to body
|
|
59
|
-
descendants so the themed html/body surface above survives this reset. */
|
|
60
|
-
body * {
|
|
61
|
-
color: inherit !important;
|
|
62
|
-
background-color: transparent !important;
|
|
63
|
-
}
|
|
64
|
-
a, a:visited {
|
|
65
|
-
color: ${t.accent} !important;
|
|
66
|
-
text-decoration: underline;
|
|
67
|
-
}
|
|
68
|
-
`},Rd=(e,t)=>e?t?"html,body{margin:0;color-scheme:dark light}":"html{margin:0;background-color:#ffffff;filter:invert(0.92) hue-rotate(180deg)}body{margin:0}img,picture,video,svg,canvas,[style*='background-image'],[background]{filter:invert(0.92) hue-rotate(180deg)}":"html,body{margin:0;background-color:#ffffff;color-scheme:light}",Md=(e,t,n)=>{if(t==="plain")return`${aa}<style>${Id(n)}</style>${e}`;const r=Ed.test(e);return`${aa}<style>${Rd(n,r)}</style>${e}`},Td=5e4,Ad=1e4,Dd="(max-width: 640px)",Od=.4,Pd="allow-same-origin allow-popups allow-popups-to-escape-sandbox",oa=(e,t,n)=>Math.min(Math.ceil(Math.max(e,t)),n),Ld=(e,t)=>e<=0||t<=0||e<=t?1:Math.max(Od,t/e),zd=e=>{const[t,n]=c.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return c.useEffect(()=>{if(typeof window>"u"||!window.matchMedia)return;const r=window.matchMedia(e);n(r.matches);const a=o=>n(o.matches);return r.addEventListener("change",a),()=>r.removeEventListener("change",a)},[e]),t},Fd=new Set(["Enter","Escape","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End"]),_d=e=>e===" "?!1:e.length===1?!0:Fd.has(e),ia=e=>{if(e.metaKey||e.ctrlKey||e.altKey||!_d(e.key))return;const t=e.currentTarget??e.target,n=t?.defaultView?.parent;!n||n===t?.defaultView||n.dispatchEvent(new KeyboardEvent("keydown",{key:e.key,code:e.code,shiftKey:e.shiftKey,bubbles:!0,cancelable:!0}))},la=({html:e,variant:t="framed",isDark:n=!1,className:r})=>{const a=c.useRef(null),o=c.useRef(null),[i,l]=c.useState(0),[u,d]=c.useState(0),[m,f]=c.useState(0),h=zd(Dd),x=c.useMemo(()=>Md(e,t,n),[e,t,n]);c.useEffect(()=>{const j=a.current;if(!j)return;const w=()=>f(k=>k===j.clientWidth?k:j.clientWidth);w();const C=new ResizeObserver(w);return C.observe(j),()=>C.disconnect()},[]),c.useEffect(()=>{const j=o.current;if(!j)return;const w=()=>{const N=j.contentDocument;if(!N?.body)return;const R=N.documentElement,A=oa(N.body.scrollHeight,R?.scrollHeight??0,Td);l(M=>M===A?M:A);const E=oa(N.body.scrollWidth,R?.scrollWidth??0,Ad);d(M=>M===E?M:E)};let C,k;const S=()=>{w();const N=j.contentDocument;N?.body&&(C=new ResizeObserver(w),C.observe(N.body),N.documentElement&&C.observe(N.documentElement),N.addEventListener("keydown",ia),k=N)};return j.addEventListener("load",S),()=>{j.removeEventListener("load",S),k?.removeEventListener("keydown",ia),C?.disconnect()}},[]);const b=h?Ld(u,m):1,p=b<1,v=p?`${u}px`:h?"100%":t==="framed"&&u>0?`max(100%, ${u}px)`:u===0?"100%":`${u}px`,g=i===0?"1px":`${i}px`,y=s.jsx("iframe",{ref:o,title:"Email content",sandbox:Pd,srcDoc:x,className:p?void 0:r,scrolling:"no",style:{width:v,maxWidth:p?"none":void 0,border:"none",display:"block",height:g,overflow:"hidden",transform:p?`scale(${b})`:void 0,transformOrigin:p?"top left":void 0,colorScheme:"normal"}});return s.jsx("div",{ref:a,className:p?r:void 0,children:p?s.jsx("div",{style:{width:"100%",height:`${Math.ceil(i*b)}px`,overflow:"hidden"},children:y}):y})},ca=()=>s.jsx("p",{className:"text-fg-muted text-sm italic",children:"This message has no body content."}),ii=({html:e,text:t,isDark:n=!1,category:r,allowImages:a=!1,resolveCid:o,className:i,renderBlockedNotice:l})=>{const u=c.useMemo(()=>!e||typeof document>"u"?null:kd({allowExternalImages:a,resolveCid:o})(e),[e,a,o]),d=u?.html??null,{framed:m,isPlain:f}=md(r,u?.hasAuthorBackground??!1),h=c.useMemo(()=>!d||a?0:(d.match(/data-blocked-src/g)||[]).length,[d,a]);return!d&&!t?s.jsx("div",{className:K("message-body",i),children:s.jsx(ca,{})}):s.jsxs("div",{className:K("message-body",i),children:[h>0&&l?.(h),d?m?s.jsx("div",{className:"w-full max-w-full overflow-x-auto",children:s.jsx(la,{html:d,variant:"framed",isDark:n})}):s.jsx("div",{className:"max-w-full overflow-x-auto lg:max-w-2xl",children:s.jsx(la,{html:d,variant:f?"plain":"framed",isDark:n})}):t?s.jsx("pre",{className:"email-text whitespace-pre-wrap text-sm leading-relaxed",children:t}):s.jsx(ca,{})]})};function cs({message:e="Select a thread to read",icon:t,showHints:n=!0,className:r}){return s.jsxs("div",{className:K("flex flex-1 flex-col items-center justify-center text-center",r),children:[t??s.jsx(ur,{className:"size-10 text-fg-subtle"}),s.jsx("p",{className:"mt-3 text-sm text-fg-muted",children:e}),n&&s.jsxs("p",{className:"text-2xs text-fg-subtle",children:[s.jsx(Xt,{children:"j"})," / ",s.jsx(Xt,{children:"k"})," to move, ",s.jsx(Xt,{children:"Enter"})," to open"]})]})}function li({message:e,onClick:t,isFocused:n,isUnread:r,trailing:a}){const o=s.jsxs(s.Fragment,{children:[s.jsx(ts,{className:"size-3.5 shrink-0 text-fg-subtle"}),s.jsxs("div",{className:"relative shrink-0",children:[s.jsx(He,{name:e.fromName,email:e.fromEmail,size:"md"}),r&&s.jsx("span",{className:"absolute -top-0.5 -right-0.5 size-2 rounded-full border border-canvas bg-accent"})]}),s.jsx("span",{className:K("w-36 shrink-0 truncate text-sm",r?"font-semibold text-fg":"font-medium text-fg-muted"),children:e.fromName}),s.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-fg-subtle",children:e.snippet}),a??s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.dateLabel})]}),i=K("group flex h-section-row w-full items-center gap-3 border-b border-line px-2 text-left transition-colors hover:bg-surface-sunken lg:px-4",n&&"bg-surface-sunken ring-1 ring-inset ring-accent/30");return t?s.jsx("div",{role:"button",tabIndex:0,"aria-expanded":!1,onClick:t,onKeyDown:l=>{Nc(l)&&(l.preventDefault(),t())},className:K(i,"cursor-pointer"),children:o}):s.jsx("div",{className:i,children:o})}function ci({message:e,warning:t,onHeaderClick:n,isFocused:r,senderBadge:a,trailing:o,to:i,indicators:l,actionMenu:u,actionBar:d,body:m}){const f=s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[s.jsxs("span",{className:"text-sm font-semibold text-fg",children:[e.fromName,a]}),o??s.jsx("span",{className:"text-2xs text-fg-subtle",children:e.dateLabel})]}),s.jsx("div",{className:"text-xs text-fg-subtle",children:e.fromEmail}),i!==null&&s.jsx("div",{className:"text-xs text-fg-subtle",children:i??s.jsxs(s.Fragment,{children:["to ",e.toLabel]})})]});return s.jsxs("div",{className:K("px-2 py-3 lg:px-4",r&&"ring-1 ring-inset ring-accent/30"),children:[s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx(pt,{className:"mt-1 size-3.5 shrink-0 text-fg-subtle"}),s.jsx(He,{name:e.fromName,email:e.fromEmail,size:"md"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[n?s.jsx("button",{type:"button",onClick:n,className:"w-full text-left",children:f}):f,l]}),u&&s.jsx("div",{className:"shrink-0",children:u})]}),t&&s.jsxs("div",{className:"mt-3 flex items-start gap-3 rounded-md bg-danger-soft p-3",children:[s.jsx(Ps,{className:"mt-0.5 size-4 shrink-0 text-danger"}),s.jsxs("div",{className:"text-sm text-fg",children:[s.jsx("span",{className:"font-semibold text-danger",children:"Caution: "}),t," ",s.jsx("button",{type:"button",className:"text-accent underline",children:"Why?"})]})]}),d&&s.jsx("div",{className:"mt-3 -mx-2 lg:-mx-4",children:d}),m??s.jsx(ii,{className:"mt-3",html:e.bodyHtml,category:e.framed?"newsletter":"personal",allowImages:!0})]})}function Bd({thread:e,onBack:t,intelligence:n,intelligenceOpen:r,onToggleIntelligence:a,actions:o,children:i,touchHandlers:l}){const[u,d]=c.useState(!1),m=a!==void 0,f=m?r??!1:u,h=!!n||m,x=()=>{if(m){a?.();return}d(p=>!p)},b=()=>{if(m){f&&a?.();return}d(!1)};return s.jsxs("article",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line bg-surface px-row-inset",children:[s.jsx(V,{variant:"ghost",size:"sm",icon:s.jsx(Bo,{className:"size-4"}),onClick:t,"aria-label":"Back to messages",className:"-ml-1 shrink-0"}),s.jsx("h2",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e.subject}),h&&s.jsx(V,{variant:"ghost",size:"sm",icon:s.jsx(bo,{className:"size-4"}),onClick:x,"aria-label":f?"Hide intelligence panel":"Show intelligence panel","aria-pressed":f,title:"Intelligence",className:K("shrink-0",f&&"bg-accent-2-soft text-accent-2")})]}),s.jsx("div",{className:"flex-1 overflow-y-auto",style:l?{touchAction:"pan-y"}:void 0,...l,children:i??e.messages.map(p=>{const v=g=>g?()=>g(p.id):void 0;return p.expanded?s.jsx(ci,{message:p,warning:e.warning,onHeaderClick:v(o?.onToggleExpand),actionBar:s.jsx(oi,{hasThread:!0,onReply:v(o?.onReply),onReplyAll:v(o?.onReplyAll),onForward:v(o?.onForward),onToggleStar:v(o?.onToggleStar),onDelete:v(o?.onDelete),onToggleRead:v(o?.onToggleRead),moveSlot:o?.moveSlot?.(p.id)})},p.id):s.jsx(li,{message:p,onClick:v(o?.onToggleExpand)},p.id)})}),n&&!m&&s.jsx(yo,{open:f,onClose:b,title:"Intelligence",anchor:"right",className:"p-0",children:s.jsx(Jo,{data:n,onClose:b,className:"h-full w-full border-l-0"})})]})}function $d({active:e,dimmed:t,indent:n}){return K("flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-sm transition-colors",n&&"pl-7",e?"bg-accent-2-soft font-medium text-accent-2":"text-fg-muted hover:bg-surface hover:text-fg",t&&"opacity-55")}function Kd({icon:e,label:t,count:n,active:r}){return s.jsxs(s.Fragment,{children:[e&&s.jsx("span",{className:K("shrink-0",r?"text-accent-2":"text-fg-subtle"),children:e}),s.jsx("span",{className:"flex-1 truncate",children:t}),n!=null&&n>0&&s.jsx("span",{className:K("text-2xs tabular-nums",r?"text-accent-2":"text-fg-subtle"),children:n})]})}function ks({icon:e,label:t,count:n,active:r,dimmed:a,indent:o,navId:i,linkComponent:l,ariaLabel:u,title:d,onClick:m}){const f=$d({active:r,dimmed:a,indent:o}),h=s.jsx(Kd,{icon:e,label:t,count:n,active:r});return i&&l?l({navId:i,className:f,ariaLabel:u??t,title:d,onClick:m,children:h}):s.jsx("button",{type:"button",onClick:m,className:f,"aria-label":u,title:d,children:h})}const ua={inbox:0,flagged:1,drafts:2,sent:3,archive:4,all:5,junk:6,trash:7};function qd(e){switch(e){case"inbox":return s.jsx(ur,{className:"size-4"});case"flagged":return s.jsx(vt,{className:"size-4"});case"drafts":return s.jsx(Lo,{className:"size-4"});case"sent":return s.jsx(As,{className:"size-4"});case"archive":return s.jsx(ju,{className:"size-4"});case"all":return s.jsx(wu,{className:"size-4"});case"junk":return s.jsx(kc,{className:"size-4"});case"trash":return s.jsx(et,{className:"size-4"})}}const da=e=>e.role!=null,Mn=8,fa="remit.nav.folders.open.",ma="remit.nav.account.open.";function ha(e,t,n){if(typeof localStorage>"u")return n;const r=localStorage.getItem(e+t);return r===null?n:r!=="0"}function ga(e,t,n){typeof localStorage>"u"||localStorage.setItem(e+t,n?"1":"0")}function Ud({query:e,onSelect:t,onRemove:n}){return s.jsxs("div",{className:"group flex w-full items-center gap-1 rounded-md pr-1 hover:bg-surface",children:[s.jsxs("button",{type:"button",onClick:t,className:"flex min-w-0 flex-1 items-center gap-2 px-2 py-1 text-left text-sm text-fg-muted transition-colors hover:text-fg",children:[s.jsx(Ts,{className:"size-4 shrink-0 text-fg-subtle"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:e})]}),n&&s.jsx("button",{type:"button",onClick:n,"aria-label":`Remove saved search: ${e}`,className:"shrink-0 rounded-full p-1 text-fg-subtle opacity-0 transition-opacity hover:bg-surface-sunken hover:text-fg group-hover:opacity-100 focus-visible:opacity-100",children:s.jsx(Ke,{className:"size-3.5"})})]})}function Qd({savedSearches:e,saveableQuery:t,onSelectSavedSearch:n,onRemoveSavedSearch:r,onSaveCurrentSearch:a}){return e.length===0&&!t?null:s.jsxs("div",{className:"mt-3",children:[s.jsx("div",{className:"px-2 pb-1 text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Saved searches"}),t&&s.jsxs("button",{type:"button",onClick:a,className:"flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-sm text-accent transition-colors hover:bg-surface",children:[s.jsx(Ou,{className:"size-4 shrink-0"}),s.jsxs("span",{className:"min-w-0 flex-1 truncate",children:["Save “",t,"”"]})]}),e.map(o=>s.jsx(Ud,{query:o,onSelect:()=>n?.(o),onRemove:r?()=>r(o):void 0},o))]})}function Hd({account:e,selectedNavId:t,onSelectNav:n,linkComponent:r}){const[a,o]=c.useState(()=>ha(ma,e.id,!0)),[i,l]=c.useState(()=>ha(fa,e.id,!0)),[u,d]=c.useState(!1),m=()=>{o(y=>{const j=!y;return ga(ma,e.id,j),j})},f=()=>{l(y=>{const j=!y;return ga(fa,e.id,j),j})},h=e.mailboxes.filter(da).sort((y,j)=>ua[y.role]-ua[j.role]),x=e.mailboxes.filter(y=>!da(y)),b=u||x.length<=Mn?x:x.slice(0,Mn),p=x.length-b.length,v=e.status??"ready",g=v==="ready"&&h.length===0&&x.length===0;return s.jsxs("div",{className:"mt-3",children:[s.jsxs("button",{type:"button",onClick:m,"aria-expanded":a,className:K("flex w-full items-center gap-1.5 px-2 pb-1 text-left transition-colors hover:text-fg",e.muted&&"opacity-55"),children:[a?s.jsx(pt,{className:"size-3 shrink-0 text-fg-subtle"}):s.jsx(ts,{className:"size-3 shrink-0 text-fg-subtle"}),s.jsx("span",{className:"truncate text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e.label}),e.muted&&s.jsxs(s.Fragment,{children:[s.jsx($o,{className:"size-3 shrink-0 text-fg-subtle"}),s.jsx("span",{className:"text-2xs text-fg-subtle",children:"muted"})]})]}),a&&s.jsxs(s.Fragment,{children:[v==="loading"&&s.jsx("div",{className:"px-2 py-1 text-sm text-fg-muted",children:"Loading…"}),v==="error"&&s.jsxs("div",{role:"alert",className:"mx-2 my-1 flex items-start gap-2 rounded-md border border-danger/40 bg-danger-soft px-2 py-1.5 text-sm",children:[s.jsx(Rt,{className:"mt-0.5 size-4 shrink-0 text-danger","aria-hidden":"true"}),s.jsx("div",{className:"min-w-0 flex-1",children:s.jsx("p",{className:"font-medium text-danger",children:"Couldn't load mailboxes"})}),e.onRetry&&s.jsx("button",{type:"button",onClick:e.onRetry,className:"shrink-0 text-sm font-medium text-accent hover:underline",children:"Retry"})]}),g&&s.jsx("div",{className:"px-2 py-1 text-sm text-fg-muted",children:"No mailboxes"}),v==="ready"&&s.jsxs(s.Fragment,{children:[h.map(y=>s.jsx(ks,{navId:y.id,linkComponent:r,icon:qd(y.role),label:y.name,ariaLabel:y.name,title:y.fullPath??y.name,count:y.unseen,active:t===y.id,dimmed:e.muted,onClick:()=>n?.(y.id)},y.id)),e.outboxPending!==void 0&&s.jsx(ks,{navId:"outbox",linkComponent:r,icon:s.jsx(As,{className:"size-4"}),label:"Outbox",ariaLabel:"Outbox",count:e.outboxPending>0?e.outboxPending:void 0,active:t==="outbox",dimmed:e.muted,onClick:()=>n?.("outbox")}),x.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs("button",{type:"button",onClick:f,"aria-expanded":i,className:"mt-1 flex w-full items-center gap-1 px-2 py-1 text-left text-2xs font-semibold uppercase tracking-wider text-fg-subtle transition-colors hover:text-fg",children:[i?s.jsx(pt,{className:"size-3 shrink-0"}):s.jsx(ts,{className:"size-3 shrink-0"}),s.jsx("span",{className:"flex-1",children:"Folders"}),s.jsx("span",{className:"tabular-nums opacity-70",children:x.length})]}),i&&s.jsxs(s.Fragment,{children:[b.map(y=>s.jsx(ks,{navId:y.id,linkComponent:r,icon:s.jsx(yu,{className:"size-4"}),label:y.name,ariaLabel:y.name,title:y.fullPath??y.name,count:y.unseen,active:t===y.id,dimmed:e.muted,onClick:()=>n?.(y.id)},y.id)),(p>0||u)&&x.length>Mn&&s.jsx("button",{type:"button",onClick:()=>d(y=>!y),className:"ml-7 flex items-center px-2 py-1 text-2xs font-medium text-accent transition-colors hover:underline",children:u?"Show less":`Show all (${x.length})`})]})]})]})]})]})}function Wd({accounts:e,selectedNavId:t,briefUnseen:n,onSelectNav:r,variant:a="desktop",linkComponent:o,savedSearches:i=[],saveableQuery:l,onSelectSavedSearch:u,onRemoveSavedSearch:d,onSaveCurrentSearch:m}){const f=s.jsxs("nav",{className:a==="drawer"?"px-2 py-2":"flex-1 overflow-y-auto px-2 py-2","aria-label":"Mailboxes",children:[s.jsx(ks,{navId:"brief",linkComponent:o,icon:s.jsx(Je,{className:"size-4"}),label:"Daily brief",ariaLabel:"Daily brief",count:n,active:t==="brief",onClick:()=>r?.("brief")}),s.jsx(ks,{navId:"flagged",linkComponent:o,icon:s.jsx(vt,{className:"size-4"}),label:"Starred",ariaLabel:"Starred",active:t==="flagged",onClick:()=>r?.("flagged")}),s.jsx(Qd,{savedSearches:i,saveableQuery:l,onSelectSavedSearch:u,onRemoveSavedSearch:d,onSaveCurrentSearch:m}),e.length===0?s.jsx("div",{className:"px-2 py-4 text-center text-sm text-fg-muted",children:"No accounts configured"}):e.map(h=>s.jsx(Hd,{account:h,selectedNavId:t,onSelectNav:r,linkComponent:o},h.id))]});return a==="drawer"?f:s.jsx("aside",{className:"flex h-full w-full flex-col bg-surface-sunken",children:f})}function Vd({leading:e,search:t,actions:n,className:r}){return s.jsxs("header",{className:K("flex min-h-16 w-full shrink-0 items-center gap-3 border-b border-line bg-canvas px-3 py-2",r),children:[e&&s.jsx("div",{className:"flex shrink-0 items-center gap-2",children:e}),s.jsx("div",{className:"flex min-w-0 flex-1 justify-start",children:s.jsx("div",{className:"w-full max-w-2xl",children:t})}),n&&s.jsx("div",{className:"flex shrink-0 items-center gap-1",children:n})]})}function Yd({label:e,size:t="sm",onUndo:n,undoLabel:r="Undo",className:a}){return s.jsxs(Ue,{tone:"accent",className:K(t==="md"&&"py-1 text-xs",a),children:[s.jsx(Uu,{className:K(t==="sm"?"size-3":"size-3.5","shrink-0"),"aria-hidden":!0}),s.jsx("span",{children:e}),n&&s.jsx("button",{type:"button",onClick:o=>{o.stopPropagation(),n()},className:"font-semibold underline decoration-dotted underline-offset-2 hover:decoration-solid",children:r})]})}const Gd=320,Xd="cubic-bezier(0.32, 0.9, 0.3, 1)",Jd=.5,Zd=.4,ef=360;function tf(e){return Math.sign(e)*Math.sqrt(Math.abs(e))*4}function sf({open:e,onClose:t,children:n,dismissLabel:r="Dismiss"}){const a=c.useRef(null),[o,i]=c.useState(ef),[l,u]=c.useState(null);c.useLayoutEffect(()=>{const g=a.current;if(!g)return;const y=()=>i(g.offsetHeight);y();const j=new ResizeObserver(y);return j.observe(g),()=>j.disconnect()},[]);const d=c.useRef(null),m=c.useCallback(g=>{g.currentTarget.setPointerCapture(g.pointerId),d.current={startY:g.clientY,lastY:g.clientY,lastT:g.timeStamp,velocity:0,moved:!1},u(0)},[]),f=c.useCallback(g=>{const y=d.current;if(!y)return;const j=g.timeStamp-y.lastT;j>0&&(y.velocity=(g.clientY-y.lastY)/j),y.lastY=g.clientY,y.lastT=g.timeStamp;const w=g.clientY-y.startY;Math.abs(w)>4&&(y.moved=!0);const C=w<0?tf(w):w;u(C)},[]),h=c.useCallback(()=>{const g=d.current;if(d.current=null,!g)return;const y=g.lastY-g.startY,w=g.velocity>Jd||y>o*Zd;u(null),w&&t()},[o,t]),x=l!==null,b=e?l??0:o,p=Math.min(Math.max(1-b/o,0),1),v=x?"none":`transform ${Gd}ms ${Xd}`;return s.jsxs("div",{className:K("absolute inset-0 z-40 select-none overflow-hidden",e||x?"":"pointer-events-none"),children:[s.jsx("button",{type:"button","aria-label":r,tabIndex:-1,onClick:t,className:K("absolute inset-0 bg-black/40",p>0?"pointer-events-auto":"pointer-events-none"),style:{opacity:p*.6,transition:v.replace("transform","opacity")}}),s.jsxs("div",{ref:a,className:"absolute inset-x-0 bottom-0 flex max-h-[92%] flex-col rounded-t-3xl border-t border-line bg-surface shadow-2xl shadow-black/30",style:{transform:`translateY(${b}px)`,transition:v},children:[s.jsx("div",{role:"slider","aria-label":"Drag down to dismiss","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(p*100),tabIndex:0,onPointerDown:m,onPointerMove:f,onPointerUp:h,onPointerCancel:h,className:"flex cursor-grab touch-none justify-center pb-1 pt-2.5 active:cursor-grabbing",children:s.jsx("div",{className:"h-1 w-10 rounded-full bg-fg-subtle/40"})}),s.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden",children:n})]})]})}const nf=({status:e})=>e==="saving"?s.jsx("span",{className:"animate-pulse text-xs text-fg-muted",children:"Saving..."}):e==="saved"?s.jsx("span",{className:"text-xs text-fg-muted",children:"Draft saved"}):e==="error"?s.jsx("span",{className:"text-xs text-danger",children:"Save failed"}):null;function rf({onSend:e,onDiscard:t,sending:n,canSend:r,saveStatus:a="idle",unavailableReason:o,onUnavailable:i}){return s.jsxs("div",{className:"flex items-center justify-between border-t border-line px-3 py-2",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx(V,{variant:"primary",size:"md","aria-busy":n,title:r?void 0:o,className:"min-h-11 rounded-full px-4",icon:n?s.jsx(Tt,{className:"size-4 animate-spin"}):s.jsx(As,{className:"size-4"}),onClick:()=>{if(!n){if(!r){o&&i?.(o);return}e()}},children:"Send"}),s.jsx(nf,{status:a})]}),s.jsx(V,{variant:"ghost",size:"md","aria-busy":n,"aria-label":"Discard",className:"min-h-11 min-w-11 px-2 hover:text-danger",icon:s.jsx(et,{className:"size-4"}),onClick:()=>{n||t()}})]})}function af({banner:e,header:t,children:n,quoted:r,actionBar:a}){return s.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e,t,s.jsxs("div",{className:"min-h-0 flex-1 overflow-auto",children:[n,r&&s.jsx("div",{className:"px-3 pb-2",children:r})]}),a]})}function of({key:e,shiftKey:t=!1,repeat:n=!1,caretAtStart:r,hasValue:a,chipCount:o}){const i=o-1;return e==="Escape"?a?{type:"clearQuery"}:{type:"blur"}:e==="Tab"&&t?o===0?{type:"none"}:{type:"focusChip",index:i}:e==="Backspace"||e==="ArrowLeft"?!r||o===0?{type:"none"}:n?{type:"none"}:{type:"focusChip",index:i}:{type:"none"}}function lf({key:e,repeat:t=!1,index:n,chipCount:r}){return e==="Backspace"||e==="Delete"?t?{type:"none"}:{type:"removeChip",index:n}:e==="ArrowLeft"?n===0?{type:"none"}:{type:"focusChip",index:n-1}:e==="ArrowRight"?n>=r-1?{type:"focusInput"}:{type:"focusChip",index:n+1}:e==="Enter"||e===" "?{type:"activateChip",index:n}:e==="Escape"?{type:"focusInput"}:{type:"none"}}function cf(e,t){const n=t-1;return n<=0?null:e<n?e:n-1}const uf=e=>e instanceof HTMLElement?e.tagName==="INPUT"||e.tagName==="TEXTAREA"||e.isContentEditable:!1,df=({chips:e=[],onRemoveChip:t,onActivateChip:n,value:r,onChange:a,onClear:o,onClearQuery:i,placeholder:l="Search mail...",globalFocusKey:u=!0,showClearButton:d=!0,size:m="sm",inputId:f,chipsLabel:h="Search filters",className:x})=>{const b=c.useId(),p=f??b,v=c.useRef(null),g=c.useRef([]),y=i??o,[j,w]=c.useState(null),C=c.useRef(void 0),[k,S]=c.useState(""),N=e.length>0;c.useEffect(()=>{w(T=>T!==null&&T>=e.length?null:T)},[e.length]),c.useEffect(()=>{const T=C.current;if(T!==void 0){if(C.current=void 0,T===null){v.current?.focus();return}g.current[T]?.focus()}});const R=c.useCallback(T=>{w(T),C.current=T},[]),A=c.useCallback(T=>{const O=e[T];O&&t&&(R(cf(T,e.length)),S(`${O.label} removed`),t(O.id))},[e,t,R]),E=c.useCallback(()=>{R(null),o()},[o,R]),M=c.useCallback(T=>{const O=T.currentTarget,_=of({key:T.key,shiftKey:T.shiftKey,repeat:T.repeat,caretAtStart:O.selectionStart===0&&O.selectionEnd===0,hasValue:r.length>0,chipCount:e.length});switch(_.type){case"focusChip":T.preventDefault(),R(_.index);return;case"clearQuery":y();return;case"blur":O.blur();return;case"none":return}},[e.length,r,y,R]),I=c.useCallback(T=>O=>{const _=lf({key:O.key,repeat:O.repeat,index:T,chipCount:e.length});switch(_.type!=="none"&&O.preventDefault(),_.type){case"removeChip":A(_.index);return;case"focusChip":R(_.index);return;case"focusInput":R(null);return;case"activateChip":{const q=e[_.index];q&&n&&n(q.id);return}case"none":return}},[e,A,R,n]);return c.useEffect(()=>{if(!u)return;const T=O=>{O.key!=="/"||O.metaKey||O.ctrlKey||O.altKey||uf(O.target)||(O.preventDefault(),v.current?.focus())};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[u]),s.jsxs("label",{htmlFor:p,className:K("flex w-full items-center gap-1.5 text-sm","bg-surface-sunken/50 border border-transparent","focus-within:bg-canvas focus-within:border-line focus-within:ring-2 focus-within:ring-ring","transition-colors",m==="lg"?"rounded-xl px-4 py-2":"rounded-md px-2.5 py-1",x),children:[s.jsx(Ts,{className:K("shrink-0 text-fg-muted pointer-events-none",m==="lg"?"size-5":"size-4")}),s.jsxs("div",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-1",children:[N&&s.jsx("div",{role:"grid","aria-label":h,className:"flex min-w-0 flex-wrap items-center gap-1",children:e.map((T,O)=>s.jsx(Cc,{ref:_=>{g.current[O]=_},label:T.label,tone:T.tone,focused:j===O,onFocusLabel:()=>w(O),onKeyDown:I(O),onRemove:()=>A(O),onActivate:n?()=>n(T.id):void 0},T.id))}),s.jsx("input",{ref:v,id:p,name:"q",type:"text","aria-label":"Search mail",autoComplete:"off",value:r,tabIndex:j===null?0:-1,onChange:T=>a(T.target.value),onKeyDown:M,onFocus:()=>w(null),placeholder:N?void 0:l,className:"min-w-24 flex-1 bg-transparent text-fg outline-none placeholder:text-fg-muted"})]}),(r||N)&&d&&s.jsx("button",{type:"button",onClick:E,className:"shrink-0 rounded p-0.5 hover:bg-surface-raised transition-colors","aria-label":"Clear search",children:s.jsx(Ke,{className:K("text-fg-muted",m==="lg"?"size-5":"size-4")})}),s.jsx("span",{role:"status","aria-live":"polite",className:"sr-only",children:k})]})},Cr=({value:e,onChange:t,onClear:n,onClearQuery:r,chips:a,onRemoveChip:o,placeholder:i="Search mail...",globalFocusKey:l=!0,showClearButton:u=!0,size:d,inputId:m,className:f})=>s.jsx(df,{value:e,onChange:t,onClear:n,onClearQuery:r,chips:a,onRemoveChip:o,placeholder:i,globalFocusKey:l,showClearButton:u,size:d,inputId:m,className:f});function ff({title:e,unreadCount:t,isDesktop:n,onMenuClick:r,searchValue:a,onSearchChange:o,onSearchClear:i,searchOpen:l,onSearchOpenChange:u,showSearch:d=!0}){const m=`${t.toLocaleString()} unread`,f=i??(()=>o("")),h=()=>{f(),u(!1)},x=p=>s.jsx(Cr,{value:a,onChange:o,onClear:f,globalFocusKey:!1,showClearButton:p}),b=s.jsx(V,{variant:"ghost",icon:s.jsx(jr,{className:"size-5"}),onClick:r,"aria-label":"Menu",className:"min-h-11 min-w-11 shrink-0 px-0"});return s.jsx("header",{className:"flex shrink-0 flex-col bg-canvas",children:s.jsx("div",{className:"flex h-12 items-center gap-2 px-row-inset",children:d?n?s.jsxs(s.Fragment,{children:[b,s.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e}),s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle",children:m}),s.jsx("div",{className:"w-64 max-w-[40%] shrink-0",children:x(!0)})]}):l||a.trim().length>0?s.jsxs("div",{className:"flex flex-1 items-center gap-1",children:[s.jsx("div",{className:"flex-1",children:x(!1)}),s.jsx(V,{variant:"ghost",icon:s.jsx(Ke,{className:"size-5"}),onClick:h,"aria-label":"Close search",className:"min-h-11 min-w-11 shrink-0 px-0"})]}):s.jsxs(s.Fragment,{children:[b,s.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e}),s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle",children:m}),s.jsx(V,{variant:"ghost",icon:s.jsx(Ts,{className:"size-5"}),onClick:()=>u(!0),"aria-label":"Search",className:"min-h-11 min-w-11 shrink-0 px-0"})]}):s.jsxs(s.Fragment,{children:[b,s.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e}),s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle",children:m})]})})})}const mf=(e,t)=>e==="vip"?"vip":e==="unknown"&&t==="md"?"unknown-pill":"hidden",ui=({senderTrust:e,size:t="sm",className:n})=>{const r=mf(e,t);return r==="vip"?s.jsx(Je,{className:K("text-warning shrink-0",t==="sm"&&"size-3.5",t==="md"&&"size-4",n),"aria-label":"VIP sender","data-testid":"sender-trust-vip"}):r==="unknown-pill"?s.jsx("span",{className:K("inline-flex items-center rounded border border-dashed border-fg-subtle/40 font-medium uppercase tracking-wide text-fg-muted/80 shrink-0","px-2 py-0.5 text-xs",n),title:"First message from this sender","aria-label":"First message from this sender","data-testid":"sender-trust-unknown",children:"new"}):null};function pa(e,t){const n=t?.trim();if(!n)return e;const r=e.toLowerCase(),a=n.toLowerCase(),o=[];let i=0,l=r.indexOf(a,i),u=0;for(;l!==-1;)l>i&&o.push(e.slice(i,l)),o.push(s.jsx("mark",{className:"bg-transparent font-semibold text-fg",children:e.slice(l,l+a.length)},u++)),i=l+a.length,l=r.indexOf(a,i);return i<e.length&&o.push(e.slice(i)),o}function hf({result:e,onClick:t,query:n,showFolder:r=!0}){const a=r&&e.folder?Su(e.folder):void 0;return s.jsxs("button",{type:"button",onClick:t,className:"flex w-full flex-col gap-0.5 border-b border-line px-row-inset py-2.5 text-left transition-colors hover:bg-surface-sunken",children:[s.jsxs("div",{className:"flex items-baseline gap-2",children:[s.jsx("span",{className:K("min-w-0 flex-1 truncate text-sm",e.unread?"font-semibold text-fg":"font-medium text-fg-muted"),children:e.sender}),s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.date})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:K("min-w-0 flex-1 truncate text-sm",e.unread?"text-fg":"text-fg-muted"),children:pa(e.subject,n)}),e.flagged&&s.jsx(Pu,{className:"size-3.5 shrink-0 fill-warning text-warning"})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-fg-subtle",children:pa(e.snippet,n)}),a&&s.jsx(Ue,{tone:"neutral",className:"shrink-0",children:a}),e.category&&s.jsx(Ue,{tone:e.category.tone??"neutral",className:"shrink-0",children:e.category.label}),e.matchedChunkLabel&&s.jsx(Ue,{tone:"neutral",className:"shrink-0",children:`matched: ${e.matchedChunkLabel}`}),e.score!=null&&s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.score.toFixed(2)})]})]})}const gf=e=>e===1?"result":"results";function pf({count:e,onScopeToSpam:t}){return s.jsx(dn,{tone:"info",variant:"soft",className:"items-center justify-between gap-3 rounded-none border-b border-line",children:s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("p",{className:"min-w-0 text-xs text-fg-muted",children:[s.jsx("span",{className:"font-semibold text-fg tabular-nums",children:e})," ",`${gf(e)} from Spam`]}),s.jsx(V,{variant:"ghost",size:"sm",onClick:t,className:"shrink-0 text-accent",children:"View them"})]})})}const xa=6,xf={kind:"global"},bf=e=>e.kind==="folder"&&e.role==="junk",vf=e=>e.folder?.role==="junk";function yf(e){const t=[],n=[];for(const r of e)vf(r)?n.push(r):t.push(r);return{kept:t,spam:n}}function wf({section:e,query:t,onSelectResult:n,showFolder:r}){const[a,o]=c.useState(e.initialCollapsed??!1),[i,l]=c.useState(!1),u=e.results.length>xa,m=!i&&u?e.results.slice(0,xa):e.results,f=e.results.length-m.length;return s.jsxs("div",{children:[s.jsxs("button",{type:"button","aria-expanded":!a,onClick:()=>o(h=>!h),className:"sticky top-0 z-10 flex h-section-row w-full items-center gap-1.5 border-b border-line bg-surface-sunken px-row-inset text-left transition-colors hover:bg-surface",children:[s.jsx("span",{className:"flex-1 text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e.label}),s.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:e.results.length}),s.jsx(pt,{className:K("size-3 shrink-0 text-fg-subtle transition-transform duration-200",a?"rotate-0":"rotate-180")})]}),!a&&s.jsxs(s.Fragment,{children:[m.map(h=>s.jsx(hf,{result:h,query:t,showFolder:r,onClick:n?()=>n(h):void 0},h.id)),u&&s.jsxs("button",{type:"button",onClick:()=>l(h=>!h),className:"flex w-full items-center justify-center border-b border-line px-row-inset py-1.5 text-2xs font-medium text-accent transition-colors hover:bg-surface",children:[i?"Show less":`Show ${f} more`,!i&&s.jsx(pt,{className:"ml-1 size-3"})]})]})]})}function di({value:e,recentSearches:t,onPickRecent:n,sections:r,loading:a,onSelectResult:o,tokens:i,scope:l=xf,spamMatchCount:u,onScopeToSpam:d}){if(!(e.trim().length>0))return t&&t.length>0?s.jsxs("div",{className:"flex flex-col",children:[s.jsx("h3",{className:"px-row-inset pb-1 pt-3 text-2xs font-semibold uppercase tracking-wide text-fg-subtle",children:"Recent searches"}),t.map(w=>s.jsxs("button",{type:"button",onClick:()=>n?.(w),className:"flex w-full items-center gap-2.5 border-b border-line px-row-inset py-2.5 text-left transition-colors hover:bg-surface-sunken",children:[s.jsx(Nr,{className:"size-4 shrink-0 text-fg-subtle"}),s.jsx("span",{className:"min-w-0 flex-1 truncate text-sm text-fg-muted",children:w})]},w))]}):s.jsx("p",{className:"px-row-inset py-6 text-center text-sm text-fg-subtle",children:"Search across your mail by sender, subject or words in the message."});const f=i&&i.length>0&&s.jsx(Ec,{tokens:i});if(a)return s.jsxs("div",{className:"flex flex-col",children:[f,s.jsx("div",{className:"flex flex-col gap-3 px-row-inset py-4",children:[0,1,2,3].map(w=>s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("div",{className:"h-3 w-1/3 animate-pulse rounded bg-surface-sunken"}),s.jsx("div",{className:"h-3 w-2/3 animate-pulse rounded bg-surface-sunken"}),s.jsx("div",{className:"h-2.5 w-1/2 animate-pulse rounded bg-surface-sunken"})]},w))})]});const h=bf(l),x=l.kind==="global",b=(r??[]).map(w=>{if(h)return{section:w,spam:[]};const{kept:C,spam:k}=yf(w.results);return{section:{...w,results:C},spam:k}}),p=b.map(w=>w.section),v=b.reduce((w,C)=>w+C.spam.length,0),g=u??v,y=x&&g>0&&d!==void 0&&s.jsx(pf,{count:g,onScopeToSpam:d});return p.some(w=>w.results.length>0)?s.jsxs("div",{className:"flex flex-col",children:[f,y,p.filter(w=>w.results.length>0).map(w=>s.jsx(wf,{section:w,query:e,showFolder:x,onSelectResult:o},w.id))]}):s.jsxs("div",{className:"flex flex-col",children:[f,y,s.jsxs("div",{className:"px-row-inset py-10 text-center",children:[s.jsxs("p",{className:"text-sm font-medium text-fg",children:["No matches for “",e,"”"]}),s.jsx("p",{className:"mt-1 text-xs text-fg-subtle",children:"Try a different word, or adjust the filters above."})]})]})}function jf({value:e,onChange:t,onClear:n,onCancel:r,filter:a,recentSearches:o,onPickRecent:i,sections:l,loading:u,onSelectResult:d,tokens:m,chips:f,onRemoveChip:h,scope:x,spamMatchCount:b,onScopeToSpam:p}){const v=s.jsx(di,{value:e,recentSearches:o,onPickRecent:i,sections:l,loading:u,onSelectResult:d,tokens:m,scope:x,spamMatchCount:b,onScopeToSpam:p});return s.jsxs("article",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line bg-surface px-row-inset",children:[s.jsx("div",{className:"min-w-0 flex-1",children:s.jsx(Cr,{value:e,onChange:t,onClear:n,chips:f,onRemoveChip:h,globalFocusKey:!1,showClearButton:!1})}),s.jsx(V,{variant:"ghost",size:"sm",icon:s.jsx(Ke,{className:"size-4"}),onClick:r,"aria-label":"Clear and close search",className:"-mr-1 shrink-0"})]}),a?s.jsx(dr,{...a,children:v}):s.jsx("div",{className:"flex-1 overflow-y-auto",children:v})]})}const ba="w-full text-left px-3 py-2.5 min-h-11 flex items-center gap-2 transition-colors text-sm rounded-md focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-canvas",Sf={searchPlaceholder:"Move to…",searchAriaLabel:"Filter folders",listAriaLabel:"Destination folders",currentSuffix:"(current folder)",currentTag:"current",emptyMessage:e=>`No folders match "${e}"`,optionLabel:e=>`Move to ${e}`},Tn=e=>{for(let t=0;t<e.length;t+=1)if(!e[t]?.isCurrent)return t;return-1},Nf=e=>{for(let t=e.length-1;t>=0;t-=1)if(!e[t]?.isCurrent)return t;return-1},va=(e,t,n)=>{const r=e.length;if(r<=0)return-1;const a=t<0?n===1?-1:r:t;for(let o=1;o<=r;o+=1){const i=((a+n*o)%r+r)%r;if(!e[i]?.isCurrent)return i}return-1},kf=(e,t)=>e.label.toLowerCase().includes(t)?!0:e.searchValue?.toLowerCase().includes(t)??!1,fi=({mailboxes:e,onSelect:t,onCancel:n,autoFocus:r=!1,labels:a})=>{const o={...Sf,...a},[i,l]=c.useState(""),[u,d]=c.useState(()=>Tn(e)),m=c.useRef(null),f=c.useRef([]);c.useEffect(()=>{r&&m.current?.focus()},[r]);const h=i.trim().toLowerCase(),x=c.useMemo(()=>h?e.filter(g=>kf(g,h)):[...e],[e,h]);c.useEffect(()=>{d(g=>g>=0&&g<x.length&&!x[g]?.isCurrent?g:Tn(x))},[x]),c.useEffect(()=>{if(u<0)return;const g=f.current[u];g&&document.activeElement!==m.current&&g.focus()},[u]);const b=c.useCallback(()=>{if(u<0)return;const g=x[u];!g||g.isCurrent||t(g.id)},[u,x,t]),p=c.useCallback(g=>{switch(g.key){case"ArrowDown":g.preventDefault(),d(y=>va(x,y,1));return;case"ArrowUp":g.preventDefault(),d(y=>va(x,y,-1));return;case"Home":g.preventDefault(),d(Tn(x));return;case"End":g.preventDefault(),d(Nf(x));return;case"Enter":case" ":g.preventDefault(),b();return;case"Escape":g.preventDefault(),n?.();return;default:return}},[x,b,n]),v=c.useCallback(g=>{if(g.key==="ArrowDown"){if(g.preventDefault(),x.length===0)return;f.current[u>=0?u:0]?.focus();return}g.key==="Escape"&&(g.preventDefault(),n?.())},[x.length,u,n]);return s.jsxs("div",{className:"flex flex-col",children:[s.jsx(wo,{variant:"inline",className:"border-b border-line px-3 py-2",icon:s.jsx(Ts,{className:"size-4","aria-hidden":"true"}),ref:m,type:"search",value:i,onChange:g=>l(g.target.value),onKeyDown:v,placeholder:o.searchPlaceholder,"aria-label":o.searchAriaLabel}),s.jsx("div",{className:"flex-1 overflow-y-auto py-1",role:"listbox","aria-label":o.listAriaLabel,onKeyDown:p,children:x.length===0?s.jsx("div",{className:"px-3 py-3 text-sm text-fg-muted","aria-live":"polite",children:o.emptyMessage(i)}):x.map((g,y)=>{const j=g.isCurrent??!1,w=y===u;return j?s.jsx("div",{children:s.jsxs("div",{role:"option","aria-selected":!1,"aria-current":"true","aria-label":`${g.label} ${o.currentSuffix}`,className:K(ba,"opacity-60 bg-surface-sunken/40"),children:[s.jsx("span",{className:"truncate flex-1",children:g.label}),s.jsx("span",{className:"text-xs text-fg-muted shrink-0",children:o.currentTag})]})},g.id):s.jsx("div",{children:s.jsx("button",{ref:C=>{f.current[y]=C},type:"button",role:"option","aria-selected":!1,tabIndex:w?0:-1,onClick:()=>t(g.id),onFocus:()=>d(y),"aria-label":o.optionLabel(g.label),className:K(ba,"hover:bg-surface-raised"),children:s.jsx("span",{className:"truncate flex-1",children:g.label})})},g.id)})})]})},Cf={queued:{icon:Nr,label:"Queued",className:"text-warning"},sending:{icon:Tt,label:"Sending…",className:"text-accent-2",spin:!0},sent:{icon:Ko,label:"Sent",className:"text-positive"},failed:{icon:Rt,label:"Failed",className:"text-danger"},blocked:{icon:fr,label:"Blocked",className:"text-warning"}};function ya({status:e,iconOnly:t,className:n}){const r=Cf[e],a=r.icon;return s.jsxs("span",{className:K("inline-flex items-center gap-1.5 text-xs font-medium",r.className,n),children:[s.jsx(a,{className:K("size-4",r.spin&&"animate-spin")}),!t&&r.label]})}const Ef=(e,t)=>t?"bg-accent-2-soft":e==="failed"?"bg-danger-soft":e==="blocked"?"bg-warning/10":"";function If({recipients:e,subject:t,time:n,status:r,error:a,selected:o,onSelect:i,onRetry:l,retrying:u,onEdit:d,onDelete:m,deleting:f}){const h=r==="failed"||r==="blocked";return s.jsxs("div",{className:K("flex items-start gap-3 border-b border-line px-4 py-3 transition-colors hover:bg-surface-raised",Ef(r,o)),children:[s.jsxs("button",{type:"button",onClick:i,className:"flex flex-1 min-w-0 items-start gap-3 text-left",children:[s.jsx("div",{className:"mt-0.5 shrink-0",children:s.jsx(ya,{status:r,iconOnly:!0})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"truncate text-sm font-medium",children:e}),s.jsx("span",{className:"shrink-0 text-xs text-fg-muted",children:n})]}),s.jsx("div",{className:"truncate text-sm",children:t||"No subject"}),s.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[s.jsx(ya,{status:r}),a&&s.jsxs("span",{className:"truncate text-xs text-fg-muted",children:["— ",a]})]})]})]}),h&&s.jsx("div",{className:"shrink-0",children:s.jsx(Nu,{actions:[...r==="failed"&&l?[{label:"Retry sending",iconOnly:!0,icon:s.jsx(Bu,{className:"size-3.5"}),busy:u,onClick:l}]:[],{label:"Edit as draft",iconOnly:!0,icon:s.jsx(As,{className:"size-3.5"}),onClick:d}],destructive:{label:"Delete message",iconOnly:!0,icon:s.jsx(et,{className:"size-3.5"}),busy:f,confirm:{prompt:"Delete this message?",confirmLabel:"Delete"},onClick:m}})})]})}const Rf=e=>{const[t,n]=c.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return c.useEffect(()=>{if(typeof window>"u"||!window.matchMedia)return;const r=window.matchMedia(e);n(r.matches);const a=o=>n(o.matches);return r.addEventListener("change",a),()=>r.removeEventListener("change",a)},[e]),t},Mf=({children:e,onRefresh:t,isRefreshing:n})=>Rf("(min-width: 1024px)")?e:s.jsx(Ic,{onRefresh:t,isPullable:!n,children:e}),Tf=({text:e,html:t,senderName:n,date:r})=>{const[a,o]=c.useState(!1);if(!e&&!t)return null;const i=[n,r].filter(Boolean).join(" on ");return s.jsxs("div",{className:"mt-2 px-3 pb-2",children:[s.jsxs("button",{type:"button",onClick:()=>o(!a),"aria-expanded":a,className:"flex items-center gap-1 text-xs text-fg-muted hover:text-fg transition-colors",children:[a?s.jsx(pt,{className:"size-3"}):s.jsx(ts,{className:"size-3"}),i?`${i} wrote:`:"Show quoted text"]}),a&&s.jsx("blockquote",{className:"mt-2 pl-3 border-l-2 border-fg-subtle/30 text-sm text-fg-muted [&_a]:text-accent [&_a]:underline [&_blockquote]:pl-3 [&_blockquote]:border-l-2 [&_blockquote]:border-fg-subtle/30",children:t?s.jsx("div",{dangerouslySetInnerHTML:{__html:t}}):e.split(`
|
|
69
|
-
`).map((l,u)=>s.jsx("p",{className:"min-h-[1.2em]",children:l},u))})]})},Af=e=>e===1?"message":"messages";function Df({count:e,onReview:t,onDismiss:n,actionLabel:r="Review & rescue"}){return s.jsx(dn,{tone:"info",variant:"soft",onDismiss:n,children:s.jsxs("div",{className:"flex flex-col gap-2",children:[s.jsxs("p",{className:"flex items-start gap-2 text-sm text-fg",children:[s.jsx(Ls,{className:"mt-0.5 size-4 shrink-0 text-positive","aria-hidden":!0}),s.jsxs("span",{children:[s.jsx("span",{className:"font-semibold text-fg",children:`${e} ${Af(e)} here`})," ","may not be spam — they're from senders we can verify."]})]}),s.jsx(V,{variant:"primary",size:"sm",onClick:t,className:"self-start",children:r})]})})}function Of({candidate:e,selected:t,onToggle:n,hideSender:r=!1}){const{senderName:a,senderAddress:o,subject:i,snippet:l,trustReason:u,trustSubReason:d,senderTrust:m}=e;return s.jsxs("label",{className:K("flex w-full cursor-pointer items-start gap-3 px-3 py-2.5 text-left transition-colors",r&&"pl-11",t?"bg-positive/10":"bg-surface hover:bg-surface-sunken"),children:[s.jsx(kr,{className:"mt-0.5",checked:t,onChange:n,"aria-label":`${t?"Deselect":"Select"} ${r?i:`message from ${a}`}`}),!r&&s.jsx(He,{name:a,email:o,size:"sm"}),s.jsxs("span",{className:"min-w-0 flex-1",children:[!r&&s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"truncate text-sm font-medium text-fg",children:a}),m&&s.jsx(ui,{senderTrust:m,size:"sm"}),s.jsx("span",{className:"truncate text-2xs text-fg-subtle",children:o})]}),s.jsx("span",{className:"block truncate text-sm text-fg-muted",children:i}),s.jsx("span",{className:"block line-clamp-1 text-xs text-fg-subtle",children:l}),!r&&s.jsxs("span",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[s.jsxs(Ue,{tone:"positive",children:[s.jsx(Ls,{className:"size-3","aria-hidden":!0}),u]}),s.jsx("span",{className:"text-2xs text-fg-subtle",children:d})]})]})]})}const Pf=e=>{const t=new Map,n=[];for(const r of e){const a=(r.senderAddress||r.senderName).toLowerCase(),o=t.get(a);if(o){o.messages.push(r);continue}t.set(a,{key:a,senderName:r.senderName,senderAddress:r.senderAddress,trustReason:r.trustReason,trustSubReason:r.trustSubReason,senderTrust:r.senderTrust,messages:[r]}),n.push(a)}return n.map(r=>t.get(r)).sort((r,a)=>a.messages.length-r.messages.length)},Lf=(e,t)=>{const n=e.messages.filter(r=>t.has(r.id)).length;return n===0?"none":n===e.messages.length?"all":"some"},wa=e=>e===1?"message":"messages";function zf({group:e,selected:t,onToggleGroup:n,onToggleMessage:r}){const[a,o]=c.useState(!1),i=Lf(e,t),l=e.messages.length,u=a?pt:ts;return s.jsxs("div",{className:K(i!=="none"?"bg-positive/10":"bg-surface"),children:[s.jsxs("div",{className:"flex w-full items-start gap-3 px-3 py-2.5",children:[s.jsx(kr,{className:"mt-0.5",checked:i==="all",indeterminate:i==="some",onChange:()=>n(e,i!=="all"),"aria-label":`${i==="all"?"Deselect":"Select"} all ${l} ${wa(l)} from ${e.senderName}`}),s.jsx(He,{name:e.senderName,email:e.senderAddress,size:"sm"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"truncate text-sm font-medium text-fg",children:e.senderName}),e.senderTrust&&s.jsx(ui,{senderTrust:e.senderTrust,size:"sm"}),s.jsx("span",{className:"truncate text-2xs text-fg-subtle",children:e.senderAddress})]}),s.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[s.jsxs(Ue,{tone:"positive",children:[s.jsx(Ls,{className:"size-3","aria-hidden":!0}),e.trustReason]}),s.jsx("span",{className:"text-2xs text-fg-subtle",children:e.trustSubReason})]})]}),s.jsxs("button",{type:"button",onClick:()=>o(d=>!d),"aria-expanded":a,className:"flex shrink-0 items-center gap-1 rounded-md px-1.5 py-1 text-2xs text-fg-muted transition-colors hover:bg-surface-sunken hover:text-fg",children:[`${l} ${wa(l)}`,s.jsx(u,{className:"size-3.5","aria-hidden":!0})]})]}),a&&s.jsx("div",{className:"divide-y divide-line border-t border-line",children:e.messages.map(d=>s.jsx(Of,{candidate:d,selected:t.has(d.id),onToggle:()=>r(d.id),hideSender:!0},d.id))})]})}const Er=e=>e===1?"message":"messages",Ff=(e,t)=>`Moves ${e===1?"this message":`these ${e} ${Er(e)}`} out of Spam to ${t} now. Nothing later.`,Xn=(e,t)=>e.find(n=>n.id===t)?.label??"Inbox";function _f(){return s.jsx(dn,{tone:"info",variant:"soft",children:s.jsx("p",{className:"text-2xs text-fg-muted",children:"We list a message here only when we can confirm the sender is who they say — usually someone you've emailed before, write to often, or a service that consistently checks out. We never guess from words in the subject. Anything we can't confirm stays in Spam."})})}function Bf({candidates:e,selected:t,onToggle:n,onToggleGroup:r,onSelectAll:a,onSelectNone:o,onContinue:i,onCancel:l}){const[u,d]=c.useState(!1),m=t.size,f=c.useMemo(()=>Pf(e),[e]);return s.jsxs("div",{className:"flex min-h-0 flex-col",children:[s.jsxs("div",{className:"px-row-inset pb-2 pt-1",children:[s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs("h2",{className:"flex items-center gap-2 text-sm font-semibold text-fg",children:[s.jsx(Ls,{className:"size-4 text-positive","aria-hidden":!0}),"Rescue from Spam"]}),s.jsx(V,{variant:"ghost",size:"sm",icon:s.jsx(bu,{className:"size-3.5"}),onClick:()=>d(h=>!h),className:"-mr-1.5 -mt-0.5",children:"Why these?"})]}),s.jsx("p",{className:"mt-1 text-2xs text-fg-subtle",children:"These look safe — from senders we can verify. Uncheck any sender that belongs in Spam, or open a sender to pick individual messages."}),u&&s.jsx("div",{className:"mt-2",children:s.jsx(_f,{})})]}),s.jsxs("div",{className:"flex items-center justify-between px-row-inset pb-1.5",children:[s.jsx("span",{className:"text-2xs font-medium text-fg-muted",children:`${m} of ${e.length} selected · ${f.length} ${f.length===1?"sender":"senders"}`}),s.jsxs("span",{className:"flex gap-1",children:[s.jsx(V,{variant:"ghost",size:"sm",onClick:a,children:"Select all"}),s.jsx(V,{variant:"ghost",size:"sm",onClick:o,children:"Select none"})]})]}),s.jsx("div",{className:"min-h-0 flex-1 divide-y divide-line overflow-y-auto border-y border-line",children:f.map(h=>s.jsx(zf,{group:h,selected:t,onToggleGroup:r,onToggleMessage:n},h.key))}),s.jsxs("div",{className:"space-y-2 border-t border-line bg-surface px-row-inset py-3",children:[s.jsx(V,{variant:"primary",onClick:i,className:"h-11 w-full font-semibold",children:`Continue with ${m} ${Er(m)}`}),s.jsx(V,{variant:"ghost",onClick:l,className:"h-11 w-full",children:"Cancel"})]})]})}function $f({count:e,folders:t,destination:n,onPick:r,onMove:a,onBack:o}){const[i,l]=c.useState(!1);return s.jsxs("div",{className:"flex min-h-0 flex-col",children:[s.jsxs("div",{className:"px-row-inset pb-2 pt-1",children:[s.jsx("h2",{className:"text-sm font-semibold text-fg",children:"Where should they go?"}),s.jsx("p",{className:"mt-1 text-2xs text-fg-subtle",children:"Pick a folder, then we move them out of Spam."})]}),s.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-row-inset py-2",children:i?s.jsx("div",{className:"overflow-hidden rounded-xl border border-line bg-surface",children:s.jsx(fi,{mailboxes:t,autoFocus:!0,onSelect:u=>{r(u),l(!1)},onCancel:()=>l(!1)})}):s.jsxs("div",{className:"rounded-xl border border-line bg-surface-sunken p-3",children:[s.jsx("p",{className:"text-2xs text-fg-subtle",children:"Destination"}),s.jsx("p",{className:"mt-0.5 text-sm font-medium text-fg",children:Xn(t,n)}),s.jsx(V,{variant:"ghost",size:"sm",onClick:()=>l(!0),className:"mt-2 px-0",children:"Move to a different folder"})]})}),s.jsxs("div",{className:"space-y-2 border-t border-line bg-surface px-row-inset py-3",children:[s.jsx("p",{className:"text-2xs text-fg-subtle",children:Ff(e,Xn(t,n))}),s.jsx(V,{variant:"primary",onClick:a,className:"h-11 w-full font-semibold",children:`Move ${e} out of Spam`}),s.jsx(V,{variant:"ghost",onClick:o,className:"h-11 w-full",children:"Back"})]})]})}function Kf({count:e,destinationLabel:t,onClose:n}){return s.jsxs("div",{className:"flex min-h-0 flex-col",children:[s.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 px-row-inset py-10 text-center",children:[s.jsx(Sr,{className:"size-10 text-positive","aria-hidden":!0}),s.jsx("p",{className:"text-base font-semibold text-fg",children:`Moved ${e} ${Er(e)} out of Spam.`}),s.jsx("p",{className:"text-2xs text-fg-subtle",children:`You'll find them in ${t}.`})]}),s.jsx("div",{className:"border-t border-line bg-surface px-row-inset py-3",children:s.jsx(V,{variant:"primary",onClick:n,className:"h-11 w-full font-semibold",children:"Done"})})]})}function qf({open:e,candidates:t,defaultDestinationId:n,availableFolders:r,onConfirmMove:a,onCancel:o}){const[i,l]=c.useState("review"),[u,d]=c.useState(()=>e?new Set(t.map(j=>j.id)):new Set),[m,f]=c.useState(n),[h,x]=c.useState(0),b=c.useRef(!1);c.useEffect(()=>{e&&!b.current&&(l("review"),d(new Set(t.map(j=>j.id))),f(n),x(0)),b.current=e},[e,t,n]);const p=u.size,v=j=>{d(w=>{const C=new Set(w);return C.has(j)?C.delete(j):C.add(j),C})},g=(j,w)=>{d(C=>{const k=new Set(C);for(const S of j.messages)w?k.add(S.id):k.delete(S.id);return k})},y=()=>{const j=Array.from(u);x(j.length),a(j,m),l("done")};return s.jsxs(sf,{open:e,onClose:o,dismissLabel:"Close rescue",children:[i==="review"&&s.jsx(Bf,{candidates:t,selected:u,onToggle:v,onToggleGroup:g,onSelectAll:()=>d(new Set(t.map(j=>j.id))),onSelectNone:()=>d(new Set),onContinue:()=>l("destination"),onCancel:o}),i==="destination"&&s.jsx($f,{count:p,folders:r,destination:m,onPick:f,onMove:y,onBack:()=>l("review")}),i==="done"&&s.jsx(Kf,{count:h,destinationLabel:Xn(r,m),onClose:o})]})}const Ir=[{id:"all",label:"All",tone:"neutral"},{id:"personal",label:"Personal",tone:"accent"},{id:"transactional",label:"Transactional",tone:"positive"},{id:"newsletter",label:"Newsletter",tone:"neutral"},{id:"marketing",label:"Marketing",tone:"warning"},{id:"social",label:"Social",tone:"warning"},{id:"automated",label:"Automated",tone:"neutral"}],mi={id:"unread",label:"Unread"},Uf={id:"flagged",label:"Starred"},hi={id:"attachment",label:"Has attachment"};function Qf(e){if(!(e.length<=1))return e.map(t=>({id:t.id,label:t.label,count:t.count,active:t.active}))}function Hf(e=[]){return{categories:[...Ir],filters:Rc,sources:Qf(e)}}function Wf(){return{categories:[...Ir],filters:[mi,Uf,hi]}}function Vf(){return{categories:[...Ir],filters:[mi,hi]}}function ht(e,t,{checkForDefaultPrevented:n=!0}={}){return function(a){if(e?.(a),n===!1||!a||!a.defaultPrevented)return t?.(a)}}function ja(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Yf(...e){return t=>{let n=!1;const r=e.map(a=>{const o=ja(a,t);return!n&&typeof o=="function"&&(n=!0),o});if(n)return()=>{for(let a=0;a<r.length;a++){const o=r[a];typeof o=="function"?o():ja(e[a],null)}}}}function At(...e){return c.useCallback(Yf(...e),e)}function Gf(e,t=[]){let n=[];function r(o,i){const l=c.createContext(i);l.displayName=o+"Context";const u=n.length;n=[...n,i];const d=f=>{const{scope:h,children:x,...b}=f,p=h?.[e]?.[u]||l,v=c.useMemo(()=>b,Object.values(b));return s.jsx(p.Provider,{value:v,children:x})};d.displayName=o+"Provider";function m(f,h,x={}){const{optional:b=!1}=x,p=h?.[e]?.[u]||l,v=c.useContext(p);if(v)return v;if(i!==void 0)return i;if(!b)throw new Error(`\`${f}\` must be used within \`${o}\``)}return[d,m]}const a=()=>{const o=n.map(i=>c.createContext(i));return function(l){const u=l?.[e]||o;return c.useMemo(()=>({[`__scope${e}`]:{...l,[e]:u}}),[l,u])}};return a.scopeName=e,[r,Xf(a,...t)]}function Xf(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(a=>({useScope:a(),scopeName:a.scopeName}));return function(o){const i=r.reduce((l,{useScope:u,scopeName:d})=>{const f=u(o)[`__scope${d}`];return{...l,...f}},{});return c.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var Is=globalThis?.document?c.useLayoutEffect:()=>{},Jf=mr[" useInsertionEffect ".trim().toString()]||Is;function Zf({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[a,o,i]=em({defaultProp:t,onChange:n}),l=e!==void 0,u=l?e:a;{const m=c.useRef(e!==void 0);c.useEffect(()=>{const f=m.current;f!==l&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${l?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),m.current=l},[l,r])}const d=c.useCallback(m=>{if(l){const f=tm(m)?m(e):m;f!==e&&i.current?.(f)}else o(m)},[l,e,o,i]);return[u,d]}function em({defaultProp:e,onChange:t}){const[n,r]=c.useState(e),a=c.useRef(n),o=c.useRef(t);return Jf(()=>{o.current=t},[t]),c.useEffect(()=>{a.current!==n&&(o.current?.(n),a.current=n)},[n,a]),[n,r,o]}function tm(e){return typeof e=="function"}function Rr(e){const t=c.forwardRef((n,r)=>{let{children:a,...o}=n,i=null,l=!1;const u=[];Sa(a)&&typeof Qs=="function"&&(a=Qs(a._payload)),c.Children.forEach(a,h=>{if(om(h)){l=!0;const x=h;let b="child"in x.props?x.props.child:x.props.children;Sa(b)&&typeof Qs=="function"&&(b=Qs(b._payload)),i=nm(x,b),u.push(i?.props?.children)}else u.push(h)}),i?i=c.cloneElement(i,void 0,u):!l&&c.Children.count(a)===1&&c.isValidElement(a)&&(i=a);const d=i?am(i):void 0,m=At(r,d);if(!i){if(a||a===0)throw new Error(l?um(e):cm(e));return a}const f=rm(o,i.props??{});return i.type!==c.Fragment&&(f.ref=r?m:d),c.cloneElement(i,f)});return t.displayName=`${e}.Slot`,t}var hy=Rr("Slot"),sm=Symbol.for("radix.slottable"),nm=(e,t)=>{if("child"in e.props){const n=e.props.child;return c.isValidElement(n)?c.cloneElement(n,void 0,e.props.children(n.props.children)):null}return c.isValidElement(t)?t:null};function rm(e,t){const n={...t};for(const r in t){const a=e[r],o=t[r];/^on[A-Z]/.test(r)?a&&o?n[r]=(...l)=>{const u=o(...l);return a(...l),u}:a&&(n[r]=a):r==="style"?n[r]={...a,...o}:r==="className"&&(n[r]=[a,o].filter(Boolean).join(" "))}return{...e,...n}}function am(e){let t=Object.getOwnPropertyDescriptor(e.props,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=Object.getOwnPropertyDescriptor(e,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}function om(e){return c.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===sm}var im=Symbol.for("react.lazy");function Sa(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===im&&"_payload"in e&&lm(e._payload)}function lm(e){return typeof e=="object"&&e!==null&&"then"in e}var cm=e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,um=e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,Qs=mr[" use ".trim().toString()],dm=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],it=dm.reduce((e,t)=>{const n=Rr(`Primitive.${t}`),r=c.forwardRef((a,o)=>{const{asChild:i,...l}=a,u=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),s.jsx(u,{...l,ref:o})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function fm(e,t){e&&hr.flushSync(()=>e.dispatchEvent(t))}function Rs(e){const t=c.useRef(e);return c.useEffect(()=>{t.current=e}),c.useMemo(()=>((...n)=>t.current?.(...n)),[])}var mm="DismissableLayer",Jn="dismissableLayer.update",hm="dismissableLayer.pointerDownOutside",gm="dismissableLayer.focusOutside",Na,Mr=c.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),gi=c.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,deferPointerDownOutside:r=!1,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:i,onInteractOutside:l,onDismiss:u,...d}=e,m=c.useContext(Mr),[f,h]=c.useState(null),x=f?.ownerDocument??globalThis?.document,[,b]=c.useState({}),p=At(t,h),v=Array.from(m.layers),[g]=[...m.layersWithOutsidePointerEventsDisabled].slice(-1),y=g?v.indexOf(g):-1,j=f?v.indexOf(f):-1,w=m.layersWithOutsidePointerEventsDisabled.size>0,C=j>=y,k=c.useRef(!1),S=ym(E=>{o?.(E),l?.(E),E.defaultPrevented||u?.()},{ownerDocument:x,deferPointerDownOutside:r,isDeferredPointerDownOutsideRef:k,dismissableSurfaces:m.dismissableSurfaces,shouldHandlePointerDownOutside:c.useCallback(E=>{if(!(E instanceof Node))return!1;const M=[...m.branches].some(I=>I.contains(E));return C&&!M},[m.branches,C])}),N=wm(E=>{if(r&&k.current)return;const M=E.target;[...m.branches].some(T=>T.contains(M))||(i?.(E),l?.(E),E.defaultPrevented||u?.())},x),R=f?j===v.length-1:!1,A=Rs(E=>{E.key==="Escape"&&(a?.(E),!E.defaultPrevented&&u&&(E.preventDefault(),u()))});return c.useEffect(()=>{if(R)return x.addEventListener("keydown",A,{capture:!0}),()=>x.removeEventListener("keydown",A,{capture:!0})},[x,R,A]),c.useEffect(()=>{if(f)return n&&(m.layersWithOutsidePointerEventsDisabled.size===0&&(Na=x.body.style.pointerEvents,x.body.style.pointerEvents="none"),m.layersWithOutsidePointerEventsDisabled.add(f)),m.layers.add(f),ka(),()=>{n&&(m.layersWithOutsidePointerEventsDisabled.delete(f),m.layersWithOutsidePointerEventsDisabled.size===0&&(x.body.style.pointerEvents=Na))}},[f,x,n,m]),c.useEffect(()=>()=>{f&&(m.layers.delete(f),m.layersWithOutsidePointerEventsDisabled.delete(f),ka())},[f,m]),c.useEffect(()=>{const E=()=>b({});return document.addEventListener(Jn,E),()=>document.removeEventListener(Jn,E)},[]),s.jsx(it.div,{...d,ref:p,style:{pointerEvents:w?C?"auto":"none":void 0,...e.style},onFocusCapture:ht(e.onFocusCapture,N.onFocusCapture),onBlurCapture:ht(e.onBlurCapture,N.onBlurCapture),onPointerDownCapture:ht(e.onPointerDownCapture,S.onPointerDownCapture)})});gi.displayName=mm;var pm="DismissableLayerBranch",xm=c.forwardRef((e,t)=>{const n=c.useContext(Mr),r=c.useRef(null),a=At(t,r);return c.useEffect(()=>{const o=r.current;if(o)return n.branches.add(o),()=>{n.branches.delete(o)}},[n.branches]),s.jsx(it.div,{...e,ref:a})});xm.displayName=pm;function bm(){const e=c.useContext(Mr),[t,n]=c.useState(null);return c.useEffect(()=>{if(t)return e.dismissableSurfaces.add(t),()=>{e.dismissableSurfaces.delete(t)}},[t,e.dismissableSurfaces]),n}var vm=()=>!0;function ym(e,t){const{ownerDocument:n=globalThis?.document,deferPointerDownOutside:r=!1,isDeferredPointerDownOutsideRef:a,dismissableSurfaces:o,shouldHandlePointerDownOutside:i=vm}=t,l=Rs(e),u=c.useRef(!1),d=c.useRef(!1),m=c.useRef(new Map),f=c.useRef(()=>{});return c.useEffect(()=>{function h(){d.current=!1,a.current=!1,m.current.clear()}function x(){return Array.from(m.current.values()).some(Boolean)}function b(j){if(!d.current)return;const w=j.target;w instanceof Node&&[...o].some(k=>k.contains(w))||m.current.set(j.type,!0),j.type==="click"&&window.setTimeout(()=>{d.current&&f.current()},0)}function p(j){d.current&&m.current.set(j.type,!1)}const v=j=>{if(j.target&&!u.current){let w=function(){n.removeEventListener("click",f.current);const k=x();h(),k||pi(hm,l,C,{discrete:!0})};if(!i(j.target)){n.removeEventListener("click",f.current),h(),u.current=!1;return}const C={originalEvent:j};d.current=!0,a.current=r&&j.button===0,m.current.clear(),!r||j.button!==0?w():(n.removeEventListener("click",f.current),f.current=w,n.addEventListener("click",f.current,{once:!0}))}else n.removeEventListener("click",f.current),h();u.current=!1},g=["pointerup","mousedown","mouseup","touchstart","touchend","click"];for(const j of g)n.addEventListener(j,b,!0),n.addEventListener(j,p);const y=window.setTimeout(()=>{n.addEventListener("pointerdown",v)},0);return()=>{window.clearTimeout(y),n.removeEventListener("pointerdown",v),n.removeEventListener("click",f.current);for(const j of g)n.removeEventListener(j,b,!0),n.removeEventListener(j,p)}},[n,l,r,a,o,i]),{onPointerDownCapture:()=>u.current=!0}}function wm(e,t=globalThis?.document){const n=Rs(e),r=c.useRef(!1);return c.useEffect(()=>{const a=o=>{o.target&&!r.current&&pi(gm,n,{originalEvent:o},{discrete:!1})};return t.addEventListener("focusin",a),()=>t.removeEventListener("focusin",a)},[t,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function ka(){const e=new CustomEvent(Jn);document.dispatchEvent(e)}function pi(e,t,n,{discrete:r}){const a=n.originalEvent.target,o=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});t&&a.addEventListener(e,t,{once:!0}),r?fm(a,o):a.dispatchEvent(o)}var Hs=0,Ut=null;function jm(){c.useEffect(()=>{Ut||(Ut={start:Ca(),end:Ca()});const{start:e,end:t}=Ut;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==t&&document.body.insertAdjacentElement("beforeend",t),Hs++,()=>{Hs===1&&(Ut?.start.remove(),Ut?.end.remove(),Ut=null),Hs=Math.max(0,Hs-1)}},[])}function Ca(){const e=document.createElement("span");return e.setAttribute("data-radix-focus-guard",""),e.tabIndex=0,e.style.outline="none",e.style.opacity="0",e.style.position="fixed",e.style.pointerEvents="none",e}var An="focusScope.autoFocusOnMount",Dn="focusScope.autoFocusOnUnmount",Ea={bubbles:!1,cancelable:!0},Sm="FocusScope",xi=c.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:a,onUnmountAutoFocus:o,...i}=e,[l,u]=c.useState(null),d=Rs(a),m=Rs(o),f=c.useRef(null),h=At(t,u),x=c.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;c.useEffect(()=>{if(r){let p=function(j){if(x.paused||!l)return;const w=j.target;l.contains(w)?f.current=w:dt(f.current,{select:!0})},v=function(j){if(x.paused||!l)return;const w=j.relatedTarget;w!==null&&(l.contains(w)||dt(f.current,{select:!0}))},g=function(j){if(document.activeElement===document.body)for(const C of j)C.removedNodes.length>0&&dt(l)};document.addEventListener("focusin",p),document.addEventListener("focusout",v);const y=new MutationObserver(g);return l&&y.observe(l,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",p),document.removeEventListener("focusout",v),y.disconnect()}}},[r,l,x.paused]),c.useEffect(()=>{if(l){Ra.add(x);const p=document.activeElement;if(!l.contains(p)){const g=new CustomEvent(An,Ea);l.addEventListener(An,d),l.dispatchEvent(g),g.defaultPrevented||(Nm(Rm(bi(l)),{select:!0}),document.activeElement===p&&dt(l))}return()=>{l.removeEventListener(An,d),setTimeout(()=>{const g=new CustomEvent(Dn,Ea);l.addEventListener(Dn,m),l.dispatchEvent(g),g.defaultPrevented||dt(p??document.body,{select:!0}),l.removeEventListener(Dn,m),Ra.remove(x)},0)}}},[l,d,m,x]);const b=c.useCallback(p=>{if(!n&&!r||x.paused)return;const v=p.key==="Tab"&&!p.altKey&&!p.ctrlKey&&!p.metaKey,g=document.activeElement;if(v&&g){const y=p.currentTarget,[j,w]=km(y);j&&w?!p.shiftKey&&g===w?(p.preventDefault(),n&&dt(j,{select:!0})):p.shiftKey&&g===j&&(p.preventDefault(),n&&dt(w,{select:!0})):g===y&&p.preventDefault()}},[n,r,x.paused]);return s.jsx(it.div,{tabIndex:-1,...i,ref:h,onKeyDown:b})});xi.displayName=Sm;function Nm(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(dt(r,{select:t}),document.activeElement!==n)return}function km(e){const t=bi(e),n=Ia(t,e),r=Ia(t.reverse(),e);return[n,r]}function bi(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const a=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||a?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function Ia(e,t){const n=typeof t.checkVisibility=="function"&&t.checkVisibility({checkVisibilityCSS:!0});for(const r of e)if(!(n?!r.checkVisibility({checkVisibilityCSS:!0}):Cm(r,{upTo:t})))return r}function Cm(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}function Em(e){return e instanceof HTMLInputElement&&"select"in e}function dt(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Em(e)&&t&&e.select()}}var Ra=Im();function Im(){let e=[];return{add(t){const n=e[0];t!==n&&n?.pause(),e=Ma(e,t),e.unshift(t)},remove(t){e=Ma(e,t),e[0]?.resume()}}}function Ma(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Rm(e){return e.filter(t=>t.tagName!=="A")}var Mm=mr[" useId ".trim().toString()]||(()=>{}),Tm=0;function On(e){const[t,n]=c.useState(Mm());return Is(()=>{n(r=>r??String(Tm++))},[e]),e||(t?`radix-${t}`:"")}var Am="Portal",vi=c.forwardRef((e,t)=>{const{container:n,...r}=e,[a,o]=c.useState(!1);Is(()=>o(!0),[]);const i=n||a&&globalThis?.document?.body;return i?hr.createPortal(s.jsx(it.div,{...r,ref:t}),i):null});vi.displayName=Am;function Dm(e,t){return c.useReducer((n,r)=>t[n][r]??n,e)}var bn=e=>{const{present:t,children:n}=e,r=Om(t),a=typeof n=="function"?n({present:r.isPresent}):c.Children.only(n),o=Pm(r.ref,Lm(a));return typeof n=="function"||r.isPresent?c.cloneElement(a,{ref:o}):null};bn.displayName="Presence";function Om(e){const[t,n]=c.useState(),r=c.useRef(null),a=c.useRef(e),o=c.useRef("none"),i=c.useRef(void 0),l=e?"mounted":"unmounted",[u,d]=Dm(l,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return c.useEffect(()=>{u==="mounted"?(o.current=i.current??xs(r.current),i.current=void 0):o.current="none"},[u]),Is(()=>{const m=r.current,f=a.current;if(f!==e){const x=o.current,b=xs(m);e?(i.current=b,d("MOUNT")):b==="none"||m?.display==="none"?d("UNMOUNT"):d(f&&x!==b?"ANIMATION_OUT":"UNMOUNT"),a.current=e}},[e,d]),Is(()=>{if(t){let m;const f=t.ownerDocument.defaultView??window,h=b=>{const v=xs(r.current).includes(CSS.escape(b.animationName));if(b.target===t&&v&&(d("ANIMATION_END"),!a.current)){const g=t.style.animationFillMode;t.style.animationFillMode="forwards",m=f.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=g)})}},x=b=>{b.target===t&&(o.current=xs(r.current))};return t.addEventListener("animationstart",x),t.addEventListener("animationcancel",h),t.addEventListener("animationend",h),()=>{f.clearTimeout(m),t.removeEventListener("animationstart",x),t.removeEventListener("animationcancel",h),t.removeEventListener("animationend",h)}}else d("ANIMATION_END")},[t,d]),{isPresent:["mounted","unmountSuspended"].includes(u),ref:c.useCallback(m=>{if(m){const f=getComputedStyle(m);r.current=f,i.current=xs(f)}else r.current=null;n(m)},[])}}function Ta(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Pm(...e){const t=c.useRef(e);return t.current=e,c.useCallback(n=>{const r=t.current;let a=!1;const o=r.map(i=>{const l=Ta(i,n);return!a&&typeof l=="function"&&(a=!0),l});if(a)return()=>{for(let i=0;i<o.length;i++){const l=o[i];typeof l=="function"?l():Ta(r[i],null)}}},[])}function xs(e){return e?.animationName||"none"}function Lm(e){let t=Object.getOwnPropertyDescriptor(e.props,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=Object.getOwnPropertyDescriptor(e,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var zm=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Qt=new WeakMap,Ws=new WeakMap,Vs={},Pn=0,yi=function(e){return e&&(e.host||yi(e.parentNode))},Fm=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=yi(n);return r&&e.contains(r)?r:(console.error("aria-hidden",n,"in not contained inside",e,". Doing nothing"),null)}).filter(function(n){return!!n})},_m=function(e,t,n,r){var a=Fm(t,Array.isArray(e)?e:[e]);Vs[n]||(Vs[n]=new WeakMap);var o=Vs[n],i=[],l=new Set,u=new Set(a),d=function(f){!f||l.has(f)||(l.add(f),d(f.parentNode))};a.forEach(d);var m=function(f){!f||u.has(f)||Array.prototype.forEach.call(f.children,function(h){if(l.has(h))m(h);else try{var x=h.getAttribute(r),b=x!==null&&x!=="false",p=(Qt.get(h)||0)+1,v=(o.get(h)||0)+1;Qt.set(h,p),o.set(h,v),i.push(h),p===1&&b&&Ws.set(h,!0),v===1&&h.setAttribute(n,"true"),b||h.setAttribute(r,"true")}catch(g){console.error("aria-hidden: cannot operate on ",h,g)}})};return m(t),l.clear(),Pn++,function(){i.forEach(function(f){var h=Qt.get(f)-1,x=o.get(f)-1;Qt.set(f,h),o.set(f,x),h||(Ws.has(f)||f.removeAttribute(r),Ws.delete(f)),x||f.removeAttribute(n)}),Pn--,Pn||(Qt=new WeakMap,Qt=new WeakMap,Ws=new WeakMap,Vs={})}},Bm=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),a=zm(e);return a?(r.push.apply(r,Array.from(a.querySelectorAll("[aria-live], script"))),_m(r,a,n,"aria-hidden")):function(){return null}},tn="right-scroll-bar-position",sn="width-before-scroll-bar",$m="with-scroll-bars-hidden",Km="--removed-body-scroll-bar-size";function Ln(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function qm(e,t){var n=c.useState(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(r){var a=n.value;a!==r&&(n.value=r,n.callback(r,a))}}}})[0];return n.callback=t,n.facade}var Um=typeof window<"u"?c.useLayoutEffect:c.useEffect,Aa=new WeakMap;function Qm(e,t){var n=qm(null,function(r){return e.forEach(function(a){return Ln(a,r)})});return Um(function(){var r=Aa.get(n);if(r){var a=new Set(r),o=new Set(e),i=n.current;a.forEach(function(l){o.has(l)||Ln(l,null)}),o.forEach(function(l){a.has(l)||Ln(l,i)})}Aa.set(n,e)},[e]),n}function Hm(e){return e}function Wm(e,t){t===void 0&&(t=Hm);var n=[],r=!1,a={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(o){var i=t(o,r);return n.push(i),function(){n=n.filter(function(l){return l!==i})}},assignSyncMedium:function(o){for(r=!0;n.length;){var i=n;n=[],i.forEach(o)}n={push:function(l){return o(l)},filter:function(){return n}}},assignMedium:function(o){r=!0;var i=[];if(n.length){var l=n;n=[],l.forEach(o),i=n}var u=function(){var m=i;i=[],m.forEach(o)},d=function(){return Promise.resolve().then(u)};d(),n={push:function(m){i.push(m),d()},filter:function(m){return i=i.filter(m),n}}}};return a}function Vm(e){e===void 0&&(e={});var t=Wm(null);return t.options=ft({async:!0,ssr:!1},e),t}var wi=function(e){var t=e.sideCar,n=jo(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return c.createElement(r,ft({},n))};wi.isSideCarExport=!0;function Ym(e,t){return e.useMedium(t),wi}var ji=Vm(),zn=function(){},vn=c.forwardRef(function(e,t){var n=c.useRef(null),r=c.useState({onScrollCapture:zn,onWheelCapture:zn,onTouchMoveCapture:zn}),a=r[0],o=r[1],i=e.forwardProps,l=e.children,u=e.className,d=e.removeScrollBar,m=e.enabled,f=e.shards,h=e.sideCar,x=e.noRelative,b=e.noIsolation,p=e.inert,v=e.allowPinchZoom,g=e.as,y=g===void 0?"div":g,j=e.gapMode,w=jo(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),C=h,k=Qm([n,t]),S=ft(ft({},w),a);return c.createElement(c.Fragment,null,m&&c.createElement(C,{sideCar:ji,removeScrollBar:d,shards:f,noRelative:x,noIsolation:b,inert:p,setCallbacks:o,allowPinchZoom:!!v,lockRef:n,gapMode:j}),i?c.cloneElement(c.Children.only(l),ft(ft({},S),{ref:k})):c.createElement(y,ft({},S,{className:u,ref:k}),l))});vn.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};vn.classNames={fullWidth:sn,zeroRight:tn};var Gm=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Xm(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Gm();return t&&e.setAttribute("nonce",t),e}function Jm(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Zm(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var eh=function(){var e=0,t=null;return{add:function(n){e==0&&(t=Xm())&&(Jm(t,n),Zm(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},th=function(){var e=eh();return function(t,n){c.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},Si=function(){var e=th(),t=function(n){var r=n.styles,a=n.dynamic;return e(r,a),null};return t},sh={left:0,top:0,right:0,gap:0},Fn=function(e){return parseInt(e||"",10)||0},nh=function(e){var t=window.getComputedStyle(document.body),n=t[e==="padding"?"paddingLeft":"marginLeft"],r=t[e==="padding"?"paddingTop":"marginTop"],a=t[e==="padding"?"paddingRight":"marginRight"];return[Fn(n),Fn(r),Fn(a)]},rh=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return sh;var t=nh(e),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-n+t[2]-t[0])}},ah=Si(),Jt="data-scroll-locked",oh=function(e,t,n,r){var a=e.left,o=e.top,i=e.right,l=e.gap;return n===void 0&&(n="margin"),`
|
|
70
|
-
.`.concat($m,` {
|
|
71
|
-
overflow: hidden `).concat(r,`;
|
|
72
|
-
padding-right: `).concat(l,"px ").concat(r,`;
|
|
73
|
-
}
|
|
74
|
-
body[`).concat(Jt,`] {
|
|
75
|
-
overflow: hidden `).concat(r,`;
|
|
76
|
-
overscroll-behavior: contain;
|
|
77
|
-
`).concat([t&&"position: relative ".concat(r,";"),n==="margin"&&`
|
|
78
|
-
padding-left: `.concat(a,`px;
|
|
79
|
-
padding-top: `).concat(o,`px;
|
|
80
|
-
padding-right: `).concat(i,`px;
|
|
81
|
-
margin-left:0;
|
|
82
|
-
margin-top:0;
|
|
83
|
-
margin-right: `).concat(l,"px ").concat(r,`;
|
|
84
|
-
`),n==="padding"&&"padding-right: ".concat(l,"px ").concat(r,";")].filter(Boolean).join(""),`
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
.`).concat(tn,` {
|
|
88
|
-
right: `).concat(l,"px ").concat(r,`;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
.`).concat(sn,` {
|
|
92
|
-
margin-right: `).concat(l,"px ").concat(r,`;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
.`).concat(tn," .").concat(tn,` {
|
|
96
|
-
right: 0 `).concat(r,`;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
.`).concat(sn," .").concat(sn,` {
|
|
100
|
-
margin-right: 0 `).concat(r,`;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
body[`).concat(Jt,`] {
|
|
104
|
-
`).concat(Km,": ").concat(l,`px;
|
|
105
|
-
}
|
|
106
|
-
`)},Da=function(){var e=parseInt(document.body.getAttribute(Jt)||"0",10);return isFinite(e)?e:0},ih=function(){c.useEffect(function(){return document.body.setAttribute(Jt,(Da()+1).toString()),function(){var e=Da()-1;e<=0?document.body.removeAttribute(Jt):document.body.setAttribute(Jt,e.toString())}},[])},lh=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,a=r===void 0?"margin":r;ih();var o=c.useMemo(function(){return rh(a)},[a]);return c.createElement(ah,{styles:oh(o,!t,a,n?"":"!important")})},Zn=!1;if(typeof window<"u")try{var Ys=Object.defineProperty({},"passive",{get:function(){return Zn=!0,!0}});window.addEventListener("test",Ys,Ys),window.removeEventListener("test",Ys,Ys)}catch{Zn=!1}var Ht=Zn?{passive:!1}:!1,ch=function(e){return e.tagName==="TEXTAREA"},Ni=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!ch(e)&&n[t]==="visible")},uh=function(e){return Ni(e,"overflowY")},dh=function(e){return Ni(e,"overflowX")},Oa=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var a=ki(e,r);if(a){var o=Ci(e,r),i=o[1],l=o[2];if(i>l)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},fh=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},mh=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},ki=function(e,t){return e==="v"?uh(t):dh(t)},Ci=function(e,t){return e==="v"?fh(t):mh(t)},hh=function(e,t){return e==="h"&&t==="rtl"?-1:1},gh=function(e,t,n,r,a){var o=hh(e,window.getComputedStyle(t).direction),i=o*r,l=n.target,u=t.contains(l),d=!1,m=i>0,f=0,h=0;do{if(!l)break;var x=Ci(e,l),b=x[0],p=x[1],v=x[2],g=p-v-o*b;(b||g)&&ki(e,l)&&(f+=g,h+=b);var y=l.parentNode;l=y&&y.nodeType===Node.DOCUMENT_FRAGMENT_NODE?y.host:y}while(!u&&l!==document.body||u&&(t.contains(l)||t===l));return(m&&Math.abs(f)<1||!m&&Math.abs(h)<1)&&(d=!0),d},Gs=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Pa=function(e){return[e.deltaX,e.deltaY]},La=function(e){return e&&"current"in e?e.current:e},ph=function(e,t){return e[0]===t[0]&&e[1]===t[1]},xh=function(e){return`
|
|
107
|
-
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
108
|
-
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
109
|
-
`)},bh=0,Wt=[];function vh(e){var t=c.useRef([]),n=c.useRef([0,0]),r=c.useRef(),a=c.useState(bh++)[0],o=c.useState(Si)[0],i=c.useRef(e);c.useEffect(function(){i.current=e},[e]),c.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(a));var p=Mc([e.lockRef.current],(e.shards||[]).map(La),!0).filter(Boolean);return p.forEach(function(v){return v.classList.add("allow-interactivity-".concat(a))}),function(){document.body.classList.remove("block-interactivity-".concat(a)),p.forEach(function(v){return v.classList.remove("allow-interactivity-".concat(a))})}}},[e.inert,e.lockRef.current,e.shards]);var l=c.useCallback(function(p,v){if("touches"in p&&p.touches.length===2||p.type==="wheel"&&p.ctrlKey)return!i.current.allowPinchZoom;var g=Gs(p),y=n.current,j="deltaX"in p?p.deltaX:y[0]-g[0],w="deltaY"in p?p.deltaY:y[1]-g[1],C,k=p.target,S=Math.abs(j)>Math.abs(w)?"h":"v";if("touches"in p&&S==="h"&&k.type==="range")return!1;var N=window.getSelection(),R=N&&N.anchorNode,A=R?R===k||R.contains(k):!1;if(A)return!1;var E=Oa(S,k);if(!E)return!0;if(E?C=S:(C=S==="v"?"h":"v",E=Oa(S,k)),!E)return!1;if(!r.current&&"changedTouches"in p&&(j||w)&&(r.current=C),!C)return!0;var M=r.current||C;return gh(M,v,p,M==="h"?j:w)},[]),u=c.useCallback(function(p){var v=p;if(!(!Wt.length||Wt[Wt.length-1]!==o)){var g="deltaY"in v?Pa(v):Gs(v),y=t.current.filter(function(C){return C.name===v.type&&(C.target===v.target||v.target===C.shadowParent)&&ph(C.delta,g)})[0];if(y&&y.should){v.cancelable&&v.preventDefault();return}if(!y){var j=(i.current.shards||[]).map(La).filter(Boolean).filter(function(C){return C.contains(v.target)}),w=j.length>0?l(v,j[0]):!i.current.noIsolation;w&&v.cancelable&&v.preventDefault()}}},[]),d=c.useCallback(function(p,v,g,y){var j={name:p,delta:v,target:g,should:y,shadowParent:yh(g)};t.current.push(j),setTimeout(function(){t.current=t.current.filter(function(w){return w!==j})},1)},[]),m=c.useCallback(function(p){n.current=Gs(p),r.current=void 0},[]),f=c.useCallback(function(p){d(p.type,Pa(p),p.target,l(p,e.lockRef.current))},[]),h=c.useCallback(function(p){d(p.type,Gs(p),p.target,l(p,e.lockRef.current))},[]);c.useEffect(function(){return Wt.push(o),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:h}),document.addEventListener("wheel",u,Ht),document.addEventListener("touchmove",u,Ht),document.addEventListener("touchstart",m,Ht),function(){Wt=Wt.filter(function(p){return p!==o}),document.removeEventListener("wheel",u,Ht),document.removeEventListener("touchmove",u,Ht),document.removeEventListener("touchstart",m,Ht)}},[]);var x=e.removeScrollBar,b=e.inert;return c.createElement(c.Fragment,null,b?c.createElement(o,{styles:xh(a)}):null,x?c.createElement(lh,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function yh(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const wh=Ym(ji,vh);var Ei=c.forwardRef(function(e,t){return c.createElement(vn,ft({},e,{ref:t,sideCar:wh}))});Ei.classNames=vn.classNames;var jh=class extends gr{constructor(e,t){super(e,t)}bindMethods(){super.bindMethods(),this.fetchNextPage=this.fetchNextPage.bind(this),this.fetchPreviousPage=this.fetchPreviousPage.bind(this)}setOptions(e){e._type="infinite",super.setOptions(e)}getOptimisticResult(e){return e._type="infinite",super.getOptimisticResult(e)}fetchNextPage(e){return this.fetch({...e,meta:{fetchMore:{direction:"forward"}}})}fetchPreviousPage(e){return this.fetch({...e,meta:{fetchMore:{direction:"backward"}}})}createResult(e,t){const{state:n}=e,r=super.createResult(e,t),{isFetching:a,isRefetching:o,isError:i,isRefetchError:l}=r,u=n.fetchMeta?.fetchMore?.direction,d=i&&u==="forward",m=a&&u==="forward",f=i&&u==="backward",h=a&&u==="backward";return{...r,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:Ac(t,n.data),hasPreviousPage:Tc(t,n.data),isFetchNextPageError:d,isFetchingNextPage:m,isFetchPreviousPageError:f,isFetchingPreviousPage:h,isRefetchError:l&&!d&&!f,isRefetching:o&&!m&&!h}}};function za(e,t){const n=new Set(t);return e.filter(r=>!n.has(r))}function Sh(e,t,n){const r=e.slice(0);return r[t]=n,r}var Nh=class extends Dc{#r;#e;#a;#n;#t;#s;#o;#i;#l;#c=[];constructor(e,t,n){super(),this.#r=e,this.#n=n,this.#a=[],this.#t=[],this.#e=[],this.setQueries(t)}onSubscribe(){this.listeners.size===1&&this.#t.forEach(e=>{e.subscribe(t=>{this.#m(e,t)})})}onUnsubscribe(){this.listeners.size||this.destroy()}destroy(){this.listeners=new Set,this.#t.forEach(e=>{e.destroy()})}setQueries(e,t){this.#a=e,this.#n=t,Wn.batch(()=>{const n=this.#t,r=this.#f(this.#a);r.forEach(m=>m.observer.setOptions(m.defaultedQueryOptions));const a=r.map(m=>m.observer),o=a.map(m=>m.getCurrentResult()),i=n.length!==a.length,l=a.some((m,f)=>m!==n[f]),u=i||l,d=u?!0:o.some((m,f)=>{const h=this.#e[f];return!h||!Oc(m,h)});!u&&!d||(u&&(this.#c=r,this.#t=a),this.#e=o,this.hasListeners()&&(u&&(za(n,a).forEach(m=>{m.destroy()}),za(a,n).forEach(m=>{m.subscribe(f=>{this.#m(m,f)})})),this.#h()))})}getCurrentResult(){return this.#e}getQueries(){return this.#t.map(e=>e.getCurrentQuery())}getObservers(){return this.#t}getOptimisticResult(e,t){const n=this.#f(e),r=n.map(o=>o.observer.getOptimisticResult(o.defaultedQueryOptions)),a=n.map(o=>o.defaultedQueryOptions.queryHash);return[r,o=>this.#d(o??r,t,a),()=>this.#u(r,n)]}#u(e,t){return t.map((n,r)=>{const a=e[r];return n.defaultedQueryOptions.notifyOnChangeProps?a:n.observer.trackResult(a,o=>{t.forEach(i=>{i.observer.trackProp(o)})})})}#d(e,t,n){if(t){const r=this.#l,a=n!==void 0&&r!==void 0&&(r.length!==n.length||n.some((o,i)=>o!==r[i]));return(!this.#s||this.#e!==this.#i||a||t!==this.#o)&&(this.#o=t,this.#i=this.#e,n!==void 0&&(this.#l=n),this.#s=Pc(this.#s,t(e))),this.#s}return e}#g(){return this.#n?.combine!==void 0&&this.#t.some((e,t)=>e.options.suspense&&this.#e[t]?.data===void 0)}#f(e){const t=new Map;this.#t.forEach(r=>{const a=r.options.queryHash;if(!a)return;const o=t.get(a);o?o.push(r):t.set(a,[r])});const n=[];return e.forEach(r=>{const a=this.#r.defaultQueryOptions(r),i=t.get(a.queryHash)?.shift()??new gr(this.#r,a);n.push({defaultedQueryOptions:a,observer:i})}),n}#m(e,t){const n=this.#t.indexOf(e);n!==-1&&(this.#e=Sh(this.#e,n,t),this.#h())}#h(){if(this.hasListeners()){const e=this.#u(this.#e,this.#c),t=this.#g(),n=this.#s,r=t?n:this.#d(e,this.#n?.combine);(t||n!==r)&&Wn.batch(()=>{this.listeners.forEach(a=>{a(this.#e)})})}}};function Dt({queries:e,...t},n){const r=je(),a=Lc(),o=zc(),i=c.useMemo(()=>e.map(p=>{const v=r.defaultQueryOptions(p);return v._optimisticResults=a?"isRestoring":"optimistic",v}),[e,r,a]);i.forEach(p=>{Fc(p);const v=r.getQueryCache().get(p.queryHash);_c(p,o,v)}),Bc(o);const[l]=c.useState(()=>new Nh(r,i,t)),[u,d,m]=l.getOptimisticResult(i,t.combine),f=!a&&t.subscribed!==!1;c.useSyncExternalStore(c.useCallback(p=>f?l.subscribe(Wn.batchCalls(p)):$c,[l,f]),()=>l.getCurrentResult(),()=>l.getCurrentResult()),c.useEffect(()=>{l.setQueries(i,t)},[i,t,l]);const x=u.some((p,v)=>Jr(i[v],p))?u.flatMap((p,v)=>{const g=i[v];if(g&&Jr(g,p)){const y=new gr(r,g);return Kc(g,y,o)}return[]}):[];if(x.length>0)throw Promise.all(x);const b=u.find((p,v)=>{const g=i[v];return g&&qc({result:p,errorResetBoundary:o,throwOnError:g.throwOnError,query:r.getQueryCache().get(g.queryHash),suspense:g.suspense})});if(b?.error)throw b.error;return d(m())}function Ii(e,t){return Uc(e,jh)}function mt(e){const t=So({warn:e?.router===void 0}),n=e?.router||t;return No(n.stores.__store,ko(e,n))}function yn(e){const t=So();return No(t.stores.location,ko(e,t))}const kh=new Set(["outbox","flagged"]),Ch=e=>{const[,t,n]=e.split(/[?#]/)[0].split("/");return t!=="mail"||!n?!1:!kh.has(n)};function Eh(e){const t=Dt({queries:e.map(n=>({...Ze({path:{accountId:n.accountId}}),staleTime:1/0}))});for(const[n,r]of e.entries()){const a=t[n];if(!a||a.isPending)return;const o=a.data?.items??[];if(o.length===0)continue;const i=is(r.folderAppointments);return(o.find(u=>i.get(u.mailboxId)==="inbox")??o[0])?.mailboxId}}function Ri(e){const{openCompose:t}=xt(),n=Me(),r=yn(),a=Eh(e);return c.useCallback(()=>{if(Ch(r.pathname)){c.startTransition(()=>{t({mode:"new"})});return}a&&(c.startTransition(()=>{t({mode:"new"})}),n({to:"/mail/$mailboxId",params:{mailboxId:a}}))},[t,n,r.pathname,a])}const Ih=e=>e.startsWith("/mail")||e.startsWith("/settings"),Rh=({accounts:e})=>{const{state:t}=xt(),n=yn(),r=Ri(e),a=n.search,o=typeof a?.selectedMessageId=="string"&&a.selectedMessageId.length>0;return!Ih(n.pathname)||t.isOpen||o?null:s.jsx("button",{type:"button",onClick:r,"aria-label":"Compose new message",className:"lg:hidden fixed right-4 z-30 h-14 w-14 rounded-full bg-accent text-accent-fg shadow-lg flex items-center justify-center hover:opacity-90 active:scale-95 transition-all",style:{bottom:"calc(env(safe-area-inset-bottom, 0) + 1rem)"},children:s.jsx(_u,{className:"size-6"})})},Mi=({trigger:e,children:t,align:n="right"})=>{const[r,a]=c.useState(!1),o=c.useRef(null),i=c.useCallback(u=>{o.current&&!o.current.contains(u.target)&&a(!1)},[]),l=c.useCallback(u=>{u.key==="Escape"&&a(!1)},[]);return c.useEffect(()=>(r&&(document.addEventListener("mousedown",i),document.addEventListener("keydown",l)),()=>{document.removeEventListener("mousedown",i),document.removeEventListener("keydown",l)}),[r,i,l]),s.jsxs("div",{ref:o,className:"relative",children:[s.jsx("button",{type:"button",onClick:u=>{u.stopPropagation(),a(!r)},className:fe("p-1.5 min-h-11 min-w-11 inline-flex items-center justify-center rounded-md transition-colors","hover:bg-surface-raised text-fg-muted hover:text-fg"),children:e}),r&&s.jsx("div",{className:fe("absolute z-50 mt-1 min-w-[180px] py-1","bg-surface border border-line rounded-md shadow-lg",n==="right"?"right-0":"left-0"),children:t})]})},Gt=({onClick:e,disabled:t,destructive:n,children:r})=>s.jsx("button",{type:"button",onClick:a=>{a.stopPropagation(),t||e()},disabled:t,className:fe("w-full px-3 py-2 text-left text-sm transition-colors","flex items-center gap-2",t&&"opacity-50 cursor-not-allowed",!t&&"hover:bg-surface-raised",n&&"text-danger hover:text-danger"),children:r}),er=()=>s.jsx("div",{className:"my-1 h-px bg-line"}),Ti=({children:e})=>{const{Account:t}=pr();return s.jsx(t,{children:e})},Mh=({email:e,onSignOut:t})=>{const n=Me(),r=e??"Account";return s.jsxs(Mi,{trigger:s.jsx(He,{name:r,email:e??void 0,size:"sm"}),align:"right",children:[e&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-3 py-2 text-xs text-fg-muted truncate",title:e,"data-testid":"account-menu-email",children:e}),s.jsx(er,{})]}),s.jsxs(Gt,{onClick:()=>n({to:"/settings/accounts"}),children:[s.jsx(Xo,{className:"size-4"}),"Settings"]}),s.jsx(er,{}),s.jsxs(Gt,{onClick:t,children:[s.jsx(Wo,{className:"size-4"}),"Sign out"]})]})},Th=()=>s.jsx(Ti,{children:({email:e,signOut:t})=>s.jsx(Mh,{email:e,onSignOut:t})}),Fa=()=>{const e=xr(),t=br(e);window.open(t,"_blank","noopener,noreferrer")};function Ai({variant:e="icon"}){return e==="drawer"?s.jsxs("button",{type:"button",onClick:Fa,className:"flex w-full items-center gap-2 rounded-md px-2 py-1 text-sm text-fg-muted transition-colors hover:bg-surface hover:text-fg",children:[s.jsx(Zr,{className:"size-4 shrink-0"}),s.jsx("span",{className:"flex-1 truncate text-left",children:"Report a bug"})]}):s.jsx(V,{variant:"ghost",size:"sm",icon:s.jsx(Zr,{className:"size-4"}),title:"Report a bug","aria-label":"Report a bug",onClick:Fa})}const Di="/mail/",Tr="/mail/$mailboxId",Oi="/mail/outbox",Pi="/mail/flagged";function Ar(e){return e.some(t=>t.routeId===Di)}function wn(e){return e.some(t=>t.routeId===Pi)}function jn(e){return e.some(t=>t.routeId===Oi)}function Li(e){return e.some(t=>t.routeId===Tr)}function Ah(e){const t=e.find(n=>n.params?.mailboxId)?.params?.mailboxId;return t?`${Tr}:${t}`:wn(e)?Pi:jn(e)?Oi:Ar(e)?Di:""}const nn="search-scope";function Dh(e){const t=e.trim().replace(/\s+/g," ").toLowerCase();return/\s/.test(t)?`in:"${t}"`:`in:${t}`}function zi(e){return wn(e)||jn(e)||Li(e)}function Oh(e){return e.find(t=>t.routeId===Tr)?.params?.mailboxId}function Ph(e){const t=Oh(e.matches);return t||(zi(e.matches)?e.callerMailboxId:e.callerMailboxId??e.inTokenMailboxId)}function Lh(e,t){return Ar(e)?{kind:"global"}:wn(e)?{kind:"scoped",chip:{id:nn,label:"is:starred"}}:jn(e)?{kind:"scoped",chip:{id:nn,label:"in:outbox"}}:Li(e)?t?{kind:"scoped",chip:{id:nn,label:Dh(t)}}:{kind:"pending"}:{kind:"global"}}const Fi=({accounts:e})=>{const t=vr({strict:!1}),n=yn(),r=t.mailboxId,{t:a}=fn("mail",{useSuspense:!1}),o=c.useCallback((l,u)=>a(l,{defaultValue:u}),[a]),i=Dt({queries:e.map(l=>({...Ze({path:{accountId:l.accountId}}),staleTime:1/0}))});if(n.pathname.startsWith("/mail/outbox"))return"Outbox";if(!r)return null;for(let l=0;l<e.length;l++){const u=i[l]?.data?.items;if(!u)continue;const d=u.find(f=>f.mailboxId===r);if(!d)continue;const m=is(e[l].folderAppointments);return es(d,m.get(r),o)}return null},zh=({accounts:e})=>{const n=vr({strict:!1}).mailboxId,r=Dt({queries:e.map(a=>({...Ze({path:{accountId:a.accountId}}),staleTime:1/0}))});if(!n)return null;for(const a of r){const o=a.data?.items;if(!o)continue;const i=o.find(l=>l.mailboxId===n);if(i)return i.unseenCount}return null};function Fh(e){const t=Me(),{searchInput:n}=ve(),r=Fi({accounts:e}),a=mt({select:l=>l.matches}),o=Lh(a,r),i=c.useCallback(l=>{l===nn&&t({to:"/mail",search:{q:n||void 0,selectedMessageId:void 0}})},[t,n]);return{scope:o,clearScope:i}}const _i=[{title:"Navigation",hints:[{action:"focusNext",keys:["j"],description:"Focus next message"},{action:"focusPrevious",keys:["k"],description:"Focus previous message"},{action:"focusNext",keys:["↓"],description:"Focus next message"},{action:"focusPrevious",keys:["↑"],description:"Focus previous message"},{action:"focusFirst",keys:["Home"],description:"Focus first"},{action:"focusLast",keys:["End"],description:"Focus last"},{action:"openFocused",keys:["Enter"],description:"Open focused thread"},{action:"back",keys:["Esc"],description:"Back / close overlay"}]},{title:"Selection",hints:[{action:"toggleSelect",keys:["x"],description:"Toggle select"},{action:"toggleSelect",keys:["Space"],description:"Toggle select"},{action:"extendSelectDown",keys:["Shift","j"],description:"Extend selection down"},{action:"extendSelectUp",keys:["Shift","k"],description:"Extend selection up"},{action:"extendSelectDown",keys:["Shift","↓"],description:"Extend selection down"},{action:"extendSelectUp",keys:["Shift","↑"],description:"Extend selection up"},{action:"selectAll",keys:["⌘","A"],description:"Select all"}]},{title:"Actions",hints:[{action:"reply",keys:["r"],description:"Reply"},{action:"replyAll",keys:["a"],description:"Reply all"},{action:"forward",keys:["f"],description:"Forward"},{action:"delete",keys:["#"],description:"Delete"},{action:"toggleStar",keys:["s"],description:"Star / unstar"},{action:"toggleRead",keys:["u"],description:"Toggle read / unread"}]},{title:"Sender",hints:[{action:"muteSender",keys:["m"],description:"Mute sender"},{action:"blockSender",keys:["b"],description:"Block sender"},{action:"vipSender",keys:["v"],description:"VIP sender"},{action:"markJunk",keys:["!"],description:"Mark junk"}]},{title:"Go to",hints:[{action:"goBrief",keys:["g","b"],description:"Daily brief"},{action:"goInbox",keys:["g","i"],description:"Inbox"},{action:"goSent",keys:["g","s"],description:"Sent"},{action:"goFlagged",keys:["g","f"],description:"Starred"},{action:"goSettings",keys:["g",","],description:"Settings"}]},{title:"View & global",hints:[{action:"toggleIntelligence",keys:["i"],description:"Toggle intelligence"},{action:"toggleDensity",keys:["d"],description:"Toggle density"},{action:"focusSearch",keys:["/"],description:"Focus search"},{action:"compose",keys:["c"],description:"Compose"},{action:"compose",keys:["⌘","N"],description:"Compose"},{action:"help",keys:["?"],description:"Shortcut help"}]}];function _h(e){for(const t of _i){const n=t.hints.find(r=>r.action===e);if(n)return n.keys}}function Yt(e){const t=_h(e);return!t||t.length===0?"":t.length===1?`(${t[0]})`:t[0]==="g"?`(${t.join(" then ")})`:`(${t.join("")})`}const Bh={global:"Search all mail",pending:"Search mail",scoped:"Search this folder"};function $h({accounts:e}){const{searchInput:t,onSearchChange:n,onSearchClear:r,onSearchClearQuery:a}=ve(),o=Ri(e),{scope:i,clearScope:l}=Fh(e),u=i.kind==="scoped"?[{id:i.chip.id,label:i.chip.label,tone:"scope"}]:void 0,d=Bh[i.kind];return s.jsx(Vd,{leading:s.jsx("span",{className:"px-1 text-sm font-semibold tracking-tight text-fg",children:"remit"}),search:s.jsx(Cr,{value:t,onChange:n,onClear:r,onClearQuery:a,chips:u,onRemoveChip:l,placeholder:d,size:"lg"}),actions:s.jsxs(s.Fragment,{children:[s.jsx(V,{variant:"ghost",size:"sm",icon:s.jsx(qu,{className:"size-4"}),title:`Compose ${Yt("compose")}`,"aria-label":"Compose",onClick:o}),s.jsx(Ai,{}),s.jsx(Th,{})]})})}const Dr=({isOpen:e,onClose:t,children:n,ariaLabel:r="Navigation",side:a="left",widthClassName:o="w-[80vw] max-w-[320px]"})=>{const i=c.useRef(null),l=c.useRef(null);if(c.useEffect(()=>{if(!e)return;l.current=document.activeElement;const d=h=>{h.key==="Escape"&&(h.preventDefault(),t())};document.addEventListener("keydown",d),i.current?.querySelector("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])")?.focus();const f=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",d),document.body.style.overflow=f,l.current?.focus()}},[e,t]),!e)return null;const u=a==="left"?"left-0 border-r animate-in slide-in-from-left duration-150":"right-0 border-l animate-in slide-in-from-right duration-150";return s.jsxs("div",{className:"fixed inset-0 z-50 lg:hidden",role:"dialog","aria-modal":"true","aria-label":r,children:[s.jsx("button",{type:"button","aria-label":"Close menu",onClick:t,className:"absolute inset-0 bg-black/40 animate-in fade-in duration-150 cursor-default"}),s.jsxs("div",{ref:i,className: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(Ke,{className:"size-5"})})}),s.jsx("div",{className:"flex-1 overflow-y-auto",children:n})]})]})},Kh=e=>{const t=e.filter(a=>!a.isMultipart&&a.disposition!=="attachment"&&a.mediaType==="TEXT"&&a.contentUrl.length>0),n=t.find(a=>a.mediaSubtype.toUpperCase()==="HTML");if(n)return{kind:"html",contentUrl:n.contentUrl};const r=t.find(a=>a.mediaSubtype.toUpperCase()==="PLAIN");return r?{kind:"text",contentUrl:r.contentUrl}:null},tr={all:["messages"],detail:e=>[...tr.all,"detail",e],body:e=>[...tr.detail(e),"body"]};class Et extends Error{reason;status;retryAfterSeconds;constructor(t,n,r,a){super(n),this.name="BodyFetchError",this.reason=t,this.status=r,this.retryAfterSeconds=a}}const qh=e=>{const t=Number.parseInt(e??"",10);return!Number.isFinite(t)||t<=0?1:Math.min(t,30)},Uh=8,Qh="x-remit-403-reason",Hh=(e,t)=>{const n=t?.trim()??"";return e===401?"auth":e===403?n.length>0?"auth":"body-missing":e===404?"body-missing":"generic"},Wh=(e,t)=>(t??"").toLowerCase().startsWith("text/html")?/<div\s+id=["']root["']/i.test(e):!1,Vh=(e,t)=>{const n=(t??"").toLowerCase();return!!(e==="text"&&n.startsWith("text/html"))},Yh=async(e,t,n=async()=>null)=>{const r={},a=await n();a&&(r.Authorization=`Bearer ${a}`);const o=await Qc(e,{headers:r});if(o.status===202)throw new Et("not-ready","Message body is still syncing",202,qh(o.headers.get("Retry-After")));if(!o.ok){const u=o.headers.get(Qh),d=Hh(o.status,u);throw new Et(d,`Failed to load message body (${o.status} ${o.statusText})`,o.status)}const i=o.headers.get("content-type");if(Vh(t,i))throw new Et("content-type-mismatch",`Refusing to render message body — expected ${t}, got Content-Type ${i}`);const l=await o.text();if(Wh(l,i))throw new Et("spa-shell-leak","Refusing to render message body — response looks like the SPA shell (CloudFront 403/404 fallback leaked through to /content/*)");return l},Gh=async(e,t)=>(t.isRetryAfterNotReady&&await e.refetchDescribeMessage(),e.fetchContent(t.contentUrl,t.kind)),Bi=({messageId:e,bodyParts:t,enabled:n=!0})=>{const r=t?Kh(t):null,a=Ms(),{getToken:o}=pr(),i=c.useRef(null),l=je(),u=c.useRef(!1),d=c.useRef(null),m=e&&r?`${e}:${r.contentUrl}`:null;d.current!==m&&(d.current=m,u.current=!1);const f=ie({queryKey:e?[...tr.body(e),r?.contentUrl??null]:["messages","body","noop"],queryFn:()=>{if(!r)throw new Error("No renderable body part");if(!e)throw new Error("No messageId");const b=u.current;return u.current=!1,Gh({fetchContent:(p,v)=>Yh(p,v,o),refetchDescribeMessage:()=>l.refetchQueries({queryKey:Co({path:{messageId:e}})})},{contentUrl:r.contentUrl,kind:r.kind,isRetryAfterNotReady:b})},enabled:n&&!!e&&!!r,staleTime:300*1e3,gcTime:1800*1e3,retry:(b,p)=>p instanceof Et&&p.reason==="not-ready"?b<Uh:b<1,retryDelay:(b,p)=>p instanceof Et&&p.reason==="not-ready"?(u.current=!0,(p.retryAfterSeconds??1)*1e3):1e3,meta:{softError:!0}}),h=f.isLoading&&!!r;c.useEffect(()=>{h&&(i.current=performance.now())},[h]),c.useEffect(()=>{f.isSuccess&&i.current!==null&&(a.recordTiming("message.body.load",Math.round(performance.now()-i.current)),i.current=null)},[f.isSuccess,a]);const x=f.data&&r?{kind:r.kind,body:f.data}:void 0;return{picked:r,data:x,isLoading:h,isError:f.isError,error:f.error,refetch:f.refetch}},Xh=({outboxMessageId:e,onDraftCreated:t})=>{const[n,r]=c.useState("idle"),[a,o]=c.useState(null),i=c.useRef(void 0),l=je(),u=pe(Eo()),d=pe(Hc()),m=c.useCallback(async b=>{if(r("saving"),o(null),e){const v=await d.mutateAsync({path:{outboxMessageId:e},body:{toAddresses:b.toAddresses,ccAddresses:b.ccAddresses,bccAddresses:b.bccAddresses,subject:b.subject,textBody:b.textBody,htmlBody:b.htmlBody,inReplyTo:b.inReplyTo,references:b.references}});return r("saved"),v}const p=await u.mutateAsync({body:{...b,sendImmediately:!1}});return t(p.outboxMessageId),r("saved"),l.invalidateQueries({queryKey:mn().queryKey}),p},[e,u,d,t,l]),f=c.useCallback(b=>{i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{m(b).catch(p=>{o(p),r("error")})},2e3)},[m]),h=c.useCallback(b=>(i.current&&clearTimeout(i.current),m(b)),[m]),x=c.useCallback(()=>{i.current&&clearTimeout(i.current)},[]);return{saveStatus:n,saveError:a,saveDraft:f,saveImmediately:h,cancelAutoSave:x}},$i=e=>"text"in e&&!("children"in e),Ki=e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),Jh=e=>{let t=Ki(e.text);return e.bold&&(t=`<strong>${t}</strong>`),e.italic&&(t=`<em>${t}</em>`),t},qi=e=>{const t=e.children.map(n=>$i(n)?Jh(n):qi(n)).join("");switch(e.type){case"blockquote":return`<blockquote>${t}</blockquote>`;case"a":{const n=e.url??"";return`<a href="${Ki(n)}">${t}</a>`}default:return`<p>${t}</p>`}},_a=e=>e.map(qi).join(""),Ui=e=>$i(e)?e.text:e.children.map(Ui).join(""),sr=e=>e.map(Ui).join(`
|
|
110
|
-
`),Zh=e=>e.displayName?`${e.displayName} <${e.normalizedEmail}>`:e.normalizedEmail,Ba=e=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.trim()),eg=e=>{const t=e.trim();if(!t)return;const n=t.match(/^(.+?)\s*<([^>]+)>$/);if(n){const r=n[1].trim(),a=n[2].trim();if(Ba(a))return{email:a,displayName:r}}if(Ba(t))return{email:t}},_n=({label:e,addresses:t,onChange:n,placeholder:r})=>{const[a,o]=c.useState(""),[i,l]=c.useState(-1),[u,d]=c.useState(!1),m=c.useRef(null),f=c.useRef(null),h=Oo(a,200),{data:x}=ie({...Io({query:{q:h,limit:8}}),enabled:h.length>=2}),b=x?.items??[],p=new Set(t.map(S=>S.email.toLowerCase())),v=b.filter(S=>!p.has(S.normalizedEmail.toLowerCase()));c.useEffect(()=>{l(-1),d(v.length>0&&a.length>=2)},[v.length,a.length]);const g=c.useCallback(S=>{p.has(S.email.toLowerCase())||(n([...t,S]),o(""),d(!1))},[t,p,n]),y=c.useCallback(S=>{n(t.filter((N,R)=>R!==S))},[t,n]),j=c.useCallback(S=>{g({email:S.normalizedEmail,displayName:S.displayName}),m.current?.focus()},[g]),w=c.useCallback(()=>{const S=eg(a);S&&g(S)},[a,g]),C=c.useCallback(S=>{if(S.key==="Backspace"&&a===""&&t.length>0){y(t.length-1);return}if(S.key==="Enter"||S.key==="Tab"||S.key===","){if(i>=0&&v[i]){S.preventDefault(),j(v[i]);return}a.trim()&&(S.preventDefault(),w());return}if(S.key==="ArrowDown"&&u){S.preventDefault(),l(N=>N<v.length-1?N+1:0);return}if(S.key==="ArrowUp"&&u){S.preventDefault(),l(N=>N>0?N-1:v.length-1);return}S.key==="Escape"&&(d(!1),l(-1))},[a,t.length,i,v,u,y,j,w]),k=c.useCallback(()=>{setTimeout(()=>{w(),d(!1)},150)},[w]);return s.jsxs("div",{className:"relative",children:[s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("label",{htmlFor:`address-field-${e}`,className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:[e,":"]}),s.jsxs("div",{className:"flex-1 flex flex-wrap items-center gap-1 min-h-[36px] px-2 py-1 border rounded-md bg-canvas cursor-text",onClick:()=>m.current?.focus(),onKeyDown:S=>{(S.key==="Enter"||S.key===" ")&&m.current?.focus()},children:[t.map((S,N)=>s.jsx(Wu,{email:S.email,displayName:S.displayName,onRemove:()=>y(N)},S.email)),s.jsx("input",{ref:m,id:`address-field-${e}`,type:"text",value:a,onChange:S=>o(S.target.value),onKeyDown:C,onBlur:k,placeholder:t.length===0?r:"",className:"flex-1 min-w-[120px] bg-transparent outline-none text-sm py-0.5"})]})]}),u&&v.length>0&&s.jsx("ul",{ref:f,className:"absolute left-12 right-0 mt-1 bg-surface border border-line rounded-md shadow-lg z-50 max-h-[200px] overflow-auto",children:v.map((S,N)=>s.jsx("li",{className:fe("px-3 py-2 text-sm cursor-pointer transition-colors",N===i&&"bg-accent-2-soft"),onMouseDown:R=>{R.preventDefault(),j(S)},onMouseEnter:()=>l(N),children:Zh(S)},S.addressId))})]})},tg=({accountId:e})=>{const t=Me();return s.jsxs("div",{role:"alert","data-testid":"compose-smtp-missing-banner",className:"flex items-start gap-3 border-b border-warning/50 bg-warning/10 px-3 py-2",children:[s.jsx(fr,{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(Au,{className:"size-3","aria-hidden":"true"})]})]})]})},nr=e=>{const[t,n]=c.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return c.useEffect(()=>{if(typeof window>"u"||!window.matchMedia)return;const r=window.matchMedia(e),a=o=>n(o.matches);return n(r.matches),r.addEventListener("change",a),()=>r.removeEventListener("change",a)},[e]),t},Ot=()=>nr("(min-width: 1024px)"),$a=150,sg=()=>{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>$a}});return c.useEffect(()=>{if(typeof window>"u"||!window.visualViewport)return;const n=window.visualViewport,r=()=>{const a=n.height;t({viewportHeight:a,isKeyboardOpen:window.innerHeight-a>$a})};return r(),n.addEventListener("resize",r),()=>n.removeEventListener("resize",r)},[]),e},ng=({selectedAccountId:e,onSelect:t})=>{const{data:n}=ie({...at(),staleTime:1/0}),r=n?.accounts??[];if(c.useEffect(()=>{!e&&r.length===1&&r[0]&&t(r[0])},[e,r,t]),r.length<=1){const a=r[0];return a?s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx("label",{className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:"From:"}),s.jsx("div",{className:"text-sm py-1.5",children:a.email})]}):null}return s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx("label",{htmlFor:"from-account-selector",className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:"From:"}),s.jsx("select",{id:"from-account-selector",value:e??"",onChange:a=>{const o=r.find(i=>i.accountId===a.target.value);o&&t(o)},className:"flex-1 px-2 py-1.5 border rounded-md bg-canvas text-sm",children:r.map(a=>s.jsx("option",{value:a.accountId,children:a.email},a.accountId))})]})},rg=({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})]}),ag=["p","br","strong","b","em","i","a","blockquote","ul","ol","li"],og=["href"],ig=e=>vo.sanitize(e,{ALLOWED_TAGS:ag,ALLOWED_ATTR:og}),lg=c.lazy(()=>Vc(()=>import("./ComposeBody-B4ijJFEZ.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}))),cg=()=>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"})]}),Qi=[{type:"p",children:[{text:""}]}],ug=[{type:"p",children:[{text:""}]},{type:"p",children:[{text:"-- "}]}],dg=e=>e?[...ug,{type:"p",children:[{text:e}]}]:Qi,fg=e=>e?/^re:\s/i.test(e)?e:`Re: ${e}`:"Re: ",mg=e=>e?/^fwd?:\s/i.test(e)?e:`Fwd: ${e}`:"Fwd: ",hg=(e,t,n)=>{const{envelope:r}=e,o=(r.replyTo.length>0?r.replyTo:r.from).map(d=>({email:d.normalizedEmail,displayName:d.displayName}));if(t!=="reply_all")return{to:o,cc:[]};const i=n?.toLowerCase(),l=new Set(o.map(d=>d.email.toLowerCase())),u=[...r.to,...r.cc].filter(d=>d.normalizedEmail.toLowerCase()!==i&&!l.has(d.normalizedEmail.toLowerCase())).map(d=>({email:d.normalizedEmail,displayName:d.displayName}));return{to:o,cc:u}},gg=e=>{const t=e.envelope.messageIdValue,r=[...e.references.filter(a=>a.referenceType==="references").sort((a,o)=>a.referenceOrder-o.referenceOrder).map(a=>a.messageIdValue)];return t&&!r.includes(t)&&r.push(t),{inReplyTo:t,references:r}},pg=(e,t,n,r,a)=>e.length===0&&t.length===0&&n.length===0&&r.trim()===""&&sr(a).trim()==="",xg=({selectedAccountId:e,onAccountChange:t,toAddresses:n,setToAddresses:r,ccAddresses:a,setCcAddresses:o,bccAddresses:i,setBccAddresses:l,showCc:u,setShowCc:d,showBcc:m,setShowBcc:f,subject:h,setSubject:x})=>{const b=Ot(),{isKeyboardOpen:p}=sg();if(!b&&p){const g=[];return n.length>0&&g.push(`To: ${n.map(y=>y.displayName??y.email).join(", ")}`),a.length>0&&g.push(`Cc: ${a.length}`),i.length>0&&g.push(`Bcc: ${i.length}`),h&&g.push(h),s.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-line overflow-hidden","data-testid":"compose-header-collapsed",children:[s.jsx("span",{className:"truncate text-xs text-fg-muted",children:g.length>0?g.join(" · "):"…"}),s.jsx("span",{className:"shrink-0 inline-flex items-center justify-center rounded bg-surface-sunken px-1.5 py-0.5 text-2xs text-fg-muted",children:"…"})]})}return s.jsxs("div",{className:"space-y-1 px-3 py-2 border-b border-line",children:[s.jsx(ng,{selectedAccountId:e,onSelect:t}),s.jsx(_n,{label:"To",addresses:n,onChange:r,placeholder:"Recipients"}),u?s.jsx(_n,{label:"Cc",addresses:a,onChange:o}):s.jsxs("div",{className:"flex gap-2 pl-14",children:[s.jsx("button",{type:"button",onClick:()=>d(!0),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:"Cc"}),s.jsx("button",{type:"button",onClick:()=>f(!0),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:"Bcc"})]}),u&&!m&&s.jsx("div",{className:"pl-14",children:s.jsx("button",{type:"button",onClick:()=>f(!0),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:"Bcc"})}),m&&s.jsx(_n,{label:"Bcc",addresses:i,onChange:l}),s.jsx(rg,{value:h,onChange:x})]})},Or=({mode:e,account:t,sourceMessage:n,onClose:r,onAccountChange:a})=>{const{state:o,setOutboxMessageId:i,startSendPolling:l}=xt(),{pushError:u}=Qe(),{outboxMessageId:d}=o,[m,f]=c.useState([]),[h,x]=c.useState([]),[b,p]=c.useState([]),[v,g]=c.useState(""),[y,j]=c.useState(!1),[w,C]=c.useState(!1),[k,S]=c.useState(t?.accountId),[N,R]=c.useState(!1),A=c.useRef(d);c.useEffect(()=>{A.current!==d&&(A.current=d,d&&(f([]),x([]),p([]),g(""),j(!1),C(!1),I(Qi),R(!1)))},[d]);const{signature:E}=ku(k),[M,I]=c.useState(()=>dg(E.plainText)),{data:T}=ie({...Wc({path:{outboxMessageId:d??""}}),enabled:!!d&&!N});c.useEffect(()=>{!T||N||(f(T.toAddresses.map(U=>({email:U,displayName:void 0}))),T.ccAddresses&&T.ccAddresses.length>0&&(x(T.ccAddresses.map(U=>({email:U,displayName:void 0}))),j(!0)),T.bccAddresses&&T.bccAddresses.length>0&&(p(T.bccAddresses.map(U=>({email:U,displayName:void 0}))),C(!0)),T.subject&&g(T.subject),T.textBody&&I([{type:"p",children:[{text:T.textBody}]}]),S(T.accountId),R(!0))},[T,N]),c.useEffect(()=>{if(n){if(e==="reply"||e==="reply_all"){const{to:U,cc:te}=hg(n,e,t?.email);f(U),x(te),te.length>0&&j(!0),g(fg(n.envelope.subject))}e==="forward"&&g(mg(n.envelope.subject))}},[e,n,t?.email]);const O=e==="reply"||e==="reply_all"||e==="forward",{data:_}=Bi({messageId:n?.message.messageId,bodyParts:n?.bodyParts,enabled:O&&!!n}),q=_?.kind==="text"?_.body:"",X=_?.kind==="html"?ig(_.body):void 0,F=n?.envelope.from[0]?.displayName??n?.envelope.from[0]?.normalizedEmail,{saveStatus:$,saveError:ae,saveDraft:ce,cancelAutoSave:J}=Xh({outboxMessageId:d,onDraftCreated:i});c.useEffect(()=>{ae&&u({title:"Couldn't save draft",detail:Xe(ae)??"Saving the draft failed.",error:ae})},[ae,u]);const D=pe(Eo()),P=pe(Ro()),Q=pe({...hn(),onError:U=>{u(Es("Couldn't discard draft","The draft wasn't discarded.",U))}}),{data:G}=ie({...at(),staleTime:1/0}),ue=G?.accounts.find(U=>U.accountId===k),le=ue?vu(ue):!1,Y=D.isPending||P.isPending,ge=m.length>0&&!!k&&!le;c.useEffect(()=>{if(!k||d&&!N||pg(m,h,b,v,M))return;const U=sr(M),te=_a(M);ce({accountId:k,toAddresses:m.map(ee=>ee.email),ccAddresses:h.length>0?h.map(ee=>ee.email):void 0,bccAddresses:b.length>0?b.map(ee=>ee.email):void 0,subject:v||void 0,textBody:U||void 0,htmlBody:te||void 0})},[k,d,N,m,h,b,v,M,ce]);const Se=c.useCallback(async()=>{if(!k||m.length===0)return;J();const U=n&&(e==="reply"||e==="reply_all")?gg(n):{};let te=d,ee=!1;if(!te){const Ie=sr(M),ze=_a(M),Ve=await D.mutateAsync({body:{accountId:k,toAddresses:m.map(Te=>Te.email),ccAddresses:h.length>0?h.map(Te=>Te.email):void 0,bccAddresses:b.length>0?b.map(Te=>Te.email):void 0,subject:v||void 0,textBody:Ie||void 0,htmlBody:ze||void 0,sendImmediately:!0,...U}}).catch(Te=>(u({title:"Couldn't send message",detail:Xe(Te)??"Saving the draft failed.",error:Te}),null));if(Ve===null)return;te=Ve.outboxMessageId,ee=!0,i(te)}await P.mutateAsync({path:{outboxMessageId:te}}).catch(Ie=>(u({title:"Couldn't send message",detail:Xe(Ie)??(ee?"The draft was saved but the send request failed. Try again from the Outbox.":"The send request failed. Try again."),error:Ie}),null))!==null&&(l(te),r())},[k,m,h,b,v,M,e,n,d,D,P,J,l,i,u,r]),Ce=c.useCallback(()=>{J(),d&&Q.mutate({path:{outboxMessageId:d}}),r()},[J,d,Q,r]),W=c.useCallback(U=>{S(U.accountId),a?.(U)},[a]);return s.jsx(af,{banner:ue&&le?s.jsx(tg,{accountId:ue.accountId}):void 0,header:s.jsx(xg,{selectedAccountId:k,onAccountChange:W,toAddresses:m,setToAddresses:f,ccAddresses:h,setCcAddresses:x,bccAddresses:b,setBccAddresses:p,showCc:y,setShowCc:j,showBcc:w,setShowBcc:C,subject:v,setSubject:g}),quoted:q||X?s.jsx(Tf,{text:q,html:X,senderName:F}):void 0,actionBar:s.jsx(rf,{onSend:Se,onDiscard:Ce,sending:Y,canSend:ge,saveStatus:$,unavailableReason:le?"SMTP not configured":void 0,onUnavailable:U=>u({title:"Can't send yet",detail:U})}),children:s.jsx(c.Suspense,{fallback:s.jsx(cg,{}),children:s.jsx(lg,{value:M,onChange:I,onSubmit:Se,autoFocus:e==="new"})})})},Ka=({mode:e,account:t,sourceMessage:n,onClose:r})=>s.jsx("div",{className:"border-t border-line bg-canvas max-h-[400px] flex flex-col",children:s.jsx(Or,{mode:e,account:t,sourceMessage:n,onClose:r})}),Hi=({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})]}),Pr=({enabled:e=!0,bindings:t,capture:n=!1})=>{const r=c.useCallback(a=>{const o=a.target;if(!(o.tagName==="INPUT"||o.tagName==="TEXTAREA"||o.isContentEditable))for(const i of t){if(!(a.key.toLowerCase()===i.key.toLowerCase())||i.requireShift!==void 0&&i.requireShift!==a.shiftKey)continue;const u=a.ctrlKey||a.metaKey;if(i.requireMeta!==void 0){if(i.requireMeta!==u)continue}else{const d=i.noModifiers??!0,m=u||a.altKey||i.requireShift===void 0&&a.shiftKey;if(d&&m)continue}i.preventDefault&&a.preventDefault(),i.stopPropagation&&(a.stopPropagation(),a.stopImmediatePropagation()),i.handler(a);return}},[t]);c.useEffect(()=>{if(e)return window.addEventListener("keydown",r,n),()=>window.removeEventListener("keydown",r,n)},[e,r,n])},Wi=e=>{const{data:t,isLoading:n}=ie({...at(),staleTime:1/0}),r=c.useMemo(()=>(t?.accounts??[]).map(l=>l.accountId),[t?.accounts]),a=Dt({queries:r.map(l=>({...Ze({path:{accountId:l}}),staleTime:1/0,enabled:!!e}))}),o=n||a.some(l=>l.isLoading);return{accountId:c.useMemo(()=>{if(e){for(let l=0;l<r.length;l++)if((a[l].data?.items??[]).some(m=>m.mailboxId===e))return r[l]}},[e,r,a]),isLoading:o}},bg=e=>typeof e=="object"&&e!==null&&Array.isArray(e.pages),vg=e=>typeof e=="object"&&e!==null&&Array.isArray(e.items),ns=(e,t)=>e===void 0?e:bg(e)?{...e,pages:e.pages.map(n=>({...n,items:t(n.items)}))}:vg(e)?{...e,items:t(e.items)}:e,yg=(e,t,n)=>{const r=new Map(t.map(o=>[o.messageId,o.mailboxId])),a=new Set;for(const o of e)a.add(r.get(o)??n);return[...a]},qa=(e,t,n)=>e.map(r=>t.has(r.messageId)?{...r,isRead:n}:r),wg=(e,t,n,r)=>e.filter(a=>!a.isRead&&t.has(a.threadMessageId)&&!n.has(a.messageId)&&!r.has(a.messageId)).map(a=>a.messageId),jg=({messages:e,expandedIds:t,threadId:n,mailboxId:r,accountId:a})=>{const o=je(),{pushError:i}=Qe(),l=c.useRef(new Set),u=c.useRef(new Set),{mutate:d}=pe({...gn(),onMutate:async h=>{const x=new Set(h.body.messageIds??[]),b=h.body.isRead??!0,p=Mt({path:{threadId:n}}),v=yg(x,e,r),g=v.map(k=>ot({path:{mailboxId:k}})),y=v.map(k=>bt({path:{mailboxId:k}}));await Promise.all([o.cancelQueries({queryKey:p}),...g.map(k=>o.cancelQueries({queryKey:k})),...y.map(k=>o.cancelQueries({queryKey:k}))]);const j=o.getQueriesData({queryKey:p}).filter(k=>k[1]!==void 0).map(([k,S])=>({queryKey:k,data:S})),w=[...g,...y].flatMap(k=>o.getQueriesData({queryKey:k})).filter(k=>k[1]!==void 0).map(([k,S])=>({queryKey:k,data:S}));o.setQueriesData({queryKey:p},k=>k&&{...k,items:qa(k.items,x,b)});const C=k=>ns(k,S=>qa(S,x,b));for(const k of[...g,...y])o.setQueriesData({queryKey:k},C);return{threadMessagesPrefix:p,threadsListPrefixes:g,threadsSearchPrefixes:y,previousThreadMessages:j,previousThreadsList:w}},onSuccess:(h,x)=>{const b=x.body.messageIds??[];for(const p of b)l.current.add(p),u.current.delete(p)},onError:(h,x,b)=>{const p=x.body.messageIds??[];for(const g of p)u.current.delete(g);if(b){for(const g of b.previousThreadMessages)o.setQueryData(g.queryKey,g.data);for(const g of b.previousThreadsList)o.setQueryData(g.queryKey,g.data)}const v=x.body.isRead??!0;i({title:v?"Couldn't mark as read":"Couldn't mark as unread",detail:Xe(h),error:h})},onSettled:(h,x,b,p)=>{if(p){o.invalidateQueries({queryKey:p.threadMessagesPrefix});for(const v of[...p.threadsListPrefixes,...p.threadsSearchPrefixes])o.invalidateQueries({queryKey:v});a&&o.invalidateQueries({queryKey:as({path:{accountId:a}})})}}}),m=c.useCallback(h=>{const x=h.filter(b=>!l.current.has(b)&&!u.current.has(b));if(x.length!==0){for(const b of x)u.current.add(b);d({body:{messageIds:x,isRead:!0}})}},[d]),f=c.useMemo(()=>wg(e,t,l.current,u.current),[e,t]);c.useEffect(()=>{f.length!==0&&m(f)},[f,m]),c.useEffect(()=>{l.current.clear(),u.current.clear()},[n])},Vi=e=>{const{mailboxId:t,accountId:n}=e,r=je(),{pushError:a}=Qe(),{mutate:o,isPending:i}=pe({...gn(),onError:(u,d)=>{const m=d.body.isRead??!0;a({title:m?"Couldn't mark as read":"Couldn't mark as unread",detail:Xe(u),error:u})},onSettled:()=>{r.invalidateQueries({queryKey:ot({path:{mailboxId:t}})}),r.invalidateQueries({queryKey:bt({path:{mailboxId:t}})}),n&&r.invalidateQueries({queryKey:as({path:{accountId:n}})})}});return{toggleReadFor:c.useCallback((u,d)=>{u.length!==0&&o({body:{messageIds:u,isRead:d}})},[o]),isPending:i}},Sg=60,Ng=1.5,kg=(e,t,n)=>{const r=Math.abs(e),a=Math.abs(t);return r<n?{direction:null}:r<a*Ng?{direction:null}:{direction:e<0?"left":"right"}},Cg=({onSwipeLeft:e,onSwipeRight:t,thresholdPx:n=Sg})=>{const r=c.useRef(null),a=c.useCallback(u=>{if(u.pointerType==="mouse"){r.current=null;return}r.current={x:u.clientX,y:u.clientY}},[]),o=c.useCallback(()=>{},[]),i=c.useCallback(u=>{const d=r.current;if(r.current=null,!d)return;const{direction:m}=kg(u.clientX-d.x,u.clientY-d.y,n);m==="left"&&e?.(),m==="right"&&t?.()},[e,t,n]),l=c.useCallback(()=>{r.current=null},[]);return{handlers:{onPointerDown:a,onPointerMove:o,onPointerUp:i,onPointerCancel:l}}},Eg=(e,t,n)=>t?.find(r=>r.messageId===e)?.mailboxId??n,Ua=(e,t,n)=>e.map(r=>r.messageId===t?{...r,hasStars:n}:r),rr=({threadId:e,mailboxId:t,messages:n})=>{const r=je(),{pushError:a}=Qe(),{mutate:o,isPending:i,variables:l}=pe({...Yc(),onMutate:async d=>{const m=d.path.messageId,f=d.body.isStarred??!1,h=Mt({path:{threadId:e}}),x=Eg(m,n,t),b=ot({path:{mailboxId:x}}),p=bt({path:{mailboxId:x}}),v=Mo();await Promise.all([r.cancelQueries({queryKey:h}),r.cancelQueries({queryKey:b}),r.cancelQueries({queryKey:p}),r.cancelQueries({queryKey:v})]);const g=r.getQueriesData({queryKey:h}).filter(k=>k[1]!==void 0).map(([k,S])=>({queryKey:k,data:S})),y=r.getQueriesData({queryKey:b}).concat(r.getQueriesData({queryKey:p})).filter(k=>k[1]!==void 0).map(([k,S])=>({queryKey:k,data:S})),j=r.getQueriesData({queryKey:v}).filter(k=>k[1]!==void 0).map(([k,S])=>({queryKey:k,data:S})),w=k=>ns(k,S=>Ua(S,m,f));r.setQueriesData({queryKey:h},w),r.setQueriesData({queryKey:v},w);const C=k=>ns(k,S=>Ua(S,m,f));return r.setQueriesData({queryKey:b},C),r.setQueriesData({queryKey:p},C),{threadMessagesPrefix:h,threadsListPrefix:b,threadsSearchPrefix:p,unifiedThreadsPrefix:v,previousThreadMessages:g,previousThreadsList:y,previousUnifiedThreads:j}},onError:(d,m,f)=>{if(f){for(const x of f.previousThreadMessages)r.setQueryData(x.queryKey,x.data);for(const x of f.previousThreadsList)r.setQueryData(x.queryKey,x.data);for(const x of f.previousUnifiedThreads)r.setQueryData(x.queryKey,x.data)}const h=m.body.isStarred??!1;a({title:h?"Couldn't star message":"Couldn't unstar message",detail:Xe(d),error:d})},onSettled:(d,m,f,h)=>{h&&(r.invalidateQueries({queryKey:h.threadMessagesPrefix}),r.invalidateQueries({queryKey:h.threadsListPrefix}),r.invalidateQueries({queryKey:h.threadsSearchPrefix}),r.invalidateQueries({queryKey:h.unifiedThreadsPrefix}))}});return{toggleStar:(d,m)=>{o({path:{messageId:d},body:{isStarred:!m}})},isPending:i,pendingMessageId:i?l?.path.messageId:void 0}};function Sn(e){return e===void 0?"uncategorized":e}const Ge={uncategorized:"uncategorized",personal:"personal",newsletter:"newsletter",marketing:"marketing",automated:"automated",transactional:"transactional",social:"social"},Qa={MoveToInbox:"MoveToInbox",MoveToJunk:"MoveToJunk"},Ig={inbox:"Inbox",junk:"Junk"},Rg=e=>`Moved from ${Ig[e]??"another folder"} by Remit`,Mg=(e,t)=>{if(e===Qa.MoveToInbox)return t.inboxMailboxId;if(e===Qa.MoveToJunk)return t.junkMailboxId},Tg=(e,t,n)=>{if(!e||!t)return!1;const r=Mg(e.action,n);return r!==void 0&&r===t},Ag=(e,t)=>{if(e==="inbox")return t.inboxMailboxId;if(e==="junk")return t.junkMailboxId},Nn=(e,t)=>{const{data:n,isLoading:r}=ie({...at(),staleTime:1/0,enabled:!!e});return{mailboxId:c.useMemo(()=>e?n?.accounts.find(i=>i.accountId===e)?.folderAppointments.find(i=>i.role===t)?.mailboxId:void 0,[n,e,t]),isLoading:r}},Dg=e=>{const{mailboxId:t,isLoading:n}=Nn(e,"Archive");return{archiveMailboxId:t,isLoading:n}},Og=e=>{const{mailboxId:t,isLoading:n}=Nn(e,"Drafts");return{draftsMailboxId:t,isLoading:n}},Lr=e=>{const{mailboxId:t,isLoading:n}=Nn(e,"Inbox");return{inboxMailboxId:t,isLoading:n}},zr=e=>{const{mailboxId:t,isLoading:n}=Nn(e,"Junk");return{junkMailboxId:t,isLoading:n}},Yi=e=>{const{data:t}=ie({...at(),staleTime:1/0,enabled:!!e});return c.useMemo(()=>t?.accounts.find(n=>n.accountId===e)?.folderAppointments??[],[t,e])},Ha=(e,t)=>e.filter(n=>!t.has(n.messageId)),gt=({mailboxId:e,threadId:t,accountId:n,onAfterOptimisticRemove:r})=>{const a=je(),{pushError:o}=Qe(),{mutate:i,isPending:l}=pe({...Gc(),onMutate:async d=>{const m=new Set(d.body.messageIds??[]),f=t?Mt({path:{threadId:t}}):[],h=ot({path:{mailboxId:e}}),x=bt({path:{mailboxId:e}});await Promise.all([...t?[a.cancelQueries({queryKey:f})]:[],a.cancelQueries({queryKey:h}),a.cancelQueries({queryKey:x})]);const b=t?a.getQueriesData({queryKey:f}).filter(g=>g[1]!==void 0).map(([g,y])=>({queryKey:g,data:y})):[],p=a.getQueriesData({queryKey:h}).concat(a.getQueriesData({queryKey:x})).filter(g=>g[1]!==void 0).map(([g,y])=>({queryKey:g,data:y}));t&&a.setQueriesData({queryKey:f},g=>g&&{...g,items:Ha(g.items,m)});const v=g=>ns(g,y=>Ha(y,m));return a.setQueriesData({queryKey:h},v),a.setQueriesData({queryKey:x},v),r?.(Array.from(m)),{threadMessagesPrefix:f,threadsListPrefix:h,threadsSearchPrefix:x,previousThreadMessages:b,previousThreadsList:p}},onError:(d,m,f)=>{if(f){for(const x of f.previousThreadMessages)a.setQueryData(x.queryKey,x.data);for(const x of f.previousThreadsList)a.setQueryData(x.queryKey,x.data)}const h=m.body.messageIds?.length??0;o({title:h>1?`Couldn't move ${h} messages`:"Couldn't move this message",detail:Xe(d),error:d})},onSettled:(d,m,f,h)=>{h&&(t&&a.invalidateQueries({queryKey:h.threadMessagesPrefix}),a.invalidateQueries({queryKey:h.threadsListPrefix}),a.invalidateQueries({queryKey:h.threadsSearchPrefix}),n&&a.invalidateQueries({queryKey:as({path:{accountId:n}})}))}});return{moveMessages:c.useCallback((d,m)=>{d.length!==0&&i({body:{messageIds:d,destinationMailboxId:m}})},[i]),isPending:l}},Pg=({accountId:e,messageId:t,threadId:n,mailboxId:r,autoMoved:a})=>{const{inboxMailboxId:o}=Lr(e),{junkMailboxId:i}=zr(e),{moveMessages:l,isPending:u}=gt({mailboxId:r,threadId:n,accountId:e}),d={inboxMailboxId:o,junkMailboxId:i},m=Tg(a,r,d),f=a?Ag(a.fromPlacement,d):void 0,h=c.useCallback(()=>{f&&l([t],f)},[l,t,f]);return!m||!a?{show:!1,label:"",isUndoing:!1}:{show:!0,label:Rg(a.fromPlacement),onUndo:f?h:void 0,isUndoing:u}};function Gi({accountId:e,messageId:t,threadId:n,mailboxId:r,autoMoved:a,size:o="sm"}){const i=Pg({accountId:e,messageId:t,threadId:n,mailboxId:r,autoMoved:a});return i.show?s.jsx(Yd,{label:i.label,size:o,onUndo:i.onUndo,undoLabel:i.isUndoing?"Undoing…":"Undo"}):null}const Wa=(e,t)=>e.filter(n=>!t.has(n.messageId)),Lg=e=>e.filter(t=>t.isDeleted!==!0),Cs=({mailboxId:e,threadId:t,accountId:n,onAfterOptimisticRemove:r})=>{const a=je(),{pushError:o}=Qe(),{mutate:i,isPending:l}=pe({...Xc(),onMutate:async d=>{const m=new Set(d.body.messageIds??[]),f=t?Mt({path:{threadId:t}}):[],h=ot({path:{mailboxId:e}}),x=bt({path:{mailboxId:e}});await Promise.all([a.cancelQueries({queryKey:f}),a.cancelQueries({queryKey:h}),a.cancelQueries({queryKey:x})]);const b=t?a.getQueriesData({queryKey:f}).filter(g=>g[1]!==void 0).map(([g,y])=>({queryKey:g,data:y})):[],p=a.getQueriesData({queryKey:h}).concat(a.getQueriesData({queryKey:x})).filter(g=>g[1]!==void 0).map(([g,y])=>({queryKey:g,data:y}));t&&a.setQueriesData({queryKey:f},g=>g&&{...g,items:Wa(g.items,m)});const v=g=>ns(g,y=>Wa(y,m));return a.setQueriesData({queryKey:h},v),a.setQueriesData({queryKey:x},v),r?.(Array.from(m)),{threadMessagesPrefix:f,threadsListPrefix:h,threadsSearchPrefix:x,previousThreadMessages:b,previousThreadsList:p}},onError:(d,m,f)=>{if(f){for(const x of f.previousThreadMessages)a.setQueryData(x.queryKey,x.data);for(const x of f.previousThreadsList)a.setQueryData(x.queryKey,x.data)}const h=m.body.messageIds?.length??0;o({title:h>1?`Couldn't delete ${h} messages`:"Couldn't delete this message",detail:Xe(d),error:d})},onSettled:(d,m,f,h)=>{h&&(t&&a.invalidateQueries({queryKey:h.threadMessagesPrefix}),a.invalidateQueries({queryKey:h.threadsListPrefix}),a.invalidateQueries({queryKey:h.threadsSearchPrefix}),n&&a.invalidateQueries({queryKey:as({path:{accountId:n}})}))}});return{deleteMessages:c.useCallback(d=>{d.length!==0&&i({body:{messageIds:d}})},[i]),isPending:l}},Xi=(e,t=Date.now())=>({value:e,setAt:t}),zg=(e,t,n,r)=>{if(e.addressId!==t)return e;const a={...e.flags??{}};return n?a.trusted=Xi(!0,r):delete a.trusted,{...e,flags:a}},Fg=(e,t,n,r)=>{const a=o=>o.map(i=>zg(i,t,n,r));return{...e,envelope:{...e.envelope,from:a(e.envelope.from),to:a(e.envelope.to),cc:a(e.envelope.cc),bcc:a(e.envelope.bcc),replyTo:a(e.envelope.replyTo)}}},Fr=({messageId:e})=>{const t=je(),{pushError:n}=Qe(),{mutate:r,isPending:a,error:o,reset:i}=pe({...To(),onMutate:async u=>{const d=u.path.addressId,f=u.body.flags?.trusted?.value===!0,h=Co({path:{messageId:e}});await t.cancelQueries({queryKey:h});const x=t.getQueriesData({queryKey:h}).filter(b=>b[1]!==void 0).map(([b,p])=>({queryKey:b,data:p}));return t.setQueriesData({queryKey:h},b=>b&&Fg(b,d,f)),{describePrefix:h,previous:x}},onError:(u,d,m)=>{if(m)for(const f of m.previous)t.setQueryData(f.queryKey,f.data);n(Es("Couldn't trust sender","The change wasn't saved.",u))},onSettled:(u,d,m,f)=>{f&&t.invalidateQueries({queryKey:f.describePrefix})}});return{toggleTrusted:(u,d)=>{r({path:{addressId:u},body:{flags:{trusted:Xi(!d)}}})},isPending:a,error:o,reset:i}};var kn="Dialog",[Ji]=Gf(kn),[_g,We]=Ji(kn),Zi=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:a,onOpenChange:o,modal:i=!0}=e,l=c.useRef(null),u=c.useRef(null),[d,m]=Zf({prop:r,defaultProp:a??!1,onChange:o,caller:kn});return s.jsx(_g,{scope:t,triggerRef:l,contentRef:u,contentId:On(),titleId:On(),descriptionId:On(),open:d,onOpenChange:m,onOpenToggle:c.useCallback(()=>m(f=>!f),[m]),modal:i,children:n})};Zi.displayName=kn;var el="DialogTrigger",Bg=c.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,a=We(el,n),o=At(t,a.triggerRef);return s.jsx(it.button,{type:"button","aria-haspopup":"dialog","aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":Br(a.open),...r,ref:o,onClick:ht(e.onClick,a.onOpenToggle)})});Bg.displayName=el;var _r="DialogPortal",[$g,tl]=Ji(_r,{forceMount:void 0}),sl=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:a}=e,o=We(_r,t);return s.jsx($g,{scope:t,forceMount:n,children:c.Children.map(r,i=>s.jsx(bn,{present:n||o.open,children:s.jsx(vi,{asChild:!0,container:a,children:i})}))})};sl.displayName=_r;var ln="DialogOverlay",nl=c.forwardRef((e,t)=>{const n=tl(ln,e.__scopeDialog),{forceMount:r=n.forceMount,...a}=e,o=We(ln,e.__scopeDialog);return o.modal?s.jsx(bn,{present:r||o.open,children:s.jsx(qg,{...a,ref:t})}):null});nl.displayName=ln;var Kg=Rr("DialogOverlay.RemoveScroll"),qg=c.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,a=We(ln,n),o=bm(),i=At(t,o);return s.jsx(Ei,{as:Kg,allowPinchZoom:!0,shards:[a.contentRef],children:s.jsx(it.div,{"data-state":Br(a.open),...r,ref:i,style:{pointerEvents:"auto",...r.style}})})}),rs="DialogContent",rl=c.forwardRef((e,t)=>{const n=tl(rs,e.__scopeDialog),{forceMount:r=n.forceMount,...a}=e,o=We(rs,e.__scopeDialog);return s.jsx(bn,{present:r||o.open,children:o.modal?s.jsx(Ug,{...a,ref:t}):s.jsx(Qg,{...a,ref:t})})});rl.displayName=rs;var Ug=c.forwardRef((e,t)=>{const n=We(rs,e.__scopeDialog),r=c.useRef(null),a=At(t,n.contentRef,r);return c.useEffect(()=>{const o=r.current;if(o)return Bm(o)},[]),s.jsx(al,{...e,ref:a,trapFocus:n.open,disableOutsidePointerEvents:n.open,onCloseAutoFocus:ht(e.onCloseAutoFocus,o=>{o.preventDefault(),n.triggerRef.current?.focus()}),onPointerDownOutside:ht(e.onPointerDownOutside,o=>{const i=o.detail.originalEvent,l=i.button===0&&i.ctrlKey===!0;(i.button===2||l)&&o.preventDefault()}),onFocusOutside:ht(e.onFocusOutside,o=>o.preventDefault())})}),Qg=c.forwardRef((e,t)=>{const n=We(rs,e.__scopeDialog),r=c.useRef(!1),a=c.useRef(!1);return s.jsx(al,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{e.onCloseAutoFocus?.(o),o.defaultPrevented||(r.current||n.triggerRef.current?.focus(),o.preventDefault()),r.current=!1,a.current=!1},onInteractOutside:o=>{e.onInteractOutside?.(o),o.defaultPrevented||(r.current=!0,o.detail.originalEvent.type==="pointerdown"&&(a.current=!0));const i=o.target;n.triggerRef.current?.contains(i)&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&a.current&&o.preventDefault()}})}),al=c.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:a,onCloseAutoFocus:o,...i}=e,l=We(rs,n);return jm(),s.jsx(s.Fragment,{children:s.jsx(xi,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:a,onUnmountAutoFocus:o,children:s.jsx(gi,{role:"dialog",id:l.contentId,"aria-describedby":l.descriptionId,"aria-labelledby":l.titleId,"data-state":Br(l.open),...i,ref:t,deferPointerDownOutside:!0,onDismiss:()=>l.onOpenChange(!1)})})})}),ol="DialogTitle",il=c.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,a=We(ol,n);return s.jsx(it.h2,{id:a.titleId,...r,ref:t})});il.displayName=ol;var ll="DialogDescription",Hg=c.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,a=We(ll,n);return s.jsx(it.p,{id:a.descriptionId,...r,ref:t})});Hg.displayName=ll;var cl="DialogClose",Wg=c.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,a=We(cl,n);return s.jsx(it.button,{type:"button",...r,ref:t,onClick:ht(e.onClick,()=>a.onOpenChange(!1))})});Wg.displayName=cl;function Br(e){return e?"open":"closed"}function Vg(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 ul=B.createContext({drawerRef:{current:null},overlayRef:{current:null},onPress:()=>{},onRelease:()=>{},onDrag:()=>{},onNestedDrag:()=>{},onNestedOpenChange:()=>{},onNestedRelease:()=>{},openProp:void 0,dismissible:!1,isOpen:!1,isDragging:!1,keyboardIsOpen:{current:!1},snapPointsOffset:null,snapPoints:null,handleOnly:!1,modal:!1,shouldFade:!1,activeSnapPoint:null,onOpenChange:()=>{},setActiveSnapPoint:()=>{},closeDrawer:()=>{},direction:"bottom",shouldAnimate:{current:!0},shouldScaleBackground:!1,setBackgroundColorOnScale:!0,noBodyStyles:!1,container:null,autoFocus:!1}),zs=()=>{const e=B.useContext(ul);if(!e)throw new Error("useDrawerContext must be used within a Drawer.Root");return e};Vg(`[data-vaul-drawer]{touch-action:none;will-change:transform;transition:transform .5s cubic-bezier(.32, .72, 0, 1);animation-duration:.5s;animation-timing-function:cubic-bezier(0.32,0.72,0,1)}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=bottom][data-state=open]{animation-name:slideFromBottom}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=bottom][data-state=closed]{animation-name:slideToBottom}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=top][data-state=open]{animation-name:slideFromTop}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=top][data-state=closed]{animation-name:slideToTop}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=left][data-state=open]{animation-name:slideFromLeft}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=left][data-state=closed]{animation-name:slideToLeft}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=right][data-state=open]{animation-name:slideFromRight}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=right][data-state=closed]{animation-name:slideToRight}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=bottom]{transform:translate3d(0,var(--initial-transform,100%),0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=top]{transform:translate3d(0,calc(var(--initial-transform,100%) * -1),0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=left]{transform:translate3d(calc(var(--initial-transform,100%) * -1),0,0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=right]{transform:translate3d(var(--initial-transform,100%),0,0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=top]{transform:translate3d(0,var(--snap-point-height,0),0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=bottom]{transform:translate3d(0,var(--snap-point-height,0),0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=left]{transform:translate3d(var(--snap-point-height,0),0,0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=right]{transform:translate3d(var(--snap-point-height,0),0,0)}[data-vaul-overlay][data-vaul-snap-points=false]{animation-duration:.5s;animation-timing-function:cubic-bezier(0.32,0.72,0,1)}[data-vaul-overlay][data-vaul-snap-points=false][data-state=open]{animation-name:fadeIn}[data-vaul-overlay][data-state=closed]{animation-name:fadeOut}[data-vaul-animate=false]{animation:none!important}[data-vaul-overlay][data-vaul-snap-points=true]{opacity:0;transition:opacity .5s cubic-bezier(.32, .72, 0, 1)}[data-vaul-overlay][data-vaul-snap-points=true]{opacity:1}[data-vaul-drawer]:not([data-vaul-custom-container=true])::after{content:'';position:absolute;background:inherit;background-color:inherit}[data-vaul-drawer][data-vaul-drawer-direction=top]::after{top:initial;bottom:100%;left:0;right:0;height:200%}[data-vaul-drawer][data-vaul-drawer-direction=bottom]::after{top:100%;bottom:initial;left:0;right:0;height:200%}[data-vaul-drawer][data-vaul-drawer-direction=left]::after{left:initial;right:100%;top:0;bottom:0;width:200%}[data-vaul-drawer][data-vaul-drawer-direction=right]::after{left:100%;right:initial;top:0;bottom:0;width:200%}[data-vaul-overlay][data-vaul-snap-points=true]:not([data-vaul-snap-points-overlay=true]):not(
|
|
111
|
-
[data-state=closed]
|
|
112
|
-
){opacity:0}[data-vaul-overlay][data-vaul-snap-points-overlay=true]{opacity:1}[data-vaul-handle]{display:block;position:relative;opacity:.7;background:#e2e2e4;margin-left:auto;margin-right:auto;height:5px;width:32px;border-radius:1rem;touch-action:pan-y}[data-vaul-handle]:active,[data-vaul-handle]:hover{opacity:1}[data-vaul-handle-hitarea]{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);width:max(100%,2.75rem);height:max(100%,2.75rem);touch-action:inherit}@media (hover:hover) and (pointer:fine){[data-vaul-drawer]{user-select:none}}@media (pointer:fine){[data-vaul-handle-hitarea]:{width:100%;height:100%}}@keyframes fadeIn{from{opacity:0}to{opacity:1}}@keyframes fadeOut{to{opacity:0}}@keyframes slideFromBottom{from{transform:translate3d(0,var(--initial-transform,100%),0)}to{transform:translate3d(0,0,0)}}@keyframes slideToBottom{to{transform:translate3d(0,var(--initial-transform,100%),0)}}@keyframes slideFromTop{from{transform:translate3d(0,calc(var(--initial-transform,100%) * -1),0)}to{transform:translate3d(0,0,0)}}@keyframes slideToTop{to{transform:translate3d(0,calc(var(--initial-transform,100%) * -1),0)}}@keyframes slideFromLeft{from{transform:translate3d(calc(var(--initial-transform,100%) * -1),0,0)}to{transform:translate3d(0,0,0)}}@keyframes slideToLeft{to{transform:translate3d(calc(var(--initial-transform,100%) * -1),0,0)}}@keyframes slideFromRight{from{transform:translate3d(var(--initial-transform,100%),0,0)}to{transform:translate3d(0,0,0)}}@keyframes slideToRight{to{transform:translate3d(var(--initial-transform,100%),0,0)}}`);function Yg(){const e=navigator.userAgent;return typeof window<"u"&&(/Firefox/.test(e)&&/Mobile/.test(e)||/FxiOS/.test(e))}function Gg(){return $r(/^Mac/)}function Xg(){return $r(/^iPhone/)}function Va(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function Jg(){return $r(/^iPad/)||Gg()&&navigator.maxTouchPoints>1}function dl(){return Xg()||Jg()}function $r(e){return typeof window<"u"&&window.navigator!=null?e.test(window.navigator.platform):void 0}const Zg=24,ep=typeof window<"u"?c.useLayoutEffect:c.useEffect;function Ya(...e){return(...t)=>{for(let n of e)typeof n=="function"&&n(...t)}}const Bn=typeof document<"u"&&window.visualViewport;function Ga(e){let t=window.getComputedStyle(e);return/(auto|scroll)/.test(t.overflow+t.overflowX+t.overflowY)}function fl(e){for(Ga(e)&&(e=e.parentElement);e&&!Ga(e);)e=e.parentElement;return e||document.scrollingElement||document.documentElement}const tp=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);let Xs=0,$n;function sp(e={}){let{isDisabled:t}=e;ep(()=>{if(!t)return Xs++,Xs===1&&dl()&&($n=np()),()=>{Xs--,Xs===0&&$n?.()}},[t])}function np(){let e,t=0,n=f=>{e=fl(f.target),!(e===document.documentElement&&e===document.body)&&(t=f.changedTouches[0].pageY)},r=f=>{if(!e||e===document.documentElement||e===document.body){f.preventDefault();return}let h=f.changedTouches[0].pageY,x=e.scrollTop,b=e.scrollHeight-e.clientHeight;b!==0&&((x<=0&&h>t||x>=b&&h<t)&&f.preventDefault(),t=h)},a=f=>{let h=f.target;ar(h)&&h!==document.activeElement&&(f.preventDefault(),h.style.transform="translateY(-2000px)",h.focus(),requestAnimationFrame(()=>{h.style.transform=""}))},o=f=>{let h=f.target;ar(h)&&(h.style.transform="translateY(-2000px)",requestAnimationFrame(()=>{h.style.transform="",Bn&&(Bn.height<window.innerHeight?requestAnimationFrame(()=>{Xa(h)}):Bn.addEventListener("resize",()=>Xa(h),{once:!0}))}))},i=()=>{window.scrollTo(0,0)},l=window.pageXOffset,u=window.pageYOffset,d=Ya(rp(document.documentElement,"paddingRight",`${window.innerWidth-document.documentElement.clientWidth}px`));window.scrollTo(0,0);let m=Ya(bs(document,"touchstart",n,{passive:!1,capture:!0}),bs(document,"touchmove",r,{passive:!1,capture:!0}),bs(document,"touchend",a,{passive:!1,capture:!0}),bs(document,"focus",o,!0),bs(window,"scroll",i));return()=>{d(),m(),window.scrollTo(l,u)}}function rp(e,t,n){let r=e.style[t];return e.style[t]=n,()=>{e.style[t]=r}}function bs(e,t,n,r){return e.addEventListener(t,n,r),()=>{e.removeEventListener(t,n,r)}}function Xa(e){let t=document.scrollingElement||document.documentElement;for(;e&&e!==t;){let n=fl(e);if(n!==document.documentElement&&n!==document.body&&n!==e){let r=n.getBoundingClientRect().top,a=e.getBoundingClientRect().top,o=e.getBoundingClientRect().bottom;const i=n.getBoundingClientRect().bottom+Zg;o>i&&(n.scrollTop+=a-r)}e=n.parentElement}}function ar(e){return e instanceof HTMLInputElement&&!tp.has(e.type)||e instanceof HTMLTextAreaElement||e instanceof HTMLElement&&e.isContentEditable}function ap(e,t){typeof e=="function"?e(t):e!=null&&(e.current=t)}function op(...e){return t=>e.forEach(n=>ap(n,t))}function ml(...e){return c.useCallback(op(...e),e)}const hl=new WeakMap;function we(e,t,n=!1){if(!e||!(e instanceof HTMLElement))return;let r={};Object.entries(t).forEach(([a,o])=>{if(a.startsWith("--")){e.style.setProperty(a,o);return}r[a]=e.style[a],e.style[a]=o}),!n&&hl.set(e,r)}function ip(e,t){if(!e||!(e instanceof HTMLElement))return;let n=hl.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 Js(e,t){if(!e)return null;const n=window.getComputedStyle(e),r=n.transform||n.webkitTransform||n.mozTransform;let a=r.match(/^matrix3d\((.+)\)$/);return a?parseFloat(a[1].split(", ")[be(t)?13:12]):(a=r.match(/^matrix\((.+)\)$/),a?parseFloat(a[1].split(", ")[be(t)?5:4]):null)}function lp(e){return 8*(Math.log(e+1)-2)}function Kn(e,t){if(!e)return()=>{};const n=e.style.cssText;return Object.assign(e.style,t),()=>{e.style.cssText=n}}function cp(...e){return(...t)=>{for(const n of e)typeof n=="function"&&n(...t)}}const he={DURATION:.5,EASE:[.32,.72,0,1]},gl=.4,up=.25,dp=100,pl=8,Ct=16,or=26,qn="vaul-dragging";function xl(e){const t=B.useRef(e);return B.useEffect(()=>{t.current=e}),B.useMemo(()=>(...n)=>t.current==null?void 0:t.current.call(t,...n),[])}function fp({defaultProp:e,onChange:t}){const n=B.useState(e),[r]=n,a=B.useRef(r),o=xl(t);return B.useEffect(()=>{a.current!==r&&(o(r),a.current=r)},[r,a,o]),n}function bl({prop:e,defaultProp:t,onChange:n=()=>{}}){const[r,a]=fp({defaultProp:t,onChange:n}),o=e!==void 0,i=o?e:r,l=xl(n),u=B.useCallback(d=>{if(o){const f=typeof d=="function"?d(e):d;f!==e&&l(f)}else a(d)},[o,e,a,l]);return[i,u]}function mp({activeSnapPointProp:e,setActiveSnapPointProp:t,snapPoints:n,drawerRef:r,overlayRef:a,fadeFromIndex:o,onSnapPointChange:i,direction:l="bottom",container:u,snapToSequentialPoint:d}){const[m,f]=bl({prop:e,defaultProp:n?.[0],onChange:t}),[h,x]=B.useState(typeof window<"u"?{innerWidth:window.innerWidth,innerHeight:window.innerHeight}:void 0);B.useEffect(()=>{function S(){x({innerWidth:window.innerWidth,innerHeight:window.innerHeight})}return window.addEventListener("resize",S),()=>window.removeEventListener("resize",S)},[]);const b=B.useMemo(()=>m===n?.[n.length-1]||null,[n,m]),p=B.useMemo(()=>{var S;return(S=n?.findIndex(N=>N===m))!=null?S:null},[n,m]),v=n&&n.length>0&&(o||o===0)&&!Number.isNaN(o)&&n[o]===m||!n,g=B.useMemo(()=>{const S=u?{width:u.getBoundingClientRect().width,height:u.getBoundingClientRect().height}:typeof window<"u"?{width:window.innerWidth,height:window.innerHeight}:{width:0,height:0};var N;return(N=n?.map(R=>{const A=typeof R=="string";let E=0;if(A&&(E=parseInt(R,10)),be(l)){const I=A?E:h?R*S.height:0;return h?l==="bottom"?S.height-I:-S.height+I:I}const M=A?E:h?R*S.width:0;return h?l==="right"?S.width-M:-S.width+M:M}))!=null?N:[]},[n,h,u]),y=B.useMemo(()=>p!==null?g?.[p]:null,[g,p]),j=B.useCallback(S=>{var N;const R=(N=g?.findIndex(A=>A===S))!=null?N:null;i(R),we(r.current,{transition:`transform ${he.DURATION}s cubic-bezier(${he.EASE.join(",")})`,transform:be(l)?`translate3d(0, ${S}px, 0)`:`translate3d(${S}px, 0, 0)`}),g&&R!==g.length-1&&o!==void 0&&R!==o&&R<o?we(a.current,{transition:`opacity ${he.DURATION}s cubic-bezier(${he.EASE.join(",")})`,opacity:"0"}):we(a.current,{transition:`opacity ${he.DURATION}s cubic-bezier(${he.EASE.join(",")})`,opacity:"1"}),f(n?.[Math.max(R,0)])},[r.current,n,g,o,a,f]);B.useEffect(()=>{if(m||e){var S;const N=(S=n?.findIndex(R=>R===e||R===m))!=null?S:-1;g&&N!==-1&&typeof g[N]=="number"&&j(g[N])}},[m,e,n,g,j]);function w({draggedDistance:S,closeDrawer:N,velocity:R,dismissible:A}){if(o===void 0)return;const E=l==="bottom"||l==="right"?(y??0)-S:(y??0)+S,M=p===o-1,I=p===0,T=S>0;if(M&&we(a.current,{transition:`opacity ${he.DURATION}s cubic-bezier(${he.EASE.join(",")})`}),!d&&R>2&&!T){A?N():j(g[0]);return}if(!d&&R>2&&T&&g&&n){j(g[n.length-1]);return}const O=g?.reduce((q,X)=>typeof q!="number"||typeof X!="number"?q:Math.abs(X-E)<Math.abs(q-E)?X:q),_=be(l)?window.innerHeight:window.innerWidth;if(R>gl&&Math.abs(S)<_*.4){const q=T?1:-1;if(q>0&&b&&n){j(g[n.length-1]);return}if(I&&q<0&&A&&N(),p===null)return;j(g[p+q]);return}j(O)}function C({draggedDistance:S}){if(y===null)return;const N=l==="bottom"||l==="right"?y-S:y+S;(l==="bottom"||l==="right")&&N<g[g.length-1]||(l==="top"||l==="left")&&N>g[g.length-1]||we(r.current,{transform:be(l)?`translate3d(0, ${N}px, 0)`:`translate3d(${N}px, 0, 0)`})}function k(S,N){if(!n||typeof p!="number"||!g||o===void 0)return null;const R=p===o-1;if(p>=o&&N)return 0;if(R&&!N)return 1;if(!v&&!R)return null;const E=R?p+1:p-1,M=R?g[E]-g[E-1]:g[E+1]-g[E],I=S/Math.abs(M);return R?1-I:I}return{isLastSnapPoint:b,activeSnapPoint:m,shouldFade:v,getPercentageDragged:k,setActiveSnapPoint:f,activeSnapPointIndex:p,onRelease:w,onDrag:C,snapPointsOffset:g}}const hp=()=>()=>{};function gp(){const{direction:e,isOpen:t,shouldScaleBackground:n,setBackgroundColorOnScale:r,noBodyStyles:a}=zs(),o=B.useRef(null),i=c.useMemo(()=>document.body.style.backgroundColor,[]);function l(){return(window.innerWidth-or)/window.innerWidth}B.useEffect(()=>{if(t&&n){o.current&&clearTimeout(o.current);const u=document.querySelector("[data-vaul-drawer-wrapper]")||document.querySelector("[vaul-drawer-wrapper]");if(!u)return;cp(r&&!a?Kn(document.body,{background:"black"}):hp,Kn(u,{transformOrigin:be(e)?"top":"left",transitionProperty:"transform, border-radius",transitionDuration:`${he.DURATION}s`,transitionTimingFunction:`cubic-bezier(${he.EASE.join(",")})`}));const d=Kn(u,{borderRadius:`${pl}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 vs=null;function pp({isOpen:e,modal:t,nested:n,hasBeenOpened:r,preventScrollRestoration:a,noBodyStyles:o}){const[i,l]=B.useState(()=>typeof window<"u"?window.location.href:""),u=B.useRef(0),d=B.useCallback(()=>{if(Va()&&vs===null&&e&&!o){vs={position:document.body.style.position,top:document.body.style.top,left:document.body.style.left,height:document.body.style.height,right:"unset"};const{scrollX:f,innerHeight:h}=window;document.body.style.setProperty("position","fixed","important"),Object.assign(document.body.style,{top:`${-u.current}px`,left:`${-f}px`,right:"0px",height:"auto"}),window.setTimeout(()=>window.requestAnimationFrame(()=>{const x=h-window.innerHeight;x&&u.current>=h&&(document.body.style.top=`${-(u.current+x)}px`)}),300)}},[e]),m=B.useCallback(()=>{if(Va()&&vs!==null&&!o){const f=-parseInt(document.body.style.top,10),h=-parseInt(document.body.style.left,10);Object.assign(document.body.style,vs),window.requestAnimationFrame(()=>{if(a&&i!==window.location.href){l(window.location.href);return}window.scrollTo(h,f)}),vs=null}},[i]);return B.useEffect(()=>{function f(){u.current=window.scrollY}return f(),window.addEventListener("scroll",f),()=>{window.removeEventListener("scroll",f)}},[]),B.useEffect(()=>{if(t)return()=>{typeof document>"u"||document.querySelector("[data-vaul-drawer]")||m()}},[t,m]),B.useEffect(()=>{n||!r||(e?(!window.matchMedia("(display-mode: standalone)").matches&&d(),t||window.setTimeout(()=>{m()},500)):m())},[e,r,i,t,n,d,m]),{restorePositionSetting:m}}function xp({open:e,onOpenChange:t,children:n,onDrag:r,onRelease:a,snapPoints:o,shouldScaleBackground:i=!1,setBackgroundColorOnScale:l=!0,closeThreshold:u=up,scrollLockTimeout:d=dp,dismissible:m=!0,handleOnly:f=!1,fadeFromIndex:h=o&&o.length-1,activeSnapPoint:x,setActiveSnapPoint:b,fixed:p,modal:v=!0,onClose:g,nested:y,noBodyStyles:j=!1,direction:w="bottom",defaultOpen:C=!1,disablePreventScroll:k=!0,snapToSequentialPoint:S=!1,preventScrollRestoration:N=!1,repositionInputs:R=!0,onAnimationEnd:A,container:E,autoFocus:M=!1}){var I,T;const[O=!1,_]=bl({defaultProp:C,prop:e,onChange:H=>{t?.(H),!H&&!y&&tt(),setTimeout(()=>{A?.(H)},he.DURATION*1e3),H&&!v&&typeof window<"u"&&window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"}),H||(document.body.style.pointerEvents="auto")}}),[q,X]=B.useState(!1),[F,$]=B.useState(!1),[ae,ce]=B.useState(!1),J=B.useRef(null),D=B.useRef(null),P=B.useRef(null),Q=B.useRef(null),G=B.useRef(null),ue=B.useRef(!1),le=B.useRef(null),Y=B.useRef(0),ge=B.useRef(!1),Se=B.useRef(!C),Ce=B.useRef(0),W=B.useRef(null),U=B.useRef(((I=W.current)==null?void 0:I.getBoundingClientRect().height)||0),te=B.useRef(((T=W.current)==null?void 0:T.getBoundingClientRect().width)||0),ee=B.useRef(0),Ee=B.useCallback(H=>{o&&H===de.length-1&&(D.current=new Date)},[]),{activeSnapPoint:Ie,activeSnapPointIndex:ze,setActiveSnapPoint:Ve,onRelease:Te,snapPointsOffset:de,onDrag:jt,shouldFade:Ae,getPercentageDragged:_s}=mp({snapPoints:o,activeSnapPointProp:x,setActiveSnapPointProp:b,drawerRef:W,fadeFromIndex:h,overlayRef:J,onSnapPointChange:Ee,direction:w,container:E,snapToSequentialPoint:S});sp({isDisabled:!O||F||!v||ae||!q||!R||!k});const{restorePositionSetting:tt}=pp({isOpen:O,modal:v,nested:y??!1,hasBeenOpened:q,preventScrollRestoration:N,noBodyStyles:j});function Pe(){return(window.innerWidth-or)/window.innerWidth}function Pt(H){var oe,se;!m&&!o||W.current&&!W.current.contains(H.target)||(U.current=((oe=W.current)==null?void 0:oe.getBoundingClientRect().height)||0,te.current=((se=W.current)==null?void 0:se.getBoundingClientRect().width)||0,$(!0),P.current=new Date,dl()&&window.addEventListener("touchend",()=>ue.current=!1,{once:!0}),H.target.setPointerCapture(H.pointerId),Y.current=be(w)?H.pageY:H.pageX)}function lt(H,oe){var se;let ne=H;const me=(se=window.getSelection())==null?void 0:se.toString(),ye=W.current?Js(W.current,w):null,xe=new Date;if(ne.tagName==="SELECT"||ne.hasAttribute("data-vaul-no-drag")||ne.closest("[data-vaul-no-drag]"))return!1;if(w==="right"||w==="left")return!0;if(D.current&&xe.getTime()-D.current.getTime()<500)return!1;if(ye!==null&&(w==="bottom"?ye>0:ye<0))return!0;if(me&&me.length>0)return!1;if(G.current&&xe.getTime()-G.current.getTime()<d&&ye===0||oe)return G.current=xe,!1;for(;ne;){if(ne.scrollHeight>ne.clientHeight){if(ne.scrollTop!==0)return G.current=new Date,!1;if(ne.getAttribute("role")==="dialog")return!0}ne=ne.parentNode}return!0}function St(H){if(W.current&&F){const oe=w==="bottom"||w==="right"?1:-1,se=(Y.current-(be(w)?H.pageY:H.pageX))*oe,ne=se>0,me=o&&!m&&!ne;if(me&&ze===0)return;const ye=Math.abs(se),xe=document.querySelector("[data-vaul-drawer-wrapper]"),Ne=w==="bottom"||w==="top"?U.current:te.current;let Re=ye/Ne;const Le=_s(ye,ne);if(Le!==null&&(Re=Le),me&&Re>=1||!ue.current&&!lt(H.target,ne))return;if(W.current.classList.add(qn),ue.current=!0,we(W.current,{transition:"none"}),we(J.current,{transition:"none"}),o&&jt({draggedDistance:se}),ne&&!o){const De=lp(se),ct=Math.min(De*-1,0)*oe;we(W.current,{transform:be(w)?`translate3d(0, ${ct}px, 0)`:`translate3d(${ct}px, 0, 0)`});return}const _e=1-Re;if((Ae||h&&ze===h-1)&&(r?.(H,Re),we(J.current,{opacity:`${_e}`,transition:"none"},!0)),xe&&J.current&&i){const De=Math.min(Pe()+Re*(1-Pe()),1),ct=8-Re*8,kt=Math.max(0,14-Re*14);we(xe,{borderRadius:`${ct}px`,transform:be(w)?`scale(${De}) translate3d(0, ${kt}px, 0)`:`scale(${De}) translate3d(${kt}px, 0, 0)`,transition:"none"},!0)}if(!o){const De=ye*oe;we(W.current,{transform:be(w)?`translate3d(0, ${De}px, 0)`:`translate3d(${De}px, 0, 0)`})}}}B.useEffect(()=>{window.requestAnimationFrame(()=>{Se.current=!0})},[]),B.useEffect(()=>{var H;function oe(){if(!W.current||!R)return;const se=document.activeElement;if(ar(se)||ge.current){var ne;const me=((ne=window.visualViewport)==null?void 0:ne.height)||0,ye=window.innerHeight;let xe=ye-me;const Ne=W.current.getBoundingClientRect().height||0,Re=Ne>ye*.8;ee.current||(ee.current=Ne);const Le=W.current.getBoundingClientRect().top;if(Math.abs(Ce.current-xe)>60&&(ge.current=!ge.current),o&&o.length>0&&de&&ze){const _e=de[ze]||0;xe+=_e}if(Ce.current=xe,Ne>me||ge.current){const _e=W.current.getBoundingClientRect().height;let De=_e;_e>me&&(De=me-(Re?Le:or)),p?W.current.style.height=`${_e-Math.max(xe,0)}px`:W.current.style.height=`${Math.max(De,me-Le)}px`}else Yg()||(W.current.style.height=`${ee.current}px`);o&&o.length>0&&!ge.current?W.current.style.bottom="0px":W.current.style.bottom=`${Math.max(xe,0)}px`}}return(H=window.visualViewport)==null||H.addEventListener("resize",oe),()=>{var se;return(se=window.visualViewport)==null?void 0:se.removeEventListener("resize",oe)}},[ze,o,de]);function qe(H){Lt(),g?.(),H||_(!1),setTimeout(()=>{o&&Ve(o[0])},he.DURATION*1e3)}function st(){if(!W.current)return;const H=document.querySelector("[data-vaul-drawer-wrapper]"),oe=Js(W.current,w);we(W.current,{transform:"translate3d(0, 0, 0)",transition:`transform ${he.DURATION}s cubic-bezier(${he.EASE.join(",")})`}),we(J.current,{transition:`opacity ${he.DURATION}s cubic-bezier(${he.EASE.join(",")})`,opacity:"1"}),i&&oe&&oe>0&&O&&we(H,{borderRadius:`${pl}px`,overflow:"hidden",...be(w)?{transform:`scale(${Pe()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`,transformOrigin:"top"}:{transform:`scale(${Pe()}) 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 Lt(){!F||!W.current||(W.current.classList.remove(qn),ue.current=!1,$(!1),Q.current=new Date)}function Ye(H){if(!F||!W.current)return;W.current.classList.remove(qn),ue.current=!1,$(!1),Q.current=new Date;const oe=Js(W.current,w);if(!H||!lt(H.target,!1)||!oe||Number.isNaN(oe)||P.current===null)return;const se=Q.current.getTime()-P.current.getTime(),ne=Y.current-(be(w)?H.pageY:H.pageX),me=Math.abs(ne)/se;if(me>.05&&(ce(!0),setTimeout(()=>{ce(!1)},200)),o){Te({draggedDistance:ne*(w==="bottom"||w==="right"?1:-1),closeDrawer:qe,velocity:me,dismissible:m}),a?.(H,!0);return}if(w==="bottom"||w==="right"?ne>0:ne<0){st(),a?.(H,!0);return}if(me>gl){qe(),a?.(H,!1);return}var ye;const xe=Math.min((ye=W.current.getBoundingClientRect().height)!=null?ye:0,window.innerHeight);var Ne;const Re=Math.min((Ne=W.current.getBoundingClientRect().width)!=null?Ne:0,window.innerWidth),Le=w==="left"||w==="right";if(Math.abs(oe)>=(Le?Re:xe)*u){qe(),a?.(H,!1);return}a?.(H,!0),st()}B.useEffect(()=>(O&&(we(document.documentElement,{scrollBehavior:"auto"}),D.current=new Date),()=>{ip(document.documentElement,"scrollBehavior")}),[O]);function hs(H){const oe=H?(window.innerWidth-Ct)/window.innerWidth:1,se=H?-Ct:0;le.current&&window.clearTimeout(le.current),we(W.current,{transition:`transform ${he.DURATION}s cubic-bezier(${he.EASE.join(",")})`,transform:be(w)?`scale(${oe}) translate3d(0, ${se}px, 0)`:`scale(${oe}) translate3d(${se}px, 0, 0)`}),!H&&W.current&&(le.current=setTimeout(()=>{const ne=Js(W.current,w);we(W.current,{transition:"none",transform:be(w)?`translate3d(0, ${ne}px, 0)`:`translate3d(${ne}px, 0, 0)`})},500))}function zt(H,oe){if(oe<0)return;const se=(window.innerWidth-Ct)/window.innerWidth,ne=se+oe*(1-se),me=-Ct+oe*Ct;we(W.current,{transform:be(w)?`scale(${ne}) translate3d(0, ${me}px, 0)`:`scale(${ne}) translate3d(${me}px, 0, 0)`,transition:"none"})}function Nt(H,oe){const se=be(w)?window.innerHeight:window.innerWidth,ne=oe?(se-Ct)/se:1,me=oe?-Ct:0;oe&&we(W.current,{transition:`transform ${he.DURATION}s cubic-bezier(${he.EASE.join(",")})`,transform:be(w)?`scale(${ne}) translate3d(0, ${me}px, 0)`:`scale(${ne}) translate3d(${me}px, 0, 0)`})}return B.useEffect(()=>{v||window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"})},[v]),B.createElement(Zi,{defaultOpen:C,onOpenChange:H=>{!m&&!H||(H?X(!0):qe(!0),_(H))},open:O},B.createElement(ul.Provider,{value:{activeSnapPoint:Ie,snapPoints:o,setActiveSnapPoint:Ve,drawerRef:W,overlayRef:J,onOpenChange:t,onPress:Pt,onRelease:Ye,onDrag:St,dismissible:m,shouldAnimate:Se,handleOnly:f,isOpen:O,isDragging:F,shouldFade:Ae,closeDrawer:qe,onNestedDrag:zt,onNestedOpenChange:hs,onNestedRelease:Nt,keyboardIsOpen:ge,modal:v,snapPointsOffset:de,activeSnapPointIndex:ze,direction:w,shouldScaleBackground:i,setBackgroundColorOnScale:l,noBodyStyles:j,container:E,autoFocus:M}},n))}const vl=B.forwardRef(function({...e},t){const{overlayRef:n,snapPoints:r,onRelease:a,shouldFade:o,isOpen:i,modal:l,shouldAnimate:u}=zs(),d=ml(t,n),m=r&&r.length>0;if(!l)return null;const f=B.useCallback(h=>a(h),[a]);return B.createElement(nl,{onMouseUp:f,ref:d,"data-vaul-overlay":"","data-vaul-snap-points":i&&m?"true":"false","data-vaul-snap-points-overlay":i&&o?"true":"false","data-vaul-animate":u?.current?"true":"false",...e})});vl.displayName="Drawer.Overlay";const yl=B.forwardRef(function({onPointerDownOutside:e,style:t,onOpenAutoFocus:n,...r},a){const{drawerRef:o,onPress:i,onRelease:l,onDrag:u,keyboardIsOpen:d,snapPointsOffset:m,activeSnapPointIndex:f,modal:h,isOpen:x,direction:b,snapPoints:p,container:v,handleOnly:g,shouldAnimate:y,autoFocus:j}=zs(),[w,C]=B.useState(!1),k=ml(a,o),S=B.useRef(null),N=B.useRef(null),R=B.useRef(!1),A=p&&p.length>0;gp();const E=(I,T,O=0)=>{if(R.current)return!0;const _=Math.abs(I.y),q=Math.abs(I.x),X=q>_,F=["bottom","right"].includes(T)?1:-1;if(T==="left"||T==="right"){if(!(I.x*F<0)&&q>=0&&q<=O)return X}else if(!(I.y*F<0)&&_>=0&&_<=O)return!X;return R.current=!0,!0};B.useEffect(()=>{A&&window.requestAnimationFrame(()=>{C(!0)})},[]);function M(I){S.current=null,R.current=!1,l(I)}return B.createElement(rl,{"data-vaul-drawer-direction":b,"data-vaul-drawer":"","data-vaul-delayed-snap-points":w?"true":"false","data-vaul-snap-points":x&&A?"true":"false","data-vaul-custom-container":v?"true":"false","data-vaul-animate":y?.current?"true":"false",...r,ref:k,style:m&&m.length>0?{"--snap-point-height":`${m[f??0]}px`,...t}:t,onPointerDown:I=>{g||(r.onPointerDown==null||r.onPointerDown.call(r,I),S.current={x:I.pageX,y:I.pageY},i(I))},onOpenAutoFocus:I=>{n?.(I),j||I.preventDefault()},onPointerDownOutside:I=>{if(e?.(I),!h||I.defaultPrevented){I.preventDefault();return}d.current&&(d.current=!1)},onFocusOutside:I=>{if(!h){I.preventDefault();return}},onPointerMove:I=>{if(N.current=I,g||(r.onPointerMove==null||r.onPointerMove.call(r,I),!S.current))return;const T=I.pageY-S.current.y,O=I.pageX-S.current.x,_=I.pointerType==="touch"?10:2;E({x:O,y:T},b,_)?u(I):(Math.abs(O)>_||Math.abs(T)>_)&&(S.current=null)},onPointerUp:I=>{r.onPointerUp==null||r.onPointerUp.call(r,I),S.current=null,R.current=!1,l(I)},onPointerOut:I=>{r.onPointerOut==null||r.onPointerOut.call(r,I),M(N.current)},onContextMenu:I=>{r.onContextMenu==null||r.onContextMenu.call(r,I),N.current&&M(N.current)}})});yl.displayName="Drawer.Content";const bp=250,vp=120,wl=B.forwardRef(function({preventCycle:e=!1,children:t,...n},r){const{closeDrawer:a,isDragging:o,snapPoints:i,activeSnapPoint:l,setActiveSnapPoint:u,dismissible:d,handleOnly:m,isOpen:f,onPress:h,onDrag:x}=zs(),b=B.useRef(null),p=B.useRef(!1);function v(){if(p.current){j();return}window.setTimeout(()=>{g()},vp)}function g(){if(o||e||p.current){j();return}if(j(),!i||i.length===0){d||a();return}if(l===i[i.length-1]&&d){a();return}const C=i.findIndex(S=>S===l);if(C===-1)return;const k=i[C+1];u(k)}function y(){b.current=window.setTimeout(()=>{p.current=!0},bp)}function j(){b.current&&window.clearTimeout(b.current),p.current=!1}return B.createElement("div",{onClick:v,onPointerCancel:j,onPointerDown:w=>{m&&h(w),y()},onPointerMove:w=>{m&&x(w)},ref:r,"data-vaul-drawer-visible":f?"true":"false","data-vaul-handle":"","aria-hidden":"true",...n},B.createElement("span",{"data-vaul-handle-hitarea":"","aria-hidden":"true"},t))});wl.displayName="Drawer.Handle";function yp(e){const t=zs(),{container:n=t.container,...r}=e;return B.createElement(sl,{container:n,...r})}const $e={Root:xp,Content:yl,Overlay:vl,Portal:yp,Handle:wl,Title:il},wp=new Set(["outbox","postvak uit","boîte d'envoi","postausgang","buzón de salida","posta in uscita","送信トレイ","送件匣","发件箱","skrzynka nadawcza"]),jp=e=>{const t=an(e.fullPath).trim().toLowerCase();return wp.has(t)},Ja=Gn.length,Kr=(e,t=[])=>{const n=is(t);return[...e.filter(a=>{const o=n.get(a.mailboxId);return o==="drafts"||o==="sent"?!1:!jp(a)})].sort((a,o)=>{const i=n.has(a.mailboxId)?Gn.indexOf(n.get(a.mailboxId)??"inbox"):Ja,l=n.has(o.mailboxId)?Gn.indexOf(n.get(o.mailboxId)??"inbox"):Ja;return i!==l?i-l:an(a.fullPath).localeCompare(an(o.fullPath),void 0,{sensitivity:"base",numeric:!0})})},jl="inline-flex items-center justify-center transition-colors",Sp=fe(jl,"min-h-11 min-w-11 rounded hover:bg-surface-raised"),Np=fe(jl,"min-h-11 gap-1.5 px-3 rounded text-sm font-medium hover:bg-surface-raised"),Fs=({accountId:e,currentMailboxId:t,onMove:n,disabled:r=!1,disabledHint:a,variant:o="icon-only",label:i})=>{const[l,u]=c.useState(!1),d=Ot(),m=c.useRef(null),f=i??"Move to folder",h=c.useId(),{t:x}=fn("mail",{useSuspense:!1}),b=c.useCallback((A,E)=>x(A,{defaultValue:E}),[x]),{data:p,isLoading:v,isError:g,error:y,refetch:j}=ie({...Ze({path:{accountId:e}}),staleTime:1/0,enabled:l}),w=Yi(e),C=c.useMemo(()=>{const A=Kr(p?.items??[],w),E=is(w);return A.map(M=>({id:M.mailboxId,label:es(M,E.get(M.mailboxId),b),searchValue:M.fullPath,isCurrent:M.mailboxId===t}))},[p?.items,w,t,b]),k=c.useCallback(A=>{u(!1),n(A)},[n]);c.useEffect(()=>{if(!l||!d)return;const A=M=>{m.current&&!m.current.contains(M.target)&&u(!1)},E=M=>{M.key==="Escape"&&u(!1)};return document.addEventListener("mousedown",A),document.addEventListener("keydown",E),()=>{document.removeEventListener("mousedown",A),document.removeEventListener("keydown",E)}},[l,d]);const S=r||!!a,N=s.jsxs("button",{type:"button",onClick:A=>{A.stopPropagation(),!S&&u(E=>!E)},"aria-label":f,"aria-haspopup":d?"listbox":"dialog","aria-expanded":l,"aria-controls":l?h:void 0,title:a,className:o==="icon-only"?Sp:Np,children:[s.jsx(Qo,{className:"size-4"}),o==="compact"&&s.jsx("span",{className:"hidden sm:inline",children:"Move"})]}),R=v?s.jsx("div",{className:"px-3 py-5 text-sm text-fg-muted",children:"Loading folders…"}):g?s.jsx("div",{className:"p-3",children:s.jsx(yt,{variant:"inline",title:"Couldn't load folders",error:y,onRetry:()=>j()})}):s.jsx(fi,{mailboxes:C,onSelect:k,onCancel:()=>u(!1),autoFocus:!d,labels:{searchPlaceholder:x("move_picker_placeholder",{defaultValue:"Move to…"}),searchAriaLabel:x("move_picker_filter_label",{defaultValue:"Filter folders"}),optionLabel:A=>`Move to ${A}`,currentSuffix:"(current folder)",currentTag:"current",emptyMessage:A=>`No folders match "${A}"`}});return d?s.jsxs("div",{ref:m,className:"relative inline-block",children:[N,l&&s.jsx("div",{id:h,className:fe("absolute right-0 mt-1 z-50 w-72 max-h-96 flex flex-col","bg-surface border border-line rounded-md shadow-lg"),children:R})]}):s.jsxs(s.Fragment,{children:[N,s.jsx($e.Root,{open:l,onOpenChange:u,children:s.jsxs($e.Portal,{children:[s.jsx($e.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),s.jsxs($e.Content,{className:"fixed inset-x-0 bottom-0 z-50 flex flex-col bg-canvas rounded-t-lg",style:{maxHeight:"85dvh"},id:h,children:[s.jsx($e.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-subtle/30"}),s.jsx($e.Title,{className:"px-4 py-2 text-base font-semibold border-b border-line",children:"Move to folder"}),s.jsx("div",{className:"flex-1 overflow-hidden",children:R})]})]})})]})},kp=({messageId:e,threadId:t,mailboxId:n,isRead:r,accountId:a,fromAddressId:o,isTrusted:i=!1,showRaw:l=!1,onToggleRaw:u})=>{const d=je(),m=Me(),{pushError:f}=Qe(),{selectedMessageId:h}=Zt({strict:!1}),{mutate:x,isPending:b}=pe({...gn(),onMutate:async O=>{const _=O.body.isRead??!0,q=new Set(O.body.messageIds??[]),X=Mt({path:{threadId:t}}),F=ot({path:{mailboxId:n}}),$=bt({path:{mailboxId:n}});await Promise.all([d.cancelQueries({queryKey:X}),d.cancelQueries({queryKey:F}),d.cancelQueries({queryKey:$})]);const ae=d.getQueriesData({queryKey:X}).filter(D=>D[1]!==void 0).map(([D,P])=>({queryKey:D,data:P})),ce=d.getQueriesData({queryKey:F}).concat(d.getQueriesData({queryKey:$})).filter(D=>D[1]!==void 0).map(([D,P])=>({queryKey:D,data:P}));d.setQueriesData({queryKey:X},D=>D&&{...D,items:D.items.map(P=>q.has(P.messageId)?{...P,isRead:_}:P)});const J=D=>ns(D,P=>P.map(Q=>q.has(Q.messageId)?{...Q,isRead:_}:Q));return d.setQueriesData({queryKey:F},J),d.setQueriesData({queryKey:$},J),{threadMessagesPrefix:X,threadsListPrefix:F,threadsSearchPrefix:$,previousThreadMessages:ae,previousThreadsList:ce}},onError:(O,_,q)=>{if(q){for(const F of q.previousThreadMessages)d.setQueryData(F.queryKey,F.data);for(const F of q.previousThreadsList)d.setQueryData(F.queryKey,F.data)}const X=_.body.isRead??!0;f({title:X?"Couldn't mark as read":"Couldn't mark as unread",detail:Xe(O),error:O})},onSettled:(O,_,q,X)=>{X&&(d.invalidateQueries({queryKey:X.threadMessagesPrefix}),d.invalidateQueries({queryKey:X.threadsListPrefix}),d.invalidateQueries({queryKey:X.threadsSearchPrefix}))}}),p=c.useCallback(O=>{h&&O.includes(h)&&m({to:"/mail/$mailboxId",params:{mailboxId:n},search:_=>({..._,selectedMessageId:void 0})})},[h,n,m]),{deleteMessages:v,isPending:g}=Cs({mailboxId:n,threadId:t,onAfterOptimisticRemove:p}),{moveMessages:y,isPending:j}=gt({mailboxId:n,threadId:t,accountId:a,onAfterOptimisticRemove:p}),{toggleTrusted:w,isPending:C,error:k,reset:S}=Fr({messageId:e}),N=()=>{x({body:{messageIds:[e],isRead:!1}})},R=()=>{v([e])},A=()=>{o&&w(o,i)},E=b||g||j||C,M=E||!o,I=c.useCallback(O=>{y([e],O)},[y,e]),T=o?void 0:"Sender has no parseable address";return s.jsxs("div",{className:"flex flex-col items-end gap-1",children:[s.jsxs("div",{className:"flex items-center gap-1",children:[a&&s.jsx(Fs,{accountId:a,currentMailboxId:n,onMove:I,disabled:E,label:"Move this message"}),s.jsxs(Mi,{trigger:s.jsx(Uo,{className:"size-4"}),children:[s.jsxs(Gt,{onClick:A,disabled:M,children:[i?s.jsx(pn,{className:"size-4 text-positive"}):s.jsx(Ds,{className:"size-4 opacity-0"}),s.jsx("span",{title:T,children:"Trusted sender"})]}),r&&s.jsxs(Gt,{onClick:N,disabled:E,children:[s.jsx(Os,{className:"size-4"}),"Mark as unread"]}),u&&s.jsxs(Gt,{onClick:u,children:[s.jsx(qo,{className:"size-4"}),l?"Show formatted":"Show raw email"]}),s.jsx(er,{}),s.jsxs(Gt,{onClick:R,disabled:E,destructive:!0,children:[s.jsx(et,{className:"size-4"}),"Delete"]})]})]}),k&&s.jsx("div",{className:"w-64",children:s.jsx(yt,{variant:"inline",title:"Couldn't update trust",error:k,onRetry:()=>{S(),A()}})})]})},Cp=()=>{const[e,t]=c.useState(()=>typeof document<"u"&&document.documentElement.classList.contains("dark"));return c.useEffect(()=>{const n=document.documentElement,r=new MutationObserver(()=>{t(n.classList.contains("dark"))});return r.observe(n,{attributes:!0,attributeFilter:["class"]}),()=>r.disconnect()},[]),e},Ep=({blockedImageCount:e,canAlwaysTrust:t,isTrustPending:n,onLoadOnce:r,onAlwaysTrust:a})=>s.jsxs("div",{className:"mb-3 flex items-center justify-between rounded-md bg-surface-sunken/50 px-3 py-2 text-sm",children:[s.jsxs("span",{className:"text-fg-muted",children:[e," image",e>1?"s":""," blocked for privacy"]}),s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("button",{type:"button",onClick:r,className:"text-accent hover:underline",children:"Load once"}),t&&s.jsx("button",{type:"button",onClick:a,"aria-busy":n,className:"text-accent hover:underline aria-busy:opacity-50",children:n?"Trusting…":"Always trust"})]})]}),Ip=(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}}},Rp=e=>e instanceof Et?e.reason:"generic",Mp=e=>e instanceof Error?e.message:typeof e=="string"?e:"An unexpected error occurred while loading the message body.",Tp=({error:e,onRetry:t})=>{const n=Rp(e),r=Mp(e),{title:a,detail:o}=Ip(n,r),[i,l]=c.useState(!1),{Account:u}=pr();return i?null:s.jsxs("div",{role:"alert","data-testid":"message-body-error-banner","data-reason":n,className:"flex items-start gap-2 rounded-md border border-danger/40 bg-danger-soft px-3 py-2 text-sm",children:[s.jsx(Rt,{className:"size-4 shrink-0 text-danger mt-0.5","aria-hidden":"true"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"font-medium text-danger",children:a}),s.jsx("p",{className:"text-fg-muted mt-1 break-words",children:o})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-3",children:[n==="auth"&&s.jsx(u,{children:({signOut:d})=>s.jsx("button",{type:"button",onClick:()=>d(),className:"text-sm font-medium text-accent hover:underline",children:"Sign in again"})}),t&&s.jsx("button",{type:"button",onClick:t,className:"text-sm font-medium text-accent hover:underline",children:"Retry"}),s.jsx("button",{type:"button",onClick:()=>l(!0),"aria-label":"Dismiss message body error",className:"rounded-md p-1 text-fg-muted hover:bg-surface-raised hover:text-fg transition-colors",children:s.jsx(Ke,{className:"size-4","aria-hidden":"true"})})]})]})},Ap=()=>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"})]}),Za=()=>s.jsx("p",{className:"text-fg-muted text-sm italic",children:"This message has no body content."}),Sl=({bodyParts:e,html:t,text:n,isTrusted:r=!1,messageId:a,fromAddressId:o,category:i,className:l})=>{const[u,d]=c.useState(!1),m=r||u,f=Cp(),{toggleTrusted:h,isPending:x}=Fr({messageId:a??""}),b=!!e&&e.length>0,{picked:p,data:v,isLoading:g,isError:y,error:j,refetch:w}=Bi({messageId:a,bodyParts:e,enabled:b}),C=c.useMemo(()=>gd(e??[]),[e]),k=b&&v?.kind==="html"?v.body:t,S=b&&v?.kind==="text"?v.body:n;if(b){if(g)return s.jsx("div",{className:fe("message-body",l),children:s.jsx(Ap,{})});if(y)return s.jsx("div",{className:fe("message-body",l),children:s.jsx(Tp,{error:j,onRetry:()=>w()})});if(!p)return s.jsx("div",{className:fe("message-body",l),children:s.jsx(Za,{})})}else if(!t&&!n)return s.jsx("div",{className:fe("message-body",l),children:s.jsx(Za,{})});const N=!!(o&&a),R=()=>{!o||x||(d(!0),h(o,!1))};return s.jsx(ii,{className:l,html:k,text:S,isDark:f,category:i,allowImages:m,resolveCid:C,renderBlockedNotice:A=>s.jsx(Ep,{blockedImageCount:A,canAlwaysTrust:N,isTrustPending:x,onLoadOnce:()=>d(!0),onAlwaysTrust:R})})},Dp=({messageId:e,threadId:t,mailboxId:n,accountId:r,isRead:a,isStarred:o,onToggleStar:i,fromAddressId:l,isTrusted:u,showRaw:d,onToggleRaw:m,onReply:f,onReplyAll:h,onForward:x})=>{const b=je(),{deleteMessages:p}=Cs({mailboxId:n,threadId:t}),{moveMessages:v}=gt({mailboxId:n,threadId:t,accountId:r}),{toggleTrusted:g}=Fr({messageId:e}),{mutate:y}=pe({...gn(),onSettled:()=>{b.invalidateQueries({queryKey:Mt({path:{threadId:t}})}),b.invalidateQueries({queryKey:ot({path:{mailboxId:n}})}),b.invalidateQueries({queryKey:bt({path:{mailboxId:n}})})}}),j=c.useCallback(S=>{v([e],S)},[v,e]),w=c.useCallback(()=>{p([e])},[p,e]),C=c.useCallback(()=>{y({body:{messageIds:[e],isRead:!a}})},[y,e,a]),k=[];return l&&k.push({key:"trusted",label:u?"Trusted sender":"Mark sender trusted",icon:u?s.jsx(pn,{className:"size-4 text-positive"}):s.jsx(Ds,{className:"size-4"}),onSelect:()=>g(l,u)}),m&&k.push({key:"raw",label:d?"Show formatted":"Show raw email",icon:s.jsx(qo,{className:"size-4"}),onSelect:m}),s.jsx(oi,{hasThread:!0,onReply:f,onReplyAll:h,onForward:x,isStarred:o,onToggleStar:i,onDelete:w,isRead:a,onToggleRead:C,overflowItems:k,moveSlot:r?s.jsx(Fs,{accountId:r,currentMailboxId:n,onMove:j,label:"Move this message"}):void 0})},Op=()=>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"})]}),Pp=({messageId:e,enabled:t=!0})=>{const{data:n,isLoading:r,isError:a,error:o,refetch:i}=ie({...Jc({path:{messageId:e}}),enabled:t});if(r)return s.jsx("div",{className:"message-body",children:s.jsx(Op,{})});if(a)return s.jsx("div",{className:"message-body",children:s.jsx(yt,{variant:"inline",title:"Couldn't load the raw email",error:o,onRetry:()=>i()})});const 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})})},Lp=()=>s.jsx(pn,{className:"inline-block size-4 ml-1 -mt-0.5 text-positive align-middle","aria-label":"Trusted sender","data-testid":"trusted-sender-badge"}),Nl=(e,t)=>({id:e.messageId,fromName:e.fromName??e.fromEmail??"?",fromEmail:e.fromEmail??"",toLabel:"",dateLabel:t,snippet:e.snippet||"",bodyHtml:""}),kl=({isStarred:e,onToggleStar:t,isStarPending:n,hoverReveal:r})=>s.jsx("button",{type:"button",onClick:a=>{a.stopPropagation(),t()},disabled:n,"aria-label":e?"Remove star":"Add star",className:fe("shrink-0 p-0.5 rounded transition-colors",e?"text-warning":fe("text-fg-subtle hover:text-warning",r&&"opacity-0 group-hover:opacity-100 focus:opacity-100"),n&&"opacity-50"),children:s.jsx(vt,{className:fe("size-3.5",e&&"fill-current")})}),zp=({threadMessage:e,isFocused:t,onToggle:n,onToggleStar:r,isStarPending:a})=>{const o=Fo(e.sentDate,"datetime"),i=Nl(e,o);return s.jsx(li,{message:i,onClick:n,isFocused:t,isUnread:!e.isRead,trailing:s.jsxs(s.Fragment,{children:[e.hasAttachment&&s.jsx(xn,{className:"size-3 shrink-0 text-fg-subtle"}),s.jsx(kl,{isStarred:e.hasStars,onToggleStar:r,isStarPending:a,hoverReveal:!0}),s.jsx("span",{"data-testid":"message-date",className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:o})]})})},Fp=({threadMessage:e,messageData:t,isLoading:n,isError:r,error:a,onRetry:o,isFocused:i,onToggle:l,onToggleStar:u,isStarPending:d,accountId:m,showRaw:f,onToggleRaw:h,mobile:x,onReply:b,onReplyAll:p,onForward:v})=>{const g=Fo(e.sentDate,"long"),y=!e.isRead,j=t?.envelope.from[0]?.flags?.trusted?.value===!0,w=t?.envelope.from[0]?.addressId,C=Nl(e,g),k=e.autoMoved?s.jsx(Gi,{accountId:m,messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,autoMoved:e.autoMoved,size:"md"}):null;return s.jsx(ci,{message:C,isFocused:i,onHeaderClick:l,senderBadge:j?s.jsx(Lp,{}):void 0,trailing:s.jsx("span",{"data-testid":"message-date",className:"text-2xs text-fg-subtle",children:g}),to:t?s.jsx(Hu,{label:"To",addresses:t.envelope.to}):null,indicators:k||!x?s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mt-0.5",children:[k,!x&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex items-center justify-end gap-1",children:[s.jsx(kl,{isStarred:e.hasStars,onToggleStar:u,isStarPending:d}),e.hasAttachment&&s.jsx("span",{className:"text-fg-subtle p-0.5",children:s.jsx(xn,{className:"size-3.5"})})]}),y&&s.jsx("span",{className:"size-1.5 rounded-full bg-accent","aria-label":"Unread"})]})]}):void 0,actionMenu:x?void 0:s.jsx(kp,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,isRead:e.isRead,accountId:m,fromAddressId:w,isTrusted:j,showRaw:f,onToggleRaw:h}),actionBar:x?s.jsx(Dp,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,accountId:m,isRead:e.isRead,isStarred:e.hasStars,onToggleStar:u,fromAddressId:w,isTrusted:j,showRaw:f,onToggleRaw:h,onReply:b,onReplyAll:p,onForward:v}):void 0,body:n?s.jsxs("div",{className:"mt-3 animate-pulse space-y-2",children:[s.jsx("div",{className:"h-4 bg-surface-sunken rounded w-full"}),s.jsx("div",{className:"h-4 bg-surface-sunken rounded w-3/4"}),s.jsx("div",{className:"h-4 bg-surface-sunken rounded w-1/2"})]}):r&&Zc(a)?s.jsx("div",{className:"mt-3",children:s.jsx(Hi,{message:"This message has been deleted"})}):r?s.jsx("div",{className:"mt-3",children:s.jsx(yt,{variant:"inline",title:"Couldn't load this message",error:a,onRetry:o})}):f?s.jsx("div",{className:"mt-3",children:s.jsx(Pp,{messageId:e.messageId})}):s.jsx("div",{className:"mt-3",children:s.jsx(Sl,{bodyParts:t?.bodyParts,messageId:e.messageId,fromAddressId:t?.envelope.from[0]?.addressId,isTrusted:j,category:Sn(e.category)})})})},_p=({threadMessage:e,isExpanded:t,isFocused:n,onToggle:r,onToggleStar:a,isStarPending:o,accountId:i,mobile:l,onReply:u,onReplyAll:d,onForward:m})=>{const[f,h]=c.useState(!1),{data:x,isLoading:b,isError:p,error:v,refetch:g}=ie({...yr({path:{messageId:e.messageId}}),enabled:t,meta:{softError:!0}});return t?s.jsx(Fp,{threadMessage:e,messageData:x,isLoading:b,isError:p,error:v,onRetry:()=>g(),isFocused:n,onToggle:r,onToggleStar:a,isStarPending:o,accountId:i,showRaw:f,onToggleRaw:()=>h(y=>!y),mobile:l,onReply:u,onReplyAll:d,onForward:m}):s.jsx(zp,{threadMessage:e,isFocused:n,onToggle:r,onToggleStar:a,isStarPending:o})},Bp=()=>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 eo({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(Ps,{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 us=({threadId:e,mailboxId:t,subject:n,selectedMessageId:r,authenticity:a,onOpenIntelligence:o,onBack:i,composeRequest:l,onComposeClose:u,onSwipeNext:d,onSwipePrevious:m,mobileIntelligenceOpen:f})=>{const h=Ot(),{handlers:x}=Cg({onSwipeLeft:d,onSwipeRight:m}),{accountId:b}=Wi(t),{data:p,isLoading:v,isError:g,error:y,refetch:j}=ie({...eu({path:{threadId:e}})}),w=c.useMemo(()=>p?.items??[],[p?.items]),C=w[w.length-1],k=c.useRef(new Map),[S,N]=c.useState(new Set),[R,A]=c.useState(null),[E,M]=c.useState(0);c.useEffect(()=>{if(w.length>0&&e!==R){A(e);const U=new Set([w[w.length-1].threadMessageId]);if(r){const te=w.find(ee=>ee.messageId===r);te&&U.add(te.threadMessageId)}N(U),M(w.length-1)}},[e,w,R,r]);const I=c.useCallback(U=>{N(te=>{const ee=new Set(te);return ee.has(U)?ee.delete(U):ee.add(U),ee})},[]),T=c.useCallback(U=>{const te=w[U];if(!te)return;k.current.get(te.threadMessageId)?.scrollIntoView({behavior:"smooth",block:"nearest"})},[w]),O=c.useCallback(()=>{if(w.length===0)return;const U=Math.min(E+1,w.length-1);M(U),T(U)},[w.length,E,T]),_=c.useCallback(()=>{if(w.length===0)return;const U=Math.max(E-1,0);M(U),T(U)},[w.length,E,T]),q=c.useCallback(()=>{const U=w[E];U&&I(U.threadMessageId)},[w,E,I]),{data:X}=ie({...at(),staleTime:1/0}),F=X?.accounts?.[0],$=!!F?.smtpHost;jg({messages:w,expandedIds:S,threadId:e,mailboxId:t,accountId:F?.accountId});const{toggleStar:ae,isPending:ce,pendingMessageId:J}=rr({threadId:e,mailboxId:t,messages:w}),[D,P]=c.useState(null);c.useEffect(()=>{l&&l!=="new"&&(P(l),u?.())},[l,u]);const{data:Q}=ie({...yr({path:{messageId:C?.messageId??""}}),enabled:!!C&&D!==null}),G=c.useCallback(()=>{P("reply")},[]),ue=c.useCallback(()=>{P("reply_all")},[]),le=c.useCallback(()=>{P("forward")},[]),Y=c.useCallback(()=>{P(null),u?.()},[u]);if(Pr({enabled:!v&&w.length>0&&D===null,bindings:[{key:"j",handler:O,preventDefault:!0},{key:"ArrowDown",handler:O,preventDefault:!0},{key:"k",handler:_,preventDefault:!0},{key:"ArrowUp",handler:_,preventDefault:!0},{key:"Enter",handler:q,preventDefault:!0},{key:"o",handler:q,preventDefault:!0},...$?[{key:"r",handler:G,preventDefault:!0},{key:"R",handler:ue,noModifiers:!1,preventDefault:!0},{key:"f",handler:le,preventDefault:!0}]:[]]}),v)return s.jsx(Bp,{});if(g)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsx(yt,{title:"Couldn't load this conversation",error:y,onRetry:()=>j()})});if(w.length===0)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsx(Hi,{message:"No messages in this thread"})});const ge=n||w[0]?.subject||"(No subject)",Se=w.length,Ce=U=>s.jsx("div",{children:w.map((te,ee)=>s.jsx("div",{ref:Ee=>{Ee&&k.current.set(te.threadMessageId,Ee)},children:s.jsx(_p,{threadMessage:te,isExpanded:S.has(te.threadMessageId),isFocused:ee===E,onToggle:()=>I(te.threadMessageId),onToggleStar:()=>ae(te.messageId,te.hasStars),isStarPending:ce&&J===te.messageId,accountId:b,mobile:U,onReply:U&&$?G:void 0,onReplyAll:U&&$?ue:void 0,onForward:U&&$?le:void 0})},te.threadMessageId))}),W=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:ge}),s.jsxs("p",{className:"mt-1 text-2xs text-fg-subtle",children:[Se," ",Se===1?"message":"messages"]})]});return h?s.jsxs("article",{className:"h-full flex flex-col",children:[W,a?.dkimMismatch&&s.jsx(eo,{authenticity:a,onOpenIntelligence:o}),s.jsx("div",{className:"flex-1 overflow-auto",children:Ce(!1)}),D!==null&&s.jsx(Ka,{mode:D,account:F,sourceMessage:Q,onClose:Y})]}):s.jsxs(Bd,{thread:{subject:ge,messages:[]},onBack:i??(()=>{}),intelligenceOpen:f,onToggleIntelligence:o,touchHandlers:x,children:[a?.dkimMismatch&&s.jsx(eo,{authenticity:a,onOpenIntelligence:o}),Ce(!0),D!==null&&s.jsx(Ka,{mode:D,account:F,sourceMessage:Q,onClose:Y})]})};function ds(){const{mailboxNameIndex:e,accountNameIndex:t}=ve();return{...mt({select:r=>zi(r.matches)})?{}:{mailboxesByName:e},accountsByName:t}}const qr=e=>e.trim().toLocaleLowerCase(),$p=/^\d{4}-\d{2}-\d{2}$/;function to(e,t,n){if(!$p.test(n))return;const r=Date.parse(`${n}T00:00:00Z`);if(!Number.isNaN(r))return{type:e,raw:t,value:n,epochSeconds:Math.floor(r/1e3)}}function Kp(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 to("before",e,e.slice(7));if(n.startsWith("after:")&&e.length>6)return to("after",e,e.slice(6));if(n.startsWith("in:")&&e.length>3){const r=e.slice(3),a=t.mailboxesByName?.get(r.toLowerCase());return a?{type:"in",raw:e,value:r,mailboxId:a}:void 0}if(n.startsWith("account:")&&e.length>8){const r=e.slice(8),a=t.accountsByName?.get(r.toLowerCase());return a?{type:"account",raw:e,value:r,accountId:a}:void 0}}function fs(e,t={}){const n=e.split(/\s+/).filter(o=>o.length>0),r=[],a=[];for(const o of n){const i=Kp(o,t);i?r.push(i):a.push(o)}return{freeText:a.join(" "),tokens:r}}function qp(e,t){return e.split(/\s+/).filter(n=>n.length>0&&n!==t.raw).join(" ")}function Up(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 Qp=20,Hp=new Set(Object.values(Ge)),Wp=e=>e!==void 0&&Hp.has(e)?e:void 0;function Cl({mailboxId:e,filterCategory:t}={}){const{searchQuery:n}=ve(),r=ds(),a=mt({select:y=>y.matches}),o=qr(n),{freeText:i,tokens:l}=fs(o,r),u=i.length>0,d=Wp(t),m=l.some(y=>y.type==="hasAttachment")?!0:void 0,f=l.some(y=>y.type==="isUnread")?!1:void 0,h=l.find(y=>y.type==="after"),x=l.find(y=>y.type==="before"),b=l.find(y=>y.type==="in"),p=Ph({matches:a,callerMailboxId:e,inTokenMailboxId:b?.mailboxId}),{data:v,isLoading:g}=ie({...Ao({query:{query:i,mailboxId:p,limit:Qp,...d!==void 0?{category:d}:{},...m!==void 0?{hasAttachment:m}:{},...f!==void 0?{isRead:f}:{},...h?{sentDateFrom:h.epochSeconds}:{},...x?{sentDateTo:x.epochSeconds}:{}}}),enabled:u,staleTime:6e4});return{hits:v?.items??[],isLoading:u&&g}}const Vp=(e,t)=>e.createdAt!==t.createdAt?e.createdAt-t.createdAt:e.accountId.localeCompare(t.accountId),Yp=e=>[...e].sort(Vp);function ir(e){const t=e.authenticity?.dkimMismatch===!0;return{id:e.messageId,accountId:e.accountId??e.accountConfigId,mailboxId:e.mailboxId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:wt(e.sentDate),sentDate:e.sentDate,isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Sn(e.category),suspicious:t}}function Gp(e,t){const n=new Set,r=[];for(const a of[...e,...t])n.has(a.id)||(n.add(a.id),r.push(a));return r.sort((a,o)=>(o.sentDate??0)-(a.sentDate??0))}const so=[{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},{id:"uncategorized",label:"Unclassified",category:Ge.uncategorized}];function Xp(e){const t=new Map(so.map(r=>[r.category,[]]));for(const r of e){const a=r.category??Ge.uncategorized;(t.get(a)??t.get(Ge.uncategorized))?.push(r)}const n=[];for(const r of so){const a=t.get(r.category);a&&a.length>0&&n.push({id:r.id,label:r.label,threads:a})}return n}function El(e,t){return e.fromName.toLowerCase().includes(t)||e.fromEmail.toLowerCase().includes(t)||e.subject.toLowerCase().includes(t)||e.snippet.toLowerCase().includes(t)}function Il(e,t){return t.every(n=>{switch(n.type){case"from":{const r=n.value.toLowerCase();return e.fromEmail.toLowerCase().includes(r)||e.fromName.toLowerCase().includes(r)}case"hasAttachment":return e.hasAttachment===!0;case"isUnread":return!e.isRead;case"after":return e.sentDate!=null&&e.sentDate>=n.epochSeconds*1e3;case"before":return e.sentDate!=null&&e.sentDate<n.epochSeconds*1e3;case"in":return e.mailboxId===n.mailboxId;case"account":return e.accountId===n.accountId;default:return!1}})}const Jp={sender:"sender",recipient:"recipient",subject:"subject",attachment:"attachment",body:"body",entities:"entities"};function Zp(e){return Jp[e]??e}function ex(e){return{id:e.messageId,sender:e.fromName??e.fromEmail??"Unknown",subject:e.subject??"(No subject)",snippet:e.snippet??"",date:wt(e.sentDate),unread:!e.isRead,flagged:e.hasStars===!0,threadId:e.threadId,mailboxId:e.mailboxId}}function Rl(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 tx(e){return{id:e.messageId,sender:e.fromName??"Unknown",subject:e.subject??"(No subject)",snippet:"",date:e.sentDate!=null?wt(e.sentDate*1e3):"",threadId:e.threadId,matchedChunkLabel:Zp(e.matchedChunkType),score:e.score,...e.mailboxIds[0]!=null?{mailboxId:e.mailboxIds[0]}:{}}}function Ml(e,t){const n=new Set(t),r=[];for(const a of[...e].sort((o,i)=>i.score-o.score))n.has(a.threadId)||(n.add(a.threadId),r.push(tx(a)));return r}const sx=768,nx=1024,Tl=e=>e!=="desktop",Cn=()=>{const e=nr(`(min-width: ${sx}px)`);return nr(`(min-width: ${nx}px)`)?"desktop":e?"tablet":"phone"},Al="remit.recentSearches",rx=5;function lr(){try{const e=localStorage.getItem(Al);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(n=>typeof n=="string"):[]}catch{return[]}}function no(e){const t=e.trim();if(!t)return lr();const n=[t,...lr().filter(r=>r!==t)].slice(0,rx);try{localStorage.setItem(Al,JSON.stringify(n))}catch{return n}return n}function Dl({title:e,unreadCount:t,children:n,footer:r,searchFilter:a,searchResults:o,searchLoading:i,relatedResults:l,relatedLoading:u,onSelectSearchResult:d,searchResultsLabel:m="Top matches",relatedResultsLabel:f="Related"}){const{searchInput:h,onSearchChange:x,onSearchClear:b,searchViewKey:p}=ve(),v=ds(),g=os(),y=Cn(),[j,w]=c.useState(!1),[C,k]=c.useState(lr),S=c.useRef(p);c.useEffect(()=>{S.current!==p&&(S.current=p,w(!1))},[p]);const N=h.trim().length>0,R=fs(h,v).tokens.map(F=>({label:Up(F),onRemove:()=>x(qp(h,F))})),A=o??[],E=l??[],M=N?[{id:"top",label:m,results:A},{id:"related",label:f,results:E}]:[],T=!(A.length+E.length>0)&&(i===!0||u===!0);if(y==="phone"&&j){const F=$=>{k(no(h)),w(!1),d?.($)};return s.jsx(jf,{value:h,onChange:x,onClear:b,onCancel:()=>{w(!1),b()},filter:a,recentSearches:C,onPickRecent:x,sections:M,loading:T,onSelectResult:F,tokens:R})}const O=y!=="phone"&&N,_=F=>{k(no(h)),d?.(F)},q=s.jsx(di,{value:h,sections:M,loading:T,onSelectResult:_,tokens:R}),X=O?a?s.jsx(dr,{...a,children:q}):s.jsx("div",{className:"h-full overflow-y-auto",children:q}):n;return s.jsxs("section",{className:"flex h-full w-full flex-col bg-surface",children:[s.jsx(ff,{title:e,unreadCount:t,isDesktop:!1,showSearch:Tl(y),onMenuClick:()=>g?.openNav(),searchValue:h,onSearchChange:x,onSearchClear:b,searchOpen:j,onSearchOpenChange:w}),s.jsx("div",{className:"min-h-0 flex-1",children:X}),r]})}const ax=200,ox={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()},ro=()=>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))}),ix=({accountEmail:e})=>{const t=Me();return s.jsxs("div",{className:"flex items-center gap-2 px-row-inset py-2 border-b border-line bg-danger-soft/40 text-xs text-danger",children:[s.jsx(Rt,{className:"size-3.5 shrink-0"}),s.jsxs("span",{className:"flex-1 truncate",children:[e," can't connect"]}),s.jsx("button",{type:"button",onClick:()=>t({to:"/settings/accounts"}),className:"shrink-0 underline text-danger hover:opacity-80",children:"Reconnect"})]})},lx=({thread:e,active:t,onClick:n})=>{const r=!e.isRead;return s.jsxs("button",{type:"button",onClick:n,className:K("group w-full",ls({active:t})),children:[r&&s.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),s.jsx(He,{name:e.fromName,email:e.fromEmail,size:"sm"}),s.jsx(It,{thread:e})]})};function Ol({accounts:e,selectedMessageId:t,onSelectMessage:n,onSelectSearchResult:r}){const{searchQuery:a}=ve(),o=ds(),i=Ot(),l=c.useMemo(()=>Yp(e.filter(D=>!D.muted?.value)),[e]),[u,d]=c.useState("all"),[m,f]=c.useState("all"),[h,x]=c.useState(new Set),[b,p]=c.useState(!1),v=c.useCallback(D=>{x(P=>{const Q=new Set(P);return Q.has(D)?Q.delete(D):Q.add(D),Q})},[]),{data:g,isLoading:y,isError:j,refetch:w}=ie({...Vn(),staleTime:6e4}),C=Dt({queries:l.map(D=>({...Ze({path:{accountId:D.accountId}}),staleTime:1/0,meta:{softError:!0}}))}),k=c.useMemo(()=>{const D=new Map;for(let P=0;P<l.length;P++){const Q=l[P].accountId,ue=(C[P]?.data?.items??[]).reduce((le,Y)=>le+(Y.unseenCount??0),0);D.set(Q,ue)}return D},[l,C]),S=c.useMemo(()=>l.filter((D,P)=>{const Q=C[P];return Q?.isError?!Yn(Q.error):!1}),[l,C]),{freeText:N,tokens:R}=fs(a.trim().toLowerCase(),o),{data:A,isFetching:E}=ie({...Vn({query:{query:N,limit:ax}}),enabled:N.length>0,staleTime:3e4}),M=c.useMemo(()=>{const D=(g?.items??[]).map(ir);return(N?Gp(D.filter(Q=>El(Q,N)),(A?.items??[]).map(ir)):D).filter(Q=>(u==="all"||Q.accountId===u)&&Il(Q,R))},[g,A,u,N,R]),I=c.useMemo(()=>Xp(M),[M]),T=c.useMemo(()=>l.length<=1?[]:[{id:"all",label:"All",active:u==="all"},...l.map(D=>({id:D.accountId,label:D.email.split("@")[0]??D.email,count:k.get(D.accountId),active:u===D.accountId}))],[l,k,u]),O=c.useMemo(()=>e.filter(D=>D.muted?.value).length,[e]),_=c.useMemo(()=>Array.from(k.values()).reduce((D,P)=>D+P,0),[k]),q=c.useMemo(()=>{const D=Array.from(h).map(P=>ox[P]).filter(P=>P!=null);return M.filter(P=>(m==="all"||P.category===m)&&D.every(Q=>Q(P))).map(Rl)},[M,m,h]),{hits:X,isLoading:F}=Cl(),$=c.useMemo(()=>{const D=new Map;for(const Q of g?.items??[])D.set(Q.messageId,Q.threadId);const P=q.map(Q=>D.get(Q.id)).filter(Q=>Q!=null);return Ml(X,P)},[X,q,g]),ae=c.useMemo(()=>{const D=Hf(T.map(P=>({id:P.id,label:P.label,count:P.count,active:P.active})));return{categories:D.categories,filters:D.filters,sources:D.sources,sourcesNote:O>0?`+${O} muted`:void 0,selectedCategory:m,activeFilters:h,expanded:b,onExpandedChange:p,onSelectCategory:P=>f(P),onSelectSource:d,onToggleFilter:v,onClear:()=>{f("all"),d("all"),x(new Set)}}},[T,O,m,h,b,v]),ce=I.length===0&&u==="all"&&N.length===0,J=y?s.jsxs("div",{className:"h-full overflow-y-auto",children:[s.jsx(ro,{}),s.jsx(ro,{})]}):j?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 py-12 text-sm text-fg-muted",children:[s.jsx(Rt,{className:"size-8 text-danger"}),s.jsx("p",{children:"Couldn't load your messages"}),s.jsxs("button",{type:"button",onClick:()=>w(),className:"flex items-center gap-1 text-accent underline text-xs",children:[s.jsx(Vo,{className:"size-3.5"}),"Try again"]})]}):ce?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 py-12 text-center px-4",children:[s.jsx(Je,{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(xo,{sections:I,Row:lx,briefCategory:m,onSelectBriefCategory:f,sources:T,sourcesNote:O>0?`+${O} muted`:void 0,onSelectSource:d,selectedThreadId:t,onSelectThread:n});return s.jsx(Dl,{title:"Daily brief",unreadCount:_,footer:i?s.jsx(Zo,{}):void 0,searchFilter:ae,searchResults:q,searchLoading:y||E,relatedResults:$,relatedLoading:F,onSelectSearchResult:r,children:s.jsxs("div",{className:"flex h-full flex-col",children:[S.map(D=>s.jsx(ix,{accountEmail:D.email,accountId:D.accountId},D.accountId)),s.jsx("div",{className:"min-h-0 flex-1",children:J})]})})}const Pl=({isOpen:e,title:t,description:n,confirmLabel:r,cancelLabel:a="Cancel",destructive:o=!1,isBusy:i=!1,onConfirm:l,onCancel:u})=>{const d=c.useRef(null),m=c.useCallback(f=>{f.key==="Escape"&&(f.preventDefault(),f.stopPropagation(),f.stopImmediatePropagation(),u())},[u]);return c.useEffect(()=>{if(e)return window.addEventListener("keydown",m,!0),()=>window.removeEventListener("keydown",m,!0)},[e,m]),c.useEffect(()=>{e&&d.current?.focus()},[e]),e?s.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[s.jsx("div",{className:"absolute inset-0 bg-canvas/80 backdrop-blur-sm","aria-hidden":"true",onClick:u}),s.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":t,className:fe("relative z-10 w-full max-w-sm","bg-surface border border-line rounded-sm shadow-lg","p-6"),onClick:f=>f.stopPropagation(),onKeyDown:f=>f.stopPropagation(),children:[s.jsx("h2",{className:"text-lg font-semibold",children:t}),n&&s.jsx("p",{className:"mt-2 text-sm text-fg-muted",children:n}),s.jsxs("div",{className:"mt-6 flex items-center justify-end gap-2",children:[s.jsx("button",{ref:d,type:"button",onClick:u,className:fe("min-h-11 inline-flex items-center justify-center px-4 rounded text-sm font-medium transition-colors","border border-line hover:bg-surface-raised"),children:a}),s.jsx("button",{type:"button",onClick: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:r})]})]})]}):null},cx=10,Ll=e=>({q:e?.toLowerCase()??"",limit:cx}),ux=(e,t)=>{if(!t)return;const n=t.toLowerCase();return e?.find(r=>r.normalizedEmail===n)};function dx(e){const t=new Date(e),n=new Date;return t.toDateString()===n.toDateString()?"today":on(t,{month:"short",year:"numeric"})}function zl(e){if(!e)return!0;const[,t]=e.split("@");return t?!t.includes("."):!0}const fx="We can't verify the sender of this email, which could mean it's from an insecure source.",mx="We couldn't read this sender's address, so we can't confirm who really sent this message.";function hx(e,t){return{name:e.fromName??e.fromEmail??"Unknown",email:e.fromEmail??"",trust:e.senderTrust,firstSeenLabel:t?dx(t.createdAt):"unknown",inboundCount:t?.inboundCount,replyCount:t?.replyCount,addressUnverified:zl(e.fromEmail)}}function gx(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 px(e,t){const n=t>0?t:void 0;if(zl(e.fromEmail))return{verdict:"mismatch",fromDomain:"",addressUnreadable:!0,summary:mx,similarCount:n};const r=e.authenticity;if(!r)return{verdict:"caution",fromDomain:e.fromEmail?.split("@")[1]??"",summary:fx};if(!r.dkimMismatch)return{verdict:"aligned",fromDomain:r.fromDomain,dkimDomain:r.dkimDomain,summary:r.dkimDomain?`We verified this message was really sent by ${r.fromDomain}.`:"Nothing looks unusual about this sender."};const a=r.fromDomain,o=r.dkimDomain,i=e.fromName&&e.fromName!==e.fromEmail?e.fromName:void 0,l=i?`The display name claims "${i}", but this message was actually sent from ${o??"another sender"} — not ${a}. Real senders use their own address.`:`This message claims to be from ${a}, but it was actually sent from ${o??"a different sender"}.`;return{verdict:"mismatch",fromDomain:a,dkimDomain:o,claimedBrand:i,summary:l,similarCount:n}}function Fl(e,t){const n=e?.fromEmail??null,r=e?.subject??"",{data:a,error:o}=ie({...Io({query:Ll(n??void 0)}),enabled:!!n,staleTime:3e4}),i=ux(a?.items,n??void 0),l=[r,n].filter(Boolean).join(" "),{data:u,isLoading:d,error:m}=ie({...Ao({query:{query:l,limit:5}}),enabled:!!(e&&l.length>3),staleTime:6e4,retry:1});return{data:c.useMemo(()=>{if(!e)return null;const h=(u?.items??[]).filter(g=>g.messageId!==e.messageId).map(g=>({id:g.messageId,mailboxId:t!=null&&g.mailboxIds.includes(t)?t:g.mailboxIds[0]??"",fromName:g.fromName??"",subject:g.subject??"(No subject)",timeLabel:g.sentDate!=null?wt(g.sentDate*1e3):"",matched:g.matchedChunkType})),x=hx(e,i),b=px(e,h.length),p={value:e.category??"personal",overridden:i?.flags?.category?.value!=null&&i.flags.category.value!==e.category},v=gx(i);return{sender:x,authenticity:b,category:p,flags:v,similar:h}},[e,i,u,t]),isSimilarLoading:d,similarError:m,similarErrorIsFatal:Yn(m),addressErrorIsFatal:Yn(o),addressId:i?.addressId,address:i}}function xx(e,t){const n={...e??{}};for(const[r,a]of Object.entries(t))a==null?delete n[r]:n[r]={...a,setAt:a.setAt??Date.now()};return n}function _l({addressId:e,senderEmail:t}){const n=je(),{pushError:r}=Qe(),a=tu({query:Ll(t)}),{mutate:o,isPending:i}=pe({...To(),onMutate:async u=>{const d=u.body.flags??{};await n.cancelQueries({queryKey:a});const m=n.getQueryData(a);return n.setQueryData(a,f=>f&&{...f,items:f.items.map(h=>h.addressId===u.path.addressId?{...h,flags:xx(h.flags,d)}:h)}),{previous:m}},onError:(u,d,m)=>{m?.previous!==void 0&&n.setQueryData(a,m.previous),r({title:"Couldn't update sender preference",detail:Xe(u),error:u})},onSettled:()=>{n.invalidateQueries({queryKey:a})}});return{updateFlags:c.useCallback(u=>{if(!e){Do(new Error(`Quick action fired but the sender's address record did not resolve (sender: ${t??"unknown"}). This should never happen — the address row exists.`));return}o({path:{addressId:e},body:{flags:u}})},[e,o,t]),isPending:i}}const bx=e=>e==="vip"?"A sender you know":e==="wellknown"?"You've emailed them before":"Passed authentication",Bl=e=>e.senderTrust!=="vip"&&e.senderTrust!=="wellknown"?!1:e.authenticity?.dkimMismatch!==!0;function vx(e,t){e.recordEvent("rescue.candidates_surfaced",{count:String(t)})}function yx(e,t){e.recordEvent("rescue.flow_opened",{count:String(t)})}function wx(e,t){e.recordEvent("rescue.committed",{selected:String(t.selected),total:String(t.total),destination:t.toInbox?"inbox":"other"})}function $l(e,t){e.recordEvent("rescue.sent_to_junk",{count:String(t.count),senderTrust:t.senderTrust,wasRescuable:String(t.wasRescuable)})}const jx=["personal","newsletter","marketing","automated","transactional","social"],Sx=e=>{const{mailboxId:t,junkMailboxId:n,inboxMailboxId:r}=e;return t?n&&t===n?r?"notSpam":null:n?"markSpam":null:null},Nx=e=>{const{similarError:t,similarErrorIsFatal:n,isSimilarLoading:r}=e;return t&&!n?"error":r?"loading":"ready"};function kx(){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(Je,{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 Cx({isOpen:e,current:t,onSelect:n,onCancel:r}){return e?s.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center","aria-hidden":"true",onClick:r,children:[s.jsx("div",{className:"absolute inset-0 bg-canvas/80 backdrop-blur-sm"}),s.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":"Reclassify sender",className:"relative z-10 w-full max-w-sm rounded-sm border border-line bg-surface p-6 shadow-lg",onClick:a=>a.stopPropagation(),onKeyDown:a=>a.stopPropagation(),children:[s.jsx("h2",{className:"text-lg font-semibold",children:"Reclassify this sender"}),s.jsx("p",{className:"mt-2 text-sm text-fg-muted",children:"Set a category override for future messages from this sender."}),s.jsx("div",{className:"mt-4 flex flex-col gap-1",children:jx.map(a=>s.jsxs("button",{type:"button",onClick:()=>n(a),className:`flex min-h-11 items-center justify-between rounded px-3 text-left text-sm capitalize transition-colors hover:bg-surface-raised ${a===t?"font-semibold text-accent":"text-fg"}`,children:[a,a===t&&s.jsx("span",{className:"text-2xs text-fg-subtle",children:"current"})]},a))}),s.jsx("div",{className:"mt-6 flex justify-end",children:s.jsx("button",{type:"button",onClick:r,className:"inline-flex min-h-11 items-center justify-center rounded border border-line px-4 text-sm font-medium transition-colors hover:bg-surface-raised",children:"Cancel"})})]})]}):null}function Ex({thread:e,onClose:t,mailboxId:n,accountId:r,hideCloseButton:a}){const{data:o,addressId:i,isSimilarLoading:l,similarError:u,similarErrorIsFatal:d}=Fl(e,n),[m,f]=c.useState(!1),[h,x]=c.useState(!1),b=e.fromEmail??void 0,{updateFlags:p,isPending:v}=_l({addressId:i,senderEmail:b}),{junkMailboxId:g}=zr(r),{inboxMailboxId:y}=Lr(r),{moveMessages:j}=gt({mailboxId:n??"",threadId:e.threadId,accountId:r}),w=Ms(),C=Sx({mailboxId:n,junkMailboxId:g,inboxMailboxId:y}),k=c.useCallback(()=>{y&&j([e.messageId],y)},[y,j,e.messageId]),S=c.useCallback(()=>{g&&($l(w,{count:1,senderTrust:e.senderTrust,wasRescuable:Bl(e)}),j([e.messageId],g))},[g,j,e,w]),N=c.useCallback(()=>{},[]),R=c.useCallback(()=>{const F=o?.flags?.vip!==!0;p({vip:{value:F}})},[o?.flags?.vip,p]),A=c.useCallback(()=>{const F=o?.flags?.muted!==!0;p({muted:{value:F}})},[o?.flags?.muted,p]),E=c.useCallback(()=>{o?.flags?.blocked===!0?p({blocked:{value:!1}}):f(!0)},[o?.flags?.blocked,p]),M=c.useCallback(()=>{f(!1),p({blocked:{value:!0}})},[p]),I=c.useCallback(()=>{const F=o?.flags?.unsubscribed!==!0;p({unsubscribed:{value:F}})},[o?.flags?.unsubscribed,p]),T=c.useCallback(F=>{x(!1),p({category:{value:F}})},[p]),O=i!==void 0,_={onToggleVip:O?R:void 0,onToggleMute:O?A:void 0,onToggleBlock:O?E:void 0,onToggleUnsubscribe:O?I:void 0,onReclassify:O?()=>x(!0):void 0,onNotSpam:C==="notSpam"?k:void 0,onMarkSpam:C==="markSpam"?S:void 0},q=({mailboxId:F,messageId:$,className:ae,ariaLabel:ce,children:J})=>s.jsx(rt,{to:"/mail/$mailboxId",params:{mailboxId:F},search:D=>({...D,selectedMessageId:$}),className:ae,"aria-label":ce,children:J});if(!o)return s.jsx(kx,{});const X=Nx({similarError:u,similarErrorIsFatal:d,isSimilarLoading:l});return s.jsxs(s.Fragment,{children:[s.jsx(Jo,{data:o,onClose:t,hideCloseButton:a,onShowSimilar:N,actions:_,similarState:X,similarLinkComponent:q,className:"border-l-0 h-full w-full"}),s.jsx(Pl,{isOpen:m,title:"Block this sender?",description:`Messages from ${b??"this sender"} will never load images and will be flagged. You can undo this in Settings → Senders.`,confirmLabel:"Block sender",destructive:!0,isBusy:v,onConfirm:M,onCancel:()=>f(!1)}),s.jsx(Cx,{isOpen:h,current:o.category.value,onSelect:T,onCancel:()=>x(!1)})]})}const ms=({onClose:e,thread:t,mailboxId:n,accountId:r,hideCloseButton:a})=>t?s.jsx(Ex,{thread:t,onClose:e,mailboxId:n,accountId:r,hideCloseButton:a}):s.jsxs("aside",{className:"flex h-full w-full flex-col bg-surface-sunken",children:[s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-1.5 border-b border-line px-row-inset",children:[s.jsx(Je,{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(Je,{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."})]})]}),Un="Open a message first",Ur=({hasThread:e,intelligenceOpen:t,canToggleIntelligence:n,onToggleIntelligence:r,onReply:a,onReplyAll:o,onForward:i,onDelete:l,canDelete:u,onToggleStar:d,isStarred:m,moveContext:f})=>{const[h,x]=c.useState(null),b=u??e,p=v=>()=>x(v);return s.jsx(fd,{hasThread:e,isStarred:m,onUnavailable:v=>x(Un),unavailableHint:h,replyTitle:`Reply ${Yt("reply")}`,replyAllTitle:`Reply all ${Yt("replyAll")}`,forwardTitle:`Forward ${Yt("forward")}`,deleteTitle:`Move to Trash ${Yt("delete")}`,flagTitle:`Star ${Yt("toggleStar")}`,onReply:a,onReplyAll:o,onForward:i,onDelete:b?l:p(Un),onToggleStar:d,onMove:p(Un),moveSlot:f?s.jsx(Fs,{accountId:f.accountId,currentMailboxId:f.currentMailboxId,onMove:f.onMove,label:"Move to mailbox"}):void 0,children:s.jsx(dd,{open:t,enabled:n,onToggle:r})})};function Ix(e){return{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,messageId:e.messageId,authenticity:e.authenticity}}function Kl(e,t){if(e)return Ix(e);if(t.messageId&&t.threadId&&t.mailboxId)return{threadId:t.threadId,mailboxId:t.mailboxId,messageId:t.messageId}}const ql=c.createContext(null);function En(){const e=c.useContext(ql);if(!e)throw new Error("BriefPane.* must be used inside <BriefPane>");return e}function Rx({selectedMessageId:e,children:t}){const n=Me(),{searchInput:r}=ve(),{selectedThreadId:a,selectedMailboxId:o}=Zt({strict:!1}),{data:i}=ie({...Vn(),staleTime:6e4}),l=c.useMemo(()=>{if(e)return i?.items.find(x=>x.messageId===e)},[i,e]),u=c.useMemo(()=>Kl(l,{messageId:e,threadId:a,mailboxId:o}),[l,e,a,o]),d=c.useCallback(x=>{n({to:"/mail",search:b=>({...b,selectedMessageId:x,selectedThreadId:void 0,selectedMailboxId:void 0})})},[n]),m=c.useCallback(x=>{n({to:"/mail",search:b=>({...b,q:r||void 0,selectedMessageId:x.id,selectedThreadId:x.threadId,selectedMailboxId:x.mailboxId})})},[n,r]),f=c.useCallback(()=>{n({to:"/mail",search:x=>({...x,selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0})})},[n]),h={selectedMessageId:e,selectedThread:l,conversation:u,onSelectMessage:d,onSelectSearchResult:m,onCloseThread:f};return s.jsx(ql.Provider,{value:h,children:t})}function Mx(){const{selectedMessageId:e,onSelectMessage:t,onSelectSearchResult:n}=En(),{accounts:r}=ve();return s.jsx(Ol,{accounts:r,selectedMessageId:e,onSelectMessage:t,onSelectSearchResult:n})}function Tx(){const{conversation:e}=En(),{intelligenceOpen:t,onToggleIntelligence:n}=ve(),r=os()?.showIntelligencePane??!1,a=!!e,o=r&&a;return s.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[s.jsx(Ur,{hasThread:a,intelligenceOpen:o&&t,canToggleIntelligence:o,onToggleIntelligence:n}),s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?s.jsx(us,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,selectedMessageId:e.messageId,authenticity:e.authenticity}):s.jsx(cs,{})})]})}function Ax(){const{selectedThread:e}=En(),{onToggleIntelligence:t}=ve();return s.jsx(ms,{onClose:t,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId})}function Dx(){const{selectedThread:e,conversation:t,selectedMessageId:n,onSelectMessage:r,onSelectSearchResult:a,onCloseThread:o}=En(),{accounts:i,intelligenceOpen:l,onToggleIntelligence:u}=ve();return t?s.jsxs(s.Fragment,{children:[s.jsx(us,{threadId:t.threadId,mailboxId:t.mailboxId,subject:t.subject,selectedMessageId:t.messageId,authenticity:t.authenticity,onBack:o,onOpenIntelligence:u}),s.jsx(Dr,{isOpen:l,onClose:u,ariaLabel:"Message details",side:"right",children:s.jsx(ms,{onClose:u,thread:e,hideCloseButton:!0})})]}):s.jsx("div",{className:"h-full",children:s.jsx(Ol,{accounts:i,selectedMessageId:n,onSelectMessage:r,onSelectSearchResult:a})})}const ys=Object.assign(Rx,{List:Mx,Reading:Tx,Intelligence:Ax,Phone:Dx}),Ox=()=>Mo({query:{starred:!0,order:"desc"}});function Ul(){const{data:e,isLoading:t,isError:n,error:r,refetch:a,fetchNextPage:o,hasNextPage:i,isFetchingNextPage:l}=Ii({queryKey:Ox(),queryFn:async({pageParam:d})=>{const{data:m}=await su({query:{starred:!0,order:"desc",continuationToken:d},throwOnError:!0});return m},initialPageParam:void 0,getNextPageParam:d=>d.continuationToken,staleTime:6e4});return{threads:c.useMemo(()=>(e?.pages??[]).flatMap(d=>d.items??[]),[e]),isLoading:t,isError:n,error:r,refetch:a,fetchNextPage:o,hasNextPage:i,isFetchingNextPage:l}}const Px=e=>{const t=new Set;return e.filter(n=>t.has(n.threadId)?!1:(t.add(n.threadId),!0))};function Ql({title:e,unreadCount:t,preset:n,selectedCategory:r,activeFilters:a,onSelectCategory:o,onToggleFilter:i,onSelectSource:l,onClearFilters:u,children:d,footer:m,searchResults:f,searchLoading:h,relatedResults:x,relatedLoading:b,onSelectSearchResult:p,searchResultsLabel:v,relatedResultsLabel:g}){const[y,j]=c.useState(!1),w={categories:n.categories,filters:n.filters,sources:n.sources,selectedCategory:r,activeFilters:a,expanded:y,onExpandedChange:j,onSelectCategory:o,onSelectSource:l,onToggleFilter:i,onClear:u};return s.jsx(Dl,{title:e,unreadCount:t,footer:m,searchFilter:w,searchResults:f,searchLoading:h,relatedResults:x,relatedLoading:b,onSelectSearchResult:p,searchResultsLabel:v,relatedResultsLabel:g,children:s.jsx(dr,{...w,children:d})})}const Lx={unread:e=>!e.isRead,attachment:e=>e.hasAttachment===!0};function zx({selectedMessageId:e,onSelectMessage:t}){const{searchQuery:n}=ve(),r=ds(),a=Ot(),[o,i]=c.useState("all"),[l,u]=c.useState(new Set),d=c.useCallback(M=>{u(I=>{const T=new Set(I);return T.has(M)?T.delete(M):T.add(M),T})},[]),m=c.useCallback(()=>{i("all"),u(new Set)},[]),{threads:f,isLoading:h,isError:x,error:b,refetch:p,fetchNextPage:v,hasNextPage:g,isFetchingNextPage:y}=Ul(),{freeText:j,tokens:w}=fs(n.trim().toLowerCase(),r),C=c.useMemo(()=>{const M=Array.from(l).map(I=>Lx[I]).filter(I=>I!=null);return Px(f).map(ir).filter(I=>(o==="all"||I.category===o)&&M.every(T=>T(I))&&(!j||El(I,j))&&Il(I,w))},[f,o,l,j,w]),k=c.useMemo(()=>Vf(),[]),S=c.useMemo(()=>C.map(Rl),[C]),N=c.useMemo(()=>C.filter(M=>!M.isRead).length,[C]),R=h?"loading":x?"error":C.length===0?"empty":"ready",A=c.useCallback(()=>{const M=br(xr());window.open(M,"_blank","noopener,noreferrer")},[]),E=s.jsxs("div",{className:"flex-1 overflow-y-auto",children:[s.jsx("div",{className:"divide-y divide-line",children:C.map(M=>s.jsx(si,{thread:M,active:M.id===e,onClick:()=>t?.(M.id)},M.id))}),g?s.jsx("button",{type:"button",className:"w-full py-3 text-sm text-muted hover:text-fg disabled:opacity-50",onClick:()=>v(),disabled:y,children:y?"Loading…":"Load more"}):null]});return s.jsx(Ql,{title:"Starred",unreadCount:N,preset:k,selectedCategory:o,activeFilters:l,onSelectCategory:i,onToggleFilter:d,onClearFilters:m,searchResults:S,searchLoading:h,onSelectSearchResult:M=>t?.(M.id),children:s.jsx(ai,{listTitle:"Starred",sections:[{id:"flagged",threads:C}],flatList:!0,hideHeader:!0,listState:R,searchQuery:j?n:void 0,errorMessage:x?zo(b):void 0,onRetry:()=>p(),onReportError:A,selectedThreadId:e,onSelectThread:t,onSelectBriefCategory:()=>{},isDesktop:a,listBody:R==="ready"?E:void 0})})}const Hl=c.createContext(null);function In(){const e=c.useContext(Hl);if(!e)throw new Error("FlaggedPane.* must be used inside <FlaggedPane>");return e}function Fx({selectedMessageId:e,children:t}){const n=Me(),{threads:r}=Ul(),a=c.useMemo(()=>{if(e)return r.find(u=>u.messageId===e)},[r,e]),o=c.useCallback(u=>{n({to:"/mail/flagged",search:d=>({...d,selectedMessageId:u})})},[n]),i=c.useCallback(()=>{n({to:"/mail/flagged",search:u=>({...u,selectedMessageId:void 0})})},[n]),l={selectedMessageId:e,selectedThread:a,onSelectMessage:o,onCloseThread:i};return s.jsx(Hl.Provider,{value:l,children:t})}function Wl(){const{selectedMessageId:e,onSelectMessage:t}=In();return s.jsx(zx,{selectedMessageId:e,onSelectMessage:t})}function _x(){const{selectedThread:e}=In(),{intelligenceOpen:t,onToggleIntelligence:n}=ve(),r=os()?.showIntelligencePane??!1,a=!!e,o=r&&a;return s.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[s.jsx(Ur,{hasThread:a,intelligenceOpen:o&&t,canToggleIntelligence:o,onToggleIntelligence:n}),s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?s.jsx(us,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,authenticity:e.authenticity}):s.jsx(cs,{})})]})}function Bx(){const{selectedThread:e}=In(),{onToggleIntelligence:t}=ve();return s.jsx(ms,{onClose:t,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId})}function $x(){const{selectedThread:e,onCloseThread:t}=In(),{intelligenceOpen:n,onToggleIntelligence:r}=ve();return e?s.jsxs(s.Fragment,{children:[s.jsx(us,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,authenticity:e.authenticity,onBack:t,onOpenIntelligence:r}),s.jsx(Dr,{isOpen:n,onClose:r,ariaLabel:"Message details",side:"right",children:s.jsx(ms,{onClose:r,thread:e,hideCloseButton:!0})})]}):s.jsx("div",{className:"h-full",children:s.jsx(Wl,{})})}const ws=Object.assign(Fx,{List:Wl,Reading:_x,Intelligence:Bx,Phone:$x}),Kx={reply:"Reply",reply_all:"Reply All",forward:"Forward",new:"New Message"},qx=()=>{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},[])},Ux=()=>{const{state:e,closeCompose:t}=xt(),n=qx(),[r,a]=c.useState(!1),{isError:o,error:i,refetch:l}=ie({...at(),staleTime:1/0}),u=c.useCallback(h=>{h||(n()?a(!0):t())},[t,n]),d=c.useCallback(()=>{a(!1),t()},[t]),m=c.useCallback(()=>{a(!1)},[]);if(!e.isOpen)return null;const f=Kx[e.mode]??"New Message";return s.jsxs($e.Root,{open:e.isOpen,onOpenChange:u,children:[s.jsxs($e.Portal,{children:[s.jsx($e.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),s.jsxs($e.Content,{className:"fixed inset-x-0 bottom-0 z-50 flex flex-col bg-canvas rounded-t-lg",style:{height:"95dvh"},children:[s.jsx($e.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-muted/30"}),s.jsx($e.Title,{className:"px-4 py-2 text-base font-semibold border-b border-line",children:f}),o?s.jsx("div",{className:"flex-1 flex items-center justify-center p-4",children:s.jsx(yt,{title:"Couldn't load compose",error:i,onRetry:()=>{l()}})}):s.jsx("div",{className:"flex-1 overflow-hidden",children:s.jsx(Or,{mode:e.mode,account:e.account,sourceMessage:e.sourceMessage,onClose:t})})]})]}),r&&s.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center bg-black/50",children:s.jsxs("div",{className:"mx-4 w-full max-w-sm rounded-xl bg-canvas p-6 shadow-xl",children:[s.jsx("h3",{className:"text-lg font-semibold",children:"Discard draft?"}),s.jsx("p",{className:"mt-2 text-sm text-fg-muted",children:"Your message has unsaved content. Are you sure you want to discard it?"}),s.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[s.jsx("button",{type:"button",onClick:m,className:"rounded-md px-4 py-2 text-sm font-medium hover:bg-surface-raised transition-colors",children:"Keep editing"}),s.jsx("button",{type:"button",onClick:d,className:"rounded-md bg-danger px-4 py-2 text-sm font-medium text-canvas hover:bg-danger/90 transition-colors",children:"Discard"})]})]})})]})},Qx={reply:"Reply",reply_all:"Reply All",forward:"Forward",new:"New Message"},Vl=()=>{const{state:e,closeCompose:t}=xt(),n=Ot(),{isError:r,error:a,refetch:o}=ie({...at(),staleTime:1/0});if(!n)return s.jsx(Ux,{});if(!e.isOpen)return null;const i=Qx[e.mode]??"New Message",l=s.jsxs("header",{className:"flex items-center justify-between gap-2 px-4 py-3 border-b border-line shrink-0",children:[s.jsx("div",{className:"flex items-center gap-2 min-w-0",children:s.jsx("h2",{className:"text-lg font-semibold truncate",children:i})}),s.jsx("button",{type:"button",onClick:t,className:"p-2 rounded-md hover:bg-surface-raised transition-colors min-h-11 min-w-11 inline-flex items-center justify-center","aria-label":"Close",children:s.jsx(Ke,{className:"size-5"})})]});return r?s.jsxs("div",{className:"h-full flex flex-col bg-canvas",children:[l,s.jsx("div",{className:"flex-1 flex items-center justify-center p-4",children:s.jsx(yt,{title:"Couldn't load compose",error:a,onRetry:()=>{o()}})})]}):s.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-canvas",children:[l,s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:s.jsx(Or,{mode:e.mode,account:e.account,sourceMessage:e.sourceMessage,onClose:t},e.outboxMessageId??"new")})]})};function Hx(e){const t=e.toAddresses.join(", ");return{id:e.outboxMessageId,accountId:e.accountId,fromName:e.fromName??e.fromAddress??"Me",fromEmail:e.fromAddress??"",subject:e.subject??"(No subject)",snippet:t?`To: ${t}`:"(No recipients)",timeLabel:wt(e.updatedAt),isRead:!0}}function Wx(e){return{id:e.messageId,accountId:e.accountConfigId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:wt(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0}}function Vx({outboxMessages:e,accountId:t,imapThreads:n}){const r=e.filter(i=>i.status==="draft"&&i.accountId===t).map(Hx),a=n.map(Wx),o=[];return r.length>0&&o.push({id:"remit-drafts",label:"Not yet sent (Remit)",threads:r}),a.length>0&&o.push({id:"imap-drafts",label:"On the server",threads:a}),o}function Qr(){const e=os();return!e||e.showNavPane?null:s.jsx(V,{variant:"ghost",size:"sm",icon:s.jsx(jr,{className:"size-4"}),onClick:e.openNav,"aria-label":"Open folders",className:"-ml-1 shrink-0"})}const Yx=({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})]}),Gx=({row:e,isSelected:t,onOpen:n,onDelete:r,isDeleting:a})=>s.jsxs("button",{type:"button",onClick:()=>n(e.id),className:K("group",ls({active:t})),children:[s.jsx(Lo,{className:"size-7 shrink-0 text-fg-muted mt-0.5"}),s.jsx(It,{thread:e}),s.jsx("div",{className:"flex items-center gap-1 shrink-0",children:s.jsx("button",{type:"button",onClick:o=>{o.stopPropagation(),r(e.id)},disabled:a,className:"p-1.5 rounded-md text-fg-muted hover:text-danger hover:bg-surface-raised transition-colors opacity-0 group-hover:opacity-100 focus:opacity-100",title:"Delete draft",children:s.jsx(et,{className:"size-3.5"})})})]}),Xx=({row:e,isSelected:t,onOpen:n})=>{const r=!e.isRead;return s.jsxs("button",{type:"button",onClick:()=>n(e.id),className:K("group",ls({active:t})),children:[r&&s.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),s.jsx(He,{name:e.fromName,email:e.fromEmail,size:"sm"}),s.jsx(It,{thread:e})]})};function Jx({mailboxId:e,accountId:t,selectedMessageId:n,imapThreads:r,title:a,unreadCount:o}){const{openCompose:i,state:l}=xt(),u=Me(),d=je(),{data:m}=ie(mn()),f=c.useMemo(()=>Vx({outboxMessages:m?.items??[],accountId:t,imapThreads:r}),[m?.items,t,r]),h=pe({...hn(),onSuccess:()=>{d.invalidateQueries({queryKey:wr()})}}),x=g=>{h.mutate({path:{outboxMessageId:g}})},b=g=>{n&&u({to:"/mail/$mailboxId",params:{mailboxId:e},search:{selectedMessageId:void 0}}),i({mode:"new",outboxMessageId:g})},p=g=>{u({to:"/mail/$mailboxId",params:{mailboxId:e},search:{selectedMessageId:g}})},v=f.length===0;return s.jsxs("section",{className:"flex h-full w-full flex-col bg-surface",children:[s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[s.jsx(Qr,{}),s.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:a}),(o??0)>0&&s.jsxs("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:[o," unread"]})]}),s.jsx("div",{className:"flex-1 overflow-y-auto",children:v?s.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-2 text-center px-4",children:[s.jsx(ur,{className:"size-8 text-fg-subtle"}),s.jsx("p",{className:"text-sm font-medium text-fg",children:"No drafts"}),s.jsx("p",{className:"text-xs text-fg-subtle",children:"Messages you start composing will appear here."})]}):f.map(g=>s.jsxs("div",{children:[g.label&&s.jsx(Yx,{label:g.label,count:g.threads.length}),s.jsx("div",{className:"divide-y divide-line",children:g.threads.map(y=>g.id==="remit-drafts"?s.jsx(Gx,{row:y,isSelected:l.isOpen&&y.id===l.outboxMessageId,onOpen:b,onDelete:x,isDeleting:h.isPending},y.id):s.jsx(Xx,{row:y,isSelected:y.id===n,onOpen:p},y.id))})]},g.id))})]})}function Zx(e,t,n){const r=new Array(e);return new Proxy(r,{get(a,o,i){if(typeof o=="string"){const l=o.charCodeAt(0);if(l>=48&&l<=57){const u=+o;if(Number.isInteger(u)&&u>=0&&u<e){let d=a[u];if(!d){const m=t[u*2];d=a[u]={index:u,key:n(u),start:m,size:t[u*2+1],end:m+t[u*2+1],lane:0}}return d}}if(o==="length")return e}return Reflect.get(a,o,i)}})}function Vt(e,t,n){let r=n.initialDeps??[],a,o=!0;function i(){const l=e();return(l.length!==r.length||l.some((d,m)=>r[m]!==d))&&(r=l,a=t(...l),n?.onChange&&!(o&&n.skipInitialOnChange)&&n.onChange(a),o=!1),a}return i.updateDeps=l=>{r=l},i}function ao(e,t){if(e===void 0)throw new Error("Unexpected undefined");return e}const eb=(e,t)=>Math.abs(e-t)<1.01,tb=(e,t,n)=>{let r;return function(...a){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,a),n)}};let js;const Qn=()=>{if(js!==void 0)return js;if(typeof navigator>"u")return js=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return js=!0;const e=navigator.maxTouchPoints;return js=navigator.platform==="MacIntel"&&e!==void 0&&e>0},oo=e=>{const{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},sb=e=>e,nb=e=>{const t=Math.max(e.startIndex-e.overscan,0),r=Math.min(e.endIndex+e.overscan,e.count-1)-t+1,a=new Array(r);for(let o=0;o<r;o++)a[o]=t+o;return a},rb=(e,t)=>{const n=e.scrollElement;if(!n)return;const r=e.targetWindow;if(!r)return;const a=i=>{const{width:l,height:u}=i;t({width:Math.round(l),height:Math.round(u)})};if(a(oo(n)),!r.ResizeObserver)return()=>{};const o=new r.ResizeObserver(i=>{const l=()=>{const u=i[0];if(u?.borderBoxSize){const d=u.borderBoxSize[0];if(d){a({width:d.inlineSize,height:d.blockSize});return}}a(oo(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(l):l()});return o.observe(n,{box:"border-box"}),()=>{o.unobserve(n)}},cn={passive:!0},ab=typeof window>"u"?!0:"onscrollend"in window,ob=(e,t,n)=>{const r=e.scrollElement;if(!r)return;const a=e.targetWindow;if(!a)return;const o=e.options.useScrollendEvent&&ab;let i=0;const l=o?null:tb(a,()=>t(i,!1),e.options.isScrollingResetDelay),u=f=>()=>{i=n(r),l?.(),t(i,f)},d=u(!0),m=u(!1);return r.addEventListener("scroll",d,cn),o&&r.addEventListener("scrollend",m,cn),()=>{r.removeEventListener("scroll",d),o&&r.removeEventListener("scrollend",m)}},ib=(e,t)=>ob(e,t,n=>{const{horizontal:r,isRtl:a}=e.options;return r?n.scrollLeft*(a&&-1||1):n.scrollTop}),lb=(e,t,n)=>{if(n.options.useCachedMeasurements){const r=n.indexFromElement(e),a=n.options.getItemKey(r);return n.itemSizeCache.get(a)??n.options.estimateSize(r)}if(t?.borderBoxSize){const r=t.borderBoxSize[0];if(r)return Math.round(r[n.options.horizontal?"inlineSize":"blockSize"])}if(!t){const r=n.indexFromElement(e),a=n.options.getItemKey(r),o=n.itemSizeCache.get(a);if(o!==void 0)return o}return e[n.options.horizontal?"offsetWidth":"offsetHeight"]},cb=(e,{adjustments:t=0,behavior:n},r)=>{var a,o;(o=(a=r.scrollElement)==null?void 0:a.scrollTo)==null||o.call(a,{[r.options.horizontal?"left":"top"]:e+t,behavior:n})},ub=cb;class db{constructor(t){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this._flatMeasurements=null,this.itemSizeCache=new Map,this.itemSizeCacheVersion=0,this.laneAssignments=new Map,this.pendingMin=null,this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.pendingScrollAnchor=null,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._intendedScrollOffset=null,this.elementsCache=new Map,this.now=()=>{var n,r,a;return((a=(r=(n=this.targetWindow)==null?void 0:n.performance)==null?void 0:r.now)==null?void 0:a.call(r))??Date.now()},this.observer=(()=>{let n=null;const r=()=>n||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:n=new this.targetWindow.ResizeObserver(a=>{a.forEach(o=>{const i=()=>{const l=o.target,u=this.indexFromElement(l);if(!l.isConnected){this.observer.unobserve(l);for(const[d,m]of this.elementsCache)if(m===l){this.elementsCache.delete(d);break}return}this.shouldMeasureDuringScroll(u)&&this.resizeItem(u,this.options.measureElement(l,o,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(i):i()})}));return{disconnect:()=>{var a;(a=r())==null||a.disconnect(),n=null},observe:a=>{var o;return(o=r())==null?void 0:o.observe(a,{box:"border-box"})},unobserve:a=>{var o;return(o=r())==null?void 0:o.unobserve(a)}}})(),this.range=null,this.setOptions=n=>{var r,a;const o={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:sb,rangeExtractor:nb,onChange:()=>{},measureElement:lb,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,anchorTo:"start",followOnAppend:!1,scrollEndThreshold:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:"estimate",useCachedMeasurements:!1};for(const h in n){const x=n[h];x!==void 0&&(o[h]=x)}const i=this.options;let l=null,u=null,d=!1;if(i!==void 0&&i.enabled&&o.enabled&&o.anchorTo==="end"&&this.scrollElement!==null){const h=i.count,x=o.count,b=this.getMeasurements(),p=h>0?((r=b[0])==null?void 0:r.key)??i.getItemKey(0):null,v=h>0?((a=b[h-1])==null?void 0:a.key)??i.getItemKey(h-1):null;if(x!==h||h>0&&x>0&&(o.getItemKey(0)!==p||o.getItemKey(x-1)!==v)){d=!0;const j=h>0?this.getVirtualItemForOffset(this.getScrollOffset())??b[0]:null;j&&(l=[j.key,this.getScrollOffset()-j.start]);const w=o.followOnAppend===!0?"auto":o.followOnAppend||null;w&&x>h&&this.isAtEnd(i.scrollEndThreshold)&&(h===0||o.getItemKey(x-1)!==v)&&(u=w)}}this.options=o,d&&(this.pendingMin=0,this.itemSizeCacheVersion++);let m=!1,f=0;if(l&&this.scrollOffset!==null){const[h,x]=l,b=this.getMeasurements(),{count:p,getItemKey:v}=this.options;let g=0;for(;g<p&&v(g)!==h;)g++;if(g<p){const y=b[g];if(y){const j=y.start+x;j!==this.scrollOffset&&(f=j-this.scrollOffset,this.scrollOffset=j,m=!0)}}}(m||u)&&(this.pendingScrollAnchor=[m?l[0]:null,m?l[1]:0,u,f])},this.notify=n=>{var r,a;(a=(r=this.options).onChange)==null||a.call(r,this,n)},this.maybeNotify=Vt(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),n=>{this.notify(n)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(n=>n()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var n;const r=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==r){if(this.cleanup(),!r){this.maybeNotify();return}if(this.scrollElement=r,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((n=this.scrollElement)==null?void 0:n.window)??null,this.elementsCache.forEach(o=>{this.observer.observe(o)}),this.unsubs.push(this.options.observeElementRect(this,o=>{this.scrollRect=o,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(o,i)=>{if(i&&this._intendedScrollOffset===null&&o===this.scrollOffset)return;this._intendedScrollOffset!==null&&Math.abs(o-this._intendedScrollOffset)<1.5&&(o=this._intendedScrollOffset),this._intendedScrollOffset=null,this.scrollAdjustments=0;const l=this.getScrollOffset();this.scrollDirection=i?l===o?this.scrollDirection:l<o?"forward":"backward":null,this.scrollOffset=o,this.isScrolling=i,this._flushIosDeferredIfReady(),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),"addEventListener"in this.scrollElement){const o=this.scrollElement,i=()=>{this._iosTouching=!0,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)},l=()=>{this._iosTouching=!1,!(!Qn()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};o.addEventListener("touchstart",i,cn),o.addEventListener("touchend",l,cn),this.unsubs.push(()=>{o.removeEventListener("touchstart",i),o.removeEventListener("touchend",l),this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)})}this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}const a=this.pendingScrollAnchor;if(this.pendingScrollAnchor=null,a&&this.scrollElement&&this.options.enabled){const[o,i,l,u]=a;o!==null&&!l&&(Qn()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?u!==0&&(this._iosDeferredAdjustment+=u):this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})),l&&this.scrollToEnd({behavior:l})}},this._flushIosDeferredIfReady=()=>{if(this._iosDeferredAdjustment===0||this.isScrolling||this._iosTouching||this._iosJustTouchEnded)return;const n=this.getScrollOffset(),r=this.getMaxScrollOffset();if(n<0||n>r)return;const a=this._iosDeferredAdjustment;this._iosDeferredAdjustment=0,this._scrollToOffset(n,{adjustments:this.scrollAdjustments+=a,behavior:void 0})},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset=="function"?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getMeasurementOptions=Vt(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode,this.options.gap],(n,r,a,o,i,l,u,d)=>(this.prevLanes!==void 0&&this.prevLanes!==l&&(this.lanesChangedFlag=!0),this.prevLanes=l,this.pendingMin=null,{count:n,paddingStart:r,scrollMargin:a,getItemKey:o,enabled:i,lanes:l,laneAssignmentMode:u,gap:d}),{key:!1}),this.getMeasurements=Vt(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:n,paddingStart:r,scrollMargin:a,getItemKey:o,enabled:i,lanes:l,laneAssignmentMode:u,gap:d},m)=>{const f=this.itemSizeCache;if(!i)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>n)for(const g of this.laneAssignments.keys())g>=n&&this.laneAssignments.delete(g);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMin=null),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(g=>{this.itemSizeCache.set(g.key,g.size)}));const h=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===n&&(this.lanesSettling=!1),l===1){const g=n*2;let y=this._flatMeasurements;if(!y||y.length<g){const C=new Float64Array(g);y&&h>0&&C.set(y.subarray(0,h*2)),y=C,this._flatMeasurements=y}let j;if(h===0)j=r+a;else{const C=h-1;j=y[C*2]+y[C*2+1]+d}for(let C=h;C<n;C++){const k=o(C),S=f.get(k),N=typeof S=="number"?S:this.options.estimateSize(C);y[C*2]=j,y[C*2+1]=N,j+=N+d}const w=Zx(n,y,o);return this.measurementsCache=w,w}const x=this.measurementsCache.slice(0,h),b=new Array(l).fill(void 0),p=new Float64Array(l);let v=0;for(let g=0;g<h;g++){const y=x[g];y&&(b[y.lane]===void 0&&v++,b[y.lane]=g,p[y.lane]=y.end)}for(let g=h;g<n;g++){const y=o(g),j=this.laneAssignments.get(g);let w,C;const k=u==="estimate"||f.has(y);if(j!==void 0&&this.options.lanes>1){w=j;const A=b[w],E=A!==void 0?x[A]:void 0;C=E?E.end+d:r+a}else if(v===l){let A=0,E=p[0],M=b[0];for(let I=1;I<l;I++){const T=p[I];(T<E||T===E&&b[I]<M)&&(A=I,E=T,M=b[I])}w=A,C=E+d,k&&this.laneAssignments.set(g,w)}else w=g%this.options.lanes,C=r+a,k&&this.laneAssignments.set(g,w);const S=f.get(y),N=typeof S=="number"?S:this.options.estimateSize(g),R=C+N;x[g]={index:g,start:C,size:N,end:R,key:y,lane:w},b[w]===void 0&&v++,b[w]=g,p[w]=R}return this.measurementsCache=x,x},{key:!1,debug:()=>this.options.debug}),this.calculateRange=Vt(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(n,r,a,o)=>n.length===0||r===0?(this.range=null,null):(this.range=mb(n,r,a,o,o===1&&this._flatMeasurements!=null?this._flatMeasurements:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=Vt(()=>{let n=null,r=null;const a=this.calculateRange();return a&&(n=a.startIndex,r=a.endIndex),this.maybeNotify.updateDeps([this.isScrolling,n,r]),[this.options.rangeExtractor,this.options.overscan,this.options.count,n,r]},(n,r,a,o,i)=>o===null||i===null?[]:n({startIndex:o,endIndex:i,overscan:r,count:a}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=n=>{const r=this.options.indexAttribute,a=n.getAttribute(r);return a?parseInt(a,10):(console.warn(`Missing attribute name '${r}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=n=>{var r;if(!this.scrollState||this.scrollState.behavior!=="smooth")return!0;const a=this.scrollState.index??((r=this.getVirtualItemForOffset(this.scrollState.lastTargetOffset))==null?void 0:r.index);if(a!==void 0&&this.range){const o=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),i=Math.max(0,a-o),l=Math.min(this.options.count-1,a+o);return n>=i&&n<=l}return!0},this.measureElement=n=>{if(!n){this.elementsCache.forEach((i,l)=>{i.isConnected||(this.observer.unobserve(i),this.elementsCache.delete(l))});return}const r=this.indexFromElement(n),a=this.options.getItemKey(r),o=this.elementsCache.get(a);o!==n&&(o&&this.observer.unobserve(o),this.observer.observe(n),this.elementsCache.set(a,n)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(r)&&this.resizeItem(r,this.options.measureElement(n,void 0,this))},this.resizeItem=(n,r)=>{var a,o;if(n<0||n>=this.options.count)return;let i,l,u;const d=this._flatMeasurements;if(this.options.lanes===1&&d!==null)u=this.options.getItemKey(n),l=d[n*2],i=d[n*2+1];else{const h=this.measurementsCache[n];if(!h)return;u=h.key,l=h.start,i=h.size}const m=this.itemSizeCache.get(u)??i,f=r-m;if(f!==0){const h=this.options.anchorTo==="end"&&((a=this.scrollState)==null?void 0:a.behavior)!=="smooth"&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,x=h?this.getTotalSize():0,b=((o=this.scrollState)==null?void 0:o.behavior)!=="smooth"&&(this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[n]??{index:n,key:u,start:l,size:i,end:l+i,lane:0},f,this):l<this.getScrollOffset()+this.scrollAdjustments&&(!this.itemSizeCache.has(u)||this.scrollDirection!=="backward"));(this.pendingMin===null||n<this.pendingMin)&&(this.pendingMin=n),this.itemSizeCache.set(u,r),this.itemSizeCacheVersion++,h?this.applyScrollAdjustment(this.getTotalSize()-x):b&&this.applyScrollAdjustment(f),this.notify(!1)}},this.getVirtualItems=Vt(()=>[this.getVirtualIndexes(),this.getMeasurements()],(n,r)=>{const a=[];for(let o=0,i=n.length;o<i;o++){const l=n[o],u=r[l];a.push(u)}return a},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=n=>{const r=this.getMeasurements();if(r.length===0)return;const a=this._flatMeasurements,o=this.options.lanes===1&&a!=null,i=Yl(0,r.length-1,o?l=>a[l*2]:l=>ao(r[l]).start,n);return ao(r[i])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if("scrollHeight"in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{const n=this.scrollElement.document.documentElement;return this.options.horizontal?n.scrollWidth-this.scrollElement.innerWidth:n.scrollHeight-this.scrollElement.innerHeight}},this.getVirtualDistanceFromEnd=()=>Math.max(this.getTotalSize()-this.getSize()-this.getScrollOffset(),0),this.getDistanceFromEnd=()=>Math.max(this.getMaxScrollOffset()-this.getScrollOffset(),0),this.isAtEnd=(n=this.options.scrollEndThreshold)=>this.getDistanceFromEnd()<=n,this.getOffsetForAlignment=(n,r,a=0)=>{if(!this.scrollElement)return 0;const o=this.getSize(),i=this.getScrollOffset();r==="auto"&&(r=n>=i+o?"end":"start"),r==="center"?n+=(a-o)/2:r==="end"&&(n-=o);const l=this.getMaxScrollOffset();return Math.max(Math.min(l,n),0)},this.getOffsetForIndex=(n,r="auto")=>{n=Math.max(0,Math.min(n,this.options.count-1));const a=this.getSize(),o=this.getScrollOffset(),i=this.measurementsCache[n];if(!i)return;if(r==="auto")if(i.end>=o+a-this.options.scrollPaddingEnd)r="end";else if(i.start<=o+this.options.scrollPaddingStart)r="start";else return[o,r];if(r==="end"&&n===this.options.count-1)return[this.getMaxScrollOffset(),r];const l=r==="end"?i.end+this.options.scrollPaddingEnd:i.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(l,r,i.size),r]},this.scrollToOffset=(n,{align:r="start",behavior:a="auto"}={})=>{const o=this.getOffsetForAlignment(n,r),i=this.now();this.scrollState={index:null,align:r,behavior:a,startedAt:i,lastTargetOffset:o,stableFrames:0},this._scrollToOffset(o,{adjustments:void 0,behavior:a}),this.scheduleScrollReconcile()},this.scrollToIndex=(n,{align:r="auto",behavior:a="auto"}={})=>{n=Math.max(0,Math.min(n,this.options.count-1));const o=this.getOffsetForIndex(n,r);if(!o)return;const[i,l]=o,u=this.now();this.scrollState={index:n,align:l,behavior:a,startedAt:u,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:a}),this.scheduleScrollReconcile()},this.scrollBy=(n,{behavior:r="auto"}={})=>{const a=this.getScrollOffset()+n,o=this.now();this.scrollState={index:null,align:"start",behavior:r,startedAt:o,lastTargetOffset:a,stableFrames:0},this._scrollToOffset(a,{adjustments:void 0,behavior:r}),this.scheduleScrollReconcile()},this.scrollToEnd=({behavior:n="auto"}={})=>{if(this.options.count>0){this.scrollToIndex(this.options.count-1,{align:"end",behavior:n});return}this.scrollToOffset(Math.max(this.getTotalSize()-this.getSize(),0),{behavior:n})},this.getTotalSize=()=>{var n;const r=this.getMeasurements();let a;if(r.length===0)a=this.options.paddingStart;else if(this.options.lanes===1){const o=r.length-1,i=this._flatMeasurements;i!=null?a=i[o*2]+i[o*2+1]:a=((n=r[o])==null?void 0:n.end)??0}else{const o=Array(this.options.lanes).fill(null);let i=r.length-1;for(;i>=0&&o.some(l=>l===null);){const l=r[i];o[l.lane]===null&&(o[l.lane]=l.end),i--}a=Math.max(...o.filter(l=>l!==null))}return Math.max(a-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{const n=[];if(this.itemSizeCache.size===0)return n;const r=this.getMeasurements();for(const a of r)a&&this.itemSizeCache.has(a.key)&&n.push({index:a.index,key:a.key,start:a.start,size:a.size,end:a.end,lane:a.lane});return n},this._scrollToOffset=(n,{adjustments:r,behavior:a})=>{this._intendedScrollOffset=n+(r??0),this.options.scrollToFn(n,{behavior:a,adjustments:r},this)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(t)}applyScrollAdjustment(t,n){t!==0&&(Qn()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?this._iosDeferredAdjustment+=t:(this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=t,behavior:n}),this.scrollOffset!==null&&(this.scrollOffset+=this.scrollAdjustments,this.scrollAdjustments=0)))}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId==null&&(this.rafId=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}))}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}const r=this.scrollState.index!=null?this.getOffsetForIndex(this.scrollState.index,this.scrollState.align):void 0,a=r?r[0]:this.scrollState.lastTargetOffset,o=1,i=a!==this.scrollState.lastTargetOffset;if(!i&&eb(a,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=o){this.getScrollOffset()!==a&&this._scrollToOffset(a,{adjustments:void 0,behavior:"auto"}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,i){const l=this.getSize()||600,u=Math.abs(a-this.getScrollOffset()),d=this.scrollState.behavior==="smooth"&&u>l;this.scrollState.lastTargetOffset=a,d||(this.scrollState.behavior="auto"),this._scrollToOffset(a,{adjustments:void 0,behavior:d?"smooth":"auto"})}this.scheduleScrollReconcile()}}const Yl=(e,t,n,r)=>{for(;e<=t;){const a=(e+t)/2|0,o=n(a);if(o<r)e=a+1;else if(o>r)t=a-1;else return a}return e>0?e-1:0};function fb(e,t,n){let r=0;for(;r<=t;){const a=(r+t)/2|0,o=e[a*2];if(o<n)r=a+1;else if(o>n)t=a-1;else return a}return r>0?r-1:0}function mb(e,t,n,r,a){const o=e.length-1;if(e.length<=r)return{startIndex:0,endIndex:o};if(r===1&&a!==null){const d=fb(a,o,n);let m=d;const f=n+t;for(;m<o&&a[m*2]+a[m*2+1]<f;)m++;return{startIndex:d,endIndex:m}}let l=Yl(0,o,d=>e[d].start,n),u=l;if(r===1)for(;u<o&&e[u].end<n+t;)u++;else if(r>1){const d=Array(r).fill(0);for(;u<o&&d.some(f=>f<n+t);){const f=e[u];d[f.lane]=f.end,u++}const m=Array(r).fill(n+t);for(;l>=0&&m.some(f=>f>=n);){const f=e[l];m[f.lane]=f.start,l--}l=Math.max(0,l-l%r),u=Math.min(o,u+(r-1-u%r))}return{startIndex:l,endIndex:u}}const Hn=typeof document<"u"?c.useLayoutEffect:c.useEffect;function hb({useFlushSync:e=!0,directDomUpdates:t=!1,directDomUpdatesMode:n="transform",...r}){const a=c.useReducer(d=>d+1,0)[1],o=c.useRef({enabled:t,mode:n,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});o.current.enabled=t,o.current.mode=n;const i=d=>{const m=o.current;if(!m.enabled||!m.container)return;const f=d.getTotalSize();if(f!==m.lastSize){m.lastSize=f;const g=d.options.horizontal?"width":"height";m.container.style[g]=`${f}px`}const h=!!d.options.horizontal,x=m.mode==="transform",b=h?"left":"top",p=d.options.scrollMargin,v=d.getVirtualItems();for(const g of v){const y=g.start-p,j=d.elementsCache.get(g.key);j&&m.lastPositions.get(j)!==y&&(m.lastPositions.set(j,y),x?j.style.transform=h?`translate3d(${y}px, 0, 0)`:`translate3d(0, ${y}px, 0)`:j.style[b]=`${y}px`)}},l={...r,onChange:(d,m)=>{var f;const h=o.current;let x=!0;if(h.enabled){i(d);const b=d.range,p=h.prevRange;x=!p||p.isScrolling!==d.isScrolling||p.startIndex!==b?.startIndex||p.endIndex!==b?.endIndex,x&&(h.prevRange=b?{startIndex:b.startIndex,endIndex:b.endIndex,isScrolling:d.isScrolling}:null)}x&&(e&&m?hr.flushSync(a):a()),(f=r.onChange)==null||f.call(r,d,m)}},[u]=c.useState(()=>{const d=new db(l);return Object.assign(d,{containerRef:m=>{const f=o.current;if(f.container=m,f.lastSize=null,m&&f.enabled){const h=d.getTotalSize();f.lastSize=h;const x=d.options.horizontal?"width":"height";m.style[x]=`${h}px`}}})});return u.setOptions(l),Hn(()=>u._didMount(),[]),Hn(()=>u._willUpdate()),Hn(()=>{i(u)}),u}function gb(e){return hb({observeElementRect:rb,observeElementOffset:ib,scrollToFn:ub,...e})}const pb=(e,t,n)=>{const r=e.indexOf(n);if(r===-1)return[];const a=t===void 0?-1:e.indexOf(t);if(a===-1)return[n];const o=Math.min(a,r),i=Math.max(a,r);return e.slice(o,i+1)},xb=(e,t,n)=>{if(e.length===0)return;const r=t===void 0?-1:e.indexOf(t);if(r===-1)return n>0?e[0]:e[e.length-1];const a=Math.min(Math.max(r+n,0),e.length-1);return e[a]},bb=e=>{const[t,n]=c.useState(new Set),[r,a]=c.useState(void 0),o=c.useCallback(b=>t.has(b),[t]),i=c.useCallback(b=>{a(b),n(p=>{const v=new Set(p);return v.has(b)?v.delete(b):v.add(b),v})},[]),l=c.useCallback(b=>{a(b),n(p=>{if(p.has(b))return p;const v=new Set(p);return v.add(b),v})},[]),u=c.useCallback(b=>{n(p=>{if(!p.has(b))return p;const v=new Set(p);return v.delete(b),v})},[]),d=c.useCallback(b=>{n(new Set(b))},[]),m=c.useCallback(()=>{a(void 0),n(new Set)},[]),f=c.useCallback(b=>{n(p=>b.every(g=>p.has(g))?new Set:new Set(b))},[]),h=c.useCallback(b=>{a(b)},[]),x=c.useCallback((b,p)=>{n(v=>{const g=pb(b,r,p);if(g.length===0)return v;const y=new Set(v);for(const j of g)y.add(j);return y}),a(v=>v??p)},[r]);return{selectedIds:t,selectedCount:t.size,hasSelection:t.size>0,isSelected:o,toggle:i,select:l,deselect:u,selectAll:d,clearSelection:m,toggleAll:f,selectRange:x,setAnchor:h,anchorId:r}};function vb(e,t){if(e.length!==0)return t!==void 0&&e.includes(t)?t:e[0]}const yb=e=>{const t=pe(nu()),{mutate:n}=t;return{preview:c.useCallback(a=>{e&&n({path:{accountId:e},body:_o(a)})},[e,n]),reset:t.reset,matchedCount:t.data?.matchedCount,messageIds:t.data?.messageIds,isPending:t.isPending,isError:t.isError,error:t.error}},wb=new Set(["Complete","Failed"]),io=e=>e!==void 0&&wb.has(e),jb=1e3,Sb=15e3,Nb=e=>{const t=Math.max(0,e),n=jb*2**t;return Math.min(n,Sb)},kb=e=>{const[t,n]=c.useState(),r=pe({...ru(),onSuccess:f=>n(f.organizeJobId)}),{mutate:a}=r,o=ie({...au({path:{accountId:e??"",organizeJobId:t??""}}),enabled:!!e&&!!t,refetchInterval:f=>{const h=f.state.data?.state;return io(h)?!1:Nb(f.state.dataUpdateCount)}}),i=c.useCallback(f=>{e&&(n(void 0),a({path:{accountId:e},body:_o(f)}))},[e,a]),l=o.data,u=l?.state??r.data?.state,d=io(l?.state),m={state:u,matchedCount:l?.matchedCount??0,appliedCount:l?.appliedCount??0,failedCount:l?.failedCount??0,errorMessage:l?.errorMessage??""};return{start:i,progress:m,isStarting:r.isPending,isRunning:!!t&&!d,isDone:d,isError:r.isError||o.isError,error:r.error??o.error}},Cb=({draft:e,scope:t,name:n,pickedDate:r})=>{if(!Ru(e))return"Pick a folder to move these into — labeling isn't available yet.";if((t==="standing"||t==="temporary")&&n.trim()==="")return"Name this filter so you can find it later.";if(t==="temporary"&&r==="")return"Pick the date this should stop on."},Eb=(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"}},Ib=(e,t,n)=>e==="just-these"?t:n,Rb=[{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 Mb({accountId:e,mailboxId:t,selectedMessageIds:n,anchorMessageId:r,matchedCount:a,onClose:o}){const[i,l]=c.useState("all-like-these"),[u,d]=c.useState(""),[m,f]=c.useState(""),[h,x]=c.useState(""),{data:b}=ie({...Ze({path:{accountId:e}}),staleTime:1/0}),p=c.useMemo(()=>Kr(b?.items??[]).map(A=>({id:A.mailboxId,label:an(A.fullPath)})),[b?.items]),v=c.useMemo(()=>({anchorMessageId:r,matchOperator:"And",literalClauses:[],moveMailboxId:u||void 0,expiresAt:i==="temporary"?Mu(h):void 0}),[r,u,i,h]),{moveMessages:g}=gt({mailboxId:t,accountId:e}),y=kb(e),j=Tu(e),w=n.length,C=Ib(i,w,a),k=Cb({draft:v,scope:i,name:m,pickedDate:h}),S=()=>{if(!k)switch(i){case"just-these":u&&g(n,u),o();return;case"all-like-these":y.start(v);return;case"standing":j.createFilter(v,"standing",m.trim());return;case"temporary":j.createFilter(v,"temporary",m.trim());return}};if(y.isRunning||y.isDone)return s.jsx(Tb,{progress:y.progress,isDone:y.isDone,onClose:o});if(j.isSuccess)return s.jsxs("div",{className:"flex flex-col items-center gap-3 px-5 py-8 text-center",children:[s.jsx(Sr,{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(V,{variant:"primary",onClick:o,className:"mt-2",children:"Done"})]});const N=i==="standing"||i==="temporary";return s.jsxs("div",{className:"flex min-h-0 flex-col",children:[s.jsxs("div",{className:"border-b border-line px-5 py-3",children:[s.jsx("h2",{className:"text-sm font-semibold text-fg",children:"Organize"}),s.jsxs("p",{className:"mt-0.5 text-xs text-fg-muted",children:[a," similar message",a===1?"":"s"," found",w>0?` from ${w} selected`:"","."]})]}),s.jsxs("div",{className:"min-h-0 flex-1 space-y-5 overflow-y-auto px-5 py-4",children:[s.jsxs("section",{className:"space-y-2 rounded-lg border border-line bg-surface-sunken p-3",children:[s.jsxs("p",{className:"text-sm leading-relaxed text-fg-muted",children:[i==="standing"&&s.jsx("span",{className:"font-semibold text-fg",children:"Always keep "}),i==="standing"?"":"Keep ",i==="just-these"?"these":"emails like these"," in"]}),s.jsxs(Iu,{"aria-label":"Destination folder",value:u,onChange:R=>d(R.target.value),children:[s.jsx("option",{value:"",children:"Choose a folder…"}),p.map(R=>s.jsx("option",{value:R.id,children:R.label},R.id))]}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx(Ue,{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:Rb.map(R=>{const A=i===R.id;return s.jsxs("button",{type:"button",onClick:()=>l(R.id),className:`flex w-full items-start gap-3 rounded-lg border px-3 py-2.5 text-left transition-colors ${A?"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 ${A?"border-accent-2 bg-accent-2":"border-line bg-surface"}`,children:A&&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 ${A?"text-accent-2":"text-fg"}`,children:R.label}),s.jsx("span",{className:"block text-xs text-fg-subtle",children:R.caption})]})]},R.id)})}),N&&s.jsxs("section",{className:"space-y-2",children:[s.jsx(wo,{value:m,onChange:R=>f(R.target.value),placeholder:"Name this filter (e.g. Travel)","aria-label":"Filter name"}),i==="temporary"&&s.jsxs("label",{className:"flex items-center gap-2 text-xs text-fg-muted",children:["Until",s.jsx("input",{type:"date",value:h,onChange:R=>x(R.target.value),"aria-label":"Expiry date",className:"rounded-md border border-line bg-surface-sunken px-2 py-1 text-sm text-fg"})]})]})]}),s.jsxs("div",{className:"space-y-2 border-t border-line px-5 py-3",children:[k&&s.jsx("p",{className:"text-xs text-fg-subtle",role:"status",children:k}),j.isError&&s.jsx("p",{className:"text-xs text-danger",role:"alert",children:"Couldn't save the filter. Please try again."}),s.jsx(V,{variant:"primary",onClick:S,disabled:!!k||j.isPending||y.isStarting,className:"w-full",children:j.isPending?"Saving…":Eb(i,C)}),s.jsx(V,{variant:"ghost",onClick:o,className:"w-full",children:"Not now"})]})]})}function Tb({progress:e,isDone:t,onClose:n}){const r=e.state==="Failed";return s.jsxs("div",{className:"flex flex-col items-center gap-3 px-5 py-8 text-center",children:[t?r?s.jsx("span",{className:"text-sm font-semibold text-danger",children:"Organize failed"}):s.jsx(Sr,{className:"size-8 text-positive"}):s.jsx(Tt,{className:"size-8 animate-spin text-accent-2"}),!t&&s.jsx("p",{className:"text-sm font-medium text-fg",children:"Organizing similar mail…"}),t&&!r&&s.jsxs("div",{className:"text-sm text-fg",children:[s.jsx("p",{className:"font-medium",children:"Done"}),s.jsxs("p",{className:"mt-1 text-xs text-fg-muted",children:[e.appliedCount," of ",e.matchedCount," moved",e.failedCount>0?` · ${e.failedCount} failed`:"","."]})]}),t&&r&&s.jsx("p",{className:"max-w-xs text-xs text-fg-muted",children:e.errorMessage||"Something went wrong. Please try again."}),t&&s.jsx(V,{variant:"primary",onClick:n,className:"mt-2",children:"Done"})]})}function Ab({open:e,accountId:t,mailboxId:n,selectedMessageIds:r,onClose:a}){const o=r[0],{preview:i,reset:l,matchedCount:u,isPending:d,isError:m,error:f}=yb(t);c.useEffect(()=>{!e||!o||i({anchorMessageId:o,matchOperator:"And",literalClauses:[]})},[e,o,i]);const h=()=>{l(),a()};return e?s.jsx(yo,{open:e,onClose:h,title:"Organize similar mail",children:d||u===void 0?m?s.jsxs("div",{className:"flex flex-col items-center gap-3 px-5 py-8 text-center",children:[s.jsx("p",{className:"text-sm font-medium text-danger",children:"Couldn't find similar messages"}),s.jsx("p",{className:"max-w-xs text-xs text-fg-muted",children:f instanceof Error?f.message:"Please try again."}),s.jsx(V,{variant:"ghost",onClick:h,className:"mt-2",children:"Close"})]}):s.jsxs("div",{className:"flex flex-col items-center gap-3 px-5 py-10 text-center",children:[s.jsx(Tt,{className:"size-8 animate-spin text-accent-2"}),s.jsx("p",{className:"text-sm font-medium text-fg",children:"Finding similar messages…"})]}):s.jsx(Mb,{accountId:t,mailboxId:n,selectedMessageIds:r,anchorMessageId:o,matchedCount:u,onClose:h})}):null}const Db=({selectedCount:e,onDelete:t,onClearSelection:n,onMarkAsRead:r,onMove:a,onOrganize:o,isDeleting:i=!1,isMoving:l=!1,accountId:u,currentMailboxId:d,moveDisabledHint:m})=>{const f=i||l;if(e===0)return null;const h=!!a&&!!u&&!!d,x=!!o&&!!u&&!!d&&!m;return s.jsxs("div",{className:"sticky top-0 z-10 flex items-center justify-between px-3 py-2 bg-surface-sunken border-b border-line",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("button",{type:"button",onClick:n,className:"min-h-11 min-w-11 inline-flex items-center justify-center rounded hover:bg-surface-raised transition-colors","aria-label":"Clear selection",children:s.jsx(Ke,{className:"size-4 text-fg-muted"})}),s.jsxs("span",{className:"text-sm font-medium",children:[e," ",e===1?"message":"messages"," ","selected"]}),m&&s.jsx("span",{className:"text-xs text-fg-muted",role:"status","aria-live":"polite",children:m})]}),s.jsxs("div",{className:"flex items-center gap-1",children:[x&&o&&s.jsxs("button",{type:"button",onClick:f?void 0:o,className:"min-h-11 inline-flex items-center justify-center gap-1.5 px-3 rounded text-sm font-medium transition-colors hover:bg-surface-raised","aria-label":"Organize similar messages",children:[s.jsx(Je,{className:"size-4"}),s.jsx("span",{className:"hidden sm:inline",children:"Organize"})]}),r&&s.jsx("button",{type:"button",onClick:f?void 0:r,className:"min-h-11 min-w-11 inline-flex items-center justify-center rounded text-sm font-medium transition-colors hover:bg-surface-raised","aria-label":"Mark as read","aria-busy":f,children:s.jsx(Os,{className:"size-4"})}),h&&a&&u&&d&&s.jsx(Fs,{accountId:u,currentMailboxId:d,onMove:f?()=>{}:a,disabledHint:m,variant:"icon-only",label:"Move selected messages"}),s.jsxs("button",{type:"button",onClick:f?void 0:t,className: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(Tt,{className:"size-4 animate-spin"}):s.jsx(et,{className:"size-4"}),s.jsx("span",{className:"hidden sm:inline",children:i?"Deleting...":"Delete"})]})]})]})},Ob=8,Pb=({onLongPress:e,delayMs:t=500})=>{const n=c.useRef(null),r=c.useRef(null),a=c.useCallback(()=>{n.current&&(clearTimeout(n.current),n.current=null),r.current=null},[]),o=c.useCallback(d=>{a(),r.current={x:d.clientX,y:d.clientY},n.current=setTimeout(()=>{e(),a()},t)},[e,t,a]),i=c.useCallback(d=>{if(!r.current)return;const m=d.clientX-r.current.x,f=d.clientY-r.current.y;Math.sqrt(m*m+f*f)>Ob&&a()},[a]),l=c.useCallback(()=>{a()},[a]),u=c.useCallback(()=>{a()},[a]);return{handlers:{onPointerDown:o,onPointerMove:i,onPointerUp:l,onPointerCancel:u}}},Lb=(e,t)=>{const n=e.authenticity?.dkimMismatch===!0;return{id:e.messageId,accountId:e.accountConfigId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:wt(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Sn(e.category),messageCount:t,suspicious:n}},zb=({thread:e,mailboxId:t,accountId:n,isSelected:r,isFocused:a=!1,isTabStop:o=!1,onFocusRow:i,isChecked:l,onToggleCheck:u,onRowSelect:d,messageCount:m,isMultiSelectMode:f=!1,onLongPress:h,isDesktop:x=!0,density:b="comfortable"})=>{const p=je(),v=e.messageId,g=Lb(e,m),y=E=>{E.preventDefault(),E.stopPropagation(),u(e.messageId)},j=c.useCallback(E=>{if(!x)return;const M={shiftKey:E.shiftKey,metaKey:E.metaKey,ctrlKey:E.ctrlKey};d(v,M)&&(E.preventDefault(),E.stopPropagation(),M.shiftKey&&window.getSelection()?.removeAllRanges())},[x,d,v]),w=c.useCallback(E=>{x&&E.shiftKey&&E.preventDefault()},[x]),C=c.useCallback(()=>{h?.(v)},[h,v]),k=Pb({onLongPress:C,delayMs:500}),S=c.useCallback(()=>{p.prefetchQuery(yr({path:{messageId:e.messageId}}))},[p,e.messageId]),N=c.useCallback(()=>{S(),i?.(v)},[S,i,v]),R={"data-message-row":!0,"data-message-id":v,role:"option","aria-selected":l,tabIndex:o?0:-1,onClick:j,onMouseDown:w,onMouseEnter:S,onFocus:N},A=!e.isRead;return b==="compact"?s.jsx(rt,{to:"/mail/$mailboxId",params:{mailboxId:t},search:E=>({...E,selectedMessageId:e.messageId}),...R,...!x&&k.handlers,className:fe(ei({active:r,focused:a}),"outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-inset",l&&"bg-accent-soft",!x&&"min-h-11"),children:s.jsx(ti,{thread:g})}):s.jsxs(rt,{to:"/mail/$mailboxId",params:{mailboxId:t},search:E=>({...E,selectedMessageId:e.messageId}),...R,...!x&&k.handlers,className:fe("group",ls({active:r,focused:a}),"outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-inset",l&&"bg-accent-soft",!x&&"min-h-11"),children:[A&&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(He,{name:e.fromName??e.fromEmail??"?",email:e.fromEmail??void 0,size:"sm",className:fe("absolute inset-0","sm:group-hover:opacity-0 transition-opacity",(l||f)&&"opacity-0")}),s.jsx("button",{type:"button",tabIndex:-1,onClick:y,className:fe("absolute inset-0 size-7 rounded-full border items-center justify-center transition-opacity",f?"flex":"hidden sm:flex",l?"bg-accent border-accent text-accent-fg opacity-100":f?"border-fg-subtle/40 opacity-100 bg-canvas":"border-fg-subtle/40 opacity-0 group-hover:opacity-100 bg-canvas"),"aria-label":l?"Deselect message":"Select message",children:l&&s.jsx(Ds,{className:"size-3"})})]}),s.jsx(It,{thread:g,badge:e.autoMoved&&s.jsx(Gi,{accountId:n,messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,autoMoved:e.autoMoved,size:"sm"})})]})},Fb=c.memo(zb),_b=e=>{const t=e.authenticity?.dkimMismatch===!0;return{id:e.messageId,accountId:e.accountConfigId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:wt(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Sn(e.category),suspicious:t}},Bb=({thread:e,mailboxId:t,accountId:n,isSelected:r,isFocused:a,isTabStop:o,onFocusRow:i,isChecked:l,onToggleCheck:u,onRowSelect:d,isMultiSelectMode:m,onLongPress:f,isDesktop:h,onDelete:x,onToggleRead:b,density:p})=>{const[v,g]=c.useState("none"),y=c.useCallback(C=>{navigator.vibrate?.(10),C==="trailing"?x(e.messageId):b(e.messageId,e.isRead),g("none")},[x,b,e.messageId,e.isRead]),j=c.useCallback(()=>{f(e.messageId)},[f,e.messageId]),w=c.useCallback(()=>{u(e.messageId)},[u,e.messageId]);return h||m?s.jsx(Fb,{thread:e,mailboxId:t,accountId:n,isSelected:r,isFocused:a,isTabStop:o,onFocusRow:i,isChecked:l,onToggleCheck:u,onRowSelect:d,isMultiSelectMode:m,onLongPress:f,isDesktop:h,density:p}):s.jsx(ri,{thread:_b(e),selectionMode:!1,checked:!1,active:r,peek:v,onPeek:g,onToggleCheck:w,onLongPress:j,onOpen:()=>{},onAct:y,linkComponent:({onOpenClick:C,children:k,...S})=>s.jsx(rt,{...S,to:"/mail/$mailboxId",params:{mailboxId:t},search:N=>({...N,selectedMessageId:e.messageId}),"data-message-row":!0,onClick:C,children:k})})},$b=72,Kb=32,qb=5,Gl="remit:list-density",Ub=()=>{try{const e=localStorage.getItem(Gl);if(e==="compact"||e==="comfortable")return e}catch{}return"comfortable"},Qb=({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(Ts,{className:"size-4 text-fg-muted"}),s.jsxs("span",{className:"text-sm text-fg-muted",children:[t," ",t===1?"result":"results"," for “",e,"”"]})]}),Hb=({mailboxId:e,threads:t,selectedMessageId:n,isLoading:r,isError:a=!1,error:o,onRetry:i,searchQuery:l,onDeleteMessages:u,onMarkAsRead:d,onMoveMessages:m,isDeleting:f=!1,isMoving:h=!1,onLoadMore:x,hasMore:b=!1,isLoadingMore:p=!1,accountId:v,listTitle:g,listMeta:y,onTriageContextChange:j,commandsRef:w,hideHeader:C=!1})=>{const k=c.useRef(null),S=Me(),N=Ot(),[R,A]=c.useState(!1),[E,M]=c.useState(!1),[I,T]=c.useState(n),[O,_]=c.useState(Ub),q=c.useCallback(()=>{_(L=>{const Z=L==="comfortable"?"compact":"comfortable";try{localStorage.setItem(Gl,Z)}catch{}return Z})},[]),{toggleReadFor:X}=Vi({mailboxId:e}),{selectedIds:F,selectedCount:$,hasSelection:ae,isSelected:ce,toggle:J,select:D,clearSelection:P,selectRange:Q,setAnchor:G,selectAll:ue}=bb(),[le,Y]=c.useState(null),ge=c.useRef(null),Se=c.useRef(!1),Ce=c.useRef(null),W=!r&&t.length>0,U=le!==null;c.useEffect(()=>{R&&$===0&&A(!1)},[R,$]);const te=gb({count:t.length,getScrollElement:()=>k.current,estimateSize:()=>O==="compact"?Kb:$b,overscan:qb}),ee=n?t.findIndex(L=>L.messageId===n):-1,Ee=I?t.findIndex(L=>L.messageId===I):-1,Ie=c.useCallback(L=>{if(L<0||L>=t.length)return;const Z=t[L];if(R){J(Z.messageId);return}ge.current=Z.messageId,Se.current=!1,T(Z.messageId)},[t,R,J]),ze=c.useCallback(()=>{if(t.length===0)return;const L=Ee<0?0:Math.min(Ee+1,t.length-1);Ie(L)},[t.length,Ee,Ie]),Ve=c.useCallback(()=>{if(t.length===0)return;const L=Ee<=0?0:Ee-1;Ie(L)},[t.length,Ee,Ie]),Te=c.useCallback(()=>Ie(0),[Ie]),de=c.useCallback(()=>Ie(t.length-1),[Ie,t.length]),jt=c.useCallback(()=>{I&&J(I)},[I,J]),Ae=c.useMemo(()=>t.map(L=>L.messageId),[t]),_s=c.useCallback((L,Z)=>Z.shiftKey?(Q(Ae,L),!0):Z.metaKey||Z.ctrlKey?(J(L),!0):(P(),G(L),!1),[Ae,Q,J,P,G]),tt=c.useCallback(L=>{!u||L.length===0||(Ce.current=I??null,Y(L))},[u,I]),Pe=c.useCallback(L=>{const Z=xb(Ae,I,L);Z!==void 0&&(Q(Ae,Z),ge.current=Z,Se.current=!1,T(Z))},[Ae,I,Q]),Pt=c.useCallback(()=>Pe(-1),[Pe]),lt=c.useCallback(()=>Pe(1),[Pe]),St=c.useCallback(()=>{Ae.length>0&&ue(Ae)},[Ae,ue]),qe=c.useCallback(()=>le!==null?!0:u?$>0?(tt(Array.from(F)),!0):I?(tt([I]),!0):!1:!1,[le,u,$,F,I,tt]),st=c.useCallback(()=>{I&&S({to:"/mail/$mailboxId",params:{mailboxId:e},search:L=>({...L,selectedMessageId:I})})},[I,S,e]),Lt=c.useCallback(()=>{$>0&&tt(Array.from(F))},[tt,$,F]),Ye=c.useCallback(()=>{if(!le||le.length===0){Y(null);return}const L=new Set(le),Z=t.findIndex(ke=>L.has(ke.messageId));let Oe;for(let ke=Z+1;ke<t.length;ke++)if(!L.has(t[ke].messageId)){Oe=t[ke].messageId;break}if(Oe===void 0){for(let ke=Z-1;ke>=0;ke--)if(!L.has(t[ke].messageId)){Oe=t[ke].messageId;break}}u?.(le),P(),Ce.current=null,Y(null),Oe!==void 0&&(ge.current=Oe,Se.current=!1,T(Oe),S({to:"/mail/$mailboxId",params:{mailboxId:e},search:ke=>({...ke,selectedMessageId:Oe}),replace:!0}))},[le,t,u,P,S,e]),hs=c.useCallback(()=>{const L=Ce.current;Ce.current=null,Y(null),L!==null&&(ge.current=L,Se.current=!1,T(L))},[]),zt=c.useCallback(()=>{d&&$>0&&d(Array.from(F))},[d,$,F]),Nt=c.useCallback(L=>{!m||$===0||(m(Array.from(F),L),P())},[m,$,F,P]),H=c.useMemo(()=>{if($===0)return;const L=new Set;for(const Z of t)F.has(Z.messageId)&&L.add(Z.accountConfigId);if(L.size>1)return"Move only works within one account — clear selection or pick messages from a single account"},[$,F,t]),oe=c.useCallback(L=>{u?.([L])},[u]),se=c.useCallback((L,Z)=>{X([L],!Z)},[X]),ne=c.useCallback(L=>{N||(A(!0),D(L))},[N,D]),me=c.useCallback(()=>{A(!1),P()},[P]);c.useEffect(()=>{if(Se.current||!N&&n)return;const L=Ee>=0?Ee:ee;L>=0&&te.scrollToIndex(L,{align:"auto"})},[Ee,ee,te,N,n]),c.useEffect(()=>{n&&(Se.current=!1,T(n))},[n]),c.useEffect(()=>{I&&(t.some(L=>L.messageId===I)||T(t[0]?.messageId))},[t,I]),c.useEffect(()=>{j?.({focusedMessageId:I,selectedIds:Array.from(F),hasList:W,blocksKeyboard:U})},[I,F,W,U,j]);const ye=c.useRef(j);ye.current=j,c.useEffect(()=>()=>ye.current?.({focusedMessageId:void 0,selectedIds:[],hasList:!1,blocksKeyboard:!1}),[]),c.useEffect(()=>{const L=new Set(t.map(Oe=>Oe.messageId));Array.from(F).some(Oe=>!L.has(Oe))&&P()},[t,F,P]),c.useEffect(()=>{const L=k.current;if(!L||!b||!x)return;const Z=()=>{if(p)return;const{scrollTop:Oe,scrollHeight:ke,clientHeight:Ks}=L;Oe+Ks>=ke-200&&x()};return L.addEventListener("scroll",Z,{passive:!0}),Z(),()=>L.removeEventListener("scroll",Z)},[b,p,x]),c.useEffect(()=>{const L=ge.current;if(!L)return;const Z=k.current?.querySelector(`[data-message-id="${L}"]`);Z&&(ge.current=null,Z.focus({preventScroll:!0}))}),c.useEffect(()=>{if(w){if(!W){w.current=null;return}return w.current={focusNext:ze,focusPrevious:Ve,focusFirst:Te,focusLast:de,openFocused:st,toggleSelect:jt,extendSelectDown:lt,extendSelectUp:Pt,selectAll:St,clearSelection:()=>ae?(P(),!0):!1,requestDelete:qe,toggleDensity:q},()=>{w.current=null}}},[w,W,ze,Ve,Te,de,st,jt,lt,Pt,St,ae,P,qe,q]);const xe=r?"loading":a?"error":t.length===0?"empty":"ready",Ne=a?zo(o):void 0,Re=c.useCallback(()=>{const L=br(xr());window.open(L,"_blank","noopener,noreferrer")},[]),Le=[{id:"inbox",threads:[]}],_e=ae&&N?s.jsx(Db,{selectedCount:$,onDelete:Lt,onClearSelection:P,onMarkAsRead:d?zt:void 0,onMove:m?Nt:void 0,onOrganize:()=>M(!0),isDeleting:f,isMoving:h,accountId:v,currentMailboxId:e,moveDisabledHint:H}):void 0,De=R&&!N?s.jsx(ni,{count:$,onCancel:me,onDelete:Lt,onMarkRead:d?zt:void 0,isBusy:f||h,notice:H?{tone:"warning",text:H}:void 0,moveSlot:m&&v&&e?s.jsxs(s.Fragment,{children:[!H&&s.jsx("button",{type:"button",onClick:()=>M(!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(Je,{className:"size-4"})}),s.jsx(Fs,{accountId:v,currentMailboxId:e,onMove:f||h?()=>{}:Nt,disabledHint:H,label:"Move selected messages"})]}):void 0}):void 0,ct=_e??De,kt=vb(Ae,I),Bs=c.useCallback(L=>{Se.current=!0,T(L)},[]),Ft=!!l?.trim(),$s=s.jsxs(s.Fragment,{children:[Ft&&l&&s.jsx(Qb,{query:l,count:t.length}),s.jsxs("div",{ref:k,role:"listbox","aria-multiselectable":!0,"aria-label":g,className:"flex-1 overflow-y-auto",children:[s.jsx("div",{role:"presentation",className:"relative w-full",style:{height:`${te.getTotalSize()}px`},children:te.getVirtualItems().map(L=>{const Z=t[L.index];return s.jsx("div",{role:"presentation","data-index":L.index,ref:te.measureElement,className:"absolute left-0 top-0 w-full border-b border-line",style:{transform:`translateY(${L.start}px)`},children:s.jsx(Bb,{thread:Z,mailboxId:e,accountId:v,isSelected:n===Z.messageId,isFocused:I===Z.messageId,isTabStop:kt===Z.messageId,onFocusRow:Bs,isChecked:ce(Z.messageId),onToggleCheck:J,onRowSelect:_s,isMultiSelectMode:R,onLongPress:ne,isDesktop:N,onDelete:oe,onToggleRead:se,density:O})},L.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(ai,{listTitle:g,listMeta:y,sections:Le,flatList:!0,listState:xe,searchQuery:Ft?l:void 0,errorMessage:Ne,onRetry:i,onReportError:Re,density:O,selectedThreadId:n,onSelectThread:L=>S({to:"/mail/$mailboxId",params:{mailboxId:e},search:Z=>({...Z,selectedMessageId:L})}),onSelectBriefCategory:()=>{},isDesktop:N,hideHeader:C,selectionBar:ct,listBody:xe==="ready"?$s:void 0}),s.jsx(Pl,{isOpen:le!==null,title:Cu(le?.length??0),description:"You can restore them from Trash later.",confirmLabel:"Move to Trash",destructive:!0,isBusy:f,onConfirm:Ye,onCancel:hs}),E&&v&&s.jsx(Ab,{open:E,accountId:v,mailboxId:e,selectedMessageIds:Array.from(F),onClose:()=>M(!1)})]})},Wb=e=>as({path:{accountId:e}}),Vb=e=>{const t=je(),n=Ms(),r=pe({...ou(),onSuccess:()=>{n.recordEvent("sync.triggered"),t.invalidateQueries({queryKey:Wb(e)})}});return{trigger:()=>{r.mutate({path:{accountId:e}})},triggerAsync:()=>r.mutateAsync({path:{accountId:e}}),isPending:r.isPending,error:r.error,reset:r.reset}},Yb=({accountId:e,children:t})=>{const{triggerAsync:n,isPending:r}=Vb(e);return s.jsx(Mf,{onRefresh:n,isRefreshing:r,children:t})};function Gb({accountId:e,currentMailboxId:t,candidates:n,onMove:r,children:a}){const[o,i]=c.useState(!1),l=Ms(),{t:u}=fn("mail",{useSuspense:!1}),d=c.useCallback((y,j)=>u(y,{defaultValue:j}),[u]),{inboxMailboxId:m}=Lr(e),f=Yi(e),{data:h}=ie({...Ze({path:{accountId:e}}),staleTime:1/0}),x=c.useMemo(()=>{const y=Kr(h?.items??[],f),j=is(f);return y.map(w=>({id:w.mailboxId,label:es(w,j.get(w.mailboxId),d),searchValue:w.fullPath,isCurrent:w.mailboxId===t}))},[h?.items,f,t,d]),b=c.useMemo(()=>m||(x.find(j=>j.label.toLowerCase()==="inbox")?.id??x.find(j=>!j.isCurrent)?.id??""),[m,x]),p=c.useRef(!1);c.useEffect(()=>{p.current||(p.current=!0,vx(l,n.length))},[l,n.length]);const v=c.useCallback(()=>{yx(l,n.length),i(!0)},[l,n.length]),g=c.useCallback((y,j)=>{wx(l,{selected:y.length,total:n.length,toInbox:j===m}),r(y,j)},[l,n.length,m,r]);return s.jsxs("div",{className:"relative flex h-full min-h-0 flex-col",children:[s.jsx("div",{className:"shrink-0 px-row-inset pt-2",children:s.jsx(Df,{count:n.length,onReview:v})}),s.jsx("div",{className:"min-h-0 flex-1",children:a}),s.jsx(qf,{open:o,candidates:n,defaultDestinationId:b,availableFolders:x,onConfirmMove:g,onCancel:()=>i(!1)})]})}const Xb="We can verify this sender";function Jb(e){const{data:t}=ie({...iu({path:{mailboxId:e??""},query:{senderTrust:["vip","wellknown"],dkimMismatch:!1,results:!0,limit:500}}),enabled:!!e,staleTime:6e4});return{candidates:(t?.items??[]).map(r=>({id:r.messageId,senderName:r.fromName||r.fromEmail||"Unknown sender",senderAddress:r.fromEmail??"",subject:r.subject||"(no subject)",snippet:r.snippet??"",trustReason:Xb,trustSubReason:bx(r.senderTrust),senderTrust:r.senderTrust}))}}const Ss={action:null,nextPrefix:null,preventDefault:!1},Zb={b:"goBrief",i:"goInbox",s:"goSent",f:"goFlagged",",":"goSettings"},ev={j:{action:"focusNext"},k:{action:"focusPrevious"},arrowdown:{action:"focusNext"},arrowup:{action:"focusPrevious"},home:{action:"focusFirst"},end:{action:"focusLast"},enter:{action:"openFocused"}," ":{action:"toggleSelect"},delete:{action:"delete"},backspace:{action:"delete"},u:{action:"toggleRead"},x:{action:"toggleSelect"},r:{action:"reply"},a:{action:"replyAll"},f:{action:"forward"},"#":{action:"delete"},s:{action:"toggleStar"},m:{action:"muteSender"},b:{action:"blockSender"},v:{action:"vipSender"},"!":{action:"markJunk"},i:{action:"toggleIntelligence"},d:{action:"toggleDensity"},"/":{action:"focusSearch"},c:{action:"compose"},"?":{action:"help"}};function tv(e,t){const n=e.key.toLowerCase(),r=e.metaKey||e.ctrlKey;if(e.inEditable)return{...Ss,nextPrefix:t==="g"?null:t};if(e.onControl&&(n==="enter"||n===" "))return{...Ss,nextPrefix:t==="g"?null:t};if(r&&n==="n")return{action:"compose",nextPrefix:null,preventDefault:!0};if(r&&n==="a")return{action:"selectAll",nextPrefix:null,preventDefault:!0};if(r)return{...Ss,nextPrefix:t==="g"?null:t};if(n==="escape")return{action:"back",nextPrefix:null,preventDefault:!1};if(t==="g"){const i=Zb[n===","?",":n]??null;return{action:i,nextPrefix:null,preventDefault:i!==null}}if(n==="g"&&!e.shiftKey)return{action:null,nextPrefix:"g",preventDefault:!0};if(e.shiftKey){const o=n==="j"||n==="arrowdown";if(o||(n==="k"||n==="arrowup"))return{action:o?"extendSelectDown":"extendSelectUp",nextPrefix:null,preventDefault:!0}}const a=ev[n];if(a){const o=a.requireShift===!0,i=n.length===1&&!/[a-z0-9]/.test(n);return!o&&e.shiftKey&&!i?Ss:{action:a.action,nextPrefix:null,preventDefault:!0}}return Ss}function sv(e){if(!(e instanceof HTMLElement))return!1;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"||e.isContentEditable}const nv="data-message-row",rv='button, a[href], summary, [role="button"], [role="menuitem"], [role="tab"], [role="switch"], [role="checkbox"]';function av(e){if(!(e instanceof HTMLElement))return!1;const t=e.closest(rv);return t?!t.hasAttribute(nv):!1}function ov({handlers:e,enabled:t=!0,sequenceTimeoutMs:n=1e3}){const r=c.useRef(e);r.current=e;const a=c.useRef(null),o=c.useRef(null);c.useEffect(()=>{if(!t)return;const i=()=>{o.current!==null&&(clearTimeout(o.current),o.current=null)},l=u=>{const d=tv({key:u.key,shiftKey:u.shiftKey,metaKey:u.metaKey,ctrlKey:u.ctrlKey,altKey:u.altKey,inEditable:sv(u.target),onControl:av(u.target)},a.current);if(i(),a.current=d.nextPrefix,d.nextPrefix!==null&&(o.current=setTimeout(()=>{a.current=null,o.current=null},n)),d.action===null)return;const m=r.current[d.action];m&&(d.preventDefault&&u.preventDefault(),m())};return window.addEventListener("keydown",l),()=>{window.removeEventListener("keydown",l),i(),a.current=null}},[t,n])}const lo=(e,t,n)=>{if(!t)return null;const r=e.indexOf(t);if(r===-1)return null;const a=n==="next"?r+1:r-1;return a<0||a>=e.length?null:e[a]},Xl="remit:intelligence-open";function iv(){try{return localStorage.getItem(Xl)!=="closed"}catch{return!0}}function co(e){try{localStorage.setItem(Xl,e?"open":"closed")}catch{}}const lv=(e,t)=>e!==t,cv=(e,t,n)=>{if(!(n||!t))return e.find(r=>r.messageId===t)},uv={unread:e=>!e.isRead,flagged:e=>e.hasStars===!0,attachment:e=>!!e.hasAttachment};function dv(e,t,n){const r=Array.from(n).map(a=>uv[a]).filter(a=>a!=null);return t==="all"&&r.length===0?e:e.filter(a=>(t==="all"||a.category===t)&&r.every(o=>o(a)))}const Jl=c.createContext(null);function Rn(){const e=c.useContext(Jl);if(!e)throw new Error("MailboxPane.* must be used inside <MailboxPane>");return e}function fv({mailboxId:e,selectedMessageId:t,children:n}){const r=Me(),o=Cn()==="desktop",i=Ms(),{accounts:l,searchQuery:u,searchInput:d,intelligenceOpen:m,onToggleIntelligence:f,onSetIntelligenceOpen:h}=ve(),x=ds(),b=qr(u),p=b.length>0,{freeText:v,tokens:g}=fs(b,x),y=g.find(z=>z.type==="from"),j={order:"desc",...v?{query:v}:{},...y?{from:y.value}:{},...g.some(z=>z.type==="hasAttachment")?{attachments:!0}:{},...g.some(z=>z.type==="isUnread")?{unread:!0}:{}},w=p?bt({path:{mailboxId:e},query:j}):ot({path:{mailboxId:e},query:{order:"desc"}}),{data:C,isLoading:k,isError:S,error:N,refetch:R,fetchNextPage:A,hasNextPage:E,isFetchingNextPage:M}=Ii({queryKey:w,queryFn:async({pageParam:z})=>{if(p){const{data:Be}=await cu({path:{mailboxId:e},query:{...j,continuationToken:z},throwOnError:!0});return Be}const{data:Fe}=await uu({path:{mailboxId:e},query:{order:"desc",continuationToken:z},throwOnError:!0});return Fe},initialPageParam:void 0,getNextPageParam:z=>z.continuationToken,enabled:p?b.length>0:!0,placeholderData:lu}),I=c.useCallback(z=>{t&&z.includes(t)&&r({to:"/mail/$mailboxId",params:{mailboxId:e},search:Fe=>({...Fe,selectedMessageId:void 0,selectedThreadId:void 0})})},[t,e,r]),{deleteMessages:T,isPending:O}=Cs({mailboxId:e,onAfterOptimisticRemove:I}),{accountId:_}=Wi(e),q=Fi({accounts:l}),{moveMessages:X,isPending:F}=gt({mailboxId:e,accountId:_,onAfterOptimisticRemove:I}),$=Lg(C?.pages.flatMap(z=>z.items??[])??[]),[ae,ce]=c.useState("all"),[J,D]=c.useState(new Set),P=c.useMemo(()=>dv($,ae,J),[$,ae,J]),Q=c.useCallback(z=>{ce(z)},[]),G=c.useCallback(z=>{D(Fe=>{const Be=new Set(Fe);return Be.has(z)?Be.delete(z):Be.add(z),Be})},[]),ue=c.useCallback(()=>{ce("all"),D(new Set)},[]),le=lv(d,u),Y=cv($,t,le),{selectedThreadId:ge}=Zt({strict:!1}),Se=c.useMemo(()=>Kl(Y,{messageId:t,threadId:le?void 0:ge,mailboxId:e}),[Y,t,ge,le,e]),[Ce,W]=c.useState(void 0),[U,te]=c.useState([]),ee=c.useRef(null),[Ee,Ie]=c.useState(!1),[ze,Ve]=c.useState(!1),Te=c.useCallback(z=>{W(z.focusedMessageId),te(z.selectedIds),Ie(z.hasList),Ve(z.blocksKeyboard)},[]),de=P.find(z=>z.messageId===Ce)??Y,jt=c.useRef(null);c.useEffect(()=>{const z=Y?.messageId??null;z&&jt.current!==z&&Y?.authenticity?.dkimMismatch&&(jt.current=z,m||f())},[Y?.messageId,Y?.authenticity?.dkimMismatch,m,f]);const Ae=c.useRef(!1);c.useEffect(()=>{Ae.current||o&&Y?.messageId&&(Ae.current=!0,iv()&&!m&&h(!0))},[o,Y?.messageId,m,h]);const tt=zh({accounts:l})??$.filter(z=>!z.isRead).length,Pe=je(),{pushError:Pt}=Qe(),{deleteMessages:lt}=Cs({mailboxId:e,threadId:Y?.threadId,onAfterOptimisticRemove:I}),{moveMessages:St}=gt({mailboxId:e,threadId:Y?.threadId,accountId:_,onAfterOptimisticRemove:I}),{draftsMailboxId:qe}=Og(_),st=qe!==void 0&&qe===e,{archiveMailboxId:Lt}=Dg(_),Ye=c.useCallback(z=>{const Fe=Mt({path:{threadId:z.threadId}}),Xr=Pe.getQueriesData({queryKey:Fe}).flatMap(([,wc])=>wc?.items.map(jc=>jc.messageId)??[]);return Xr.length>0?Xr:[z.messageId]},[Pe]),hs=c.useCallback(()=>{if(!Y)return;const z=Ye(Y);lt(z)},[Y,Ye,lt]),zt=c.useCallback(z=>{if(!Y)return;const Fe=Ye(Y);St(Fe,z)},[Y,Ye,St]),{toggleStar:Nt}=rr({threadId:Y?.threadId??"",mailboxId:e}),H=c.useCallback(()=>{Y&&Nt(Y.messageId,Y.hasStars)},[Y,Nt]),[oe,se]=c.useState(null),ne=c.useCallback(()=>{se("reply")},[]),me=c.useCallback(()=>{se("reply_all")},[]),ye=c.useCallback(()=>{se("forward")},[]),xe=c.useCallback(()=>{se(null)},[]),{state:Ne,openCompose:Re,closeCompose:Le}=xt(),_e=c.useCallback(()=>{Re({mode:"new"})},[Re]),De=pe({...hn(),onError:z=>{Pt(Es("Couldn't discard draft","The draft wasn't deleted.",z))}}),ct=c.useCallback(()=>{const z=Ne.outboxMessageId;z&&(De.mutate({path:{outboxMessageId:z}}),Pe.invalidateQueries({queryKey:wr()}),Le())},[Ne.outboxMessageId,De,Pe,Le]),kt=c.useCallback(()=>{ee.current?.clearSelection()||t&&r({to:"/mail/$mailboxId",params:{mailboxId:e},search:z=>({...z,selectedMessageId:void 0,selectedThreadId:void 0})})},[t,e,r]),Bs=c.useCallback(z=>z?Ye(z):[],[Ye]),{toggleStar:Ft}=rr({threadId:de?.threadId??"",mailboxId:e}),{toggleReadFor:$s}=Vi({mailboxId:e,accountId:_}),{junkMailboxId:L}=zr(_),Z=L!=null&&L===e,{candidates:Oe}=Jb(Z?L:void 0),{moveMessages:ke}=gt({mailboxId:e,threadId:de?.threadId,accountId:_,onAfterOptimisticRemove:I}),{deleteMessages:Ks}=Cs({mailboxId:e,threadId:de?.threadId,onAfterOptimisticRemove:I}),{addressId:_t,address:qs}=Fl(de),{updateFlags:Us}=_l({addressId:_t,senderEmail:de?.fromEmail??void 0}),Bt=c.useCallback(()=>t||!Ce?!1:(r({to:"/mail/$mailboxId",params:{mailboxId:e},search:z=>({...z,selectedMessageId:Ce})}),!0),[t,Ce,e,r]),ic=c.useCallback(()=>{Bt()||Y&&se("reply")},[Bt,Y]),lc=c.useCallback(()=>{Bt()||Y&&se("reply_all")},[Bt,Y]),cc=c.useCallback(()=>{Bt()||Y&&se("forward")},[Bt,Y]),$t=c.useCallback(()=>U.length>0?U:Bs(de),[U,Bs,de]),uc=c.useCallback(()=>{if(ee.current?.requestDelete())return;const z=$t();z.length>0&&Ks(z)},[$t,Ks]),dc=c.useCallback(()=>{if(!L)return;const z=$t();z.length!==0&&($l(i,{count:z.length,senderTrust:de?.senderTrust??"unknown",wasRescuable:de?Bl(de):!1}),ke(z,L))},[L,$t,ke,i,de]),fc=c.useCallback(()=>{if(U.length>0){const z=!(de?.hasStars??!1),Fe=new Set(U);for(const Be of P)Fe.has(Be.messageId)&&Be.hasStars!==z&&Ft(Be.messageId,Be.hasStars);return}de&&Ft(de.messageId,de.hasStars)},[U,P,de,Ft]),mc=c.useCallback(()=>{const z=$t();if(z.length===0)return;const Fe=!(de?.isRead??!1);$s(z,Fe)},[$t,de,$s]),hc=c.useCallback(()=>{if(!_t)return;const z=qs?.flags?.muted?.value!==!0;Us({muted:{value:z}})},[_t,qs,Us]),gc=c.useCallback(()=>{if(!_t)return;const z=qs?.flags?.vip?.value!==!0;Us({vip:{value:z}})},[_t,qs,Us]),pc=c.useCallback(()=>{m||f()},[m,f]),gs=c.useCallback(z=>{r({to:z})},[r]),Vr=st?"drafts":Lt===e?"archive":L===e?"junk":"inbox",Yr=c.useRef("");c.useEffect(()=>{const z=Yr.current;Yr.current=b,b.length>0&&z.length===0&&i.recordEvent("search.submitted",{mailboxType:Vr})},[b,Vr,i]);const xc=st&&Ne.isOpen&&!!Ne.outboxMessageId&&!Y;ov({enabled:!Ne.isOpen&&!ze,handlers:{...Ee?{focusNext:()=>ee.current?.focusNext(),focusPrevious:()=>ee.current?.focusPrevious(),focusFirst:()=>ee.current?.focusFirst(),focusLast:()=>ee.current?.focusLast(),openFocused:()=>ee.current?.openFocused(),toggleSelect:()=>ee.current?.toggleSelect(),extendSelectDown:()=>ee.current?.extendSelectDown(),extendSelectUp:()=>ee.current?.extendSelectUp(),selectAll:()=>ee.current?.selectAll(),toggleDensity:()=>ee.current?.toggleDensity()}:{},back:kt,reply:ic,replyAll:lc,forward:cc,delete:uc,toggleStar:fc,toggleRead:mc,muteSender:hc,blockSender:pc,vipSender:gc,markJunk:dc,toggleIntelligence:Y?f:void 0,compose:_e,goBrief:()=>gs("/mail"),goInbox:()=>gs("/mail"),goSent:()=>gs("/mail"),goFlagged:()=>gs("/mail/flagged"),goSettings:()=>gs("/settings")}}),Pr({enabled:Ne.isOpen,bindings:[{key:"Escape",handler:Le,preventDefault:!0}]});const Gr=P.map(z=>z.messageId),bc=lo(Gr,t,"next")??void 0,vc=lo(Gr,t,"previous")??void 0,yc={mailboxId:e,selectedMessageId:t,selectedThread:Y,conversation:Se,threads:P,isLoading:k,isError:S,error:N,mailboxAccountId:_,mailboxName:q,unreadCount:tt,isDraftsMailbox:st,isSpamFolder:Z,rescueCandidates:Oe,filterCategory:ae,filterAttributes:J,onSelectFilterCategory:Q,onToggleFilterAttribute:G,onClearFilters:ue,intelligenceOpen:m,onToggleIntelligence:f,onDeleteMessages:T,onMoveMessages:X,isDeleting:O,isMoving:F,onLoadMore:A,hasMore:E,isLoadingMore:M,onTriageContextChange:Te,listCommandsRef:ee,onRetry:()=>R(),toolbarComposeRequest:oe,onToolbarReply:ne,onToolbarReplyAll:me,onToolbarForward:ye,onClearComposeRequest:xe,onToolbarDelete:hs,onToolbarStar:H,onToolbarDiscardDraft:ct,onToolbarMove:zt,composeState:Ne,closeCompose:Le,hasRemitDraftOpen:xc,onBack:kt,nextMessageId:bc,previousMessageId:vc};return s.jsx(Jl.Provider,{value:yc,children:n})}function Zl(){const{mailboxId:e,selectedMessageId:t,threads:n,isLoading:r,isError:a,error:o,onDeleteMessages:i,onMoveMessages:l,isDeleting:u,isMoving:d,onLoadMore:m,hasMore:f,isLoadingMore:h,mailboxAccountId:x,mailboxName:b,unreadCount:p,isDraftsMailbox:v,isSpamFolder:g,rescueCandidates:y,onTriageContextChange:j,listCommandsRef:w,onRetry:C,filterCategory:k,filterAttributes:S,onSelectFilterCategory:N,onToggleFilterAttribute:R,onClearFilters:A}=Rn(),{searchQuery:E,searchInput:M,accounts:I}=ve(),T=Cn(),O=Me(),_=b??"Inbox",q=c.useMemo(()=>Wf(),[]),X=c.useMemo(()=>n.map(ex),[n]),{hits:F,isLoading:$}=Cl({mailboxId:e,filterCategory:k}),ae=c.useMemo(()=>Ml(F,n.map(G=>G.threadId)),[F,n]),ce=c.useCallback(G=>O({to:"/mail/$mailboxId",params:{mailboxId:G.mailboxId??e},search:ue=>({...ue,q:M||void 0,selectedMessageId:G.id,selectedThreadId:G.threadId})}),[e,O,M]);if(v&&x)return s.jsx(Jx,{mailboxId:e,accountId:x,selectedMessageId:t,imapThreads:n,title:b??"Drafts",unreadCount:p??void 0});const J=s.jsx(Hb,{mailboxId:e,threads:n,selectedMessageId:t,isLoading:r,isError:a,error:o,onRetry:C,searchQuery:E,onDeleteMessages:i,onMoveMessages:l,isDeleting:u,isMoving:d,onLoadMore:m,hasMore:f,isLoadingMore:h,accountId:x,listTitle:_,hideHeader:!0,onTriageContextChange:j,commandsRef:w}),D=I[0]?.accountId,P=T==="phone"&&D?s.jsx(Yb,{accountId:D,children:J}):J,Q=g&&y.length>0&&x?s.jsx(Gb,{accountId:x,currentMailboxId:e,candidates:y,onMove:l,children:P}):P;return s.jsx(Ql,{title:_,unreadCount:p,preset:q,selectedCategory:k,activeFilters:S,onSelectCategory:N,onToggleFilter:R,onClearFilters:A,searchResults:X,searchLoading:r,relatedResults:ae,relatedLoading:$,onSelectSearchResult:ce,children:Q})}function mv(){const{mailboxId:e,mailboxAccountId:t,selectedThread:n,conversation:r,hasRemitDraftOpen:a,intelligenceOpen:o,onToggleIntelligence:i,toolbarComposeRequest:l,onToolbarReply:u,onToolbarReplyAll:d,onToolbarForward:m,onClearComposeRequest:f,onToolbarDelete:h,onToolbarStar:x,onToolbarDiscardDraft:b,onToolbarMove:p,composeState:v}=Rn(),g=os()?.showIntelligencePane??!1,y=!!r,j=g&&y,w=v.isOpen&&!r?s.jsx(Vl,{}):r?s.jsx(us,{threadId:r.threadId,mailboxId:r.mailboxId,subject:r.subject,selectedMessageId:r.messageId,authenticity:r.authenticity,onOpenIntelligence:r.authenticity?.dkimMismatch?i:void 0,composeRequest:l,onComposeClose:f}):s.jsx(cs,{});return s.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[s.jsx(Ur,{hasThread:y,intelligenceOpen:j&&o,canToggleIntelligence:j,onToggleIntelligence:i,onReply:y?u:void 0,onReplyAll:y?d:void 0,onForward:y?m:void 0,canDelete:y||a,onDelete:y?h:a?b:void 0,onToggleStar:y?x:void 0,isStarred:n?.hasStars,moveContext:y&&t?{accountId:t,currentMailboxId:e,onMove:p}:void 0}),s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:w})]})}function hv(){const{mailboxId:e,mailboxAccountId:t,selectedThread:n,onToggleIntelligence:r}=Rn();return s.jsx(ms,{onClose:r,thread:n,mailboxId:e,accountId:t})}function gv(){const{mailboxId:e,selectedThread:t,conversation:n,intelligenceOpen:r,onToggleIntelligence:a,onBack:o,nextMessageId:i,previousMessageId:l,composeState:u}=Rn(),d=Me();if(n){const m=f=>d({to:"/mail/$mailboxId",params:{mailboxId:e},search:h=>({...h,selectedMessageId:f,selectedThreadId:void 0})});return s.jsxs(s.Fragment,{children:[s.jsx(us,{threadId:n.threadId,mailboxId:n.mailboxId,subject:n.subject,selectedMessageId:n.messageId,authenticity:n.authenticity,onBack:o,onOpenIntelligence:a,onSwipeNext:i?()=>m(i):void 0,onSwipePrevious:l?()=>m(l):void 0,mobileIntelligenceOpen:r}),s.jsx(Dr,{isOpen:r,onClose:a,ariaLabel:"Message details",side:"right",children:s.jsx(ms,{onClose:a,thread:t,hideCloseButton:!0})})]})}return u.isOpen?s.jsx("div",{className:"h-full",children:s.jsx(Vl,{})}):s.jsx(Zl,{})}const Ns=Object.assign(fv,{List:Zl,Reading:mv,Intelligence:hv,Phone:gv}),ec=e=>e==="failed"||e==="blocked",tc=e=>e!=="draft"&&e!=="sent",Hr="remit.savedSearches",pv=25;function un(){try{const e=localStorage.getItem(Hr);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(n=>typeof n=="string"):[]}catch{return[]}}function xv(e){const t=e.trim();if(!t)return un();const n=[t,...un().filter(r=>r!==t)].slice(0,pv);try{localStorage.setItem(Hr,JSON.stringify(n))}catch{return n}return n}function bv(e){const t=un().filter(n=>n!==e);try{localStorage.setItem(Hr,JSON.stringify(t))}catch{return t}return t}const uo=e=>/^\d/.test(e),vv=(e,t)=>{const n=uo(e),r=uo(t);return n&&!r?-1:!n&&r?1:e.localeCompare(t,void 0,{sensitivity:"base",numeric:!0})};function yv(e,t,n){const r=[],a=[];for(const o of e)t.has(o.mailboxId)?r.push(o):a.push(o);return a.sort((o,i)=>vv(es(o,void 0,n),es(i,void 0,n))),{system:r,labels:a}}function wv(e,t,n){const r=xu(t)&&e.unseenCount>0;return{id:e.mailboxId,name:es(e,t,n),unseen:r?e.unseenCount:void 0,role:t,fullPath:e.fullPath}}function jv(){const e=yn(),t=vr({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 fo({accounts:e,onMailboxSelect:t,variant:n="desktop"}){const r=je(),a=Me(),o=jv(),{searchInput:i,onSearchChange:l}=ve(),[u,d]=c.useState(un),{t:m}=fn("mail",{useSuspense:!1}),f=c.useCallback((N,R)=>m(N,{defaultValue:R}),[m]),h=Dt({queries:e.map(N=>({...Ze({path:{accountId:N.accountId}}),staleTime:1/0}))}),{data:x}=ie(mn()),b=c.useMemo(()=>(x?.items??[]).filter(N=>tc(N.status)).length,[x?.items]),p=c.useMemo(()=>e.map((N,R)=>{const A=h[R],E=A?.data?.items??[],M=is(N.folderAppointments),{system:I,labels:T}=yv(E,M,f),O=A?.isError?"error":A?.isLoading?"loading":"ready";return{id:N.accountId,label:N.email,email:N.email,muted:!!N.muted,outboxPending:b,status:O,onRetry:()=>A?.refetch(),mailboxes:[...I,...T].map(_=>wv(_,M.get(_.mailboxId),f))}}),[e,h,b,f]),v=N=>{r.invalidateQueries({queryKey:ot({path:{mailboxId:N},query:{order:"desc"}})})},g=({navId:N,className:R,ariaLabel:A,title:E,children:M,onClick:I})=>N==="brief"?s.jsx(rt,{to:"/mail",search:{q:void 0,selectedMessageId:void 0},onClick:()=>I?.(),className:R,"aria-label":A,title:E,children:M}):N==="outbox"?s.jsx(rt,{to:"/mail/outbox",search:{q:void 0,selectedOutboxMessageId:void 0},onClick:()=>I?.(),className:R,"aria-label":A,title:E,children:M}):N==="flagged"?s.jsx(rt,{to:"/mail/flagged",search:{q:void 0,selectedMessageId:void 0},onClick:()=>I?.(),className:R,"aria-label":A,title:E,children:M}):s.jsx(rt,{to:"/mail/$mailboxId",params:{mailboxId:N},search:{q:void 0,selectedMessageId:void 0},onClick:()=>{v(N),I?.()},className:R,"aria-label":A,title:E,children:M}),y=()=>{l(""),t?.()},j=i.trim(),w=j.length>0&&!u.includes(j)?j:void 0,C=c.useCallback(()=>{w&&d(xv(w))},[w]),k=c.useCallback(N=>{d(bv(N))},[]),S=c.useCallback(N=>{l(N),a({to:"/mail",search:{q:N,selectedMessageId:void 0}}),t?.()},[l,a,t]);return s.jsx(Wd,{accounts:p,selectedNavId:o,onSelectNav:y,linkComponent:g,variant:n,savedSearches:u,saveableQuery:w,onSaveCurrentSearch:C,onSelectSavedSearch:S,onRemoveSavedSearch:k})}function Sv({accounts:e,onMailboxSelect:t}){return os()?.showNavPane??!0?s.jsx(fo,{accounts:e}):s.jsxs("div",{className:"flex h-full flex-col",children:[s.jsx("div",{className:"flex-1 overflow-y-auto",children:s.jsx(fo,{accounts:e,onMailboxSelect:t,variant:"drawer"})}),s.jsxs("div",{className:"border-t border-line px-2 py-2",children:[s.jsxs(rt,{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(Xo,{className:"size-4 shrink-0"}),s.jsx("span",{className:"flex-1 truncate text-left",children:"Settings"})]}),s.jsx(Ai,{variant:"drawer"}),s.jsx(Ti,{children:({signOut:a})=>s.jsxs("button",{type:"button",onClick:()=>{t?.(),a()},className:"flex min-h-11 w-full items-center gap-2 rounded-md px-2 py-1 text-sm text-fg-muted transition-colors hover:bg-surface hover:text-fg","data-testid":"sign-out-button",children:[s.jsx(Wo,{className:"size-4 shrink-0"}),s.jsx("span",{className:"flex-1 truncate text-left",children:"Sign out"})]})})]})]})}function Nv(e,t){const n=t.trim().toLowerCase();if(n.length===0)return!0;const r=[e.subject,e.fromAddress,e.fromName,...e.toAddresses??[],...e.ccAddresses??[]].filter(a=>typeof a=="string").join(" ").toLowerCase();return n.split(/\s+/).every(a=>a.length===0||r.includes(a))}function kv(e){return e.tokens.length>0&&e.freeText.trim().length===0}const sc={queued:{icon:Nr,label:"Queued",className:"text-warning"},sending:{icon:Tt,label:"Sending…",className:"text-accent-2"},sent:{icon:Ko,label:"Sent",className:"text-positive"},failed:{icon:Rt,label:"Failed",className:"text-danger"},blocked:{icon:fr,label:"Blocked",className:"text-warning"}},Cv=e=>Eu(e).toDateString()===new Date().toDateString()?on(e,{hour:"numeric",minute:"2-digit"}):on(e,{month:"short",day:"numeric"}),mo=e=>on(e,{dateStyle:"medium",timeStyle:"short"}),Ev=e=>{const t=e.toAddresses??[];return t.length===0?"No recipients":t.length===1?t[0]:`${t[0]} +${t.length-1}`},nc=(e,t)=>t?"The outbox cannot filter on those terms":e?"No matching outbox messages":"No outbox messages",rc=c.createContext(null);function Wr(){const e=c.useContext(rc);if(!e)throw new Error("OutboxPane.* must be used inside <OutboxPane>");return e}function Iv({children:e}){const t=Me(),{selectedOutboxMessageId:n}=Zt({strict:!1}),{data:r,isLoading:a}=ie(mn()),{searchQuery:o}=ve(),i=ds(),l=qr(o),u=fs(l,i),d=l.length>0,m=kv(u),f=c.useMemo(()=>m?[]:(r?.items??[]).filter(p=>tc(p.status)).filter(p=>Nv(p,u.freeText)),[r,u.freeText,m]),h=c.useMemo(()=>f.find(p=>p.outboxMessageId===n),[f,n]),x=c.useCallback(p=>{t({to:"/mail/outbox",search:v=>({...v,selectedOutboxMessageId:p})})},[t]),b={messages:f,hasQuery:d,unsupportedQuery:m,isLoading:a,selectedMessageId:n,selectedMessage:h,onSelectMessage:x};return s.jsx(rc.Provider,{value:b,children:e})}function ac({message:e,isSelected:t,onSelect:n}){const r=je(),{openCompose:a}=xt(),{pushError:o}=Qe(),i=c.useCallback(()=>{r.invalidateQueries({queryKey:wr()})},[r]),l=pe({...Ro(),onSuccess:i,onError:f=>{o(Es("Couldn't resend message","The message wasn't sent.",f))}}),u=pe({...hn(),onSuccess:i,onError:f=>{o(Es("Couldn't delete message","The message wasn't deleted.",f))}}),d=e.status;if(!sc[d])return null;const m=ec(e.status);return s.jsx(If,{recipients:Ev(e),subject:e.subject||"",time:Cv(e.sentAt??e.updatedAt),status:d,error:m?e.lastError??void 0:void 0,selected:t,onSelect:n,onRetry:d==="failed"?()=>l.mutate({path:{outboxMessageId:e.outboxMessageId}}):void 0,retrying:l.isPending,onEdit:()=>a({mode:"new",outboxMessageId:e.outboxMessageId}),onDelete:()=>u.mutate({path:{outboxMessageId:e.outboxMessageId}}),deleting:u.isPending})}function oc({message:e,onBack:t}){const n=e.status,r=sc[n],a=r?.icon??As,o=e.sentAt?mo(e.sentAt):mo(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(Bo,{className:"size-4"}),s.jsx("span",{children:"Back"})]}),s.jsx("h1",{className:"text-xl font-semibold mb-3",children:e.subject||"(No subject)"}),s.jsxs("div",{className:"space-y-1 text-sm",children:[s.jsxs("div",{className:"flex gap-2",children:[s.jsx("span",{className:"text-fg-muted shrink-0 w-12",children:"From:"}),s.jsx("span",{className:"text-fg",children:e.fromName?`${e.fromName} <${e.fromAddress}>`:e.fromAddress})]}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx("span",{className:"text-fg-muted shrink-0 w-12",children:"To:"}),s.jsx("span",{className:"text-fg",children:(e.toAddresses??[]).join(", ")})]}),e.ccAddresses&&e.ccAddresses.length>0&&s.jsxs("div",{className:"flex gap-2",children:[s.jsx("span",{className:"text-fg-muted shrink-0 w-12",children:"Cc:"}),s.jsx("span",{className:"text-fg",children:e.ccAddresses.join(", ")})]}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx("span",{className:"text-fg-muted shrink-0 w-12",children:"Date:"}),s.jsx("span",{className:"text-fg",children:o})]}),r&&s.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[s.jsx(a,{className:fe("size-4",r.className,n==="sending"&&"animate-spin")}),s.jsx("span",{className:fe("text-xs font-medium",r.className),children:r.label}),ec(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(Sl,{html:e.htmlBody,text:e.textBody})})]})}function Rv(){const{messages:e,hasQuery:t,unsupportedQuery:n,isLoading:r,selectedMessageId:a,onSelectMessage:o}=Wr();return r?s.jsx("div",{className:"flex h-full items-center justify-center bg-canvas",children:s.jsx("span",{className:"text-fg-muted",children:"Loading..."})}):e.length===0?s.jsx("div",{className:"flex h-full bg-surface",children:s.jsx(cs,{message:nc(t,n),showHints:!1})}):s.jsxs("div",{className:"h-full flex flex-col bg-canvas",children:[s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[s.jsx(Qr,{}),s.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:"Outbox"}),s.jsxs("span",{className:"shrink-0 text-2xs text-fg-subtle",children:[e.length," ",e.length===1?"message":"messages"]})]}),s.jsx("div",{className:"flex-1 overflow-y-auto",children:e.map(i=>s.jsx(ac,{message:i,isSelected:a===i.outboxMessageId,onSelect:()=>o(i.outboxMessageId)},i.outboxMessageId))})]})}function Mv(){const{selectedMessage:e}=Wr();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(oc,{message:e}):s.jsx(cs,{message:"Select a message to read",showHints:!1})})]})}function Tv(){const{messages:e,hasQuery:t,unsupportedQuery:n,isLoading:r,selectedMessageId:a,selectedMessage:o,onSelectMessage:i}=Wr();return r?s.jsx("div",{className:"flex h-full items-center justify-center bg-canvas",children:s.jsx("span",{className:"text-fg-muted",children:"Loading..."})}):o?s.jsx(oc,{message:o,onBack:()=>i(void 0)}):e.length===0?s.jsx("div",{className:"flex h-full bg-surface",children:s.jsx(cs,{message:nc(t,n),showHints:!1})}):s.jsxs("div",{className:"h-full flex flex-col bg-canvas",children:[s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[s.jsx(Qr,{}),s.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:"Outbox"}),s.jsxs("span",{className:"shrink-0 text-2xs text-fg-subtle",children:[e.length," ",e.length===1?"message":"messages"]})]}),s.jsx("div",{className:"flex-1 overflow-y-auto",children:e.map(l=>s.jsx(ac,{message:l,isSelected:a===l.outboxMessageId,onSelect:()=>i(l.outboxMessageId)},l.outboxMessageId))})]})}const Zs=Object.assign(Iv,{List:Rv,Reading:Mv,Phone:Tv}),Av=({isOpen:e,onClose:t})=>{const n=c.useCallback(r=>{r.key==="Escape"&&(r.preventDefault(),t())},[t]);return c.useEffect(()=>{if(e)return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[e,n]),e?s.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",role:"dialog","aria-modal":"true","aria-label":"Keyboard shortcuts",onClick:t,onKeyDown:r=>r.key==="Escape"&&t(),children:[s.jsx("div",{className:"absolute inset-0 bg-canvas/80 backdrop-blur-sm"}),s.jsxs("div",{className:fe("relative z-10 max-h-[85vh] w-full max-w-2xl overflow-y-auto","rounded-lg border border-line bg-surface shadow-lg","p-6"),onClick:r=>r.stopPropagation(),onKeyDown:r=>{r.key!=="Escape"&&r.stopPropagation()},children:[s.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[s.jsx("h2",{className:"text-lg font-semibold",children:"Keyboard shortcuts"}),s.jsx("button",{type:"button",onClick:t,className:"p-1 text-fg-muted transition-colors hover:text-fg","aria-label":"Close",children:s.jsx(Ke,{className:"size-5"})})]}),s.jsx("div",{className:"grid gap-x-8 gap-y-6 sm:grid-cols-2",children:_i.map(r=>s.jsxs("div",{children:[s.jsx("h3",{className:"mb-3 text-sm font-medium text-fg-muted",children:r.title}),s.jsx("div",{className:"space-y-2",children:r.hints.map(a=>s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"text-sm",children:a.description}),s.jsx("span",{className:"flex shrink-0 items-center gap-1",children:a.keys.map((o,i)=>s.jsxs(c.Fragment,{children:[i>0&&a.keys[0]==="g"&&s.jsx("span",{className:"text-2xs text-fg-subtle",children:"then"}),s.jsx(Xt,{children:o})]},o))})]},`${a.action}-${a.keys.join("+")}`))})]},r.title))}),s.jsx("div",{className:"mt-6 border-t border-line pt-4",children:s.jsxs("p",{className:"text-center text-xs text-fg-muted",children:["Press ",s.jsx(Xt,{children:"Esc"})," to close"]})})]})]}):null};function Dv(e){const t=new Map;for(const n of e){const r=n.email.toLowerCase(),a=r.split("@")[0];a&&!t.has(a)&&t.set(a,n.accountId),t.has(r)||t.set(r,n.accountId)}return t}function Ov(e){const t=new Map;for(const n of e)for(const r of n){const a=r.fullPath?.toLowerCase();if(!a)continue;const o=a.split("/").pop();t.has(a)||t.set(a,r.mailboxId),o&&!t.has(o)&&t.set(o,r.mailboxId)}return t}function Pv(e){const t=Dt({queries:e.map(n=>({...Ze({path:{accountId:n.accountId}}),staleTime:1/0}))});return c.useMemo(()=>Ov(t.map(n=>n.data?.items??[])),[t])}var en={exports:{}},ho;function Lv(){if(ho)return en.exports;ho=1;const e=(t,n,r)=>new Promise((a,o)=>{if(r=Object.assign({concurrency:1/0},r),typeof n!="function")throw new TypeError("Mapper function is required");const{concurrency:i}=r;if(!(typeof i=="number"&&i>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${i}\` (${typeof i})`);const l=[],u=t[Symbol.iterator]();let d=!1,m=!1,f=0,h=0;const x=()=>{if(d)return;const b=u.next(),p=h;if(h++,b.done){m=!0,f===0&&a(l);return}f++,Promise.resolve(b.value).then(v=>n(v,p)).then(v=>{l[p]=v,f--,x()},v=>{d=!0,o(v)})};for(let b=0;b<i&&(x(),!m);b++);});return en.exports=e,en.exports.default=e,en.exports}var zv=Lv();const Fv=du(zv),_v=900*1e3,Bv=300,$v=(e,t)=>{if(!e)return t;const n=Number.parseInt(e,10);return Number.isFinite(n)&&n>0?n:t},Kv=60*1e3,qv=e=>Math.max($v(e,Bv)*1e3,Kv),rn=qv(hu().mailboxPollIntervalSeconds),Uv=5,cr=new Set,Qv=(e,t,n=_v)=>e.filter(r=>{const a=r.lastSyncAt;return a==null?!0:t-a>n}).map(r=>r.accountId),Hv=(e,t,n=rn)=>e-t>=n,Wv=(e,t)=>e.filter(n=>!t.has(n)),go=(e,t)=>{if(cr.delete(e),mu(t,{softError:!0})){Do(t);return}console.warn("[remit] background mailbox sync failed",{accountId:e,error:t})},po=(e,t)=>fu({path:{accountId:e},throwOnError:!0}).then(()=>{t.invalidateQueries({queryKey:as({path:{accountId:e}})})}),Vv=e=>{const t=je(),n=c.useRef(e);n.current=e;const r=e.map(a=>a.accountId).join(",");c.useEffect(()=>{const a=Date.now(),i=Qv(n.current,a).filter(l=>!cr.has(l));if(i.length!==0)for(const l of i)cr.add(l),po(l,t).catch(u=>{go(l,u)})},[r,t]),c.useEffect(()=>{let a=Date.now(),o;const i=new Set,l=()=>{a=Date.now();const m=Wv(n.current.map(f=>f.accountId),i);for(const f of m)i.add(f);Fv(m,f=>po(f,t).catch(h=>{go(f,h)}).finally(()=>{i.delete(f)}),{concurrency:Uv})},u=()=>{if(document.visibilityState==="visible"){l(),o=setTimeout(u,rn);return}},d=()=>{document.visibilityState==="visible"&&Hv(Date.now(),a)&&(o!==void 0&&clearTimeout(o),l(),o=setTimeout(u,rn))};return o=setTimeout(u,rn),document.addEventListener("visibilitychange",d),()=>{o!==void 0&&clearTimeout(o),document.removeEventListener("visibilitychange",d)}},[r,t])};function Yv(e,t,n){if(e!==t)return n}function Gv(e,t){return e===""?"":t}function Xv(e,t,n){return t!==e?!1:t!==n}function Jv(){const{q:e=""}=Zt({from:"/mail"}),t=Me(),n=Cn(),r=Tl(n),[a,o]=c.useState(!1),[i,l]=c.useState(!1),[u,d]=c.useState(!1),m=c.useCallback(G=>{d(G),co(G)},[]),[f,h]=c.useState(e),x=Oo(f,200),b=Gv(f,x),p=c.useRef(e);p.current=e;const v=mt({select:G=>Ah(G.matches)}),[g,y]=c.useState(v);if(g!==v){const G=Yv(g,v,e);y(v),G!==void 0&&h(G)}c.useEffect(()=>{Xv(f,b,p.current)&&t({to:".",search:G=>{const ue=G.q===b;return{...G,q:b||void 0,...b&&!ue?{selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0}:{}}},replace:!0})},[f,b,t]);const{data:j,isLoading:w,isError:C,error:k,refetch:S}=ie({...at(),staleTime:1/0}),N=!!(j&&(j.accounts?.length??0)===0);c.useEffect(()=>{N&&t({to:"/onboarding",replace:!0})},[N,t]),Pr({enabled:!a,bindings:[{key:"?",handler:()=>o(!0),noModifiers:!1,preventDefault:!0}]});const R=c.useCallback(G=>{h(G)},[]),A=c.useCallback(()=>{h("")},[]),E=c.useCallback(()=>{h("")},[]),M=c.useCallback(()=>{d(G=>{const ue=!G;return co(ue),ue})},[]),I=j?.accounts??[],T=Pv(I),O=c.useMemo(()=>Dv(I),[I]),_=mt({select:G=>G.matches.find(le=>"mailboxId"in le.params)?.params.mailboxId}),{selectedMessageId:q}=Zt({strict:!1}),X=mt({select:G=>Ar(G.matches)}),F=mt({select:G=>wn(G.matches)}),$=mt({select:G=>jn(G.matches)});Vv(I);const ae=c.useCallback(()=>{l(!1)},[]),ce={accounts:I,mailboxNameIndex:T,accountNameIndex:O,searchQuery:b,searchInput:f,searchViewKey:v,onSearchChange:R,onSearchClear:A,onSearchClearQuery:E,intelligenceOpen:u,onToggleIntelligence:M,onSetIntelligenceOpen:m},J=s.jsx(Sv,{accounts:I,onMailboxSelect:ae}),D=r?s.jsx(Rh,{accounts:I}):void 0,P=r?void 0:s.jsx($h,{accounts:I}),Q={navOpen:i,onOpenNav:()=>l(!0),onCloseNav:()=>l(!1)};return s.jsxs(gu.Provider,{value:ce,children:[C?s.jsx("div",{className:"flex h-full items-center justify-center bg-canvas p-4",children:s.jsx(yt,{title:"Couldn't load your account",error:k,onRetry:()=>{S()}})}):X?s.jsx(ys,{selectedMessageId:q,children:r?s.jsx(ut,{nav:J,list:s.jsx(ys.Phone,{}),intelligenceOpen:u,overlay:D,skeleton:s.jsx(nt,{}),isLoading:w||N,...Q}):s.jsx(ut,{nav:J,topBar:P,list:s.jsx(ys.List,{}),reading:s.jsx(ys.Reading,{}),intelligence:s.jsx(ys.Intelligence,{}),intelligenceOpen:u,hasThread:!!q,overlay:D,skeleton:s.jsx(nt,{}),isLoading:w||N,...Q})}):F?s.jsx(ws,{selectedMessageId:q,children:r?s.jsx(ut,{nav:J,list:s.jsx(ws.Phone,{}),intelligenceOpen:u,overlay:D,skeleton:s.jsx(nt,{}),isLoading:w||N,...Q}):s.jsx(ut,{nav:J,topBar:P,list:s.jsx(ws.List,{}),reading:s.jsx(ws.Reading,{}),intelligence:s.jsx(ws.Intelligence,{}),intelligenceOpen:u,hasThread:!!q,overlay:D,skeleton:s.jsx(nt,{}),isLoading:w||N,...Q})}):_?s.jsx(Ns,{mailboxId:_,selectedMessageId:q,children:r?s.jsx(ut,{nav:J,list:s.jsx(Ns.Phone,{}),intelligenceOpen:u,overlay:D,skeleton:s.jsx(nt,{}),isLoading:w||N,...Q}):s.jsx(ut,{nav:J,topBar:P,list:s.jsx(Ns.List,{}),reading:s.jsx(Ns.Reading,{}),intelligence:s.jsx(Ns.Intelligence,{}),intelligenceOpen:u,hasThread:!!q,overlay:D,skeleton:s.jsx(nt,{}),isLoading:w||N,...Q})}):$?s.jsx(Zs,{children:r?s.jsx(ut,{nav:J,list:s.jsx(Zs.Phone,{}),intelligenceOpen:!1,overlay:D,skeleton:s.jsx(nt,{}),isLoading:w||N,...Q}):s.jsx(ut,{nav:J,topBar:P,list:s.jsx(Zs.List,{}),reading:s.jsx(Zs.Reading,{}),intelligenceOpen:!1,overlay:D,skeleton:s.jsx(nt,{}),isLoading:w||N,...Q})}):s.jsx(nt,{}),s.jsx(Av,{isOpen:a,onClose:()=>o(!1)}),s.jsx(pu,{})]})}const gy=Object.freeze(Object.defineProperty({__proto__:null,component:Jv,useMailContext:ve},Symbol.toStringTag,{value:"Module"}));export{hy as S,Uu as U,gy as m};
|