@remit/web-client-dist 0.0.372 → 0.0.373

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/assets/{BriefPane-BDUlX1dd.js → BriefPane-BZi_aEKt.js} +1 -1
  2. package/assets/{ErrorState-CNRyRb6l.js → ErrorState-WGrYWxuU.js} +1 -1
  3. package/assets/FlaggedPane-C2iEXZTu.js +1 -0
  4. package/assets/{FullCompose-sO0aEoyo.js → FullCompose-CE_sqive.js} +1 -1
  5. package/assets/MailListHeader-D1EP0Mvb.js +7 -0
  6. package/assets/{MailViewChrome-CUDvmwTn.js → MailViewChrome-B0RnNca9.js} +1 -1
  7. package/assets/{MailboxPane-DbcxmYLE.js → MailboxPane-DWkh2FLP.js} +1 -1
  8. package/assets/{NavMenuButton-BmjnuYnv.js → NavMenuButton-CSBomLqq.js} +1 -1
  9. package/assets/{OnboardingWizard-NmbXX13A.js → OnboardingWizard-Dw8Y8lna.js} +1 -1
  10. package/assets/{OutboxPane-CuFD7jTd.js → OutboxPane-B3iAgf5b.js} +1 -1
  11. package/assets/_mailboxId-D-DnfySx.js +1 -0
  12. package/assets/_messageId-B2NdRuIB.js +1 -0
  13. package/assets/_messageId-BKSVcJhD.js +1 -0
  14. package/assets/_messageId-DroAUmHv.js +1 -0
  15. package/assets/_outboxMessageId-CYD-7dua.js +1 -0
  16. package/assets/_threadId-BCNf8KAg.js +1 -0
  17. package/assets/_threadId-DI5UuEt2.js +1 -0
  18. package/assets/_threadId-DnnV5Nxm.js +1 -0
  19. package/assets/{accounts-idwnTro-.js → accounts-WbDk3ns5.js} +1 -1
  20. package/assets/{advanced-BtUfq8Sd.js → advanced-B-Pkzxyo.js} +1 -1
  21. package/assets/{appearance-D_C_f5Pv.js → appearance-B6EMh1Yv.js} +1 -1
  22. package/assets/{attachment-file-CmBlR4Nw.js → attachment-file-DxHCGaVA.js} +1 -1
  23. package/assets/{avatar-DADuvAhc.js → avatar-DOcUvLmy.js} +1 -1
  24. package/assets/{bottom-sheet-DkNRMhO-.js → bottom-sheet-cWbZOtLT.js} +1 -1
  25. package/assets/brief-CVU8p537.js +1 -0
  26. package/assets/{brief-RCH5MtG1.js → brief-DuSltoZJ.js} +1 -1
  27. package/assets/{browser-ponyfill-BHPGYQtP.js → browser-ponyfill-ClXjI9iy.js} +1 -1
  28. package/assets/{bug-B1DCV8k2.js → bug-DqhuT0S8.js} +1 -1
  29. package/assets/{circle-check-CZ6Y-mRM.js → circle-check-PV3f07l3.js} +1 -1
  30. package/assets/{circle-check-big-CcGlW81M.js → circle-check-big-CZn0ayhn.js} +1 -1
  31. package/assets/{circle-help-BgtRhroK.js → circle-help-DtBvvpll.js} +1 -1
  32. package/assets/{clock-BAfOPOro.js → clock-7hrnAMXu.js} +1 -1
  33. package/assets/compose._-_outboxMessageId_-5epLswPH.js +1 -0
  34. package/assets/compose._-_outboxMessageId_-BRXLPv8E.js +1 -0
  35. package/assets/compose._-_outboxMessageId_-CxsdkbNB.js +1 -0
  36. package/assets/compose._-_outboxMessageId_-Dre-CSnM.js +1 -0
  37. package/assets/{confirm-dialog-D9gyhlPW.js → confirm-dialog-WJVmZbjC.js} +1 -1
  38. package/assets/{download-CiIP3hvx.js → download-DxzBCaT5.js} +1 -1
  39. package/assets/{filters-C3OBPVW-.js → filters-B30W9jbr.js} +1 -1
  40. package/assets/{flagged-BTDPgxgF.js → flagged-BBtTQTdS.js} +1 -1
  41. package/assets/flagged-xoN1EtZX.js +1 -0
  42. package/assets/{folders-DKVIZCXc.js → folders-DB4kKfKN.js} +1 -1
  43. package/assets/index-B2NdRuIB.js +1 -0
  44. package/assets/index-Bp41sfOw.js +1 -0
  45. package/assets/index-CVSD0sMl.js +1 -0
  46. package/assets/{index-CruZwy_j.js → index-CdDX4Aix.js} +54 -54
  47. package/assets/index-ClhixJ7m.js +1 -0
  48. package/assets/index-D0Gmx1jS.js +1 -0
  49. package/assets/index-DO-TnDyk.js +1 -0
  50. package/assets/index-DrkRmWLy.js +46 -0
  51. package/assets/index-DroAUmHv.js +1 -0
  52. package/assets/index-QEreRUpn.js +1 -0
  53. package/assets/{kbd-CPpFVi9O.js → kbd-BEXM-I0X.js} +1 -1
  54. package/assets/{labels-Caie2UeA.js → labels-DXi3bjxb.js} +1 -1
  55. package/assets/{mail-C1G9szr-.js → mail-BR_rIUxg.js} +1 -1
  56. package/assets/{mail-CvhP0j2e.js → mail-BuEsczSz.js} +1 -1
  57. package/assets/{menu-Csa6gu1E.js → menu-CmqMnJvh.js} +1 -1
  58. package/assets/{move-options-XwMlkuRe.js → move-options-BPevoCXc.js} +1 -1
  59. package/assets/{onboarding-DXQhAMkk.js → onboarding-Baoq1ug6.js} +1 -1
  60. package/assets/outbox-wzh-SgB_.js +1 -0
  61. package/assets/{pencil-DHiKxe2W.js → pencil-nhqo3z_q.js} +1 -1
  62. package/assets/{rich-text-C9mGofSm.js → rich-text-qXbLsxFA.js} +1 -1
  63. package/assets/{rich-text-spellcheck-worker-provider-ofHr_Ndk.js → rich-text-spellcheck-worker-provider-1N9kepb6.js} +1 -1
  64. package/assets/{rotate-ccw-BSKwjQcA.js → rotate-ccw-BZfuBNmh.js} +1 -1
  65. package/assets/{row-actions-BxDbSihO.js → row-actions-BaUs_LqY.js} +1 -1
  66. package/assets/{search-scope-BhgcAbIG.js → search-scope-ISFv18Tx.js} +1 -1
  67. package/assets/{search-token-index-Bduf_pxP.js → search-token-index-LDBCO_Kw.js} +1 -1
  68. package/assets/{search-view-D0WpJ5LA.js → search-view-B3zs_vi9.js} +1 -1
  69. package/assets/{senders-DQj-mz1j.js → senders-skxKRHMS.js} +1 -1
  70. package/assets/settings-CF-lDjes.js +1 -0
  71. package/assets/{settings-screen-Dr5expLP.js → settings-screen-oX6cegXP.js} +1 -1
  72. package/assets/{shield-check-DiUF5wWn.js → shield-check-yjZblOtm.js} +1 -1
  73. package/assets/{suggested-vips-C2YZDZ28.js → suggested-vips-CDB3gIYK.js} +1 -1
  74. package/assets/{useDebouncedValue-DOo7UPcD.js → useDebouncedValue-CGuhyli4.js} +1 -1
  75. package/assets/{useFilters-DloCKDYh.js → useFilters-BmVyD1yI.js} +1 -1
  76. package/assets/{useLabels-zav64w0S.js → useLabels-D78oY1RR.js} +1 -1
  77. package/assets/{useMediaQuery-C5e0Az56.js → useMediaQuery-D8qC0uHL.js} +1 -1
  78. package/assets/{useMessageBodyContent-DPqly9Qg.js → useMessageBodyContent-0MCTPuF1.js} +1 -1
  79. package/assets/{useRefreshControl-BliVFItV.js → useRefreshControl-CrEecOQC.js} +1 -1
  80. package/assets/{useSearchMirror-DsCLU4Os.js → useSearchMirror-Bj6ucnqh.js} +1 -1
  81. package/assets/{useSearchTokenContext-D18dJFny.js → useSearchTokenContext-C2D9az6p.js} +1 -1
  82. package/assets/{useSemanticSearch-BnRS-ivx.js → useSemanticSearch-oXsRInm8.js} +1 -1
  83. package/assets/{useSignature-B2YdvIEW.js → useSignature-C_yr3j0p.js} +1 -1
  84. package/index.html +1 -1
  85. package/package.json +1 -1
  86. package/assets/FlaggedPane-Y2qJ-pRo.js +0 -1
  87. package/assets/MailListHeader-D31JcI05.js +0 -7
  88. package/assets/_mailboxId-BMoBs8x5.js +0 -1
  89. package/assets/_messageId-DZ-036Eg.js +0 -1
  90. package/assets/_messageId-DwLC2u56.js +0 -1
  91. package/assets/_messageId-DxTnKS-9.js +0 -1
  92. package/assets/_outboxMessageId-BGSaMsgb.js +0 -1
  93. package/assets/_threadId-D1gZ7Nwd.js +0 -1
  94. package/assets/_threadId-Dboy5fMG.js +0 -1
  95. package/assets/_threadId-I8cwucoX.js +0 -1
  96. package/assets/brief-DICffxfb.js +0 -1
  97. package/assets/compose._-_outboxMessageId_-BDqy5AQx.js +0 -1
  98. package/assets/compose._-_outboxMessageId_-BLvXHEbf.js +0 -1
  99. package/assets/compose._-_outboxMessageId_-DLTwyDE0.js +0 -1
  100. package/assets/compose._-_outboxMessageId_-yO7wXDO3.js +0 -1
  101. package/assets/flagged-DqZib9uq.js +0 -1
  102. package/assets/index-B7lXGXvZ.js +0 -1
  103. package/assets/index-BOTjtS9M.js +0 -46
  104. package/assets/index-CevfsXBN.js +0 -1
  105. package/assets/index-D0jtKZ0E.js +0 -1
  106. package/assets/index-DZ-036Eg.js +0 -1
  107. package/assets/index-Din4hbj5.js +0 -1
  108. package/assets/index-DxTnKS-9.js +0 -1
  109. package/assets/index-tumrcnwg.js +0 -1
  110. package/assets/index-wvh1_3xJ.js +0 -1
  111. package/assets/outbox-BLDXNwHc.js +0 -1
  112. package/assets/settings-vtqgdivN.js +0 -1
@@ -1 +1 @@
1
- import{j as a,af as Ze,S as Xe,bh as es,l as E,bb as ss,m as oe,r as o,s as ae,bi as ne,q as ts,bj as as,bk as ns,bl as os,e as Te,bm as rs,i as is}from"./index-CruZwy_j.js";import{s as Re,a as ls,b as Me,u as cs,p as ds,R as us}from"./useSearchTokenContext-D18dJFny.js";import{a2 as ve,D as ye,a3 as ms,a4 as fs,E as hs,a5 as Se,a6 as gs,a7 as xs,a8 as ps,a1 as Is,a9 as bs,aa as vs,ab as ys,M as Ss,ac as Cs,ad as js,ae as Ts,e as Rs,v as Ms,af as ws,r as ks,S as As,H as Fs,L as Ce,K as Ns,I as Bs,d as Os,W as Ls,X as we,Y as Es,Z as ke,_ as Ds}from"./MailListHeader-D31JcI05.js";import{u as Ps,a as qs,R as zs,i as Hs,b as Qs}from"./useRefreshControl-BliVFItV.js";import{e as _s,c as $s,R as Ws}from"./search-token-index-Bduf_pxP.js";import{a as Us}from"./useLabels-zav64w0S.js";import{u as Vs}from"./useMediaQuery-C5e0Az56.js";import{u as Ys,L as Gs}from"./useSemanticSearch-BnRS-ivx.js";import{n as Js,e as Ks,g as Zs,o as Xs,r as et}from"./useMessageBodyContent-DPqly9Qg.js";function st({sync:e}){return e?a.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 py-12 text-center px-4",role:"status","aria-live":"polite",children:[a.jsx(Ze,{className:"size-8 animate-spin text-fg-subtle","aria-hidden":"true"}),a.jsx("p",{className:"text-sm font-medium text-fg",children:"Still syncing your mail"}),a.jsx("p",{className:"text-xs text-fg-subtle",children:tt(e)})]}):a.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 py-12 text-center px-4",children:[a.jsx(Xe,{className:"size-8 text-fg-subtle","aria-hidden":"true"}),a.jsx("p",{className:"text-sm font-medium text-fg",children:"You're caught up"}),a.jsx("p",{className:"text-xs text-fg-subtle",children:"Nothing needs attention."})]})}function tt({synced:e,total:s}){return s>0?`${e.toLocaleString()} of ${s.toLocaleString()} messages downloaded. This list fills in as they arrive.`:"Downloading your messages. This list fills in as they arrive."}const Ae=[{id:"unread",name:"is",value:"unread"},{id:"attachment",name:"has",value:"attachment"}],Fe="category",at={unclassified:"uncategorized"},W=e=>ls(e).map(s=>s.raw),$=e=>e.join(" "),re=e=>{const s=Me(e);if(s)return Ae.find(n=>n.name===s.name&&n.value===s.value.toLowerCase())?.id},ie=e=>{const s=Me(e);if(!s||s.name!==Fe)return;const n=s.value.toLowerCase(),r=at[n];if(r)return r;if(!(!es(n)||n==="all"))return n},Ne=e=>Ae.find(s=>s.id===e),Be=e=>Ne(e)!==void 0,nt=e=>{const s=new Set;for(const n of W(e)){const r=re(n);r&&s.add(r)}return s},ot=e=>{let s="all";for(const n of W(e)){const r=ie(n);r&&(s=r)}return s},rt=(e,s)=>{const n=Ne(s);if(!n)return;const r=W(e),d=r.filter(l=>re(l)!==s);return d.length<r.length?$(d):$([...r,Re(n.name,n.value)])},it=(e,s)=>{const n=W(e).filter(r=>!ie(r));return $(s==="all"?n:[...n,Re(Fe,s)])},lt=e=>$(W(e).filter(s=>!re(s)&&!ie(s))),Oe=e=>e.trim().length>0,ct=e=>{if(!Oe(e.query))return e.ownFilters;const s=new Set(nt(e.query));for(const n of e.ownFilters)Be(n)||s.add(n);return s},dt=e=>Oe(e.query)?ot(e.query):e.ownCategory,ut=(e,s)=>e.createdAt!==s.createdAt?e.createdAt-s.createdAt:e.accountId.localeCompare(s.accountId),mt=e=>[...e].sort(ut),ft=200,je=()=>a.jsx("div",{className:"animate-pulse",children:Array.from({length:3}).map((e,s)=>a.jsxs("div",{className:"flex items-start gap-3 py-2 pl-5 pr-4 border-b border-line",children:[a.jsx("div",{className:"size-7 rounded-full bg-surface-sunken shrink-0 mt-0.5"}),a.jsxs("div",{className:"flex-1 space-y-1.5",children:[a.jsxs("div",{className:"flex justify-between gap-2",children:[a.jsx("div",{className:"h-3.5 bg-surface-sunken rounded w-28"}),a.jsx("div",{className:"h-3 bg-surface-sunken rounded w-12"})]}),a.jsx("div",{className:"h-3.5 bg-surface-sunken rounded w-48"}),a.jsx("div",{className:"h-3 bg-surface-sunken rounded w-full"})]})]},s))}),ht=({accountEmail:e})=>{const s=oe();return a.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:[a.jsx(Te,{className:"size-3.5 shrink-0"}),a.jsxs("span",{className:"flex-1 truncate",children:[e," can't connect"]}),a.jsx("button",{type:"button",onClick:()=>s({to:"/settings/accounts"}),className:"shrink-0 underline text-danger hover:opacity-80",children:"Reconnect"})]})},gt=(e,s)=>{if(s.size===0)return{};const n=new Set,r=new Set;for(const l of e)s.has(l.id)&&(l.accountId&&n.add(l.accountId),l.mailboxId&&r.add(l.mailboxId));if(n.size>1)return{restriction:"spansAccounts",moveDisabledHint:"Move only works within one account — clear selection or pick messages from a single account"};const d=n.size===1?[...n][0]:void 0;return r.size>1?{accountId:d,restriction:"spansFolders",moveDisabledHint:`Move only works within one folder — this selection spans ${r.size} folders`}:{accountId:d,mailboxId:r.size===1?[...r][0]:void 0}};function xt({header:e,rows:s,wizard:n,children:r}){const{selectedIds:d,selectedCount:l,exitSelection:g,orderedIds:m,allSelected:u,toggleAllLoaded:S}=Ts(),p=o.useMemo(()=>gt(s,d),[s,d]),{junkMailboxId:I}=Rs(p.accountId),{labels:b}=Us(p.accountId),F=o.useMemo(()=>Array.from(d),[d]),D=o.useMemo(()=>s.filter(x=>d.has(x.id)).map(x=>({id:x.id,sender:x.fromName,email:x.fromEmail,subject:x.subject,date:x.timeLabel})),[s,d]),f=Ms(I,p.mailboxId),v=o.useMemo(()=>m.length>0?{checked:u,indeterminate:l>0&&!u,onChange:S}:void 0,[m.length,u,l,S]),N=p.moveDisabledHint?{tone:"warning",text:p.moveDisabledHint}:void 0,C=x=>a.jsx(As,{title:x.title,navSlot:x.navSlot,titleMeta:x.titleMeta,searchSlot:x.searchSlot,searchField:x.searchField,idleSlot:x.makeFilterSlot,count:l,onCancel:g,onDelete:()=>n.start("delete"),onMove:()=>n.start("move"),onOrganize:()=>n.start("organize"),onJunk:f?()=>n.start("junk"):void 0,onMarkRead:()=>n.start("markRead"),overflowSlot:p.accountId&&p.mailboxId&&l>0&&b.length>0?a.jsx(Gs,{accountId:p.accountId,mailboxId:p.mailboxId,messageIds:F}):void 0,selectAll:v,notice:N});return a.jsx(ws,{...e,selectionBar:C,paneOverlay:a.jsx(ks,{verb:n.verb,accountId:p.accountId,mailboxId:p.mailboxId,selection:D,selectionRestriction:p.restriction,onFinished:g}),children:r})}function pt({accounts:e,selectedMessageId:s,onOpenThread:n,commandsRef:r,onTriageContextChange:d,onDeleteMessages:l}){const{searchQuery:g,searchInput:m,resultFolderIndex:u,onSearchChange:S}=E(),p=cs(),I=Vs(),b=_s(),F=ss(),D=oe(),f=o.useMemo(()=>mt(e.filter(t=>!t.muted?.value)),[e]),[v,N]=o.useState("all"),[C,x]=o.useState("all"),[U,P]=o.useState(new Set),[K,j]=o.useState(!1),q=o.useCallback(t=>{P(i=>{const c=new Set(i);return c.has(t)?c.delete(t):c.add(t),c})},[]),V=o.useCallback(()=>P(new Set),[]),R=m.trim().length>0,T=o.useMemo(()=>ct({query:m,ownFilters:U}),[m,U]),M=o.useMemo(()=>dt({query:m,ownCategory:C}),[m,C]),B=o.useCallback(t=>{if(!R||!Be(t)){q(t);return}const i=rt(m,t);i!==void 0&&S(i)},[R,m,S,q]),z=o.useCallback(t=>{if(!R){x(t);return}S(it(m,t))},[R,m,S]),H=o.useCallback(()=>{x("all"),N("all"),V(),R&&S(lt(m))},[R,m,S,V]),{data:O,isLoading:Q,isError:h,refetch:L}=ae({...ne(),staleTime:6e4}),w=$s({queries:f.map(t=>({...ts({path:{accountId:t.accountId}}),staleTime:1/0,meta:{softError:!0}}))}),Y=o.useMemo(()=>{const t=new Map;for(let i=0;i<f.length;i++){const c=f[i].accountId,Ge=(w[i]?.data?.items??[]).reduce((Je,Ke)=>Je+(Ke.unseenCount??0),0);t.set(c,Ge)}return t},[f,w]),De=o.useMemo(()=>f.filter((t,i)=>{const c=w[i];return c?.isError?!as(c.error):!1}),[f,w]),{freeText:k,tokens:Z}=ds(g.trim().toLowerCase(),p),{data:le,isFetching:Pe}=ae({...ne({query:{query:k,limit:ft}}),enabled:k.length>0,staleTime:3e4}),y=o.useMemo(()=>{const t=ve(O?.items??[]).map(ye);return(k?ms(t.filter(c=>fs(c,k)),ve(le?.items??[]).map(ye)):t).filter(c=>(v==="all"||c.accountId===v)&&hs(c,Z))},[O,le,v,k,Z]),{bodyRows:ce,briefSpamOffer:X}=o.useMemo(()=>{if(!k)return{bodyRows:y,briefSpamOffer:void 0};const t=y.map(A=>Se(A,u)),{spam:i}=gs(t);if(i.length===0)return{bodyRows:y,briefSpamOffer:void 0};const c=new Set(i.map(A=>A.id));return{bodyRows:y.filter(A=>!c.has(A.id)),briefSpamOffer:xs(t)}},[y,k,u]),de=o.useMemo(()=>ps(ce),[ce]),ue=o.useCallback((t,i)=>{const c=y.find(A=>A.id===t)?.threadId;c&&n?.({threadId:c,messageId:t},i)},[y,n]),qe=o.useCallback(t=>{const i=t.threadId??y.find(c=>c.id===t.id)?.threadId;i&&n?.({threadId:i,messageId:t.id})},[y,n]),ee=o.useMemo(()=>f.length<=1?[]:[{id:"all",label:"All",active:v==="all"},...f.map(t=>({id:t.accountId,label:t.email.split("@")[0]??t.email,count:Y.get(t.accountId),active:v===t.accountId}))],[f,Y,v]),_=o.useMemo(()=>e.filter(t=>t.muted?.value).length,[e]),ze=o.useMemo(()=>Array.from(Y.values()).reduce((t,i)=>t+i,0),[Y]),se=o.useMemo(()=>f.map(t=>t.accountId),[f]),{hasNewMail:me}=Ps(),{state:fe,errorMessage:he,refresh:ge}=qs(se,{onSettled:()=>L()}),He=o.useMemo(()=>a.jsx(zs,{state:fe,onRefresh:ge,label:"Refresh daily brief",errorMessage:he,hasUpdate:me(se)}),[fe,ge,he,me,se]),te=o.useMemo(()=>y.filter(t=>(M==="all"||t.category===M)&&ns(t,T)).map(t=>Se(t,u)),[y,M,T,u]),{hits:xe,isLoading:Qe}=Ys(),_e=o.useMemo(()=>{const t=new Map;for(const c of O?.items??[])t.set(c.messageId,c.threadId);const i=te.map(c=>t.get(c.id)).filter(c=>c!=null);return Is(xe,i,u)},[xe,te,O,u]),$e=o.useMemo(()=>{const t=bs(ee.map(i=>({id:i.id,label:i.label,count:i.count,active:i.active})));return{categories:t.categories,filters:t.filters,sources:t.sources,sourcesNote:_>0?`+${_} muted`:void 0,selectedCategory:M,activeFilters:T,expanded:K,onExpandedChange:j,onSelectCategory:i=>z(i),onSelectSource:N,onToggleFilter:i=>B(i),onClear:H}},[ee,_,M,T,K,B,z,H]),pe=de.length===0&&v==="all"&&k.length===0&&Z.length===0,We=o.useMemo(()=>f.map(t=>t.accountId),[f]),Ue=o.useMemo(()=>f.some(t=>Hs(t.syncPhase)),[f]),G=Qs(We,pe||Ue),Ie=a.jsxs("div",{className:"h-full overflow-y-auto",children:[a.jsx(je,{}),a.jsx(je,{})]}),be=!Q&&!h&&!pe,Ve=vs({tier:b,hasLiveInput:R,hasCommittedQuery:g.trim().length>0,bodyRendersCommittedResults:!0}),Ye=be?a.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[X&&a.jsx(ys,{count:X.count,onScopeToSpam:()=>D({to:"/mail/$mailboxId",params:{mailboxId:X.mailboxId},search:{q:g||void 0}})}),a.jsx("div",{className:"min-h-0 flex-1",children:a.jsx(os,{sections:de,briefCategory:M,Row:Ss,selectedThreadId:s,onSelectThread:ue,onSelectBriefCategory:z,sources:ee,sourcesNote:_>0?`+${_} muted`:void 0,onSelectSource:N,activeFilters:T,onToggleFilter:B,onClearFilters:H})})]}):Q?Ie:h?a.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 py-12 text-sm text-fg-muted",children:[a.jsx(Te,{className:"size-8 text-danger"}),a.jsx("p",{children:"Couldn't load your messages"}),a.jsxs("button",{type:"button",onClick:()=>L(),className:"flex items-center gap-1 text-accent underline text-xs",children:[a.jsx(Ws,{className:"size-3.5"}),"Try again"]})]}):G.resolved?a.jsx(st,{sync:G.syncing?{synced:G.synced,total:G.total}:void 0}):Ie;return a.jsx(rs,{hasSheet:be&&!Ve,children:a.jsx(Cs,{selectedMessageId:s,onOpen:ue,onDeleteMessages:l,onSelectionVerb:F.start,wizardOpen:F.isOpen,commandsRef:r,onTriageContextChange:d,children:a.jsx(xt,{wizard:F,header:{title:"Daily brief",unreadCount:ze,footer:I?a.jsx(js,{}):void 0,searchFilter:$e,searchResults:te,searchLoading:Q||Pe,relatedResults:_e,relatedLoading:Qe,onSelectSearchResult:qe,searchResultsInBody:!0,refreshControl:He},rows:y,children:a.jsxs("div",{className:"flex h-full flex-col",children:[De.map(t=>a.jsx(ht,{accountEmail:t.email,accountId:t.accountId},t.accountId)),a.jsx("div",{className:"min-h-0 flex-1",children:Ye})]})})})})}const Le=o.createContext(null);function J(){const e=o.useContext(Le);if(!e)throw new Error("BriefPane.* must be used inside <BriefPane>");return e}function It({thread:e,children:s}){const n=oe(),r=Js(),{searchInput:d}=E(),l=e?.threadId,g=e?.messageId,{data:m}=ae({...ne(),staleTime:6e4}),u=o.useMemo(()=>m?.items??[],[m]),S=o.useMemo(()=>{if(l)return u.find(h=>h.messageId===g)??u.find(h=>h.threadId===l)},[u,l,g]),p=Fs(l,g),I=S??p,b=g??I?.messageId,F=o.useMemo(()=>{if(l)return{threadId:l,mailboxId:I?.mailboxId??"",subject:I?.subject,messageId:b,authenticity:I?.authenticity}},[l,I,b]),D=o.useCallback((h,L)=>{n({to:"/mail/brief/$threadId/$messageId",params:h,replace:L?.replace,search:w=>({...w,q:d||void 0}),hash:r})},[n,r,d]),f=o.useCallback(()=>{n({to:"/mail/brief",search:h=>h,hash:r})},[n,r]),v=o.useCallback(h=>{b&&h.includes(b)&&f()},[b,f]),N=Ce({thread:I,onAfterOptimisticRemove:v}),C=Ns(),{deleteMessages:x}=Bs({mailboxId:I?.mailboxId??"",messages:u,onAfterOptimisticRemove:v}),{toggleReadFor:U}=Os({mailboxId:I?.mailboxId??"",messages:u}),P=C.focusedMessageId,j=o.useMemo(()=>u.find(h=>h.messageId===P),[u,P])??I,q=Ce({thread:j}),V=Ks(),R=Zs(),T=Xs(),M=o.useMemo(()=>et(T,l,b),[T,l,b]),B=o.useMemo(()=>{if(j)return h=>T({threadId:j.threadId,messageId:j.messageId,mode:h})},[T,j]),{nextMessageId:z,previousMessageId:H}=Ls({context:C,orderedIds:C.orderedIds,selectedMessageId:b,enabled:!V&&!R,onClose:f,handlers:{reply:()=>B?.("reply"),replyAll:()=>B?.("reply-all"),forward:()=>B?.("forward"),delete:()=>{C.listCommandsRef.current?.requestVerb("delete")||q.deleteThread()},toggleStar:q.toggleStar,toggleRead:()=>{C.listCommandsRef.current?.requestVerb("markRead")||j&&U([j.messageId],!j.isRead)},goFlagged:()=>n({to:"/mail/flagged"}),goSettings:()=>n({to:"/settings"})}}),O=o.useCallback(h=>{if(!h)return;const L=u.find(w=>w.messageId===h);return L?{threadId:L.threadId,messageId:h}:void 0},[u]),Q={selectedMessageId:b,selectedThread:I,conversation:F,onOpenThread:D,onCloseThread:f,nextThread:O(z),previousThread:O(H),actions:N,onReply:M,triage:C,onDeleteMessages:x,handleDeselectIfRemoved:v};return a.jsx(Le.Provider,{value:Q,children:s})}function Ee(){const{selectedMessageId:e,onOpenThread:s,triage:n,onDeleteMessages:r}=J(),{accounts:d}=E();return a.jsx(pt,{accounts:d,selectedMessageId:e,onOpenThread:s,commandsRef:n.listCommandsRef,onTriageContextChange:n.onTriageContextChange,onDeleteMessages:r})}function bt(){const{conversation:e,actions:s,onReply:n}=J(),{intelligenceOpen:r,onToggleIntelligence:d}=E(),l=is()?.showIntelligencePane??!1,g=!!e,m=l&&g;return a.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[a.jsx(Ds,{hasThread:g,intelligenceOpen:m&&r,canToggleIntelligence:m,onToggleIntelligence:d,onReply:n?()=>n("reply"):void 0,onReplyAll:n?()=>n("reply-all"):void 0,onForward:n?()=>n("forward"):void 0,onDelete:g?s.deleteThread:void 0,onToggleStar:g?s.toggleStar:void 0,isStarred:s.isStarred,moveContext:g&&s.accountId&&s.mailboxId?{accountId:s.accountId,currentMailboxId:s.mailboxId,onMove:s.moveThread}:void 0}),a.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?a.jsx(we,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,selectedMessageId:e.messageId,authenticity:e.authenticity}):a.jsx(us,{})})]})}function vt(){const{selectedThread:e,handleDeselectIfRemoved:s}=J(),{onToggleIntelligence:n}=E();return a.jsx(ke,{onClose:n,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId,onAfterOptimisticRemove:s})}function yt(){const{selectedThread:e,conversation:s,onOpenThread:n,onCloseThread:r,nextThread:d,previousThread:l,handleDeselectIfRemoved:g}=J(),{intelligenceOpen:m,onToggleIntelligence:u}=E();return s?a.jsxs(a.Fragment,{children:[a.jsx(we,{threadId:s.threadId,mailboxId:s.mailboxId,subject:s.subject,selectedMessageId:s.messageId,authenticity:s.authenticity,onBack:r,onOpenIntelligence:u,onSwipeNext:d?()=>n(d):void 0,onSwipePrevious:l?()=>n(l):void 0,mobileIntelligenceOpen:m}),a.jsx(Es,{isOpen:m,onClose:u,ariaLabel:"Message details",side:"right",children:a.jsx(ke,{onClose:u,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId,hideCloseButton:!0,onAfterOptimisticRemove:g})})]}):a.jsx("div",{className:"h-full",children:a.jsx(Ee,{})})}const Ft=Object.assign(It,{List:Ee,Reading:bt,Intelligence:vt,Phone:yt});export{Ft as B};
1
+ import{j as a,af as Ze,S as Xe,bh as es,l as E,bb as ss,m as oe,r as o,s as ae,bi as ne,q as ts,bj as as,bk as ns,bl as os,e as Te,bm as rs,i as is}from"./index-CdDX4Aix.js";import{s as Re,a as ls,b as Me,u as cs,p as ds,R as us}from"./useSearchTokenContext-C2D9az6p.js";import{a2 as ve,D as ye,a3 as ms,a4 as fs,E as hs,a5 as Se,a6 as gs,a7 as xs,a8 as ps,a1 as Is,a9 as bs,aa as vs,ab as ys,M as Ss,ac as Cs,ad as js,ae as Ts,e as Rs,v as Ms,af as ws,r as ks,S as As,H as Fs,L as Ce,K as Ns,I as Bs,d as Os,W as Ls,X as we,Y as Es,Z as ke,_ as Ds}from"./MailListHeader-D1EP0Mvb.js";import{u as Ps,a as qs,R as zs,i as Hs,b as Qs}from"./useRefreshControl-CrEecOQC.js";import{e as _s,c as $s,R as Ws}from"./search-token-index-LDBCO_Kw.js";import{a as Us}from"./useLabels-D78oY1RR.js";import{u as Vs}from"./useMediaQuery-D8qC0uHL.js";import{u as Ys,L as Gs}from"./useSemanticSearch-oXsRInm8.js";import{n as Js,e as Ks,g as Zs,o as Xs,r as et}from"./useMessageBodyContent-0MCTPuF1.js";function st({sync:e}){return e?a.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 py-12 text-center px-4",role:"status","aria-live":"polite",children:[a.jsx(Ze,{className:"size-8 animate-spin text-fg-subtle","aria-hidden":"true"}),a.jsx("p",{className:"text-sm font-medium text-fg",children:"Still syncing your mail"}),a.jsx("p",{className:"text-xs text-fg-subtle",children:tt(e)})]}):a.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 py-12 text-center px-4",children:[a.jsx(Xe,{className:"size-8 text-fg-subtle","aria-hidden":"true"}),a.jsx("p",{className:"text-sm font-medium text-fg",children:"You're caught up"}),a.jsx("p",{className:"text-xs text-fg-subtle",children:"Nothing needs attention."})]})}function tt({synced:e,total:s}){return s>0?`${e.toLocaleString()} of ${s.toLocaleString()} messages downloaded. This list fills in as they arrive.`:"Downloading your messages. This list fills in as they arrive."}const Ae=[{id:"unread",name:"is",value:"unread"},{id:"attachment",name:"has",value:"attachment"}],Fe="category",at={unclassified:"uncategorized"},W=e=>ls(e).map(s=>s.raw),$=e=>e.join(" "),re=e=>{const s=Me(e);if(s)return Ae.find(n=>n.name===s.name&&n.value===s.value.toLowerCase())?.id},ie=e=>{const s=Me(e);if(!s||s.name!==Fe)return;const n=s.value.toLowerCase(),r=at[n];if(r)return r;if(!(!es(n)||n==="all"))return n},Ne=e=>Ae.find(s=>s.id===e),Be=e=>Ne(e)!==void 0,nt=e=>{const s=new Set;for(const n of W(e)){const r=re(n);r&&s.add(r)}return s},ot=e=>{let s="all";for(const n of W(e)){const r=ie(n);r&&(s=r)}return s},rt=(e,s)=>{const n=Ne(s);if(!n)return;const r=W(e),d=r.filter(l=>re(l)!==s);return d.length<r.length?$(d):$([...r,Re(n.name,n.value)])},it=(e,s)=>{const n=W(e).filter(r=>!ie(r));return $(s==="all"?n:[...n,Re(Fe,s)])},lt=e=>$(W(e).filter(s=>!re(s)&&!ie(s))),Oe=e=>e.trim().length>0,ct=e=>{if(!Oe(e.query))return e.ownFilters;const s=new Set(nt(e.query));for(const n of e.ownFilters)Be(n)||s.add(n);return s},dt=e=>Oe(e.query)?ot(e.query):e.ownCategory,ut=(e,s)=>e.createdAt!==s.createdAt?e.createdAt-s.createdAt:e.accountId.localeCompare(s.accountId),mt=e=>[...e].sort(ut),ft=200,je=()=>a.jsx("div",{className:"animate-pulse",children:Array.from({length:3}).map((e,s)=>a.jsxs("div",{className:"flex items-start gap-3 py-2 pl-5 pr-4 border-b border-line",children:[a.jsx("div",{className:"size-7 rounded-full bg-surface-sunken shrink-0 mt-0.5"}),a.jsxs("div",{className:"flex-1 space-y-1.5",children:[a.jsxs("div",{className:"flex justify-between gap-2",children:[a.jsx("div",{className:"h-3.5 bg-surface-sunken rounded w-28"}),a.jsx("div",{className:"h-3 bg-surface-sunken rounded w-12"})]}),a.jsx("div",{className:"h-3.5 bg-surface-sunken rounded w-48"}),a.jsx("div",{className:"h-3 bg-surface-sunken rounded w-full"})]})]},s))}),ht=({accountEmail:e})=>{const s=oe();return a.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:[a.jsx(Te,{className:"size-3.5 shrink-0"}),a.jsxs("span",{className:"flex-1 truncate",children:[e," can't connect"]}),a.jsx("button",{type:"button",onClick:()=>s({to:"/settings/accounts"}),className:"shrink-0 underline text-danger hover:opacity-80",children:"Reconnect"})]})},gt=(e,s)=>{if(s.size===0)return{};const n=new Set,r=new Set;for(const l of e)s.has(l.id)&&(l.accountId&&n.add(l.accountId),l.mailboxId&&r.add(l.mailboxId));if(n.size>1)return{restriction:"spansAccounts",moveDisabledHint:"Move only works within one account — clear selection or pick messages from a single account"};const d=n.size===1?[...n][0]:void 0;return r.size>1?{accountId:d,restriction:"spansFolders",moveDisabledHint:`Move only works within one folder — this selection spans ${r.size} folders`}:{accountId:d,mailboxId:r.size===1?[...r][0]:void 0}};function xt({header:e,rows:s,wizard:n,children:r}){const{selectedIds:d,selectedCount:l,exitSelection:g,orderedIds:m,allSelected:u,toggleAllLoaded:S}=Ts(),p=o.useMemo(()=>gt(s,d),[s,d]),{junkMailboxId:I}=Rs(p.accountId),{labels:b}=Us(p.accountId),F=o.useMemo(()=>Array.from(d),[d]),D=o.useMemo(()=>s.filter(x=>d.has(x.id)).map(x=>({id:x.id,sender:x.fromName,email:x.fromEmail,subject:x.subject,date:x.timeLabel})),[s,d]),f=Ms(I,p.mailboxId),v=o.useMemo(()=>m.length>0?{checked:u,indeterminate:l>0&&!u,onChange:S}:void 0,[m.length,u,l,S]),N=p.moveDisabledHint?{tone:"warning",text:p.moveDisabledHint}:void 0,C=x=>a.jsx(As,{title:x.title,navSlot:x.navSlot,titleMeta:x.titleMeta,searchSlot:x.searchSlot,searchField:x.searchField,idleSlot:x.makeFilterSlot,count:l,onCancel:g,onDelete:()=>n.start("delete"),onMove:()=>n.start("move"),onOrganize:()=>n.start("organize"),onJunk:f?()=>n.start("junk"):void 0,onMarkRead:()=>n.start("markRead"),overflowSlot:p.accountId&&p.mailboxId&&l>0&&b.length>0?a.jsx(Gs,{accountId:p.accountId,mailboxId:p.mailboxId,messageIds:F}):void 0,selectAll:v,notice:N});return a.jsx(ws,{...e,selectionBar:C,paneOverlay:a.jsx(ks,{verb:n.verb,accountId:p.accountId,mailboxId:p.mailboxId,selection:D,selectionRestriction:p.restriction,onFinished:g}),children:r})}function pt({accounts:e,selectedMessageId:s,onOpenThread:n,commandsRef:r,onTriageContextChange:d,onDeleteMessages:l}){const{searchQuery:g,searchInput:m,resultFolderIndex:u,onSearchChange:S}=E(),p=cs(),I=Vs(),b=_s(),F=ss(),D=oe(),f=o.useMemo(()=>mt(e.filter(t=>!t.muted?.value)),[e]),[v,N]=o.useState("all"),[C,x]=o.useState("all"),[U,P]=o.useState(new Set),[K,j]=o.useState(!1),q=o.useCallback(t=>{P(i=>{const c=new Set(i);return c.has(t)?c.delete(t):c.add(t),c})},[]),V=o.useCallback(()=>P(new Set),[]),R=m.trim().length>0,T=o.useMemo(()=>ct({query:m,ownFilters:U}),[m,U]),M=o.useMemo(()=>dt({query:m,ownCategory:C}),[m,C]),B=o.useCallback(t=>{if(!R||!Be(t)){q(t);return}const i=rt(m,t);i!==void 0&&S(i)},[R,m,S,q]),z=o.useCallback(t=>{if(!R){x(t);return}S(it(m,t))},[R,m,S]),H=o.useCallback(()=>{x("all"),N("all"),V(),R&&S(lt(m))},[R,m,S,V]),{data:O,isLoading:Q,isError:h,refetch:L}=ae({...ne(),staleTime:6e4}),w=$s({queries:f.map(t=>({...ts({path:{accountId:t.accountId}}),staleTime:1/0,meta:{softError:!0}}))}),Y=o.useMemo(()=>{const t=new Map;for(let i=0;i<f.length;i++){const c=f[i].accountId,Ge=(w[i]?.data?.items??[]).reduce((Je,Ke)=>Je+(Ke.unseenCount??0),0);t.set(c,Ge)}return t},[f,w]),De=o.useMemo(()=>f.filter((t,i)=>{const c=w[i];return c?.isError?!as(c.error):!1}),[f,w]),{freeText:k,tokens:Z}=ds(g.trim().toLowerCase(),p),{data:le,isFetching:Pe}=ae({...ne({query:{query:k,limit:ft}}),enabled:k.length>0,staleTime:3e4}),y=o.useMemo(()=>{const t=ve(O?.items??[]).map(ye);return(k?ms(t.filter(c=>fs(c,k)),ve(le?.items??[]).map(ye)):t).filter(c=>(v==="all"||c.accountId===v)&&hs(c,Z))},[O,le,v,k,Z]),{bodyRows:ce,briefSpamOffer:X}=o.useMemo(()=>{if(!k)return{bodyRows:y,briefSpamOffer:void 0};const t=y.map(A=>Se(A,u)),{spam:i}=gs(t);if(i.length===0)return{bodyRows:y,briefSpamOffer:void 0};const c=new Set(i.map(A=>A.id));return{bodyRows:y.filter(A=>!c.has(A.id)),briefSpamOffer:xs(t)}},[y,k,u]),de=o.useMemo(()=>ps(ce),[ce]),ue=o.useCallback((t,i)=>{const c=y.find(A=>A.id===t)?.threadId;c&&n?.({threadId:c,messageId:t},i)},[y,n]),qe=o.useCallback(t=>{const i=t.threadId??y.find(c=>c.id===t.id)?.threadId;i&&n?.({threadId:i,messageId:t.id})},[y,n]),ee=o.useMemo(()=>f.length<=1?[]:[{id:"all",label:"All",active:v==="all"},...f.map(t=>({id:t.accountId,label:t.email.split("@")[0]??t.email,count:Y.get(t.accountId),active:v===t.accountId}))],[f,Y,v]),_=o.useMemo(()=>e.filter(t=>t.muted?.value).length,[e]),ze=o.useMemo(()=>Array.from(Y.values()).reduce((t,i)=>t+i,0),[Y]),se=o.useMemo(()=>f.map(t=>t.accountId),[f]),{hasNewMail:me}=Ps(),{state:fe,errorMessage:he,refresh:ge}=qs(se,{onSettled:()=>L()}),He=o.useMemo(()=>a.jsx(zs,{state:fe,onRefresh:ge,label:"Refresh daily brief",errorMessage:he,hasUpdate:me(se)}),[fe,ge,he,me,se]),te=o.useMemo(()=>y.filter(t=>(M==="all"||t.category===M)&&ns(t,T)).map(t=>Se(t,u)),[y,M,T,u]),{hits:xe,isLoading:Qe}=Ys(),_e=o.useMemo(()=>{const t=new Map;for(const c of O?.items??[])t.set(c.messageId,c.threadId);const i=te.map(c=>t.get(c.id)).filter(c=>c!=null);return Is(xe,i,u)},[xe,te,O,u]),$e=o.useMemo(()=>{const t=bs(ee.map(i=>({id:i.id,label:i.label,count:i.count,active:i.active})));return{categories:t.categories,filters:t.filters,sources:t.sources,sourcesNote:_>0?`+${_} muted`:void 0,selectedCategory:M,activeFilters:T,expanded:K,onExpandedChange:j,onSelectCategory:i=>z(i),onSelectSource:N,onToggleFilter:i=>B(i),onClear:H}},[ee,_,M,T,K,B,z,H]),pe=de.length===0&&v==="all"&&k.length===0&&Z.length===0,We=o.useMemo(()=>f.map(t=>t.accountId),[f]),Ue=o.useMemo(()=>f.some(t=>Hs(t.syncPhase)),[f]),G=Qs(We,pe||Ue),Ie=a.jsxs("div",{className:"h-full overflow-y-auto",children:[a.jsx(je,{}),a.jsx(je,{})]}),be=!Q&&!h&&!pe,Ve=vs({tier:b,hasLiveInput:R,hasCommittedQuery:g.trim().length>0,bodyRendersCommittedResults:!0}),Ye=be?a.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[X&&a.jsx(ys,{count:X.count,onScopeToSpam:()=>D({to:"/mail/$mailboxId",params:{mailboxId:X.mailboxId},search:{q:g||void 0}})}),a.jsx("div",{className:"min-h-0 flex-1",children:a.jsx(os,{sections:de,briefCategory:M,Row:Ss,selectedThreadId:s,onSelectThread:ue,onSelectBriefCategory:z,sources:ee,sourcesNote:_>0?`+${_} muted`:void 0,onSelectSource:N,activeFilters:T,onToggleFilter:B,onClearFilters:H})})]}):Q?Ie:h?a.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 py-12 text-sm text-fg-muted",children:[a.jsx(Te,{className:"size-8 text-danger"}),a.jsx("p",{children:"Couldn't load your messages"}),a.jsxs("button",{type:"button",onClick:()=>L(),className:"flex items-center gap-1 text-accent underline text-xs",children:[a.jsx(Ws,{className:"size-3.5"}),"Try again"]})]}):G.resolved?a.jsx(st,{sync:G.syncing?{synced:G.synced,total:G.total}:void 0}):Ie;return a.jsx(rs,{hasSheet:be&&!Ve,children:a.jsx(Cs,{selectedMessageId:s,onOpen:ue,onDeleteMessages:l,onSelectionVerb:F.start,wizardOpen:F.isOpen,commandsRef:r,onTriageContextChange:d,children:a.jsx(xt,{wizard:F,header:{title:"Daily brief",unreadCount:ze,footer:I?a.jsx(js,{}):void 0,searchFilter:$e,searchResults:te,searchLoading:Q||Pe,relatedResults:_e,relatedLoading:Qe,onSelectSearchResult:qe,searchResultsInBody:!0,refreshControl:He},rows:y,children:a.jsxs("div",{className:"flex h-full flex-col",children:[De.map(t=>a.jsx(ht,{accountEmail:t.email,accountId:t.accountId},t.accountId)),a.jsx("div",{className:"min-h-0 flex-1",children:Ye})]})})})})}const Le=o.createContext(null);function J(){const e=o.useContext(Le);if(!e)throw new Error("BriefPane.* must be used inside <BriefPane>");return e}function It({thread:e,children:s}){const n=oe(),r=Js(),{searchInput:d}=E(),l=e?.threadId,g=e?.messageId,{data:m}=ae({...ne(),staleTime:6e4}),u=o.useMemo(()=>m?.items??[],[m]),S=o.useMemo(()=>{if(l)return u.find(h=>h.messageId===g)??u.find(h=>h.threadId===l)},[u,l,g]),p=Fs(l,g),I=S??p,b=g??I?.messageId,F=o.useMemo(()=>{if(l)return{threadId:l,mailboxId:I?.mailboxId??"",subject:I?.subject,messageId:b,authenticity:I?.authenticity}},[l,I,b]),D=o.useCallback((h,L)=>{n({to:"/mail/brief/$threadId/$messageId",params:h,replace:L?.replace,search:w=>({...w,q:d||void 0}),hash:r})},[n,r,d]),f=o.useCallback(()=>{n({to:"/mail/brief",search:h=>h,hash:r})},[n,r]),v=o.useCallback(h=>{b&&h.includes(b)&&f()},[b,f]),N=Ce({thread:I,onAfterOptimisticRemove:v}),C=Ns(),{deleteMessages:x}=Bs({mailboxId:I?.mailboxId??"",messages:u,onAfterOptimisticRemove:v}),{toggleReadFor:U}=Os({mailboxId:I?.mailboxId??"",messages:u}),P=C.focusedMessageId,j=o.useMemo(()=>u.find(h=>h.messageId===P),[u,P])??I,q=Ce({thread:j}),V=Ks(),R=Zs(),T=Xs(),M=o.useMemo(()=>et(T,l,b),[T,l,b]),B=o.useMemo(()=>{if(j)return h=>T({threadId:j.threadId,messageId:j.messageId,mode:h})},[T,j]),{nextMessageId:z,previousMessageId:H}=Ls({context:C,orderedIds:C.orderedIds,selectedMessageId:b,enabled:!V&&!R,onClose:f,handlers:{reply:()=>B?.("reply"),replyAll:()=>B?.("reply-all"),forward:()=>B?.("forward"),delete:()=>{C.listCommandsRef.current?.requestVerb("delete")||q.deleteThread()},toggleStar:q.toggleStar,toggleRead:()=>{C.listCommandsRef.current?.requestVerb("markRead")||j&&U([j.messageId],!j.isRead)},goFlagged:()=>n({to:"/mail/flagged"}),goSettings:()=>n({to:"/settings"})}}),O=o.useCallback(h=>{if(!h)return;const L=u.find(w=>w.messageId===h);return L?{threadId:L.threadId,messageId:h}:void 0},[u]),Q={selectedMessageId:b,selectedThread:I,conversation:F,onOpenThread:D,onCloseThread:f,nextThread:O(z),previousThread:O(H),actions:N,onReply:M,triage:C,onDeleteMessages:x,handleDeselectIfRemoved:v};return a.jsx(Le.Provider,{value:Q,children:s})}function Ee(){const{selectedMessageId:e,onOpenThread:s,triage:n,onDeleteMessages:r}=J(),{accounts:d}=E();return a.jsx(pt,{accounts:d,selectedMessageId:e,onOpenThread:s,commandsRef:n.listCommandsRef,onTriageContextChange:n.onTriageContextChange,onDeleteMessages:r})}function bt(){const{conversation:e,actions:s,onReply:n}=J(),{intelligenceOpen:r,onToggleIntelligence:d}=E(),l=is()?.showIntelligencePane??!1,g=!!e,m=l&&g;return a.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[a.jsx(Ds,{hasThread:g,intelligenceOpen:m&&r,canToggleIntelligence:m,onToggleIntelligence:d,onReply:n?()=>n("reply"):void 0,onReplyAll:n?()=>n("reply-all"):void 0,onForward:n?()=>n("forward"):void 0,onDelete:g?s.deleteThread:void 0,onToggleStar:g?s.toggleStar:void 0,isStarred:s.isStarred,moveContext:g&&s.accountId&&s.mailboxId?{accountId:s.accountId,currentMailboxId:s.mailboxId,onMove:s.moveThread}:void 0}),a.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?a.jsx(we,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,selectedMessageId:e.messageId,authenticity:e.authenticity}):a.jsx(us,{})})]})}function vt(){const{selectedThread:e,handleDeselectIfRemoved:s}=J(),{onToggleIntelligence:n}=E();return a.jsx(ke,{onClose:n,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId,onAfterOptimisticRemove:s})}function yt(){const{selectedThread:e,conversation:s,onOpenThread:n,onCloseThread:r,nextThread:d,previousThread:l,handleDeselectIfRemoved:g}=J(),{intelligenceOpen:m,onToggleIntelligence:u}=E();return s?a.jsxs(a.Fragment,{children:[a.jsx(we,{threadId:s.threadId,mailboxId:s.mailboxId,subject:s.subject,selectedMessageId:s.messageId,authenticity:s.authenticity,onBack:r,onOpenIntelligence:u,onSwipeNext:d?()=>n(d):void 0,onSwipePrevious:l?()=>n(l):void 0,mobileIntelligenceOpen:m}),a.jsx(Es,{isOpen:m,onClose:u,ariaLabel:"Message details",side:"right",children:a.jsx(ke,{onClose:u,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId,hideCloseButton:!0,onAfterOptimisticRemove:g})})]}):a.jsx("div",{className:"h-full",children:a.jsx(Ee,{})})}const Ft=Object.assign(It,{List:Ee,Reading:bt,Intelligence:vt,Phone:yt});export{Ft as B};
@@ -1 +1 @@
1
- import{j as t,e as r}from"./index-CruZwy_j.js";const d=e=>e instanceof Error?e.message:typeof e=="string"?e:typeof e=="object"&&e!==null&&"message"in e&&typeof e.message=="string"?e.message:"An unexpected error occurred",l=({title:e="Couldn't load content",error:a,onRetry:s,variant:i="block"})=>{const n=d(a);return i==="inline"?t.jsxs("div",{role:"alert",className:"flex items-start gap-2 rounded-md border border-danger/40 bg-danger-soft px-3 py-2 text-sm",children:[t.jsx(r,{className:"size-4 shrink-0 text-danger mt-0.5","aria-hidden":"true"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("p",{className:"font-medium text-danger",children:e}),t.jsx("p",{className:"text-fg-muted mt-0.5 break-words",children:n})]}),s&&t.jsx("button",{type:"button",onClick:s,className:"shrink-0 text-sm font-medium text-accent hover:underline",children:"Retry"})]}):t.jsxs("div",{role:"alert",className:"flex flex-col items-center justify-center gap-3 p-8 text-center",children:[t.jsx(r,{className:"size-8 text-danger","aria-hidden":"true"}),t.jsxs("div",{children:[t.jsx("p",{className:"font-medium text-danger",children:e}),t.jsx("p",{className:"text-sm text-fg-muted mt-1 break-words",children:n})]}),s&&t.jsx("button",{type:"button",onClick:s,className:"inline-flex items-center rounded-md border border-line bg-canvas px-4 py-2 text-sm font-medium hover:bg-surface-raised transition-colors",children:"Retry"})]})};export{l as E,d as f};
1
+ import{j as t,e as r}from"./index-CdDX4Aix.js";const d=e=>e instanceof Error?e.message:typeof e=="string"?e:typeof e=="object"&&e!==null&&"message"in e&&typeof e.message=="string"?e.message:"An unexpected error occurred",l=({title:e="Couldn't load content",error:a,onRetry:s,variant:i="block"})=>{const n=d(a);return i==="inline"?t.jsxs("div",{role:"alert",className:"flex items-start gap-2 rounded-md border border-danger/40 bg-danger-soft px-3 py-2 text-sm",children:[t.jsx(r,{className:"size-4 shrink-0 text-danger mt-0.5","aria-hidden":"true"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("p",{className:"font-medium text-danger",children:e}),t.jsx("p",{className:"text-fg-muted mt-0.5 break-words",children:n})]}),s&&t.jsx("button",{type:"button",onClick:s,className:"shrink-0 text-sm font-medium text-accent hover:underline",children:"Retry"})]}):t.jsxs("div",{role:"alert",className:"flex flex-col items-center justify-center gap-3 p-8 text-center",children:[t.jsx(r,{className:"size-8 text-danger","aria-hidden":"true"}),t.jsxs("div",{children:[t.jsx("p",{className:"font-medium text-danger",children:e}),t.jsx("p",{className:"text-sm text-fg-muted mt-1 break-words",children:n})]}),s&&t.jsx("button",{type:"button",onClick:s,className:"inline-flex items-center rounded-md border border-line bg-canvas px-4 py-2 text-sm font-medium hover:bg-surface-raised transition-colors",children:"Retry"})]})};export{l as E,d as f};
@@ -0,0 +1 @@
1
+ import{d5 as X,r as n,cr as Y,l as P,bb as Z,aF as J,aG as ee,j as r,m as te,i as se}from"./index-CdDX4Aix.js";import{u as ae,p as re,R as ne}from"./useSearchTokenContext-C2D9az6p.js";import{D as oe,a4 as de,E as ie,aq as le,a5 as ce,b as ue,M as ge,ac as he,ar as me,ae as fe,r as Ie,H as pe,L as V,K as xe,I as Te,d as be,W as ye,X as K,Y as ve,Z as W,_ as Re}from"./MailListHeader-D1EP0Mvb.js";import{u as Ce,b as Se,a as je}from"./MailViewChrome-B0RnNca9.js";import{f as Me}from"./ErrorState-WGrYWxuU.js";import{u as we}from"./useMediaQuery-D8qC0uHL.js";import{n as Fe,e as Pe,g as ke,o as Le,r as Oe}from"./useMessageBodyContent-0MCTPuF1.js";const Ae=()=>Y({query:{starred:!0,order:"desc"}});function _(){const{data:e,isLoading:t,isError:s,error:l,refetch:m,fetchNextPage:a,hasNextPage:c,isFetchingNextPage:d}=Ce({queryKey:Ae(),queryFn:async({pageParam:I})=>{const{data:u}=await X({query:{starred:!0,order:"desc",continuationToken:I},throwOnError:!0});return u},initialPageParam:void 0,getNextPageParam:I=>I.continuationToken,staleTime:6e4});return{threads:n.useMemo(()=>(e?.pages??[]).flatMap(I=>I.items??[]),[e]),isLoading:t,isError:s,error:l,refetch:m,fetchNextPage:a,hasNextPage:c,isFetchingNextPage:d}}const Ne=e=>{const t=new Set;return e.filter(s=>t.has(s.threadId)?!1:(t.add(s.threadId),!0))},Ee={unread:e=>!e.isRead,attachment:e=>e.hasAttachment===!0};function De({rows:e,verb:t}){const{selectedIds:s,exitSelection:l}=fe(),m=n.useMemo(()=>e.filter(a=>s.has(a.id)).map(a=>({id:a.id,sender:a.fromName,email:a.fromEmail,subject:a.subject,date:a.timeLabel})),[e,s]);return r.jsx(Ie,{verb:t,selection:m,selectionRestriction:"spansAccounts",onFinished:l})}function Be({selectedMessageId:e,onOpenThread:t,commandsRef:s,onTriageContextChange:l,onDeleteMessages:m}){const{searchQuery:a,resultFolderIndex:c}=P(),d=ae(),b=we(),I=Z(),[u,f]=n.useState("all"),[C,k]=n.useState(new Set),v=n.useCallback(o=>{k(h=>{const p=new Set(h);return p.has(o)?p.delete(o):p.add(o),p})},[]),S=n.useCallback(()=>{f("all"),k(new Set)},[]),{threads:L,isLoading:T,isError:O,error:q,refetch:A,fetchNextPage:Q,hasNextPage:x,isFetchingNextPage:j}=_(),{freeText:R,tokens:N}=re(a.trim().toLowerCase(),d),g=n.useMemo(()=>{const o=Array.from(C).map(h=>Ee[h]).filter(h=>h!=null);return Ne(L).map(oe).filter(h=>(u==="all"||h.category===u)&&o.every(p=>p(h))&&(!R||de(h,R))&&ie(h,N))},[L,u,C,R,N]),M=n.useCallback((o,h)=>{const p=g.find(U=>U.id===o)?.threadId;p&&t?.({threadId:p,messageId:o},h)},[g,t]),w=n.useCallback(o=>{const h=o.threadId??g.find(p=>p.id===o.id)?.threadId;h&&t?.({threadId:h,messageId:o.id})},[g,t]),H=n.useMemo(()=>le(),[]),z=n.useMemo(()=>g.map(o=>ce(o,c)),[g,c]),E=n.useMemo(()=>g.filter(o=>!o.isRead).length,[g]),D=T?"loading":O?"error":g.length===0?"empty":"ready",i=n.useCallback(()=>{const o=J(ee());window.open(o,"_blank","noopener,noreferrer")},[]),y=ue(),F=r.jsx("div",{className:"flex h-full min-h-0 flex-col",children:r.jsxs("div",{className:"flex-1 overflow-y-auto",children:[r.jsx("div",{className:"divide-y divide-line",children:g.map(o=>r.jsx(ge,{thread:o,active:o.id===e,onClick:()=>M(o.id)},o.id))}),x?r.jsx("button",{type:"button",className:"w-full py-3 text-sm text-muted hover:text-fg disabled:opacity-50",onClick:()=>Q(),disabled:j,children:j?"Loading…":"Load more"}):null]})});return r.jsx(Se,{title:"Starred",unreadCount:E,preset:H,selectedCategory:u,activeFilters:C,onSelectCategory:f,onToggleFilter:v,onClearFilters:S,searchResults:z,searchLoading:T,onSelectSearchResult:w,searchResultsInBody:!0,children:r.jsxs(he,{selectedMessageId:e,onOpen:M,onDeleteMessages:m,onSelectionVerb:I.start,wizardOpen:I.isOpen,commandsRef:s,onTriageContextChange:l,children:[r.jsx(je,{listTitle:"Starred",sections:[{id:"flagged",threads:g}],flatList:!0,hideHeader:!0,listState:y.searchResults?"ready":D,searchQuery:R?a:void 0,errorMessage:O?Me(q):void 0,onRetry:()=>A(),onReportError:i,selectedThreadId:e,onSelectThread:M,isDesktop:b,selectionBar:r.jsx(me,{title:"Starred"}),listBody:y.searchResults??(D==="ready"?F:void 0)}),r.jsx(De,{rows:g,verb:I.verb})]})})}const G=n.createContext(null);function B(){const e=n.useContext(G);if(!e)throw new Error("FlaggedPane.* must be used inside <FlaggedPane>");return e}function qe({thread:e,children:t}){const s=te(),l=Fe(),{searchInput:m}=P(),a=e?.threadId,c=e?.messageId,{threads:d}=_(),b=n.useMemo(()=>{if(a)return d.find(i=>i.messageId===c)??d.find(i=>i.threadId===a)},[d,a,c]),I=pe(a,c),u=b??I,f=c??u?.messageId,C=n.useMemo(()=>{if(a)return{threadId:a,mailboxId:u?.mailboxId??"",subject:u?.subject,messageId:f,authenticity:u?.authenticity}},[a,u,f]),k=n.useCallback((i,y)=>{s({to:"/mail/flagged/$threadId/$messageId",params:i,replace:y?.replace,search:F=>({...F,q:m||void 0}),hash:l})},[s,l,m]),v=n.useCallback(()=>{s({to:"/mail/flagged",search:i=>i,hash:l})},[s,l]),S=n.useCallback(i=>{f&&i.includes(f)&&v()},[f,v]),L=V({thread:u,onAfterOptimisticRemove:S}),T=xe(),{deleteMessages:O}=Te({mailboxId:u?.mailboxId??"",messages:d,onAfterOptimisticRemove:S}),{toggleReadFor:q}=be({mailboxId:u?.mailboxId??"",messages:d}),A=T.focusedMessageId,x=n.useMemo(()=>d.find(i=>i.messageId===A),[d,A])??u,j=V({thread:x}),R=Pe(),N=ke(),g=Le(),M=n.useMemo(()=>Oe(g,a,f),[g,a,f]),w=n.useMemo(()=>{if(x)return i=>g({threadId:x.threadId,messageId:x.messageId,mode:i})},[g,x]),{nextMessageId:H,previousMessageId:z}=ye({context:T,orderedIds:T.orderedIds,selectedMessageId:f,enabled:!R&&!N,onClose:v,handlers:{reply:()=>w?.("reply"),replyAll:()=>w?.("reply-all"),forward:()=>w?.("forward"),delete:()=>{T.listCommandsRef.current?.requestVerb("delete")||j.deleteThread()},toggleStar:j.toggleStar,toggleRead:()=>{T.listCommandsRef.current?.requestVerb("markRead")||x&&q([x.messageId],!x.isRead)},goBrief:()=>s({to:"/mail/brief"}),goSettings:()=>s({to:"/settings"})}}),E=n.useCallback(i=>{if(!i)return;const y=d.find(F=>F.messageId===i);return y?{threadId:y.threadId,messageId:i}:void 0},[d]),D={selectedMessageId:f,selectedThread:u,conversation:C,onOpenThread:k,onCloseThread:v,nextThread:E(H),previousThread:E(z),actions:L,onReply:M,triage:T,onDeleteMessages:O,handleDeselectIfRemoved:S};return r.jsx(G.Provider,{value:D,children:t})}function $(){const{selectedMessageId:e,onOpenThread:t,triage:s,onDeleteMessages:l}=B();return r.jsx(Be,{selectedMessageId:e,onOpenThread:t,commandsRef:s.listCommandsRef,onTriageContextChange:s.onTriageContextChange,onDeleteMessages:l})}function He(){const{conversation:e,actions:t,onReply:s}=B(),{intelligenceOpen:l,onToggleIntelligence:m}=P(),a=se()?.showIntelligencePane??!1,c=!!e,d=a&&c;return r.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[r.jsx(Re,{hasThread:c,intelligenceOpen:d&&l,canToggleIntelligence:d,onToggleIntelligence:m,onReply:s?()=>s("reply"):void 0,onReplyAll:s?()=>s("reply-all"):void 0,onForward:s?()=>s("forward"):void 0,onDelete:c?t.deleteThread:void 0,onToggleStar:c?t.toggleStar:void 0,isStarred:t.isStarred,moveContext:c&&t.accountId&&t.mailboxId?{accountId:t.accountId,currentMailboxId:t.mailboxId,onMove:t.moveThread}:void 0}),r.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?r.jsx(K,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,selectedMessageId:e.messageId,authenticity:e.authenticity}):r.jsx(ne,{})})]})}function ze(){const{selectedThread:e,handleDeselectIfRemoved:t}=B(),{onToggleIntelligence:s}=P();return r.jsx(W,{onClose:s,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId,onAfterOptimisticRemove:t})}function Qe(){const{selectedThread:e,conversation:t,onCloseThread:s,onOpenThread:l,nextThread:m,previousThread:a,handleDeselectIfRemoved:c}=B(),{intelligenceOpen:d,onToggleIntelligence:b}=P();return t?r.jsxs(r.Fragment,{children:[r.jsx(K,{threadId:t.threadId,mailboxId:t.mailboxId,subject:t.subject,selectedMessageId:t.messageId,authenticity:t.authenticity,onBack:s,onOpenIntelligence:b,onSwipeNext:m?()=>l(m):void 0,onSwipePrevious:a?()=>l(a):void 0,mobileIntelligenceOpen:d}),r.jsx(ve,{isOpen:d,onClose:b,ariaLabel:"Message details",side:"right",children:r.jsx(W,{onClose:b,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId,hideCloseButton:!0,onAfterOptimisticRemove:c})})]}):r.jsx("div",{className:"h-full",children:r.jsx($,{})})}const Xe=Object.assign(qe,{List:$,Reading:He,Intelligence:ze,Phone:Qe});export{Xe as F};
@@ -1 +1 @@
1
- import{r as n,s as f,Q as m,j as e,X as N}from"./index-CruZwy_j.js";import{E as u}from"./ErrorState-CNRyRb6l.js";import{D as r,C as x,u as w}from"./index-BOTjtS9M.js";import{u as E}from"./useMediaQuery-C5e0Az56.js";import{j as p,q as h,s as C}from"./useMessageBodyContent-DPqly9Qg.js";import{C as k}from"./confirm-dialog-D9gyhlPW.js";const b=t=>t?"Draft":"New Message",I=()=>{const t=n.useRef(!1);return n.useCallback(()=>{const s=document.querySelector("[data-subject-field]")?.value??"",o=(document.querySelector('[data-testid="compose-body"]')?.textContent??"").replace(/--\s*/g,"").trim();return t.current=s.trim().length>0||o.length>0,t.current},[])},S=()=>{const t=p(),i=h(),s=C(),a=I(),[l,o]=n.useState(!1),{isError:d,error:c,refetch:g}=f({...m(),staleTime:1/0}),j=n.useCallback(D=>{D||(a()?o(!0):s())},[s,a]),y=n.useCallback(()=>{o(!1),s()},[s]),v=n.useCallback(()=>{o(!1)},[]);return e.jsxs(r.Root,{open:!0,onOpenChange:j,children:[e.jsxs(r.Portal,{children:[e.jsx(r.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),e.jsxs(r.Content,{className:"fixed inset-x-0 bottom-0 z-50 flex flex-col rounded-t-lg bg-canvas pb-[env(safe-area-inset-bottom,0px)]",style:{height:"95dvh"},children:[e.jsx(r.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-muted/30"}),e.jsx(r.Title,{className:"px-4 py-2 text-base font-semibold border-b border-line",children:b(t)}),d?e.jsx("div",{className:"flex-1 flex items-center justify-center p-4",children:e.jsx(u,{title:"Couldn't load compose",error:c,onRetry:()=>{g()}})}):e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsx(x,{mode:"new",outboxMessageId:t,onDraftCreated:i,onClose:s})})]})]}),e.jsx(k,{isOpen:l,title:"Discard draft?",description:"Your message has unsaved content. Are you sure you want to discard it?",confirmLabel:"Discard",cancelLabel:"Keep editing",destructive:!0,onConfirm:y,onCancel:v})]})},F=()=>{const t=p(),i=h(),s=C(),a=E(),{isError:l,error:o,refetch:d}=f({...m(),staleTime:1/0});if(w({bindings:[{key:"Escape",handler:s,preventDefault:!0}]}),!a)return e.jsx(S,{});const c=e.jsxs("header",{className:"flex items-center justify-between gap-2 px-4 py-3 border-b border-line shrink-0",children:[e.jsx("div",{className:"flex items-center gap-2 min-w-0",children:e.jsx("h2",{className:"text-lg font-semibold truncate",children:b(t)})}),e.jsx("button",{type:"button",onClick:s,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:e.jsx(N,{className:"size-5"})})]});return l?e.jsxs("div",{className:"h-full flex flex-col bg-canvas",children:[c,e.jsx("div",{className:"flex-1 flex items-center justify-center p-4",children:e.jsx(u,{title:"Couldn't load compose",error:o,onRetry:()=>{d()}})})]}):e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-canvas",children:[c,e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e.jsx(x,{mode:"new",outboxMessageId:t,onDraftCreated:i,onClose:s})})]})};export{F};
1
+ import{r as n,s as f,Q as m,j as e,X as N}from"./index-CdDX4Aix.js";import{E as u}from"./ErrorState-WGrYWxuU.js";import{D as r,C as x,u as w}from"./index-DrkRmWLy.js";import{u as E}from"./useMediaQuery-D8qC0uHL.js";import{j as p,q as h,s as C}from"./useMessageBodyContent-0MCTPuF1.js";import{C as k}from"./confirm-dialog-WJVmZbjC.js";const b=t=>t?"Draft":"New Message",I=()=>{const t=n.useRef(!1);return n.useCallback(()=>{const s=document.querySelector("[data-subject-field]")?.value??"",o=(document.querySelector('[data-testid="compose-body"]')?.textContent??"").replace(/--\s*/g,"").trim();return t.current=s.trim().length>0||o.length>0,t.current},[])},S=()=>{const t=p(),i=h(),s=C(),a=I(),[l,o]=n.useState(!1),{isError:d,error:c,refetch:g}=f({...m(),staleTime:1/0}),j=n.useCallback(D=>{D||(a()?o(!0):s())},[s,a]),y=n.useCallback(()=>{o(!1),s()},[s]),v=n.useCallback(()=>{o(!1)},[]);return e.jsxs(r.Root,{open:!0,onOpenChange:j,children:[e.jsxs(r.Portal,{children:[e.jsx(r.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),e.jsxs(r.Content,{className:"fixed inset-x-0 bottom-0 z-50 flex flex-col rounded-t-lg bg-canvas pb-[env(safe-area-inset-bottom,0px)]",style:{height:"95dvh"},children:[e.jsx(r.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-muted/30"}),e.jsx(r.Title,{className:"px-4 py-2 text-base font-semibold border-b border-line",children:b(t)}),d?e.jsx("div",{className:"flex-1 flex items-center justify-center p-4",children:e.jsx(u,{title:"Couldn't load compose",error:c,onRetry:()=>{g()}})}):e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsx(x,{mode:"new",outboxMessageId:t,onDraftCreated:i,onClose:s})})]})]}),e.jsx(k,{isOpen:l,title:"Discard draft?",description:"Your message has unsaved content. Are you sure you want to discard it?",confirmLabel:"Discard",cancelLabel:"Keep editing",destructive:!0,onConfirm:y,onCancel:v})]})},F=()=>{const t=p(),i=h(),s=C(),a=E(),{isError:l,error:o,refetch:d}=f({...m(),staleTime:1/0});if(w({bindings:[{key:"Escape",handler:s,preventDefault:!0}]}),!a)return e.jsx(S,{});const c=e.jsxs("header",{className:"flex items-center justify-between gap-2 px-4 py-3 border-b border-line shrink-0",children:[e.jsx("div",{className:"flex items-center gap-2 min-w-0",children:e.jsx("h2",{className:"text-lg font-semibold truncate",children:b(t)})}),e.jsx("button",{type:"button",onClick:s,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:e.jsx(N,{className:"size-5"})})]});return l?e.jsxs("div",{className:"h-full flex flex-col bg-canvas",children:[c,e.jsx("div",{className:"flex-1 flex items-center justify-center p-4",children:e.jsx(u,{title:"Couldn't load compose",error:o,onRetry:()=>{d()}})})]}):e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-canvas",children:[c,e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e.jsx(x,{mode:"new",outboxMessageId:t,onDraftCreated:i,onClose:s})})]})};export{F};
@@ -0,0 +1,7 @@
1
+ import{a4 as xs,cb as gr,r as l,c as ie,j as a,C as mt,d as Fn,B as H,X as Dt,at as Te,cc as On,b as F,a as Ye,S as We,aT as br,cd as xr,ag as Ft,T as Ot,ce as zn,a_ as vs,cf as vr,cg as _n,an as yr,af as Un,e as kr,ch as jr,as as Kn,ci as wr,cj as Cr,ck as Sr,cl as Nr,cm as Tr,cn as Er,co as Rr,cp as Mr,bO as Ir,s as te,cq as zt,Q as xt,q as vt,z as Bn,bf as Qn,cr as qn,n as ae,a5 as ke,a7 as ue,J as Je,bn as Re,cs as _t,c2 as Ar,ct as Me,cu as $r,cv as Lr,cw as Pr,cx as Dr,cy as Fr,bN as Or,cz as zr,p as _r,aU as Ur,m as Hn,aF as Kr,aG as Br,bV as Qr,k as qr,bU as Hr,cA as Vr,cB as Gr,cC as Vn,b6 as ys,bs as Wr,bj as qs,cD as Yr,cE as Jr,b5 as Xr,L as Zr,W as eo,D as to,bg as Hs,aY as so,cF as no,cG as ao,a8 as Vs,be as ro,cH as oo,cI as io,l as ks,cJ as lo,cK as co,cL as Gs,cM as uo,cN as fo,cO as mo,cP as js,i as po,cQ as ho,bW as go,cR as bo,cS as Ws,g as xo,bX as vo}from"./index-CdDX4Aix.js";import{B as yo,l as ko,m as jo,S as Gn,c as ws,f as wo,D as Co,b as Rt,a as So,t as ct,g as No,n as To,o as Eo,e as Ro,u as Mo,i as Io}from"./search-token-index-LDBCO_Kw.js";import{K as Ao}from"./kbd-BEXM-I0X.js";import{P as Wn,f as $o,U as Lo,E as Po,s as Do}from"./attachment-file-DxHCGaVA.js";import{M as Fo}from"./mail-BR_rIUxg.js";import{A as pt}from"./avatar-DOcUvLmy.js";import{M as Oo,c as zo,d as Yn,e as _o,f as Jn,g as Xn,a as Uo,b as Ko,S as Ys,s as Zn,u as ea,p as Bo,r as Qo}from"./useSearchTokenContext-C2D9az6p.js";import{t as qo,v as Ho,n as Vo,w as Go,x as Wo,o as Yo,N as ta,d as Jo}from"./useMessageBodyContent-0MCTPuF1.js";import{C as Xo,D as qe,u as Zo}from"./index-DrkRmWLy.js";import{E as _e}from"./ErrorState-WGrYWxuU.js";import{u as Cs}from"./useMediaQuery-D8qC0uHL.js";import{e as sa,b as Xe,a as ei,c as Ue,d as ti}from"./format-De9HZKjg.js";import{P as Js,C as si,D as Xs,M as ye}from"./enums-CCxx0t2v.js";import{D as ni}from"./download-DxzBCaT5.js";import{S as ai}from"./shield-check-yjZblOtm.js";import{u as na}from"./useDebouncedValue-CGuhyli4.js";import{a as aa,u as ra,b as oa,f as ia}from"./move-options-BPevoCXc.js";import{h as Zs,u as ri,a as oi,i as ii,n as li,o as ci,j as di,k as ui,S as fi}from"./useFilters-BmVyD1yI.js";import{C as mi}from"./confirm-dialog-WJVmZbjC.js";import{C as pi}from"./clock-7hrnAMXu.js";import{r as hi,b as gi}from"./search-scope-ISFv18Tx.js";import{M as bi}from"./menu-CmqMnJvh.js";function ht(e){if(xi())e.focus({preventScroll:!0});else{let t=vi(e);e.focus(),yi(t)}}let Mt=null;function xi(){if(Mt==null){Mt=!1;try{document.createElement("div").focus({get preventScroll(){return Mt=!0,!0}})}catch{}}return Mt}function vi(e){let t=e.parentNode,s=[],n=document.scrollingElement||document.documentElement;for(;t instanceof HTMLElement&&t!==n;)(t.offsetHeight<t.scrollHeight||t.offsetWidth<t.scrollWidth)&&s.push({element:t,scrollTop:t.scrollTop,scrollLeft:t.scrollLeft}),t=t.parentNode;return n instanceof HTMLElement&&s.push({element:n,scrollTop:n.scrollTop,scrollLeft:n.scrollLeft}),s}function yi(e){for(let{element:t,scrollTop:s,scrollLeft:n}of e)t.scrollTop=s,t.scrollLeft=n}const Ne=e=>e?.ownerDocument??document,Ee=e=>e&&"window"in e&&e.window===e?e:Ne(e).defaultView||window;function ki(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&typeof e.nodeType=="number"}function ji(e){return ki(e)&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e}let wi=!1;function la(){return wi}function pe(e,t){if(!la())return t&&e?e.contains(t):!1;if(!e||!t)return!1;let s=t;for(;s!==null;){if(s===e)return!0;s.tagName==="SLOT"&&s.assignedSlot?s=s.assignedSlot.parentNode:ji(s)?s=s.host:s=s.parentNode}return!1}function ee(e){if(la()&&e.target instanceof Element&&e.target.shadowRoot){if("composedPath"in e)return e.composedPath()[0]??null;if("composedPath"in e.nativeEvent)return e.nativeEvent.composedPath()[0]??null}return e.target}const Ci=typeof Element<"u"&&"checkVisibility"in Element.prototype;function Si(e){const t=Ee(e);if(!(e instanceof t.HTMLElement)&&!(e instanceof t.SVGElement))return!1;let{display:s,visibility:n}=e.style,r=s!=="none"&&n!=="hidden"&&n!=="collapse";if(r){const{getComputedStyle:o}=Ee(e);let{display:i,visibility:c}=o(e);r=i!=="none"&&c!=="hidden"&&c!=="collapse"}return r}function Ni(e,t){return!e.hasAttribute("hidden")&&!e.hasAttribute("data-react-aria-prevent-focus")&&(e.nodeName==="DETAILS"&&t&&t.nodeName!=="SUMMARY"?e.hasAttribute("open"):!0)}function ca(e,t){return Ci?e.checkVisibility({visibilityProperty:!0})&&!e.closest("[data-react-aria-prevent-focus]"):e.nodeName!=="#comment"&&Si(e)&&Ni(e,t)&&(!e.parentElement||ca(e.parentElement,e))}const da=["input:not([disabled]):not([type=hidden])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","a[href]","area[href]","summary","iframe","object","embed","audio[controls]","video[controls]",'[contenteditable]:not([contenteditable^="false"])',"permission"],Ti=da.join(":not([hidden]),")+",[tabindex]:not([disabled]):not([hidden])";da.push('[tabindex]:not([tabindex="-1"]):not([disabled])');function Ei(e,t){return e.matches(Ti)&&!Ri(e)&&(t?.skipVisibilityCheck||ca(e))}function Ri(e){let t=e;for(;t!=null;){if(t instanceof Ee(t).HTMLElement&&t.inert)return!0;t=t.parentElement}return!1}const Ss=typeof document<"u"?xs.useLayoutEffect:()=>{};function Mi(e){let t=e;return t.nativeEvent=e,t.isDefaultPrevented=()=>t.defaultPrevented,t.isPropagationStopped=()=>t.cancelBubble,t.persist=()=>{},t}function Ii(e,t){Object.defineProperty(e,"target",{value:t}),Object.defineProperty(e,"currentTarget",{value:t})}function Ai(e){for(;e&&!Ei(e,{skipVisibilityCheck:!0});)e=e.parentElement;let t=Ee(e),s=t.document.activeElement;if(!s||s===e)return;let n=!1,r=h=>{(ee(h)===s||n)&&h.stopImmediatePropagation()},o=h=>{(ee(h)===s||n)&&(h.stopImmediatePropagation(),!e&&!n&&(n=!0,ht(s),d()))},i=h=>{(ee(h)===e||n)&&h.stopImmediatePropagation()},c=h=>{(ee(h)===e||n)&&(h.stopImmediatePropagation(),n||(n=!0,ht(s),d()))};t.addEventListener("blur",r,!0),t.addEventListener("focusout",o,!0),t.addEventListener("focusin",c,!0),t.addEventListener("focus",i,!0);let d=()=>{cancelAnimationFrame(v),t.removeEventListener("blur",r,!0),t.removeEventListener("focusout",o,!0),t.removeEventListener("focusin",c,!0),t.removeEventListener("focus",i,!0),n=!1},v=requestAnimationFrame(d);return d}function Ut(e){if(typeof window>"u"||window.navigator==null)return!1;let t=window.navigator.userAgentData?.brands;return Array.isArray(t)&&t.some(s=>e.test(s.brand))||e.test(window.navigator.userAgent)}function Ns(e){return typeof window<"u"&&window.navigator!=null?e.test(window.navigator.userAgentData?.platform||window.navigator.platform):!1}function Ie(e){let t=null;return()=>(t==null&&(t=e()),t)}const $t=Ie(function(){return Ns(/^Mac/i)}),$i=Ie(function(){return Ns(/^iPhone/i)}),ua=Ie(function(){return Ns(/^iPad/i)||$t()&&navigator.maxTouchPoints>1}),fa=Ie(function(){return $i()||ua()}),Li=Ie(function(){return Ut(/AppleWebKit/i)&&!Pi()}),Pi=Ie(function(){return Ut(/Chrome/i)}),ma=Ie(function(){return Ut(/Android/i)}),Di=Ie(function(){return Ut(/Firefox/i)});function Fi(e){return e.pointerType===""&&e.isTrusted?!0:ma()&&e.pointerType?e.type==="click"&&e.buttons===1:e.detail===0&&!e.pointerType}function Oi(e){return!ma()&&e.width===0&&e.height===0||e.width===1&&e.height===1&&e.pressure===0&&e.detail===0&&e.pointerType==="mouse"}function gt(e,t,s=!0){let{metaKey:n,ctrlKey:r,altKey:o,shiftKey:i}=t;Di()&&window.event?.type?.startsWith("key")&&e.target==="_blank"&&($t()?n=!0:r=!0);let c=Li()&&$t()&&!ua()?new KeyboardEvent("keydown",{keyIdentifier:"Enter",metaKey:n,ctrlKey:r,altKey:o,shiftKey:i}):new MouseEvent("click",{metaKey:n,ctrlKey:r,altKey:o,shiftKey:i,detail:1,bubbles:!0,cancelable:!0});gt.isOpening=s,ht(e),e.dispatchEvent(c),gt.isOpening=!1}gt.isOpening=!1;let Se=new Map,ls=new Set;function en(){if(typeof window>"u")return;function e(n){return"propertyName"in n}let t=n=>{let r=ee(n);if(!e(n)||!r)return;let o=Se.get(r);o||(o=new Set,Se.set(r,o),r.addEventListener("transitioncancel",s,{once:!0})),o.add(n.propertyName)},s=n=>{let r=ee(n);if(!e(n)||!r)return;let o=Se.get(r);if(o&&(o.delete(n.propertyName),o.size===0&&(r.removeEventListener("transitioncancel",s),Se.delete(r)),Se.size===0)){for(let i of ls)i();ls.clear()}};document.body.addEventListener("transitionrun",t),document.body.addEventListener("transitionend",s)}typeof document<"u"&&(document.readyState!=="loading"?en():document.addEventListener("DOMContentLoaded",en));function zi(){for(const[e]of Se)"isConnected"in e&&!e.isConnected&&Se.delete(e)}function _i(e){requestAnimationFrame(()=>{zi(),Se.size===0?e():ls.add(e)})}function pa(...e){return(...t)=>{for(let s of e)typeof s=="function"&&s(...t)}}let cs=new Map;typeof FinalizationRegistry<"u"&&new FinalizationRegistry(e=>{cs.delete(e)});function Ui(e,t){if(e===t)return e;let s=cs.get(e);if(s)return s.forEach(r=>r.current=t),t;let n=cs.get(t);return n?(n.forEach(r=>r.current=e),e):t}function Ki(...e){return e.length===1&&e[0]?e[0]:t=>{let s=!1;const n=e.map(r=>{const o=tn(r,t);return s||=typeof o=="function",o});if(s)return()=>{n.forEach((r,o)=>{typeof r=="function"?r():tn(e[o],null)})}}}function tn(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function yt(...e){let t={...e[0]};for(let s=1;s<e.length;s++){let n=e[s];for(let r in n){let o=t[r],i=n[r];typeof o=="function"&&typeof i=="function"&&r[0]==="o"&&r[1]==="n"&&r.charCodeAt(2)>=65&&r.charCodeAt(2)<=90?t[r]=pa(o,i):(r==="className"||r==="UNSAFE_className")&&typeof o=="string"&&typeof i=="string"?t[r]=gr(o,i):r==="id"&&o&&i?t.id=Ui(o,i):r==="ref"&&o&&i?t.ref=Ki(o,i):t[r]=i!==void 0?i:o}}return t}function Bi(e,t){Ss(()=>{if(e&&e.ref&&t)return e.ref.current=t.current,()=>{e.ref&&(e.ref.current=null)}})}const Qi=xs.useInsertionEffect??Ss;function Xt(e){const t=l.useRef(null);return Qi(()=>{t.current=e},[e]),l.useCallback((...s)=>{const n=t.current;return n?.(...s)},[])}let Ve="default",ds="",At=new WeakMap;function qi(e){if(fa()){if(Ve==="default"){const t=Ne(e);ds=t.documentElement.style.webkitUserSelect,t.documentElement.style.webkitUserSelect="none"}Ve="disabled"}else if(e instanceof HTMLElement||e instanceof SVGElement){let t="userSelect"in e.style?"userSelect":"webkitUserSelect";At.set(e,e.style[t]),e.style[t]="none"}}function sn(e){if(fa()){if(Ve!=="disabled")return;Ve="restoring",setTimeout(()=>{_i(()=>{if(Ve==="restoring"){const t=Ne(e);t.documentElement.style.webkitUserSelect==="none"&&(t.documentElement.style.webkitUserSelect=ds||""),ds="",Ve="default"}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&e&&At.has(e)){let t=At.get(e),s="userSelect"in e.style?"userSelect":"webkitUserSelect";e.style[s]==="none"&&(e.style[s]=t),e.getAttribute("style")===""&&e.removeAttribute("style"),At.delete(e)}}function nn(e){return e?.defaultView?.__webpack_nonce__||globalThis.__webpack_nonce__||void 0}let Zt=new WeakMap;function Hi(e){let t=e??(typeof document<"u"?document:void 0);if(!t)return nn(t);if(Zt.has(t))return Zt.get(t);let s=t.querySelector('meta[property="csp-nonce"]'),n=s&&s instanceof Ee(s).HTMLMetaElement&&(s.nonce||s.content)||nn(t)||void 0;return n!==void 0&&Zt.set(t,n),n}const ha=xs.createContext({register:()=>{}});ha.displayName="PressResponderContext";function ga(){let e=l.useRef(new Map),t=l.useCallback((r,o,i,c)=>{let d=c?.once?(...v)=>{e.current.delete(i),i(...v)}:i;e.current.set(i,{type:o,eventTarget:r,fn:d,options:c}),r.addEventListener(o,d,c)},[]),s=l.useCallback((r,o,i,c)=>{let d=e.current.get(i)?.fn||i;r.removeEventListener(o,d,c),e.current.delete(i)},[]),n=l.useCallback(()=>{e.current.forEach((r,o)=>{s(r.eventTarget,r.type,o,r.options)})},[s]);return l.useEffect(()=>n,[n]),{addGlobalListener:t,removeGlobalListener:s,removeAllGlobalListeners:n}}function Vi(e){let t=l.useContext(ha);if(t){let{register:s,ref:n,...r}=t;e=yt(r,e),s()}return Bi(t,e.ref),e}class It{#e;constructor(t,s,n,r){this.#e=!0;const i=(r?.target??n.currentTarget)?.getBoundingClientRect();let c,d=0,v,h=null;n.clientX!=null&&n.clientY!=null&&(v=n.clientX,h=n.clientY),i&&(v!=null&&h!=null?(c=v-i.left,d=h-i.top):(c=i.width/2,d=i.height/2)),this.type=t,this.pointerType=s,this.target=n.currentTarget,this.shiftKey=n.shiftKey,this.metaKey=n.metaKey,this.ctrlKey=n.ctrlKey,this.altKey=n.altKey,this.x=c,this.y=d,this.key=n.key}continuePropagation(){this.#e=!1}get shouldStopPropagation(){return this.#e}}const an=Symbol("linkClicked"),rn="react-aria-pressable-style",on="data-react-aria-pressable";function Gi(e){let{onPress:t,onPressChange:s,onPressStart:n,onPressEnd:r,onPressUp:o,onClick:i,isDisabled:c,isPressed:d,preventFocusOnPress:v,shouldCancelOnPointerExit:h,allowTextSelectionOnPress:p,ref:m,...b}=Vi(e),[g,u]=l.useState(!1),f=l.useRef({isPressed:!1,ignoreEmulatedMouseEvents:!1,didFirePressStart:!1,isTriggeringEvent:!1,activePointerId:null,target:null,isOverTarget:!1,pointerType:null,disposables:[]}),{addGlobalListener:x,removeAllGlobalListeners:S}=ga(),y=l.useCallback((k,M)=>{let I=f.current;if(c||I.didFirePressStart)return!1;let w=!0;if(I.isTriggeringEvent=!0,n){let E=new It("pressstart",M,k);n(E),w=E.shouldStopPropagation}return s&&s(!0),I.isTriggeringEvent=!1,I.didFirePressStart=!0,u(!0),w},[c,n,s]),j=l.useCallback((k,M,I=!0)=>{let w=f.current;if(!w.didFirePressStart)return!1;w.didFirePressStart=!1,w.isTriggeringEvent=!0;let E=!0;if(r){let C=new It("pressend",M,k);r(C),E=C.shouldStopPropagation}if(s&&s(!1),u(!1),t&&I&&!c){let C=new It("press",M,k);t(C),E&&=C.shouldStopPropagation}return w.isTriggeringEvent=!1,E},[c,r,s,t]),T=Xt(j),R=l.useCallback((k,M)=>{let I=f.current;if(c)return!1;if(o){I.isTriggeringEvent=!0;let w=new It("pressup",M,k);return o(w),I.isTriggeringEvent=!1,w.shouldStopPropagation}return!0},[c,o]),O=Xt(R),$=l.useCallback(k=>{let M=f.current;if(M.isPressed&&M.target){M.didFirePressStart&&M.pointerType!=null&&j(Oe(M.target,k),M.pointerType,!1),M.isPressed=!1,M.isOverTarget=!1,M.activePointerId=null,M.pointerType=null,S(),p||sn(M.target);for(let I of M.disposables)I();M.disposables=[]}},[p,S,j]),z=Xt($);l.useEffect(()=>{c&&f.current.isPressed&&z({currentTarget:f.current.target,shiftKey:!1,ctrlKey:!1,metaKey:!1,altKey:!1})},[c]);let L=l.useCallback(k=>{h&&$(k)},[h,$]),P=l.useCallback(k=>{c||i?.(k)},[c,i]),D=l.useCallback((k,M)=>{if(!c&&i){let I=new MouseEvent("click",k);Ii(I,M),i(Mi(I))}},[c,i]),K=l.useMemo(()=>{let k=f.current,M={onKeyDown(w){if(es(w.nativeEvent,w.currentTarget)&&pe(w.currentTarget,ee(w))){ln(ee(w),w.key)&&w.preventDefault();let E=!0;!k.isPressed&&!w.repeat&&(k.target=w.currentTarget,k.isPressed=!0,k.pointerType="keyboard",E=y(w,"keyboard"));let C=w.currentTarget,_=U=>{es(U,C)&&!U.repeat&&pe(C,ee(U))&&k.target&&O(Oe(k.target,U),"keyboard")};x(Ne(w.currentTarget),"keyup",pa(_,I),!0),E&&w.stopPropagation(),w.metaKey&&$t()&&k.metaKeyEvents?.set(w.key,w.nativeEvent)}else w.key==="Meta"&&(k.metaKeyEvents=new Map)},onClick(w){if(!(w&&!pe(w.currentTarget,ee(w)))&&w&&w.button===0&&!k.isTriggeringEvent&&!gt.isOpening){let E=!0;if(c&&w.preventDefault(),!k.ignoreEmulatedMouseEvents&&!k.isPressed&&(k.pointerType==="virtual"||Fi(w.nativeEvent))){let C=y(w,"virtual"),_=O(w,"virtual"),U=T(w,"virtual");P(w),E=C&&_&&U}else if(k.isPressed&&k.pointerType!=="keyboard"){let C=k.pointerType||w.nativeEvent.pointerType||"virtual",_=O(Oe(w.currentTarget,w),C),U=T(Oe(w.currentTarget,w),C,!0);E=_&&U,k.isOverTarget=!1,P(w),z(w)}k.ignoreEmulatedMouseEvents=!1,E&&w.stopPropagation()}}},I=w=>{if(k.isPressed&&k.target&&es(w,k.target)){ln(ee(w),w.key)&&w.preventDefault();let E=ee(w),C=pe(k.target,E);T(Oe(k.target,w),"keyboard",C),C&&D(w,k.target),S(),w.key!=="Enter"&&Ts(k.target)&&pe(k.target,E)&&!w[an]&&(w[an]=!0,gt(k.target,w,!1)),k.isPressed=!1,k.metaKeyEvents?.delete(w.key)}else if(w.key==="Meta"&&k.metaKeyEvents?.size){let E=k.metaKeyEvents;k.metaKeyEvents=void 0;for(let C of E.values())k.target?.dispatchEvent(new KeyboardEvent("keyup",C))}};if(typeof PointerEvent<"u"){M.onPointerDown=C=>{if(C.button!==0||!pe(C.currentTarget,ee(C)))return;if(Oi(C.nativeEvent)){k.pointerType="virtual";return}k.pointerType=C.pointerType;let _=!0;if(!k.isPressed){k.isPressed=!0,k.isOverTarget=!0,k.activePointerId=C.pointerId,k.target=C.currentTarget,p||qi(k.target),_=y(C,k.pointerType);let U=ee(C);"releasePointerCapture"in U&&("hasPointerCapture"in U?U.hasPointerCapture(C.pointerId)&&U.releasePointerCapture(C.pointerId):U.releasePointerCapture(C.pointerId)),x(Ne(C.currentTarget),"pointerup",w,!1),x(Ne(C.currentTarget),"pointercancel",E,!1)}_&&C.stopPropagation()},M.onMouseDown=C=>{if(pe(C.currentTarget,ee(C))&&C.button===0){if(v){let _=Ai(C.target);_&&k.disposables.push(_)}C.stopPropagation()}},M.onPointerUp=C=>{!pe(C.currentTarget,ee(C))||k.pointerType==="virtual"||C.button===0&&!k.isPressed&&O(C,k.pointerType||C.pointerType)},M.onPointerEnter=C=>{C.pointerId===k.activePointerId&&k.target&&!k.isOverTarget&&k.pointerType!=null&&(k.isOverTarget=!0,y(Oe(k.target,C),k.pointerType))},M.onPointerLeave=C=>{C.pointerId===k.activePointerId&&k.target&&k.isOverTarget&&k.pointerType!=null&&(k.isOverTarget=!1,T(Oe(k.target,C),k.pointerType,!1),L(C))};let w=C=>{if(C.pointerId===k.activePointerId&&k.isPressed&&C.button===0&&k.target){if(pe(k.target,ee(C))&&k.pointerType!=null){let _=!1,U=setTimeout(()=>{k.isPressed&&k.target instanceof HTMLElement&&(_?z(C):(ht(k.target),k.target.click()))},80);x(C.currentTarget,"click",()=>_=!0,!0),k.disposables.push(()=>clearTimeout(U))}else z(C);k.isOverTarget=!1}},E=C=>{z(C)};M.onDragStart=C=>{pe(C.currentTarget,ee(C))&&z(C)}}return M},[x,c,v,S,p,L,y,P,D]);return l.useEffect(()=>{if(!m)return;const k=Ne(m.current);if(!k||!k.head||k.getElementById(rn))return;const M=k.createElement("style");M.id=rn;let I=Hi(k);I&&(M.nonce=I),M.textContent=`
2
+ @layer {
3
+ [${on}] {
4
+ touch-action: pan-x pan-y pinch-zoom;
5
+ }
6
+ }
7
+ `.trim(),k.head.prepend(M)},[m]),l.useEffect(()=>{let k=f.current;return()=>{p||sn(k.target??void 0);for(let M of k.disposables)M();k.disposables=[]}},[p]),{isPressed:d||g,pressProps:yt(b,K,{[on]:!0})}}function Ts(e){return e.tagName==="A"&&e.hasAttribute("href")}function es(e,t){const{key:s,code:n}=e,r=t,o=r.getAttribute("role");return(s==="Enter"||s===" "||s==="Spacebar"||n==="Space")&&!(r instanceof Ee(r).HTMLInputElement&&!ba(r,s)||r instanceof Ee(r).HTMLTextAreaElement||r.isContentEditable)&&!((o==="link"||!o&&Ts(r))&&s!=="Enter")}function Oe(e,t){let s=t.clientX,n=t.clientY;return{currentTarget:e,shiftKey:t.shiftKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,altKey:t.altKey,clientX:s,clientY:n,key:t.key}}function Wi(e){return e instanceof HTMLInputElement?!1:e instanceof HTMLButtonElement?e.type!=="submit"&&e.type!=="reset":!Ts(e)}function ln(e,t){return e instanceof HTMLInputElement?!ba(e,t):Wi(e)}const Yi=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);function ba(e,t){return e.type==="checkbox"||e.type==="radio"?t===" ":Yi.has(e.type)}let Ji=0;const ts=new Map;function Xi(e){let[t,s]=l.useState();return Ss(()=>{if(!e)return;let n=ts.get(e);if(n)s(n.element.id);else{let r=`react-aria-description-${Ji++}`;s(r);let o=document.createElement("div");o.id=r,o.style.display="none",o.textContent=e,document.body.appendChild(o),n={refCount:0,element:o},ts.set(e,n)}return n.refCount++,()=>{n&&--n.refCount===0&&(n.element.remove(),ts.delete(e))}},[e]),{"aria-describedby":e?t:void 0}}const Zi=500;function el(e){let{isDisabled:t,onLongPressStart:s,onLongPressEnd:n,onLongPress:r,threshold:o=Zi,accessibilityDescription:i}=e;const c=l.useRef(void 0);let{addGlobalListener:d,removeGlobalListener:v}=ga(),{pressProps:h}=Gi({isDisabled:t,onPressStart(m){if(m.continuePropagation(),(m.pointerType==="mouse"||m.pointerType==="touch")&&(s&&s({...m,type:"longpressstart"}),c.current=setTimeout(()=>{m.target.dispatchEvent(new PointerEvent("pointercancel",{bubbles:!0})),Ne(m.target).activeElement!==m.target&&ht(m.target),r&&r({...m,type:"longpress"}),c.current=void 0},o),m.pointerType==="touch")){let b=u=>{u.preventDefault()},g=Ee(m.target);d(m.target,"contextmenu",b,{once:!0}),d(g,"pointerup",()=>{setTimeout(()=>{v(m.target,"contextmenu",b)},30)},{once:!0})}},onPressEnd(m){c.current&&clearTimeout(c.current),n&&(m.pointerType==="mouse"||m.pointerType==="touch")&&n({...m,type:"longpressend"})}}),p=Xi(r&&!t?i:void 0);return{longPressProps:yt(h,p)}}const Kt=ie("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 xa=ie("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]);const va=ie("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 tl=ie("MailCheck",[["path",{d:"M22 13V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v12c0 1.1.9 2 2 2h8",key:"12jkf8"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}],["path",{d:"m16 19 2 2 4-4",key:"1b14m6"}]]);const Es=ie("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 sl=ie("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 nl=ie("Minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);const Bt=ie("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 ya=ie("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 ka=ie("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 Ze=ie("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 al=ie("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 rl=ie("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"}]]),ol=({address:e,showTrustedBadge:t=!1})=>{const s=t?a.jsx(Kt,{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?a.jsxs("span",{children:[a.jsx("span",{className:"text-fg",children:e.displayName}),a.jsxs("span",{className:"text-fg-muted",children:[" ","<",e.normalizedEmail,">"]}),s]}):a.jsxs("span",{className:"text-fg",children:[e.normalizedEmail,s]})},il=({label:e,addresses:t,showTrustedBadge:s=!1})=>{const[n,r]=l.useState(!1);if(t.length===0)return null;const o=t.length>3,i=c=>{const d=s&&c.flags?.trusted?.value===!0;return a.jsx(ol,{address:c,showTrustedBadge:d})};return a.jsxs("div",{className:"flex gap-2 text-sm",children:[a.jsxs("span",{className:"text-fg-muted shrink-0 w-12",children:[e,":"]}),a.jsx("div",{className:"flex-1 min-w-0",children:n?a.jsx("div",{className:"flex flex-wrap gap-1",children:t.map((c,d)=>a.jsxs("span",{children:[i(c),d<t.length-1&&", "]},d))}):a.jsx("div",{className:"truncate",children:t.map((c,d)=>a.jsxs("span",{children:[i(c),d<t.length-1&&", "]},d))})}),o&&a.jsx("button",{type:"button",onClick:c=>{c.stopPropagation(),r(!n)},className:"shrink-0 text-fg-muted hover:text-fg transition-colors","aria-label":n?"Collapse":"Expand",children:n?a.jsx(mt,{className:"h-4 w-4"}):a.jsx(Fn,{className:"h-4 w-4"})})]})},ll={unknown:{label:"Unknown sender",tone:"neutral"},wellknown:{label:"Known sender",tone:"positive"},vip:{label:"VIP",tone:"accent"}};function He({label:e,children:t,className:s}){return a.jsxs("section",{className:F("border-b border-line px-row-inset py-3",s),children:[a.jsx("h3",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e}),a.jsx("div",{className:"mt-2",children:t})]})}function cl({sender:e}){const t=ll[e.trust],s=e.inboundCount==null?null:(e.replyCount??0)>0?`${e.inboundCount} received · you replied ${e.replyCount}×`:`${e.inboundCount} received · you've never replied`;return a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx(pt,{name:e.name,email:e.email,size:"md"}),a.jsxs("div",{className:"min-w-0",children:[a.jsx("div",{className:"truncate text-sm font-semibold text-fg",children:e.name}),a.jsx("div",{className:"truncate text-2xs text-fg-subtle",children:e.email})]})]}),a.jsx("div",{className:"mt-2 flex items-center gap-2",children:e.addressUnverified?a.jsx(Te,{tone:"danger",dot:!0,children:"Address couldn't be verified"}):a.jsx(Te,{tone:t.tone,dot:!0,children:t.label})}),a.jsxs("p",{className:"mt-2 text-xs text-fg-muted",children:["First seen ",e.firstSeenLabel,s?` · ${s}`:""]})]})}function dl({auth:e,onShowSimilar:t}){if(e.verdict==="aligned")return a.jsxs("div",{className:"flex items-start gap-2 text-xs text-fg-muted",children:[a.jsx(ai,{className:"mt-0.5 size-3.5 shrink-0 text-positive"}),a.jsx("span",{children:e.summary})]});if(e.verdict==="caution")return a.jsxs("div",{className:"flex items-start gap-2 rounded-md bg-warning/10 p-3 text-warning",children:[a.jsx(al,{className:"mt-0.5 size-4 shrink-0"}),a.jsx("p",{className:"text-xs leading-relaxed",children:e.summary})]});const s=e.addressUnreadable?"This sender can't be verified":"This message may be impersonating someone";return a.jsxs("div",{className:"rounded-md bg-danger-soft p-3",children:[a.jsxs("div",{className:"flex items-start gap-2",children:[a.jsx(Ze,{className:"mt-0.5 size-4 shrink-0 text-danger"}),a.jsxs("div",{className:"min-w-0",children:[a.jsx("p",{className:"text-sm font-semibold text-danger",children:s}),a.jsx("p",{className:"mt-1 text-xs leading-relaxed text-fg",children:e.summary}),!e.addressUnreadable&&e.dkimDomain&&a.jsxs("p",{className:"mt-1 text-2xs text-fg-muted",children:["Sent from"," ",a.jsx("code",{className:"rounded bg-surface px-1 py-0.5",children:e.dkimDomain}),", claims to be"," ",a.jsx("code",{className:"rounded bg-surface px-1 py-0.5",children:e.fromDomain})]})]})]}),e.similarCount!=null&&e.similarCount>0&&a.jsxs(H,{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 dt({icon:e,label:t,active:s,danger:n,onClick:r,pending:o}){const i=r===void 0||o===!0;return a.jsxs("button",{type:"button",onClick:r,disabled:i,className:F("flex items-center gap-2 rounded-md border px-2 py-1 text-xs transition-colors",s?"border-accent-2 bg-accent-2-soft text-accent-2":"border-line text-fg-muted hover:border-line-strong hover:text-fg",n&&!s&&"text-danger hover:bg-danger-soft",i&&"cursor-not-allowed opacity-50 hover:border-line"),children:[e,t]})}const ul={sender:"matched: sender",recipient:"matched: recipient",subject:"matched: subject",attachment:"matched: attachment",body:"matched: body",entities:"matched: entities"};function ja({data:e,onClose:t,onShowSimilar:s,actions:n,similarState:r="ready",similarLinkComponent:o,className:i,hideCloseButton:c=!1,reportSpamPending:d=!1,notSpamPending:v=!1}){const{sender:h,authenticity:p,category:m,flags:b={},similar:g}=e;return a.jsxs("aside",{className:F("flex w-76 shrink-0 flex-col overflow-y-auto border-l border-line bg-surface",i),children:[a.jsxs("header",{className:"flex h-pane-header shrink-0 items-center justify-between border-b border-line px-row-inset",children:[a.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"}),!c&&a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(Dt,{className:"size-3.5"}),onClick:t,"aria-label":"Collapse intelligence sidebar"})]}),a.jsx(He,{label:"Sender",children:a.jsx(cl,{sender:h})}),a.jsx(He,{label:"Authenticity",children:a.jsx(dl,{auth:p,onShowSimilar:s})}),a.jsx(He,{label:"Category",children:a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Te,{tone:On[m.value],children:m.value}),m.overridden&&a.jsx("span",{className:"text-2xs text-fg-subtle",children:"your override"}),a.jsx("button",{type:"button",className:F("ml-auto text-2xs text-accent hover:underline",!n?.onReclassify&&"cursor-not-allowed opacity-50 hover:no-underline"),disabled:!n?.onReclassify,onClick:n?.onReclassify,children:"reclassify"})]})}),a.jsxs(He,{label:"Quick actions",children:[a.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[a.jsx(dt,{icon:a.jsx(Ye,{className:"size-3.5"}),label:"VIP",active:b.vip,onClick:n?.onToggleVip}),a.jsx(dt,{icon:a.jsx(yo,{className:"size-3.5"}),label:"Mute",active:b.muted,onClick:n?.onToggleMute}),n?.onNotSpam&&a.jsx(dt,{icon:a.jsx(tl,{className:"size-3.5"}),label:v?"Undoing…":"Not spam",active:!0,onClick:n.onNotSpam,pending:v}),n?.onReportSpam&&a.jsx(dt,{icon:a.jsx(rl,{className:"size-3.5"}),label:d?"Reporting…":"Report spam",danger:!0,onClick:n.onReportSpam,pending:d}),a.jsx(dt,{icon:a.jsx(sl,{className:"size-3.5"}),label:"Unsubscribe",active:b.unsubscribed,onClick:n?.onToggleUnsubscribe})]}),n?.onNotSpam&&a.jsx("p",{className:"mt-1.5 text-2xs text-fg-subtle",children:"You reported this message as spam"})]}),(r!=="ready"||g.length>0)&&a.jsx(He,{label:"Similar messages",children:r==="loading"?a.jsx("div",{className:"animate-pulse space-y-2",children:Array.from({length:3}).map((u,f)=>a.jsxs("div",{className:"space-y-1",children:[a.jsx("div",{className:"h-3 w-3/4 rounded bg-surface-sunken"}),a.jsx("div",{className:"h-2.5 w-1/2 rounded bg-surface-sunken"})]},f))}):r==="error"?a.jsx("p",{className:"text-xs text-fg-subtle",children:"Similarity search unavailable"}):a.jsx("ul",{className:"-mx-1 space-y-1",children:g.map(u=>{const f="block w-full rounded-md px-1 py-1 text-left hover:bg-surface-sunken",x=`Open message from ${u.fromName||"unknown sender"}: ${u.subject}`,S=a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[a.jsx("span",{className:"truncate text-xs font-medium text-fg",children:u.fromName}),a.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:u.timeLabel})]}),a.jsx("div",{className:"truncate text-xs text-fg-muted",children:u.subject}),a.jsx("span",{className:"mt-1 inline-block rounded-full bg-surface-sunken px-1.5 py-px text-2xs text-fg-subtle",children:ul[u.matched]})]});return a.jsx("li",{children:o?o({mailboxId:u.mailboxId,threadId:u.threadId,messageId:u.id,className:f,ariaLabel:x,children:S}):a.jsx("div",{className:f,children:S})},u.id)})})}),a.jsx(He,{label:"Coming soon",className:"border-b-0 opacity-70",children:a.jsxs("div",{className:"space-y-2",children:[a.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed border-line p-2",children:[a.jsx(We,{className:"mt-0.5 size-3.5 shrink-0 text-fg-subtle"}),a.jsxs("div",{children:[a.jsx("div",{className:"text-xs font-medium text-fg-muted",children:"Suggested actions"}),a.jsx("div",{className:"text-2xs text-fg-subtle",children:'"Create a filter for messages like this" — on-device model'})]})]}),a.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed border-line p-2",children:[a.jsx(We,{className:"mt-0.5 size-3.5 shrink-0 text-fg-subtle"}),a.jsxs("div",{children:[a.jsx("div",{className:"text-xs font-medium text-fg-muted",children:"Thread summary"}),a.jsx("div",{className:"text-2xs text-fg-subtle",children:"One-paragraph digest — Bedrock"})]})]})]})})]})}const us=e=>({shiftKey:e.shiftKey,metaKey:e.metaKey,ctrlKey:e.ctrlKey}),cn=e=>e.shiftKey||e.metaKey||e.ctrlKey,fl=e=>e.shiftKey?"range":e.metaKey||e.ctrlKey?"toggle":"open",ml=(e,t)=>!t&&e>0,pl=(e,t,s)=>{const n=e.indexOf(s);if(n===-1)return[];const r=t===void 0?-1:e.indexOf(t);if(r===-1)return[s];const o=Math.min(r,n),i=Math.max(r,n);return e.slice(o,i+1)},hl=(e,t,s,n)=>t!==void 0&&e.includes(t)?t:s!==void 0&&e.includes(s)?s:n,gl=(e,t)=>{const s=new Set(t),n=new Set;for(const r of e)s.has(r)&&n.add(r);return n},bl=(e,t,s)=>{if(e.length===0)return;const n=t===void 0?-1:e.indexOf(t);if(n===-1)return s>0?e[0]:e[e.length-1];const r=Math.min(Math.max(n+s,0),e.length-1);return e[r]},xl=e=>{const[t,s]=l.useState(()=>new Set(e?.initialSelectedIds)),[n,r]=l.useState(void 0),o=l.useCallback(u=>t.has(u),[t]),i=l.useCallback(u=>{r(u),s(f=>{const x=new Set(f);return x.has(u)?x.delete(u):x.add(u),x})},[]),c=l.useCallback(u=>{r(u),s(f=>{if(f.has(u))return f;const x=new Set(f);return x.add(u),x})},[]),d=l.useCallback(u=>{s(f=>{if(!f.has(u))return f;const x=new Set(f);return x.delete(u),x})},[]),v=l.useCallback(u=>{s(new Set(u))},[]),h=l.useCallback(()=>{r(void 0),s(new Set)},[]),p=l.useCallback(u=>{s(f=>u.every(S=>f.has(S))?new Set:new Set(u))},[]),m=l.useCallback(u=>{r(u)},[]),b=l.useCallback(u=>{s(f=>{if(f.size===0)return f;const x=gl(f,u);return x.size===f.size?f:x})},[]),g=l.useCallback((u,f,x)=>{const S=hl(u,n,x,f);s(y=>{const j=pl(u,S,f);if(j.length===0)return y;const T=new Set(y);for(const R of j)T.add(R);return T}),r(S)},[n]);return{selectedIds:t,selectedCount:t.size,hasSelection:t.size>0,isSelected:o,toggle:i,select:c,deselect:d,selectAll:v,clearSelection:h,toggleAll:p,selectRange:g,setAnchor:m,anchorId:n,intersectWith:b}};function Cf({hints:e=ko,className:t}){return e.length===0?null:a.jsx("footer",{className:F("flex items-center gap-2 border-t border-line px-row-inset py-1 text-2xs text-fg-subtle",t),children:e.map(s=>a.jsx(vl,{hint:s},s.label))})}function vl({hint:e}){return a.jsxs("span",{className:"flex items-center gap-1",children:[e.keys.map(t=>a.jsx(Ao,{children:t},t)),a.jsx("span",{children:e.label})]})}const wa="outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",Ca=({active:e,focused:t})=>F("relative flex h-8 w-full items-center gap-2 px-row-inset text-left",wa,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"),Rs=({active:e,focused:t})=>F("relative flex w-full items-start gap-3 py-2 pl-5 pr-row-inset text-left transition-colors",wa,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 Sa({thread:e}){const t=!e.isRead;return a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"flex w-4 shrink-0 items-center justify-center",children:e.suspicious?a.jsx(Ze,{className:"size-3.5 text-danger"}):e.starred?a.jsx(Ye,{className:"size-3 fill-warning text-warning"}):t?a.jsx("span",{className:"size-1.5 rounded-full bg-accent"}):null}),a.jsx("span",{className:F("w-36 shrink-0 truncate text-xs",t?"font-semibold text-fg":"text-fg-muted"),children:e.fromName}),a.jsxs("span",{className:"min-w-0 flex-1 truncate text-xs",children:[a.jsx("span",{className:F(t?"font-medium text-fg":"text-fg-muted"),children:e.subject}),a.jsxs("span",{className:"text-fg-subtle",children:[" — ",e.snippet]})]}),e.hasAttachment&&a.jsx(Bt,{className:"size-3 shrink-0 text-fg-subtle",role:"img","aria-label":"Has an attachment"}),a.jsx("span",{className:"w-11 shrink-0 text-right text-2xs text-fg-subtle tabular-nums",children:e.timeLabel})]})}function dn(e,t){const s=t?.trim();if(!s)return e;const n=e.toLowerCase(),r=s.toLowerCase(),o=[];let i=0,c=n.indexOf(r,i),d=0;for(;c!==-1;)c>i&&o.push(e.slice(i,c)),o.push(a.jsx("mark",{className:"bg-transparent font-semibold text-fg",children:e.slice(c,c+r.length)},d++)),i=c+r.length,c=n.indexOf(r,i);return i<e.length&&o.push(e.slice(i)),o}function yl({thread:e,badge:t,highlightQuery:s}){const n=!e.isRead;return a.jsxs("span",{className:"min-w-0 flex-1",children:[a.jsxs("span",{className:"flex items-baseline justify-between gap-2",children:[a.jsxs("span",{className:F("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"&&a.jsx("span",{className:"size-1.5 shrink-0 rounded-full bg-accent-2"}),a.jsx("span",{className:"truncate",children:e.fromName}),e.messageCount!=null&&e.messageCount>1&&a.jsx("span",{className:"shrink-0 text-2xs font-normal text-fg-subtle",children:e.messageCount})]}),a.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.timeLabel})]}),a.jsxs("span",{className:"flex items-center gap-1.5",children:[a.jsx("span",{className:F("truncate text-sm",n?"text-fg":"text-fg-muted"),children:dn(e.subject,s)}),e.suspicious&&a.jsx(Ze,{className:"size-3.5 shrink-0 text-danger"}),e.starred&&a.jsx(Ye,{className:"size-3 shrink-0 fill-warning text-warning"}),e.hasAttachment&&a.jsx(Bt,{className:"size-3 shrink-0 text-fg-subtle",role:"img","aria-label":"Has an attachment"})]}),a.jsxs("span",{className:"flex items-center gap-1.5",children:[a.jsx("span",{className:"line-clamp-1 min-w-0 flex-1 text-xs text-fg-subtle",children:dn(e.snippet,s)}),e.category&&e.category!=="personal"&&a.jsx(Te,{tone:On[e.category],className:"shrink-0",children:e.category}),e.labels?.map(r=>a.jsx(br,{label:r,className:"max-w-20"},r.labelId)),t]})]})}function kl({thread:e,selection:t}){if(!t)return a.jsx(pt,{name:e.fromName,email:e.fromEmail,size:"sm"});const{checked:s,alwaysVisible:n}=t;return a.jsxs("span",{className:"relative size-7 shrink-0",children:[a.jsx(pt,{name:e.fromName,email:e.fromEmail,size:"sm",className:F("absolute inset-0 transition-opacity sm:group-hover:opacity-0",(s||n)&&"opacity-0")}),a.jsx("span",{role:"button",tabIndex:-1,onClick:t.onToggle,onKeyDown:r=>{r.key!=="Enter"&&r.key!==" "||(r.preventDefault(),r.stopPropagation(),t.onToggle(r))},className:F("absolute inset-0 size-7 items-center justify-center rounded-full border transition-opacity",n?"flex":"hidden sm:flex",s?"bg-accent border-accent text-accent-fg opacity-100":n?"border-fg-subtle/40 bg-canvas opacity-100":"border-fg-subtle/40 bg-canvas opacity-0 group-hover:opacity-100"),"aria-label":s?"Deselect message":"Select message",children:s&&a.jsx(Ft,{className:"size-3"})})]})}function Ms({thread:e,selection:t,badge:s,highlightQuery:n}){const r=!e.isRead;return a.jsxs(a.Fragment,{children:[r&&a.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),a.jsx(kl,{thread:e,selection:t}),a.jsx(yl,{thread:e,badge:s,highlightQuery:n})]})}const Na=e=>({...xr,[jo]:"","data-message-id":e.id});function Sf({thread:e,active:t,focused:s,tabIndex:n,onClick:r}){return a.jsx("button",{type:"button",...Na(e),tabIndex:n,onClick:r,className:Ca({active:t,focused:s}),children:a.jsx(Sa,{thread:e})})}function Nf({thread:e,active:t,focused:s,tabIndex:n,selection:r,onClick:o}){return a.jsx("button",{type:"button",...Na(e),tabIndex:n,onClick:o,className:F("group",Rs({active:t,focused:s})),children:a.jsx(Ms,{thread:e,selection:r})})}let Ge;const jl=5e3;function Ta(e){e.preventDefault(),Lt()}function Lt(){Ge!==void 0&&(clearTimeout(Ge),Ge=void 0,document.removeEventListener("contextmenu",Ta,!0),document.removeEventListener("pointerup",Lt,!0))}function wl(){Ge===void 0?(document.addEventListener("contextmenu",Ta,!0),document.addEventListener("pointerup",Lt,!0)):clearTimeout(Ge),Ge=setTimeout(Lt,jl)}function Cl({onLongPress:e,isDisabled:t,delayMs:s=500,accessibilityDescription:n}){const{longPressProps:r}=el({isDisabled:t,threshold:s,accessibilityDescription:n,onLongPress:e}),o=l.useCallback(i=>{i.pointerType!=="touch"&&i.pointerType!=="pen"||wl()},[]);return{longPressProps:yt(r,{onPointerDown:o})}}const ut="min-h-11 min-w-11 px-0";function Ea({hasThread:e,onReply:t,onReplyAll:s,onForward:n,isStarred:r,onToggleStar:o,onDelete:i,isRead:c,onToggleRead:d,moveSlot:v,overflowItems:h=[],onUnavailable:p,unavailableHint:m,className:b}){const g=(f,x)=>()=>{if(!e){p?.(f);return}x?.()},u=d?[{key:"toggle-read",label:c?"Mark as unread":"Mark as read",icon:c?a.jsx(Fo,{className:"size-4"}):a.jsx(Es,{className:"size-4"}),onSelect:g("toggleRead",d)}]:[];return a.jsxs("div",{className:F("relative",b),children:[a.jsxs("div",{className:"flex h-12 shrink-0 items-center gap-0.5 bg-canvas px-1",children:[t&&a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(ka,{className:"size-5"}),onClick:g("reply",t),"aria-label":"Reply",title:"Reply",className:ut}),s&&a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(ya,{className:"size-5"}),onClick:g("replyAll",s),"aria-label":"Reply all",title:"Reply all",className:ut}),n&&a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(va,{className:"size-5"}),onClick:g("forward",n),"aria-label":"Forward",title:"Forward",className:ut}),a.jsx("div",{className:"flex-1"}),o&&a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(Ye,{className:F("size-5",r&&"fill-warning text-warning")}),onClick:g("star",o),"aria-label":r?"Unstar":"Star","aria-pressed":r,title:r?"Unstar":"Star",className:ut}),v,i&&a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(Ot,{className:"size-5"}),onClick:g("delete",i),"aria-label":"Move to Trash",title:"Move to Trash",className:ut}),a.jsx(Wn,{triggerLabel:"More actions",items:[...u,...h]})]}),!e&&m&&a.jsx("p",{role:"status",className:"bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:m})]})}function Sl({open:e=!1,enabled:t=!0,onToggle:s,className:n}){return a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(zn,{className:"size-4"}),title:"Intelligence","aria-label":e?"Hide intelligence sidebar":"Show intelligence sidebar","aria-pressed":e,disabled:!t,onClick:s,className:F(e&&"bg-accent-2-soft text-accent-2",n)})}function Nl({hasThread:e,onUnavailable:t,unavailableHint:s,isStarred:n,showTriage:r=!0,onReply:o,onReplyAll:i,onForward:c,onDelete:d,onToggleStar:v,moveSlot:h,onMove:p,replyTitle:m="Reply (r)",replyAllTitle:b="Reply all (a)",forwardTitle:g="Forward (f)",deleteTitle:u="Move to Trash (#)",flagTitle:f="Star (s)",children:x,className:S}){const y=(j,T)=>()=>{if(!e||!T){t?.(j);return}T()};return a.jsxs("div",{className:"relative",children:[a.jsxs("header",{className:F("flex h-pane-header shrink-0 items-center gap-1 border-b border-line bg-surface px-3",S),children:[a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(ka,{className:"size-4"}),title:m,"aria-label":"Reply",onClick:y("reply",o)}),a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(ya,{className:"size-4"}),title:b,"aria-label":"Reply all",onClick:y("replyAll",i)}),a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(va,{className:"size-4"}),title:g,"aria-label":"Forward",onClick:y("forward",c)}),r&&a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"mx-1 h-4 w-px bg-line","aria-hidden":!0}),a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(Ot,{className:"size-4"}),title:u,"aria-label":"Move to Trash",onClick:y("delete",d)}),h??a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(vs,{className:"size-4"}),title:"Move to mailbox","aria-label":"Move to mailbox",onClick:y("move",p)}),a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(Ye,{className:F("size-4",n&&"fill-warning text-warning")}),title:f,"aria-label":"Star",onClick:y("flag",v)})]}),a.jsx("div",{className:"flex-1"}),x]}),s&&a.jsx("p",{role:"status",className:"border-b border-line bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:s})]})}function Ra({message:e,onClick:t,isFocused:s,isUnread:n,trailing:r}){const o=a.jsxs(a.Fragment,{children:[a.jsx(Fn,{className:"size-3.5 shrink-0 text-fg-subtle"}),a.jsxs("div",{className:"relative shrink-0",children:[a.jsx(pt,{name:e.fromName,email:e.fromEmail,size:"md"}),n&&a.jsx("span",{className:"absolute -top-0.5 -right-0.5 size-2 rounded-full border border-canvas bg-accent"})]}),a.jsx("span",{className:F("w-36 shrink-0 truncate text-sm",n?"font-semibold text-fg":"font-medium text-fg-muted"),children:e.fromName}),a.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-fg-subtle",children:e.snippet}),r??a.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.dateLabel})]}),i=F("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",s&&"bg-surface-sunken ring-1 ring-inset ring-accent/30");return t?a.jsx("div",{role:"button",tabIndex:0,"aria-expanded":!1,onClick:t,onKeyDown:c=>{vr(c)&&(c.preventDefault(),t())},className:F(i,"cursor-pointer"),children:o}):a.jsx("div",{className:i,children:o})}function Ma({message:e,warning:t,onHeaderClick:s,isFocused:n,senderBadge:r,trailing:o,to:i,indicators:c,actionMenu:d,actionBar:v,body:h}){const p=a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[a.jsxs("span",{className:"text-sm font-semibold text-fg",children:[e.fromName,r]}),o??a.jsx("span",{className:"text-2xs text-fg-subtle",children:e.dateLabel})]}),a.jsx("div",{className:"text-xs text-fg-subtle",children:e.fromEmail}),i!==null&&a.jsx("div",{className:"text-xs text-fg-subtle",children:i??a.jsxs(a.Fragment,{children:["to ",e.toLabel]})})]});return a.jsxs("div",{className:"px-2 py-3 lg:px-4",children:[a.jsxs("div",{className:F("-mx-2 -my-1 flex items-start gap-3 rounded-sm px-2 py-1",n&&"ring-1 ring-inset ring-accent/30"),children:[s?a.jsx("button",{type:"button",onClick:s,"aria-expanded":!0,"aria-label":"Collapse message",className:"mt-1 shrink-0 text-fg-subtle transition-colors hover:text-fg",children:a.jsx(mt,{className:"size-3.5"})}):a.jsx(mt,{className:"mt-1 size-3.5 shrink-0 text-fg-subtle"}),a.jsx(pt,{name:e.fromName,email:e.fromEmail,size:"md"}),a.jsxs("div",{className:"min-w-0 flex-1",children:[s?a.jsx("button",{type:"button",onClick:s,className:"w-full text-left",children:p}):p,c]}),d&&a.jsx("div",{className:"shrink-0",children:d})]}),t&&a.jsxs("div",{className:"mt-3 flex items-start gap-3 rounded-md bg-danger-soft p-3",children:[a.jsx(Ze,{className:"mt-0.5 size-4 shrink-0 text-danger"}),a.jsxs("div",{className:"text-sm text-fg",children:[a.jsx("span",{className:"font-semibold text-danger",children:"Caution: "}),t," ",a.jsx("button",{type:"button",className:"text-accent underline",children:"Why?"})]})]}),v&&a.jsx("div",{className:"mt-3 -mx-2 lg:-mx-4",children:v}),a.jsx(Oo,{children:h??a.jsx(zo,{className:"mt-3",html:e.bodyHtml,category:e.framed?"newsletter":"personal",allowImages:!0})})]})}function Tl({thread:e,onBack:t,intelligence:s,intelligenceOpen:n,onToggleIntelligence:r,actions:o,children:i,touchHandlers:c}){const[d,v]=l.useState(!1),h=r!==void 0,p=h?n??!1:d,m=!!s||h,b=()=>{if(h){r?.();return}v(u=>!u)},g=()=>{if(h){p&&r?.();return}v(!1)};return a.jsxs("article",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[a.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line bg-surface px-row-inset",children:[a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(_n,{className:"size-4"}),onClick:t,"aria-label":"Back to messages",className:"-ml-1 shrink-0"}),a.jsx("h2",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e.subject}),m&&a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(zn,{className:"size-4"}),onClick:b,"aria-label":p?"Hide intelligence panel":"Show intelligence panel","aria-pressed":p,title:"Intelligence",className:F("shrink-0",p&&"bg-accent-2-soft text-accent-2")})]}),a.jsx("div",{className:"flex-1 overflow-y-auto",style:c?{touchAction:"pan-y"}:void 0,...c,children:i??[...e.messages].reverse().map(u=>{const f=x=>x?()=>x(u.id):void 0;return u.expanded?a.jsx(Ma,{message:u,warning:e.warning,onHeaderClick:f(o?.onToggleExpand),actionBar:a.jsx(Ea,{hasThread:!0,onReply:f(o?.onReply),onReplyAll:f(o?.onReplyAll),onForward:f(o?.onForward),onToggleStar:f(o?.onToggleStar),onDelete:f(o?.onDelete),onToggleRead:f(o?.onToggleRead),moveSlot:o?.moveSlot?.(u.id)})},u.id):a.jsx(Ra,{message:u,onClick:f(o?.onToggleExpand)},u.id)})}),s&&!h&&a.jsx(yr,{open:p,onClose:g,title:"Intelligence",anchor:"right",className:"p-0",children:a.jsx(ja,{data:s,onClose:g,className:"h-full w-full border-l-0"})})]})}function El({state:e,onRetry:t}){return a.jsxs("div",{role:"alert","data-testid":"attachment-error",className:"flex items-start gap-2 border-t border-danger/30 bg-danger-soft px-2 py-2 text-xs",children:[a.jsx(kr,{className:"mt-0.5 size-3.5 shrink-0 text-danger","aria-hidden":!0}),a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsx("p",{className:"font-medium text-danger",children:e.title}),a.jsx("p",{className:"mt-0.5 text-fg-muted",children:e.detail})]}),a.jsxs("div",{className:"flex shrink-0 items-center gap-3",children:[a.jsx("button",{type:"button",onClick:t,className:"font-medium text-accent hover:underline",children:"Try again"}),e.reportUrl&&a.jsx("a",{href:e.reportUrl,target:"_blank",rel:"noreferrer",className:"font-medium text-accent hover:underline",children:"Report this"})]})]})}function Rl({attachments:e,onDownload:t,hasUnlistedAttachment:s=!1,className:n}){return e.length===0&&!s?null:a.jsxs("section",{"aria-label":"Attachments","data-testid":"attachment-list",className:F("space-y-1.5",n),children:[a.jsxs("h3",{className:"flex items-center gap-1.5 text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:[a.jsx(Bt,{className:"size-3","aria-hidden":!0}),e.length===0?"Attachment":e.length===1?"1 attachment":`${e.length} attachments`]}),e.length>0&&a.jsx("ul",{className:"overflow-hidden rounded-sm border border-line bg-surface",children:e.map(r=>{const o=r.download.status==="downloading";return a.jsxs("li",{className:"border-t border-line first:border-t-0",children:[a.jsxs("button",{type:"button",onClick:()=>t(r.attachmentId),disabled:o,"data-testid":"attachment-download","aria-label":`Download ${r.filename}`,className:"flex w-full items-center gap-2 px-2 py-2 text-left transition-colors hover:bg-surface-sunken disabled:cursor-progress disabled:opacity-60",children:[a.jsxs("span",{className:"min-w-0 flex-1",children:[a.jsx("bdi",{className:"block truncate text-sm text-fg",title:r.filename,children:r.filename}),a.jsxs("span",{className:"block truncate text-2xs text-fg-subtle",children:[r.typeLabel," ·"," ",$o(r.sizeOctets)]})]}),o?a.jsx(Un,{className:"size-4 shrink-0 animate-spin text-fg-subtle","aria-hidden":!0}):a.jsx(ni,{className:"size-4 shrink-0 text-fg-subtle","aria-hidden":!0})]}),r.download.status==="failed"&&a.jsx(El,{state:r.download,onRetry:()=>t(r.attachmentId)})]},r.attachmentId)})}),s&&a.jsx("p",{role:"alert","data-testid":"attachment-unlisted",className:"rounded-sm border border-line bg-surface px-2 py-2 text-xs text-fg-muted",children:"The mail server says this message carries an attachment, but none of its parts describe one. Re-sync the account from Settings; if the attachment still does not appear, the message is worth reporting."})]})}function Ml({label:e,onUndo:t,undoLabel:s="Undo",filtersHref:n,className:r}){return a.jsxs(Te,{tone:"accent",className:F("py-1 text-xs",r),children:[a.jsx(Lo,{className:"size-3.5 shrink-0","aria-hidden":!0}),a.jsx("span",{children:e}),t&&a.jsx("button",{type:"button",onClick:o=>{o.stopPropagation(),t()},className:"font-semibold underline decoration-dotted underline-offset-2 hover:decoration-solid",children:s}),n&&a.jsx("a",{href:n,onClick:o=>{o.stopPropagation()},className:"font-semibold underline decoration-dotted underline-offset-2 hover:decoration-solid",children:"Manage filter"})]})}const Il="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",un="pointer-events-none absolute inset-0 m-auto size-3.5 text-accent-fg";function Al({label:e,description:t,indeterminate:s=!1,checked:n,onChange:r,className:o,...i}){const c=l.useRef(null);l.useEffect(()=>{c.current&&(c.current.indeterminate=s)},[s]);const d=a.jsxs("span",{className:"relative inline-flex",children:[a.jsx("input",{ref:c,type:"checkbox",checked:n,onChange:r,className:Il,...i}),a.jsx(Ft,{className:F(un,"hidden peer-checked:block"),"aria-hidden":!0}),a.jsx(nl,{className:F(un,"hidden peer-indeterminate:block"),"aria-hidden":!0})]});return e===void 0&&t===void 0?a.jsx("span",{className:o,children:d}):a.jsxs("label",{className:F("flex min-h-11 cursor-pointer items-center gap-3 text-left",o),children:[d,a.jsxs("span",{className:"flex min-w-0 flex-col",children:[e!==void 0&&a.jsx("span",{className:"text-sm text-fg",children:e}),t!==void 0&&a.jsx("span",{className:"text-xs text-fg-subtle",children:t})]})]})}function $l(e){return{id:e.id,fromName:e.sender,fromEmail:e.senderEmail??e.sender,subject:e.subject,snippet:e.snippet,timeLabel:e.date,isRead:!e.unread,starred:e.flagged,...e.mailboxId?{mailboxId:e.mailboxId}:{}}}function Ll({result:e,onClick:t,query:s,showFolder:n=!0}){const r=n&&e.folder?jr(e.folder):void 0;return a.jsx("button",{type:"button",onClick:t,className:F("group",Rs({}),"border-b border-line"),children:a.jsx(Ms,{thread:$l(e),highlightQuery:s,badge:a.jsxs(a.Fragment,{children:[r&&a.jsx(Te,{tone:"neutral",className:"shrink-0",children:r}),e.category&&a.jsx(Te,{tone:e.category.tone??"neutral",className:"shrink-0",children:e.category.label}),e.matchedChunkLabel&&a.jsx(Te,{tone:"neutral",className:"shrink-0",children:`matched: ${e.matchedChunkLabel}`}),e.score!=null&&a.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.score.toFixed(2)})]})})})}const Pl=e=>e===1?"result":"results";function Dl({count:e,onScopeToSpam:t}){return a.jsx(Kn,{tone:"info",variant:"soft",className:"items-center justify-between gap-3 rounded-none border-b border-line",children:a.jsxs("div",{className:"flex items-center justify-between gap-3",children:[a.jsxs("p",{className:"min-w-0 text-xs text-fg-muted",children:[a.jsx("span",{className:"font-semibold text-fg tabular-nums",children:e})," ",`${Pl(e)} from Spam`]}),a.jsx(H,{variant:"ghost",size:"sm",onClick:t,className:"shrink-0 text-accent",children:"Go to Spam"})]})})}const fn=6,Fl={kind:"global"},Ol=e=>e.kind==="folder"&&e.role==="junk",zl=e=>e.folder?.role==="junk";function Ia(e){const t=[],s=[];for(const n of e)zl(n)?s.push(n):t.push(n);return{kept:t,spam:s}}function Aa({onClick:e,blockedReason:t}){const s=l.useId(),[n,r]=l.useState(!1);return a.jsxs("div",{className:"border-b border-line px-row-inset py-1.5",children:[a.jsxs("button",{type:"button",onClick:()=>{if(t){r(!0);return}e()},"aria-describedby":t?s:void 0,className:F("flex w-full items-center gap-1.5 rounded-md px-2 py-1.5 text-left text-xs font-medium transition-colors",t?"text-fg-subtle opacity-55":"text-accent hover:bg-surface-sunken"),children:[a.jsx(wr,{className:"size-3.5 shrink-0","aria-hidden":"true"}),a.jsx("span",{children:"Make this a filter"})]}),t&&a.jsx(Cr,{id:s,reason:t,nudged:n,className:"px-2 pt-1 text-2xs text-warning"})]})}function _l({section:e,query:t,onSelectResult:s,showFolder:n}){const[r,o]=l.useState(e.initialCollapsed??!1),[i,c]=l.useState(!1),d=e.results.length>fn,h=!i&&d?e.results.slice(0,fn):e.results,p=e.results.length-h.length;return a.jsxs("div",{children:[a.jsxs("button",{type:"button","aria-expanded":!r,onClick:()=>o(m=>!m),className:"sticky top-0 z-10 flex h-section-row w-full items-center gap-1.5 border-b border-line bg-surface-sunken px-row-inset text-left transition-colors hover:bg-surface",children:[a.jsx("span",{className:"flex-1 text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e.label}),a.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:e.results.length}),a.jsx(mt,{className:F("size-3 shrink-0 text-fg-subtle transition-transform duration-200",r?"rotate-0":"rotate-180")})]}),!r&&a.jsxs(a.Fragment,{children:[h.map(m=>a.jsx(Ll,{result:m,query:t,showFolder:n,onClick:s?()=>s(m):void 0},m.id)),d&&a.jsxs("button",{type:"button",onClick:()=>c(m=>!m),className:"flex w-full items-center justify-center border-b border-line px-row-inset py-1.5 text-2xs font-medium text-accent transition-colors hover:bg-surface",children:[i?"Show less":`Show ${p} more`,!i&&a.jsx(mt,{className:"ml-1 size-3"})]})]})]})}function $a({value:e,recentSearches:t,onPickRecent:s,sections:n,loading:r,onSelectResult:o,tokens:i,scope:c=Fl,makeFilter:d}){if(!(e.trim().length>0))return t&&t.length>0?a.jsxs("div",{className:"flex flex-col",children:[a.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(j=>a.jsxs("button",{type:"button",onClick:()=>s?.(j),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:[a.jsx(pi,{className:"size-4 shrink-0 text-fg-subtle"}),a.jsx("span",{className:"min-w-0 flex-1 truncate text-sm text-fg-muted",children:j})]},j))]}):a.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 h=i&&i.length>0&&a.jsx(Sr,{tokens:i}),p=d&&a.jsx(Aa,{...d});if(r)return a.jsxs("div",{className:"flex flex-col",children:[p,h,a.jsx("div",{className:"flex flex-col gap-3 px-row-inset py-4",children:[0,1,2,3].map(j=>a.jsxs("div",{className:"flex flex-col gap-1.5",children:[a.jsx("div",{className:"h-3 w-1/3 animate-pulse rounded bg-surface-sunken"}),a.jsx("div",{className:"h-3 w-2/3 animate-pulse rounded bg-surface-sunken"}),a.jsx("div",{className:"h-2.5 w-1/2 animate-pulse rounded bg-surface-sunken"})]},j))})]});const m=c.kind==="global",b=Ol(c)||c.kind==="collection",g=m||c.kind==="collection",u=(n??[]).map(j=>{if(b)return{section:j,spam:[]};const{kept:T,spam:R}=Ia(j.results);return{section:{...j,results:T},spam:R}}),f=u.map(j=>j.section),x=u.reduce((j,T)=>j+T.spam.length,0),S=c.kind==="global"&&x>0&&c.onScopeToSpam!==void 0?a.jsx(Dl,{count:x,onScopeToSpam:c.onScopeToSpam}):void 0;return f.some(j=>j.results.length>0)?a.jsxs("div",{className:"flex flex-col",children:[p,h,S,f.filter(j=>j.results.length>0).map(j=>a.jsx(_l,{section:j,query:e,showFolder:g,onSelectResult:o},j.id))]}):a.jsxs("div",{className:"flex flex-col",children:[p,h,S,a.jsxs("div",{className:"px-row-inset py-10 text-center",children:[a.jsxs("p",{className:"text-sm font-medium text-fg",children:["No matches for “",e,"”"]}),a.jsx("p",{className:"mt-1 text-xs text-fg-subtle",children:"Try a different word, or adjust the filters above."})]})]})}function Ul({value:e,onChange:t,onClear:s,onCancel:n,filter:r,recentSearches:o,onPickRecent:i,sections:c,loading:d,onSelectResult:v,tokens:h,chips:p,onRemoveChip:m,scope:b,makeFilter:g,suggest:u,suggestList:f}){const x=a.jsx($a,{value:e,recentSearches:o,onPickRecent:i,sections:c,loading:d,onSelectResult:v,tokens:h,scope:b,makeFilter:g});return a.jsxs("article",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[a.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line bg-surface px-row-inset",children:[a.jsx("div",{className:"min-w-0 flex-1",children:a.jsx(Gn,{value:e,onChange:t,onClear:s,chips:p,onRemoveChip:m,globalFocusKey:!1,showClearButton:!1,suggest:u})}),a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(Dt,{className:"size-4"}),onClick:n,"aria-label":"Clear and close search",className:"-mr-1 shrink-0"})]}),f,r&&e.trim().length===0?a.jsx(Nr,{children:a.jsx(Tr,{...r,children:x})}):a.jsx("div",{className:"flex-1 overflow-y-auto",children:x})]})}const mn=e=>e.toLocaleString();function pn({selectAll:e,selecting:t,className:s}){return a.jsx(Al,{className:s,checked:e.checked,indeterminate:e.indeterminate,onChange:e.onChange,label:a.jsx("span",{className:"font-medium text-accent",children:e.checked&&t?"Deselect all":"Select all"})})}function Kl({title:e,count:t,onCancel:s,onDelete:n,onMove:r,onOrganize:o,onJunk:i,onMarkRead:c,navSlot:d,titleMeta:v,searchSlot:h,searchField:p,idleSlot:m,overflowSlot:b,isBusy:g=!1,isCounting:u=!1,selectAll:f,statusLabel:x,progress:S,notice:y}){const j=t>0||u,T=f?.checked?`All ${mn(t)} loaded selected`:`${mn(t)} ${t===1?"message":"messages"} selected`,R=[];return i&&!g&&!u&&R.push({key:"junk",label:"Junk",icon:a.jsx(Ze,{className:"size-4"}),onSelect:i}),c&&!g&&!u&&R.push({key:"mark-read",label:"Mark read",icon:a.jsx(Es,{className:"size-4"}),onSelect:c}),a.jsxs("header",{"data-selection-bar":"",className:"flex shrink-0 flex-col border-b border-line bg-surface-sunken",children:[a.jsxs("div",{"data-selection-bar-row":"actions",className:"flex h-pane-header items-center gap-1 px-row-inset",children:[j?a.jsx(H,{variant:"ghost",size:"touch",icon:a.jsx(_n,{className:"size-5"}),onClick:s,"aria-label":"Cancel selection",className:"-ml-2 shrink-0"}):d,f&&a.jsx(pn,{selectAll:f,selecting:j,className:"hidden shrink-0 pr-2 md:flex"}),j?a.jsx("span",{"data-selection-count":"",className:"min-w-0 flex-1 truncate px-1 text-sm font-medium text-fg",role:"status","aria-live":"polite",children:x??T}):p?a.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-1",children:p}):a.jsxs(a.Fragment,{children:[a.jsx("h1",{className:"min-w-0 flex-1 truncate px-1 text-sm font-semibold text-fg",children:e}),v,h]}),j&&!u&&a.jsxs(a.Fragment,{children:[a.jsx(H,{variant:"ghost",size:"touch",icon:g?a.jsx(Un,{className:"size-5 animate-spin"}):a.jsx(Ot,{className:"size-5 text-danger"}),onClick:g?void 0:n,"aria-label":"Move selected messages to Trash","aria-busy":g||void 0,className:"shrink-0"}),!g&&r&&a.jsx(H,{variant:"ghost",size:"touch",icon:a.jsx(vs,{className:"size-5"}),onClick:r,"aria-label":"Move selected messages",className:"shrink-0"}),!g&&o&&a.jsx(H,{variant:"ghost",size:"touch",icon:a.jsx(We,{className:"size-5"}),onClick:o,"aria-label":"Organize selected messages",className:"shrink-0"})]}),j&&a.jsx(Wn,{triggerLabel:"More actions",items:R,className:"shrink-0",children:!g&&!u&&b})]}),!j&&m,j&&f&&a.jsx("div",{"data-selection-bar-row":"select-all",className:"px-row-inset pb-2 md:hidden",children:a.jsx(pn,{selectAll:f,selecting:j,className:"w-full"})}),S&&a.jsx("div",{className:"px-row-inset pb-2",children:a.jsx(Er,{value:S.value,max:S.max,tone:S.tone})}),y&&a.jsx(Kn,{"data-selection-notice":"",tone:y.tone,variant:"soft",role:"status","aria-live":"polite",className:"mx-row-inset mb-2",children:a.jsxs("div",{className:"flex items-center justify-between gap-2",children:[y.text&&a.jsx("span",{children:y.text}),y.action&&a.jsx(H,{variant:"ghost",size:"md",onClick:y.action.onClick,className:"-my-1 min-h-11 shrink-0",children:y.action.label})]})})]})}const Is=[{id:"all",label:"All",tone:"neutral"},{id:"personal",label:"Personal",tone:"accent"},{id:"uncategorized",label:"Unclassified",tone:"neutral"},{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"}],La={id:"unread",label:"Unread"},Bl={id:"flagged",label:"Starred"},Pa={id:"attachment",label:"Has attachment"};function Ql(e){if(!(e.length<=1))return e.map(t=>({id:t.id,label:t.label,count:t.count,active:t.active}))}function Tf(e=[]){return{categories:[...Is],filters:Rr,sources:Ql(e)}}function Ef(){return{categories:[...Is],filters:[La,Bl,Pa]}}function Rf(){return{categories:[...Is],filters:[La,Pa]}}function ql(e,t){return e.endsWith(t)?e.length===t.length||e[e.length-t.length-1]===".":!1}function Hl(e,t){const s=e.length-t.length-2,n=e.lastIndexOf(".",s);return n===-1?e:e.slice(n+1)}function Vl(e,t,s){if(s.validHosts!==null){const r=s.validHosts;for(const o of r)if(ql(t,o))return o}let n=0;if(t.startsWith("."))for(;n<t.length&&t[n]===".";)n+=1;return e.length===t.length-n?null:Hl(t,e)}const ss=/[\t\n\r]/g;let fs=!1;function hn(e){return e>=97&&e<=122||e>=48&&e<=57||e>127||e>=65&&e<=90||e===45||e===95}function gn(e,t,s){const n=s-t,r=e.charCodeAt(t)|32;if(n===2)return r===119&&(e.charCodeAt(t+1)|32)===115?1:0;if(n===3){const o=e.charCodeAt(t+1)|32,i=e.charCodeAt(t+2)|32;return r===119&&o===115&&i===115||r===102&&o===116&&i===112?1:0}else if(n===4){const o=e.charCodeAt(t+1)|32,i=e.charCodeAt(t+2)|32,c=e.charCodeAt(t+3)|32;return r===104&&o===116&&i===116&&c===112?1:r===102&&o===105&&i===108&&c===101?2:0}else if(n===5)return r===104&&(e.charCodeAt(t+1)|32)===116&&(e.charCodeAt(t+2)|32)===116&&(e.charCodeAt(t+3)|32)===112&&(e.charCodeAt(t+4)|32)===115?1:0;return 0}function ft(e,t,s=!1){let n=0,r=e.length,o=!1,i=!1;if(fs=!1,!t){if(e.startsWith("data:"))return null;for(;n<e.length&&e.charCodeAt(n)<=32;)n+=1;for(;r>n+1&&e.charCodeAt(r-1)<=32;)r-=1;if(e.charCodeAt(n)===47&&e.charCodeAt(n+1)===47)n+=2;else{const f=e.indexOf(":/",n);if(f!==-1){const x=gn(e,n,f);if(x===1)for(i=!0,n=f+2;e.charCodeAt(n)===47||e.charCodeAt(n)===92;)n+=1;else if(x===2){i=!0,n=f+1;let S=0;for(;(e.charCodeAt(n)===47||e.charCodeAt(n)===92)&&S<2;)n+=1,S+=1;if(S<2)return null}else{for(let S=n;S<f;S+=1){const y=e.charCodeAt(S)|32;if(!(y>=97&&y<=122||y>=48&&y<=57||y===46||y===45||y===43)){const j=e.charCodeAt(S);return j===9||j===10||j===13?ft(e.replace(ss,""),t,s):null}}if(e.charCodeAt(f+2)===47)n=f+3;else return null}}else if(e.charCodeAt(n)!==91){let x=-1;for(let S=n;S<r;S+=1){const y=e.charCodeAt(S);if(y===9||y===10||y===13)return ft(e.replace(ss,""),t,s);if(y===58){x=S;break}if(y===47||y===92||y===63||y===35)break}if(x!==-1){let S=!1;for(let y=x+1;y<r;y+=1){const j=e.charCodeAt(y);if(j===47||j===92||j===63||j===35)break;if(j===64){S=!0;break}}if(!S){let y=!0,j=x+1;for(;j<r;j+=1){const T=e.charCodeAt(j);if(T===47||T===92||T===63||T===35)break;if(T<48||T>57){y=!1;break}}if(j===x+1&&(y=!1),!y){const T=gn(e,n,x);if(T===0){let R=!1;for(let O=x+1;O<r;O+=1){const $=e.charCodeAt(O);if($===47||$===92||$===63||$===35)break;if($===58){R=!0;break}}if(!R)return null}else if(i=!0,n=x+1,T===2){let R=0;for(;(e.charCodeAt(n)===47||e.charCodeAt(n)===92)&&R<2;)n+=1,R+=1;if(R<2)return null}else for(;e.charCodeAt(n)===47||e.charCodeAt(n)===92;)n+=1}}}}}let d=-1,v=-1,h=-1,p=-1,m=!1,b=s,g=n-1,u=-1;if(s&&n<r){const f=e.charCodeAt(n);(!(hn(f)||f===46||f===95)||f===45)&&(b=!1)}for(let f=n;f<r;f+=1){const x=e.charCodeAt(f);if(x<64)if(x===47||x===35||x===63){r=f;break}else x===58?(p===-1&&(p=f),h=f):x===9||x===10||x===13?m=!0:s&&(x===46?((f-g>64||u===46||u===45)&&(b=!1),g=f):(x<48||x>57)&&(x!==45||u===46)&&(b=!1));else if(i&&x===92){r=f;break}else x===64?(d=f,p=-1):x===93?v=f:x>=65&&x<=90?o=!0:s&&!hn(x)&&(b=!1);s&&(u=x)}if(m)return ft(e.replace(ss,""),t,s);if(d!==-1&&d>=n&&d<r&&(n=d+1),e.charCodeAt(n)===91)return v!==-1?e.slice(n+1,v).toLowerCase():null;if(h!==-1&&h>n&&h<r&&p===h&&(r=h),n>=r)return null;s&&b&&d===-1&&h===-1&&v===-1&&e.charCodeAt(r-1)!==46&&r-n<=255&&r-g-1<=63&&u!==45&&(fs=!0)}for(;r>n+1&&e.charCodeAt(r-1)===46;)r-=1;const c=n!==0||r!==e.length?e.slice(n,r):e;return o?c.toLowerCase():c}function Gl(e){if(e.length<7||e.length>15)return!1;let t=0;for(let s=0;s<e.length;s+=1){const n=e.charCodeAt(s);if(n===46)t+=1;else if(n<48||n>57)return!1}return t===3&&e.charCodeAt(0)!==46&&e.charCodeAt(e.length-1)!==46}function Wl(e){if(e.length<3)return!1;let t=e.startsWith("[")?1:0,s=e.length;if(e[s-1]==="]"&&(s-=1),s-t>39)return!1;let n=!1;for(;t<s;t+=1){const r=e.charCodeAt(t);if(r===58)n=!0;else if(!(r>=48&&r<=57||r>=97&&r<=102||r>=65&&r<=70))return!1}return n}function Yl(e){return Wl(e)||Gl(e)}function bn(e){return e>=97&&e<=122||e>=48&&e<=57||e>127}function xn(e){if(e.length>255||e.length===0||!bn(e.charCodeAt(0))&&e.charCodeAt(0)!==46&&e.charCodeAt(0)!==95)return!1;let t=-1,s=-1;const n=e.length;for(let r=0;r<n;r+=1){const o=e.charCodeAt(r);if(o===46){if(r-t>64||s===46||s===45)return!1;t=r}else if(!(bn(o)||o===45||o===95)||o===45&&s===46)return!1;s=o}return n-t-1<=63&&s!==45}function Jl({allowIcannDomains:e=!0,allowPrivateDomains:t=!1,detectIp:s=!0,detectSpecialUse:n=!1,extractHostname:r=!0,mixedInputs:o=!0,validHosts:i=null,validateHostname:c=!0}){return{allowIcannDomains:e,allowPrivateDomains:t,detectIp:s,detectSpecialUse:n,extractHostname:r,mixedInputs:o,validHosts:i,validateHostname:c}}const Xl=Jl({});function Zl(e){return Xl}function ec(){return{domain:null,domainWithoutSuffix:null,hostname:null,isIcann:null,isIp:null,isPrivate:null,isSpecialUse:null,publicSuffix:null,subdomain:null}}function tc(e){e.domain=null,e.domainWithoutSuffix=null,e.hostname=null,e.isIcann=null,e.isIp=null,e.isPrivate=null,e.isSpecialUse=null,e.publicSuffix=null,e.subdomain=null}function sc(e,t,s,n,r){const o=Zl();if(typeof e!="string")return r;let i=!1;return o.extractHostname?o.mixedInputs?(i=xn(e),r.hostname=ft(e,i,o.validateHostname)):r.hostname=ft(e,!1,o.validateHostname):r.hostname=e,o.detectIp&&r.hostname!==null&&(r.isIp=Yl(r.hostname),r.isIp)?r:o.validateHostname&&o.extractHostname&&r.hostname!==null&&!(i&&r.hostname===e)&&!fs&&!xn(r.hostname)?(r.hostname=null,r):(r.hostname===null||(s(r.hostname,o,r),r.publicSuffix===null)||(r.domain=Vl(r.publicSuffix,r.hostname,o)),r)}const vn=ec();function nc(e,t){return tc(vn),sc(e,3,Mr,t,vn).domain}const Qt=e=>{const t=new Set,s=[];for(const n of e){const r=n.trim();if(r==="")continue;const o=r.toLowerCase();t.has(o)||(t.add(o),s.push(r))}return s},ac=e=>{const t=e.lastIndexOf("@");return t>=0?e.slice(t+1):e},Da=e=>nc(ac(e.trim())),rc=e=>{const t=Qt(e);if(t.length<2)return null;let s=null;for(const n of t){const r=Da(n);if(r===null)return null;if(s===null)s=r;else if(s!==r)return null}return s},qt=e=>{const t=rc(e);return t!==null?[{field:"FromDomain",value:t}]:Qt(e).map(s=>({field:"From",value:s}))},oc=e=>{const t=new Map;for(const r of e){const o=r.normalizedEmail.trim().toLowerCase();if(o==="")continue;const i=t.get(o);i?i.count+=1:t.set(o,{sender:r,count:1})}let s,n=0;for(const{sender:r,count:o}of t.values())o<=n||(s=r,n=o);return s},Fa=e=>e.displayName?.trim()||e.normalizedEmail,ic=/^\s*(?:(?:re|aw|fwd?|vs|sv|antw|res|enc|tr)\s*(?:\[\d+\])?\s*:|\[[^\]]{1,32}\])\s*/i,lc=e=>{let t=e.replace(/\s+/g," ").trim();for(;;){const s=t.replace(ic,"");if(s===t)return t.trim();t=s}},cc=new Set(["a","an","and","are","as","at","be","by","for","from","has","have","in","is","it","me","my","new","of","on","or","our","the","this","to","was","we","with","you","your"]),dc=3,ns=e=>e.split(" ").filter(t=>t!==""),yn=e=>e.length===0||e.join(" ").length<dc?!1:e.some(t=>!cc.has(t.toLowerCase())),uc=(e,t)=>e.findIndex((s,n)=>t.every((r,o)=>e[n+o]?.toLowerCase()===r.toLowerCase())),fc=e=>{const t=e.map(lc).filter(o=>o!=="");if(t.length===0)return;const[s,...n]=t;if(n.length===0)return yn(ns(s))?s:void 0;const r=ns(s);for(let o=r.length;o>0;o-=1)for(let i=0;i+o<=r.length;i+=1){const c=r.slice(i,i+o);if(yn(c)&&n.every(d=>uc(ns(d),c)>=0))return c.join(" ")}},mc=(e,t)=>{const s=qt(e);if(Qt(e).length===1||s.length===1&&s[0].field==="FromDomain")return s;const n=fc(t);return n!==void 0?[{field:"Subject",value:n}]:s},pc=({match:e,sender:t,folder:s})=>{const n=e??t;return n?s?`${n} → ${s}`:e?`Mail matching ${e}`:`Mail from ${n}`:s?`Mail to ${s}`:""},hc=e=>e.clauses.length>0,gc=e=>({scopedOutFolder:e.scopedOut?.label,droppedFacets:e.droppedFacets.map(t=>t.label),droppedSemantic:e.droppedSemantic}),bc=({orderedIds:e,isDesktop:t,initialFocusedId:s,initialSelectedIds:n,onExitSelection:r})=>{const[o,i]=l.useState(s),[c,d]=l.useState(),v=l.useCallback(w=>{d(E=>E===w?E:void 0),i(w)},[]),h=xl({initialSelectedIds:n}),{selectedCount:p,toggle:m,clearSelection:b,selectRange:g,setAnchor:u,selectAll:f}=h,x=ml(p,t),S=l.useRef(null),y=l.useRef(!1),j=l.useCallback(()=>{r?.(),b()},[b,r]),T=l.useMemo(()=>o?e.indexOf(o):-1,[e,o]),R=l.useCallback(w=>{if(w<0||w>=e.length)return;const E=e[w];if(x){m(E);return}S.current=E,y.current=!1,d(E),i(E)},[e,x,m]),O=l.useCallback(()=>{e.length!==0&&R(T<0?0:Math.min(T+1,e.length-1))},[e.length,T,R]),$=l.useCallback(()=>{e.length!==0&&R(T<=0?0:T-1)},[e.length,T,R]),z=l.useCallback(()=>R(0),[R]),L=l.useCallback(()=>R(e.length-1),[R,e.length]),P=l.useCallback(()=>{o&&m(o)},[o,m]),D=l.useCallback((w,E)=>{const C=fl(E);return C==="range"?(g(e,w,o),!0):C==="toggle"?(m(w),!0):(j(),u(w),!1)},[e,o,g,m,j,u]),K=l.useCallback(w=>{const E=bl(e,o,w);E!==void 0&&(g(e,E),S.current=E,y.current=!1,d(void 0),i(E))},[e,o,g]),k=l.useCallback(()=>K(-1),[K]),M=l.useCallback(()=>K(1),[K]),I=l.useCallback(()=>{e.length>0&&f(e)},[e,f]);return{focusedMessageId:o,setFocusedMessageId:v,keyboardFocusedMessageId:c,focusIndex:T,pendingDomFocusRef:S,cursorMovedByPointerRef:y,selection:h,isMultiSelectMode:x,exitSelection:j,moveFocusToIndex:R,focusNext:O,focusPrevious:$,focusFirst:z,focusLast:L,toggleFocusedSelection:P,extendRangeUp:k,extendRangeDown:M,selectAllLoaded:I,handleRowSelect:D}};function xc(e,t){if(e===void 0)return{shouldBlockFn:()=>!0,withResolver:!1};if("shouldBlockFn"in e)return e;if(typeof e=="function")return{shouldBlockFn:async()=>await e(),enableBeforeUnload:!0,withResolver:!1};const s=!!(e.condition??!0),n=e.blockerFn;return{shouldBlockFn:async()=>s&&n!==void 0?await n():s,enableBeforeUnload:s,withResolver:n===void 0}}function vc(e,t){const{shouldBlockFn:s,enableBeforeUnload:n=!0,disabled:r=!1,withResolver:o=!1}=xc(e),i=Ir(),{history:c}=i,[d,v]=l.useState({status:"idle",current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0});return l.useEffect(()=>{const h=async p=>{function m(x){const S=i.parseLocation(x),y=i.getMatchedRoutes(S.pathname);return y.foundRoute===void 0?{routeId:"__notFound__",fullPath:S.pathname,pathname:S.pathname,params:y.routeParams,search:i.options.parseSearch(x.search)}:{routeId:y.foundRoute.id,fullPath:y.foundRoute.fullPath,pathname:S.pathname,params:y.routeParams,search:i.options.parseSearch(x.search)}}const b=m(p.currentLocation),g=m(p.nextLocation);if(b.routeId==="__notFound__"&&g.routeId!=="__notFound__")return!1;const u=await s({action:p.action,current:b,next:g});if(!o)return u;if(!u)return!1;const f=await new Promise(x=>{v({status:"blocked",current:b,next:g,action:p.action,proceed:()=>x(!1),reset:()=>x(!0)})});return v({status:"idle",current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0}),f};return r?void 0:c.block({blockerFn:h,enableBeforeUnload:n})},[s,n,r,o,c,i]),d}const Mf=({isOpen:e,onClose:t,children:s,ariaLabel:n="Navigation",side:r="left",widthClassName:o="w-[80vw] max-w-[320px]"})=>{const i=l.useRef(null),c=l.useRef(null);if(l.useEffect(()=>{if(!e)return;c.current=document.activeElement;const v=m=>{m.key==="Escape"&&(m.preventDefault(),t())};document.addEventListener("keydown",v),i.current?.querySelector("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])")?.focus();const p=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",v),document.body.style.overflow=p,c.current?.focus()}},[e,t]),!e)return null;const d=r==="left"?"left-0 border-r animate-in slide-in-from-left duration-150":"right-0 border-l animate-in slide-in-from-right duration-150";return a.jsxs("div",{className:"fixed inset-0 z-50",role:"dialog","aria-modal":"true","aria-label":n,children:[a.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"}),a.jsxs("div",{ref:i,className:F("safe-area-frame absolute top-0 bottom-0 bg-canvas border-line shadow-xl flex flex-col",o,d),children:[a.jsx("div",{className:"flex items-center justify-end h-12 px-2 border-b border-line shrink-0",children:a.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:a.jsx(Dt,{className:"size-5"})})}),a.jsx("div",{className:"flex-1 overflow-y-auto",children:s})]})]})},yc=({surface:e})=>{const t=qo(),s=Ho(),{data:n}=te({...zt({path:{messageId:e.sourceMessageId}})}),{data:r}=te({...xt(),staleTime:1/0});return a.jsx("div",{className:"border-b border-line bg-canvas",children:a.jsx(Xo,{layout:"flow",mode:e.mode,account:r?.accounts?.[0],sourceMessage:n,outboxMessageId:e.outboxMessageId,onDraftCreated:t,onClose:s})})},Oa=({message:e,icon:t})=>a.jsxs("div",{className:"flex flex-col items-center justify-center p-8 text-center",children:[t&&a.jsx("div",{className:"mb-4 text-fg-muted",children:t}),a.jsx("p",{className:"text-fg-muted",children:e})]}),za=e=>{const{data:t,isLoading:s}=te({...xt(),staleTime:1/0}),n=l.useMemo(()=>(t?.accounts??[]).map(c=>c.accountId),[t?.accounts]),r=ws({queries:n.map(c=>({...vt({path:{accountId:c}}),staleTime:1/0,enabled:!!e}))}),o=s||r.some(c=>c.isLoading);return{accountId:l.useMemo(()=>{if(e){for(let c=0;c<n.length;c++)if((r[c].data?.items??[]).some(h=>h.mailboxId===e))return n[c]}},[e,n,r]),isLoading:o}},kc=100,ms=async e=>e.then(t=>({ok:!0,value:t}),t=>({ok:!1,error:t})),jc=(e,t=kc)=>{if(e.length===0)return[];const s=[];for(let n=0;n<e.length;n+=t)s.push(e.slice(n,n+t));return s},_a=async(e,t,s,n)=>{const r=jc(e),o=e.length;let i=0;const c=[];for(let d=0;d<r.length;d++){if(n())return c.push(...r.slice(d).flat()),{done:i,failedIds:c,cancelled:!0};const v=r[d],h=await ms(t(v));if(!h.ok)return c.push(...r.slice(d).flat()),s({done:i,total:o}),{done:i,failedIds:c,cancelled:!1,error:h.error};i+=v.length,s({done:i,total:o})}return{done:i,failedIds:c,cancelled:!1}},bt=async(e,t)=>{await _a(e,async s=>(await t(s),{successCount:s.length,failureCount:0}),()=>{},()=>!1)},wc=async(e,t,s,n,r)=>{let o=0;const i=[];let c;do{if(r())return{done:o,failedIds:i,cancelled:!0};const d=await ms(e(c));if(!d.ok)return{done:o,failedIds:i,cancelled:!1,error:d.error};const v=d.value;if(v.ids.length>0){const h=await ms(s(v.ids));if(!h.ok)return{done:o,failedIds:i,cancelled:!1,error:h.error};o+=v.ids.length,n({done:o,total:t})}c=v.continuationToken}while(c);return{done:o,failedIds:i,cancelled:!1}},Cc=e=>({done:e.done,total:Math.max(e.total,e.done)}),Ua=e=>typeof e=="object"&&e!==null&&Array.isArray(e.pages),Ka=e=>typeof e=="object"&&e!==null&&Array.isArray(e.items),Ba=(e,t)=>e===void 0?e:Ua(e)?{...e,pages:e.pages.map(s=>({...s,items:t(s.items)}))}:Ka(e)?{...e,items:t(e.items)}:e,je=e=>{const t=[];for(const s of new Set(e))t.push(Bn({path:{mailboxId:s}})),t.push(Qn({path:{mailboxId:s}}));return t.push(qn()),t},kt=(e,t)=>Promise.all(t.map(s=>e.cancelQueries({queryKey:s}))),jt=(e,t)=>t.flatMap(s=>e.getQueriesData({queryKey:s})).filter(s=>s[1]!==void 0).map(([s,n])=>({queryKey:s,data:n})),wt=(e,t,s)=>{const n=r=>Ba(r,s);for(const r of t)e.setQueriesData({queryKey:r},n)},Ct=(e,t)=>{for(const s of t)e.setQueryData(s.queryKey,s.data)},we=(e,t)=>{for(const s of t)e.invalidateQueries({queryKey:s})},Sc=3e3,Nc=(e,t,s)=>{if(e.length===0)return()=>{};const n=setTimeout(()=>s(e),t);return()=>clearTimeout(n)},As=(e,t,s)=>{const n=new Map(t.map(o=>[o.messageId,o.mailboxId])),r=new Set;for(const o of e)r.add(n.get(o)??s);return[...r]},Pt=(e,t,s)=>e.map(n=>t.has(n.messageId)?{...n,isRead:s}:n),Tc=(e,t,s,n)=>e.filter(r=>!r.isRead&&t.has(r.threadMessageId)&&!s.has(r.messageId)&&!n.has(r.messageId)).map(r=>r.messageId),Ec=({messages:e,expandedIds:t,threadId:s,mailboxId:n,accountId:r})=>{const o=ae(),{pushError:i}=ke(),c=l.useRef(new Set),d=l.useRef(new Set),{mutate:v}=ue({..._t(),meta:Ar,onMutate:async m=>{const b=new Set(m.body.messageIds??[]),g=m.body.isRead??!0,u=Me({path:{threadId:s}}),f=je(As(b,e,n));await Promise.all([o.cancelQueries({queryKey:u}),kt(o,f)]);const x=o.getQueriesData({queryKey:u}).filter(y=>y[1]!==void 0).map(([y,j])=>({queryKey:y,data:j})),S=jt(o,f);return o.setQueriesData({queryKey:u},y=>y&&{...y,items:Pt(y.items,b,g)}),wt(o,f,y=>Pt(y,b,g)),{threadMessagesPrefix:u,listPrefixes:f,previousThreadMessages:x,previousThreadsList:S}},onSuccess:(m,b)=>{const g=b.body.messageIds??[];for(const u of g)c.current.add(u),d.current.delete(u)},onError:(m,b,g)=>{const u=b.body.messageIds??[];for(const x of u)d.current.delete(x);if(g){for(const x of g.previousThreadMessages)o.setQueryData(x.queryKey,x.data);Ct(o,g.previousThreadsList)}const f=b.body.isRead??!0;i({title:f?"Couldn't mark as read":"Couldn't mark as unread",detail:Re(m),error:m})},onSettled:(m,b,g,u)=>{u&&(o.invalidateQueries({queryKey:u.threadMessagesPrefix}),we(o,u.listPrefixes),r&&o.invalidateQueries({queryKey:Je({path:{accountId:r}})}))}}),h=l.useCallback(m=>{const b=m.filter(g=>!c.current.has(g)&&!d.current.has(g));if(b.length!==0){for(const g of b)d.current.add(g);v({body:{messageIds:b,isRead:!0}})}},[v]),p=l.useMemo(()=>Tc(e,t,c.current,d.current),[e,t]);l.useEffect(()=>Nc(p,Sc,h),[p,h]),l.useEffect(()=>{c.current.clear(),d.current.clear()},[s])},If=e=>{const{mailboxId:t,accountId:s,messages:n}=e,r=ae(),{pushError:o}=ke(),{mutateAsync:i,isPending:c}=ue({..._t(),onError:(v,h)=>{const p=h.body.isRead??!0;o({title:p?"Couldn't mark as read":"Couldn't mark as unread",detail:Re(v),error:v})},onSettled:(v,h,p)=>{we(r,je(As(p.body.messageIds??[],n??[],t))),s&&r.invalidateQueries({queryKey:Je({path:{accountId:s}})})}});return{toggleReadFor:l.useCallback((v,h)=>{v.length!==0&&bt(v,p=>i({body:{messageIds:p,isRead:h}}))},[i]),isPending:c}},Rc=60,Mc=1.5,Ic=(e,t,s)=>{const n=Math.abs(e),r=Math.abs(t);return n<s?{direction:null}:n<r*Mc?{direction:null}:{direction:e<0?"left":"right"}},Ac=({onSwipeLeft:e,onSwipeRight:t,thresholdPx:s=Rc})=>{const n=l.useRef(null),r=l.useCallback(d=>{if(d.pointerType==="mouse"){n.current=null;return}n.current={x:d.clientX,y:d.clientY}},[]),o=l.useCallback(()=>{},[]),i=l.useCallback(d=>{const v=n.current;if(n.current=null,!v)return;const{direction:h}=Ic(d.clientX-v.x,d.clientY-v.y,s);h==="left"&&e?.(),h==="right"&&t?.()},[e,t,s]),c=l.useCallback(()=>{n.current=null},[]);return{handlers:{onPointerDown:r,onPointerMove:o,onPointerUp:i,onPointerCancel:c}}},$c=(e,t,s)=>t?.find(n=>n.messageId===e)?.mailboxId??s,kn=(e,t,s)=>e.map(n=>n.messageId===t?{...n,hasStars:s}:n),Qa=({threadId:e,mailboxId:t,messages:s})=>{const n=ae(),{pushError:r}=ke(),{mutate:o,isPending:i,variables:c}=ue({...$r(),onMutate:async v=>{const h=v.path.messageId,p=v.body.isStarred??!1,m=Me({path:{threadId:e}}),b=je([$c(h,s,t)]);await Promise.all([n.cancelQueries({queryKey:m}),kt(n,b)]);const g=n.getQueriesData({queryKey:m}).filter(f=>f[1]!==void 0).map(([f,x])=>({queryKey:f,data:x})),u=jt(n,b);return n.setQueriesData({queryKey:m},f=>Ba(f,x=>kn(x,h,p))),wt(n,b,f=>kn(f,h,p)),{threadMessagesPrefix:m,listPrefixes:b,previousThreadMessages:g,previousThreadsList:u}},onError:(v,h,p)=>{if(p){for(const b of p.previousThreadMessages)n.setQueryData(b.queryKey,b.data);Ct(n,p.previousThreadsList)}const m=h.body.isStarred??!1;r({title:m?"Couldn't star message":"Couldn't unstar message",detail:Re(v),error:v})},onSettled:(v,h,p,m)=>{m&&(n.invalidateQueries({queryKey:m.threadMessagesPrefix}),we(n,m.listPrefixes))}});return{toggleStar:(v,h)=>{o({path:{messageId:v},body:{isStarred:!h}})},isPending:i,pendingMessageId:i?c?.path.messageId:void 0}};function jn({authenticity:e,onOpenIntelligence:t}){return e.dkimMismatch?a.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:[a.jsx(Ze,{className:"mt-0.5 size-4 shrink-0 text-danger"}),a.jsxs("p",{className:"flex-1 leading-snug text-fg",children:["This message claims to be from"," ",a.jsx("span",{className:"font-semibold",children:e.fromDomain})," but was sent",e.dkimDomain?` via ${e.dkimDomain}`:" from a different domain","."," ",t&&a.jsx("button",{type:"button",onClick:t,className:"font-medium text-danger hover:underline",children:"Why?"})]})]}):null}function qa(e){return e===void 0?"uncategorized":e}const Lc={inbox:"Inbox",junk:"Junk"},$s=e=>e.destinationMailboxId!==void 0,Pc=(e,t)=>{if($s(e))return`Moved from ${t??"another folder"} by Remit`;const s=e.fromPlacement??"";return`Moved from ${Lc[s]??"another folder"} by Remit`},Dc=(e,t)=>{if(e===Js.MoveToInbox)return t.inboxMailboxId;if(e===Js.MoveToJunk)return t.junkMailboxId},Fc=(e,t,s)=>{if(!e||!t)return!1;const n=$s(e)?e.destinationMailboxId:Dc(e.action,s);return n!==void 0&&n===t},Oc="Reported as spam",zc=(e,t)=>{if(e){if($s(e))return e.fromMailboxId;if(e.fromPlacement==="inbox")return t.inboxMailboxId;if(e.fromPlacement==="junk")return t.junkMailboxId}},Ht=(e,t)=>{const{data:s,isLoading:n}=te({...xt(),staleTime:1/0,enabled:!!e});return{mailboxId:l.useMemo(()=>e?s?.accounts.find(i=>i.accountId===e)?.folderAppointments.find(i=>i.role===t)?.mailboxId:void 0,[s,e,t]),isLoading:n}},Af=e=>{const{mailboxId:t,isLoading:s}=Ht(e,"Archive");return{archiveMailboxId:t,isLoading:s}},$f=e=>{const{mailboxId:t,isLoading:s}=Ht(e,"Drafts");return{draftsMailboxId:t,isLoading:s}},_c=e=>{const{mailboxId:t,isLoading:s}=Ht(e,"Inbox");return{inboxMailboxId:t,isLoading:s}},Ha=e=>{const{mailboxId:t,isLoading:s}=Ht(e,"Junk");return{junkMailboxId:t,isLoading:s}},Va=e=>{const{data:t}=te({...xt(),staleTime:1/0,enabled:!!e});return l.useMemo(()=>t?.accounts.find(s=>s.accountId===e)?.folderAppointments??[],[t,e])},wn=(e,t)=>e.filter(s=>!t.has(s.messageId)),Vt=({mailboxId:e,threadId:t,accountId:s,onAfterOptimisticRemove:n})=>{const r=ae(),{pushError:o}=ke(),{mutateAsync:i,isPending:c,isError:d}=ue({...Lr(),onMutate:async h=>{const p=new Set(h.body.messageIds??[]),m=t?Me({path:{threadId:t}}):[],b=je([e,h.body.destinationMailboxId]);await Promise.all([...t?[r.cancelQueries({queryKey:m})]:[],kt(r,b)]);const g=t?r.getQueriesData({queryKey:m}).filter(f=>f[1]!==void 0).map(([f,x])=>({queryKey:f,data:x})):[],u=jt(r,b);return t&&r.setQueriesData({queryKey:m},f=>f&&{...f,items:wn(f.items,p)}),wt(r,b,f=>wn(f,p)),n?.(Array.from(p)),{threadMessagesPrefix:m,listPrefixes:b,previousThreadMessages:g,previousThreadsList:u}},onError:(h,p,m)=>{if(m){for(const g of m.previousThreadMessages)r.setQueryData(g.queryKey,g.data);Ct(r,m.previousThreadsList)}const b=p.body.messageIds?.length??0;o({title:b>1?`Couldn't move ${b} messages`:"Couldn't move this message",detail:Re(h),error:h})},onSettled:(h,p,m,b)=>{b&&(t&&r.invalidateQueries({queryKey:b.threadMessagesPrefix}),we(r,b.listPrefixes),s&&r.invalidateQueries({queryKey:Je({path:{accountId:s}})}))}});return{moveMessages:l.useCallback((h,p)=>{h.length!==0&&bt(h,m=>i({body:{messageIds:m,destinationMailboxId:p}}))},[i]),isPending:c,isError:d}},Uc="This message could not be processed. Please try again. If it keeps failing, report it.",Kc=(e,t)=>e.replace(`Message ${t}'s`,"This message's"),Cn=e=>{if(e.failureCount===0)return;const t=e.failures?.[0],s=t?.reason??Uc,n=t?Kc(s,t.messageId):s;throw new Fr(n,422)};function Ga({mailboxId:e,threadId:t,accountId:s,onAfterOptimisticRemove:n}){const r=ae(),{pushError:o}=ke(),i=je([e]),c=t?Me({path:{threadId:t}}):[],d=()=>{t&&r.invalidateQueries({queryKey:c}),we(r,i),s&&r.invalidateQueries({queryKey:Je({path:{accountId:s}})})},v=()=>(u,f)=>{d(),n?.(f.body.messageIds)},h=u=>(f,x)=>{o({title:u(x.body.messageIds.length),detail:Re(f),error:f})},p=ue({mutationFn:async u=>{const{data:f}=await Pr({...u,throwOnError:!0});return Cn(f),f},meta:{softError:!0},onSuccess:v(),onError:h(u=>u>1?`Couldn't report ${u} messages as spam`:"Couldn't report this message as spam")}),m=ue({mutationFn:async u=>{const{data:f}=await Dr({...u,throwOnError:!0});return Cn(f),f},meta:{softError:!0},onSuccess:v(),onError:h(u=>u>1?`Couldn't undo the spam report for ${u} messages`:"Couldn't undo the spam report")}),b=l.useCallback(u=>{u.length!==0&&bt(u,f=>p.mutateAsync({body:{messageIds:f}}))},[p.mutateAsync]),g=l.useCallback(u=>{u.length!==0&&bt(u,f=>m.mutateAsync({body:{messageIds:f}}))},[m.mutateAsync]);return{reportSpam:b,notSpam:g,isReporting:p.isPending,isRestoring:m.isPending}}const Bc=({accountId:e,messageId:t,threadId:s,mailboxId:n,autoMoved:r,spamReport:o})=>{const{inboxMailboxId:i}=_c(e),{junkMailboxId:c}=Ha(e),{moveMessages:d,isPending:v}=Vt({mailboxId:n,threadId:s,accountId:e}),{notSpam:h,isRestoring:p}=Ga({mailboxId:n,threadId:s,accountId:e}),{data:m}=te({...vt({path:{accountId:e??""}}),staleTime:1/0,enabled:!!e&&r?.fromMailboxId!==void 0}),b={inboxMailboxId:i,junkMailboxId:c},g=zc(r,b),u=l.useCallback(()=>{g&&d([t],g)},[d,t,g]),f=l.useCallback(()=>{h([t])},[h,t]);if(o)return{show:!0,label:Oc,onUndo:f,isUndoing:p};if(!Fc(r,n,b)||!r)return{show:!1,label:"",isUndoing:!1};const S=r.fromMailboxId?m?.items.filter(y=>y.mailboxId===r.fromMailboxId).map(y=>Or(y.fullPath))[0]:void 0;return{show:!0,label:Pc(r,S),onUndo:g?u:void 0,isUndoing:v,...r.filterId?{filtersHref:"/settings/filters"}:{}}};function Qc({accountId:e,messageId:t,threadId:s,mailboxId:n,autoMoved:r,spamReport:o}){const i=Bc({accountId:e,messageId:t,threadId:s,mailboxId:n,autoMoved:r,spamReport:o});return i.show?a.jsx(Ml,{label:i.label,onUndo:i.onUndo,undoLabel:i.isUndoing?"Undoing…":"Undo",filtersHref:i.filtersHref}):null}const Sn=(e,t)=>e.filter(s=>!t.has(s.messageId)),Lf=e=>e.filter(t=>t.isDeleted!==!0),Ls=({mailboxId:e,threadId:t,accountId:s,messages:n,onAfterOptimisticRemove:r})=>{const o=ae(),{pushError:i}=ke(),{mutateAsync:c,isPending:d}=ue({...zr(),onMutate:async h=>{const p=new Set(h.body.messageIds??[]),m=t?Me({path:{threadId:t}}):[],b=je(As(p,n??[],e));await Promise.all([o.cancelQueries({queryKey:m}),kt(o,b)]);const g=t?o.getQueriesData({queryKey:m}).filter(f=>f[1]!==void 0).map(([f,x])=>({queryKey:f,data:x})):[],u=jt(o,b);return t&&o.setQueriesData({queryKey:m},f=>f&&{...f,items:Sn(f.items,p)}),wt(o,b,f=>Sn(f,p)),r?.(Array.from(p)),{threadMessagesPrefix:m,listPrefixes:b,previousThreadMessages:g,previousThreadsList:u}},onError:(h,p,m)=>{if(m){for(const g of m.previousThreadMessages)o.setQueryData(g.queryKey,g.data);Ct(o,m.previousThreadsList)}const b=p.body.messageIds?.length??0;i({title:b>1?`Couldn't delete ${b} messages`:"Couldn't delete this message",detail:Re(h),error:h})},onSettled:(h,p,m,b)=>{b&&(t&&o.invalidateQueries({queryKey:b.threadMessagesPrefix}),we(o,b.listPrefixes),s&&o.invalidateQueries({queryKey:Je({path:{accountId:s}})}))}});return{deleteMessages:l.useCallback(h=>{h.length!==0&&bt(h,p=>c({body:{messageIds:p}}))},[c]),isPending:d}},Wa="inline-flex items-center justify-center transition-colors",qc=F(Wa,"min-h-11 min-w-11 rounded hover:bg-surface-raised"),Hc=F(Wa,"min-h-11 gap-1.5 px-3 rounded text-sm font-medium hover:bg-surface-raised"),Ps=({accountId:e,currentMailboxId:t,onMove:s,disabled:n=!1,disabledHint:r,variant:o="icon-only",label:i})=>{const[c,d]=l.useState(!1),[v,h]=l.useState(),p=Cs(),m=l.useRef(null),b=i??"Move to folder",g=l.useId(),{t:u}=_r("mail",{useSuspense:!1}),f=aa(),{data:x,isLoading:S,isError:y,error:j,refetch:T}=te({...vt({path:{accountId:e}}),staleTime:1/0,enabled:c}),R=Va(e),{createFolderIn:O}=ra(e),$=l.useMemo(()=>oa({mailboxes:x?.items??[],folderAppointments:R,currentMailboxId:t,translator:f}),[x?.items,R,t,f]),z=ia(x?.items??[]),L=$.find(w=>w.id===v),P=l.useCallback(()=>{d(!1),h(void 0)},[]),D=l.useCallback(()=>{L&&(P(),s(L.id))},[L,P,s]);l.useEffect(()=>{if(!c||!p)return;const w=C=>{m.current&&!m.current.contains(C.target)&&P()},E=C=>{C.key==="Escape"&&P()};return document.addEventListener("mousedown",w),document.addEventListener("keydown",E),()=>{document.removeEventListener("mousedown",w),document.removeEventListener("keydown",E)}},[c,p,P]);const K=n||!!r,k=a.jsxs("button",{type:"button",onClick:w=>{w.stopPropagation(),!K&&d(E=>!E)},"aria-label":b,"aria-haspopup":p?"tree":"dialog","aria-expanded":c,"aria-controls":c?g:void 0,title:r,className:o==="icon-only"?qc:Hc,children:[a.jsx(vs,{className:o==="icon-only"?"size-5":"size-4"}),o==="compact"&&a.jsx("span",{className:"hidden sm:inline",children:"Move"})]}),M=S?a.jsx("div",{className:"px-3 py-5 text-sm text-fg-muted",children:"Loading folders…"}):y?a.jsx("div",{className:"p-3",children:a.jsx(_e,{variant:"inline",title:"Couldn't load folders",error:j,onRetry:()=>T()})}):a.jsx(Ur,{folders:$,selectedId:v,delimiter:z,onSelect:h,onCreateFolder:O,onCancel:P,labels:{filterPlaceholder:u("move_picker_filter_placeholder",{defaultValue:"Filter folders…"}),filterAriaLabel:u("move_picker_filter_label",{defaultValue:"Filter folders"})}}),I=L&&a.jsx("div",{className:"shrink-0 border-t border-line p-2",children:a.jsx(H,{variant:"primary",onClick:D,className:"h-11 w-full font-semibold",children:`Move to ${L.label}`})});return p?a.jsxs("div",{ref:m,className:"relative inline-block",children:[k,c&&a.jsxs("div",{id:g,className:F("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:[M,I]})]}):a.jsxs(a.Fragment,{children:[k,a.jsx(qe.Root,{open:c,onOpenChange:w=>w?d(!0):P(),children:a.jsxs(qe.Portal,{children:[a.jsx(qe.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),a.jsxs(qe.Content,{className:"fixed inset-x-0 bottom-0 z-50 flex flex-col rounded-t-lg bg-canvas pb-[env(safe-area-inset-bottom,0px)]",style:{maxHeight:"85dvh"},id:g,children:[a.jsx(qe.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-subtle/30"}),a.jsx(qe.Title,{className:"px-4 py-2 text-base font-semibold border-b border-line",children:"Move to folder"}),a.jsx("div",{className:"flex min-h-0 flex-1 overflow-hidden",children:M}),I]})]})})]})},Vc=({messageId:e,threadId:t,mailboxId:s,isRead:n,accountId:r,fromAddressId:o,isTrusted:i=!1,showRaw:c=!1,onToggleRaw:d})=>{const v=ae(),h=Hn(),p=Vo(),{pushError:m}=ke(),b=wo()?.messageId,{mutate:g,isPending:u}=ue({..._t(),onMutate:async I=>{const w=I.body.isRead??!0,E=new Set(I.body.messageIds??[]),C=Me({path:{threadId:t}}),_=je([s]);await Promise.all([v.cancelQueries({queryKey:C}),kt(v,_)]);const U=v.getQueriesData({queryKey:C}).filter(J=>J[1]!==void 0).map(([J,X])=>({queryKey:J,data:X})),W=jt(v,_);return v.setQueriesData({queryKey:C},J=>J&&{...J,items:Pt(J.items,E,w)}),wt(v,_,J=>Pt(J,E,w)),{threadMessagesPrefix:C,listPrefixes:_,previousThreadMessages:U,previousThreadsList:W}},onError:(I,w,E)=>{if(E){for(const _ of E.previousThreadMessages)v.setQueryData(_.queryKey,_.data);Ct(v,E.previousThreadsList)}const C=w.body.isRead??!0;m({title:C?"Couldn't mark as read":"Couldn't mark as unread",detail:Re(I),error:I})},onSettled:(I,w,E,C)=>{C&&(v.invalidateQueries({queryKey:C.threadMessagesPrefix}),we(v,C.listPrefixes))}}),f=l.useCallback(I=>{b&&I.includes(b)&&h({to:"/mail/$mailboxId",params:{mailboxId:s},search:w=>w,hash:p})},[b,s,h,p]),{deleteMessages:x,isPending:S}=Ls({mailboxId:s,threadId:t,onAfterOptimisticRemove:f}),{moveMessages:y,isPending:j}=Vt({mailboxId:s,threadId:t,accountId:r,onAfterOptimisticRemove:f}),{toggleTrusted:T,isPending:R,error:O,reset:$}=Yn({messageId:e}),z=()=>{g({body:{messageIds:[e],isRead:!1}})},L=()=>{x([e])},P=()=>{o&&T(o,i)},D=u||S||j||R,K=D||!o,k=l.useCallback(I=>{y([e],I)},[y,e]),M=o?void 0:"Sender has no parseable address";return a.jsxs("div",{className:"flex flex-col items-end gap-1",children:[a.jsxs("div",{className:"flex items-center gap-1",children:[r&&a.jsx(Ps,{accountId:r,currentMailboxId:s,onMove:k,disabled:D,label:"Move this message"}),a.jsxs(Co,{trigger:a.jsx(Po,{className:"size-4"}),children:[a.jsxs(Rt,{onClick:P,disabled:K,children:[i?a.jsx(Kt,{className:"size-4 text-positive"}):a.jsx(Ft,{className:"size-4 opacity-0"}),a.jsx("span",{title:M,children:"Trusted sender"})]}),n&&a.jsxs(Rt,{onClick:z,disabled:D,children:[a.jsx(Es,{className:"size-4"}),"Mark as unread"]}),d&&a.jsxs(Rt,{onClick:d,children:[a.jsx(xa,{className:"size-4"}),c?"Show formatted":"Show raw email"]}),a.jsx(So,{}),a.jsxs(Rt,{onClick:L,disabled:D,destructive:!0,children:[a.jsx(Ot,{className:"size-4"}),"Delete"]})]})]}),O&&a.jsx("div",{className:"w-64",children:a.jsx(_e,{variant:"inline",title:"Couldn't update trust",error:O,onRetry:()=>{$(),P()}})})]})},Gc=e=>e==="link-expired"||e==="not-ready";class ps extends Error{reason;status;constructor(t,s,n){super(s),this.name="AttachmentFetchError",this.reason=t,this.status=n}}const Wc="x-remit-403-reason",Yc="expired",Jc=(e,t)=>{if(t?.trim()===Yc)return"link-expired";const s=Go(e,t);return s==="auth"?"auth":s==="body-missing"?"missing":"generic"},Xc=300*1e3,Nn=async(e,t)=>{const s={},n=await t();n&&(s.Authorization=`Bearer ${n}`);const r=await Qr(e,{headers:s,signal:AbortSignal.timeout(Xc)});if(r.status===202)throw new ps("not-ready","Attachment is still being fetched from the mail server",202);if(!r.ok)throw new ps(Jc(r.status,r.headers.get(Wc)),`Failed to download attachment (${r.status} ${r.statusText})`,r.status);return r.blob()},Zc=(e,t,s)=>{switch(e){case"auth":return{title:"Your session expired",detail:`Sign in again, then download ${t} once more. Other parts of the app may also stop responding until you do.`};case"link-expired":return{title:"This download link expired and could not be renewed",detail:`Reload the page, then download ${t} again. If that keeps failing, this is worth reporting.`};case"missing":return{title:"This attachment is missing from storage",detail:"Remit has the message but not the file. Re-sync the account from Settings, then try again."};case"not-ready":return{title:"Still fetching this attachment",detail:"Remit is downloading it from the mail server now. Try again in a few seconds."};default:return{title:"Couldn't download this attachment",detail:s}}},Tn=e=>e instanceof ps?e.reason:"generic",ed=e=>e instanceof Error?e.message:typeof e=="string"?e:"An unexpected error occurred while downloading this attachment.",td=(e,t,s)=>{if(e!=="auth")return Kr(Br({title:`Bug: attachment download failed (${e})`,errorMessage:`Downloading "${t}" failed: ${s}`}))},sd=(e,t)=>{const s=URL.createObjectURL(e),n=document.createElement("a");n.href=s,n.download=t,n.rel="noopener",document.body.append(n),n.click(),n.remove(),setTimeout(()=>URL.revokeObjectURL(s),0)},nd=e=>{const t=e.toUpperCase();return t==="OCTET-STREAM"?"FILE":t},ad=e=>{const t=e.toLowerCase().replace(/[^a-z0-9]/g,"");return t.length>0?`attachment.${t}`:"attachment"},En=e=>e.filter(t=>!t.isMultipart&&t.disposition===si.Attachment&&t.contentUrl.length>0).map(t=>({bodyPartId:t.bodyPartId,filename:Do(t.dispositionFilename??"",ad(t.mediaSubtype)),typeLabel:nd(t.mediaSubtype),sizeOctets:t.sizeOctets,contentUrl:t.contentUrl})),Rn={status:"idle"},rd=({messageId:e,bodyParts:t,hasAttachment:s=!1,className:n})=>{const{getToken:r}=qr(),o=ae(),[i,c]=l.useState({}),d=l.useMemo(()=>En(t??[]),[t]),v=Hr({path:{messageId:e}}),h=g=>Nn(g.contentUrl,r).catch(u=>{if(!Gc(Tn(u)))throw u;return o.refetchQueries({queryKey:v}).then(()=>{const f=o.getQueryData(v),x=f?En(f.bodyParts).find(S=>S.bodyPartId===g.bodyPartId):void 0;return Nn(x?.contentUrl??g.contentUrl,r)})}),p=(g,u)=>c(f=>({...f,[g]:u})),m=g=>{const u=d.find(f=>f.bodyPartId===g);if(!u)throw new Error(`No attachment part ${g} on message ${e}`);p(g,{status:"downloading"}),h(u).then(f=>{sd(f,u.filename),p(g,Rn)}).catch(f=>{const x=Tn(f),S=ed(f),{title:y,detail:j}=Zc(x,u.filename,S);p(g,{status:"failed",title:y,detail:j,reportUrl:td(x,u.filename,S)})})},b=s&&t!==void 0&&d.length===0;return a.jsx(Rl,{className:n,attachments:d.map(g=>({attachmentId:g.bodyPartId,filename:g.filename,typeLabel:g.typeLabel,sizeOctets:g.sizeOctets,download:i[g.bodyPartId]??Rn})),onDownload:m,hasUnlistedAttachment:b})},od=({messageId:e,threadId:t,mailboxId:s,accountId:n,isRead:r,isStarred:o,onToggleStar:i,fromAddressId:c,isTrusted:d,showRaw:v,onToggleRaw:h,onReply:p,onReplyAll:m,onForward:b})=>{const g=ae(),{deleteMessages:u}=Ls({mailboxId:s,threadId:t}),{moveMessages:f}=Vt({mailboxId:s,threadId:t,accountId:n}),{toggleTrusted:x}=Yn({messageId:e}),{mutate:S}=ue({..._t(),onSettled:()=>{g.invalidateQueries({queryKey:Me({path:{threadId:t}})}),we(g,je([s]))}}),y=l.useCallback(O=>{f([e],O)},[f,e]),j=l.useCallback(()=>{u([e])},[u,e]),T=l.useCallback(()=>{S({body:{messageIds:[e],isRead:!r}})},[S,e,r]),R=[];return c&&R.push({key:"trusted",label:d?"Trusted sender":"Mark sender trusted",icon:d?a.jsx(Kt,{className:"size-4 text-positive"}):a.jsx(Ft,{className:"size-4"}),onSelect:()=>x(c,d)}),h&&R.push({key:"raw",label:v?"Show formatted":"Show raw email",icon:a.jsx(xa,{className:"size-4"}),onSelect:h}),a.jsx(Ea,{hasThread:!0,onReply:p,onReplyAll:m,onForward:b,isStarred:o,onToggleStar:i,onDelete:j,isRead:r,onToggleRead:T,overflowItems:R,moveSlot:n?a.jsx(Ps,{accountId:n,currentMailboxId:s,onMove:y,label:"Move this message"}):void 0})},id=()=>a.jsxs("div",{className:"animate-pulse space-y-2",role:"status","aria-label":"Loading raw email",children:[a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-full"}),a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-11/12"}),a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-5/6"}),a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-3/4"})]}),ld=({messageId:e,enabled:t=!0})=>{const{data:s,isLoading:n,isError:r,error:o,refetch:i}=te({...Vr({path:{messageId:e}}),enabled:t});if(n)return a.jsx("div",{className:"message-body",children:a.jsx(id,{})});if(r)return a.jsx("div",{className:"message-body",children:a.jsx(_e,{variant:"inline",title:"Couldn't load the raw email",error:o,onRetry:()=>i()})});const c=s?.raw??"";return c===""?a.jsx("div",{className:"message-body",children:a.jsx("p",{className:"text-fg-muted text-sm italic",children:"No raw source available for this message."})}):a.jsx("div",{className:"message-body",children:a.jsx("pre",{className:"email-text whitespace-pre-wrap break-words text-sm leading-relaxed bg-surface-sunken rounded-md p-3 max-h-[32rem] overflow-auto",children:c})})},cd=()=>a.jsx(Kt,{className:"inline-block size-4 ml-1 -mt-0.5 text-positive align-middle","aria-label":"Trusted sender","data-testid":"trusted-sender-badge"}),Ya=(e,t)=>({id:e.messageId,fromName:e.fromName??e.fromEmail??"?",fromEmail:e.fromEmail??"",toLabel:"",dateLabel:t,snippet:e.snippet||"",bodyHtml:""}),Ja=({isStarred:e,onToggleStar:t,isStarPending:s,hoverReveal:n})=>a.jsx("button",{type:"button",onClick:r=>{r.stopPropagation(),t()},disabled:s,"aria-label":e?"Remove star":"Add star",className:F("shrink-0 p-0.5 rounded transition-colors",e?"text-warning":F("text-fg-subtle hover:text-warning",n&&"opacity-0 group-hover:opacity-100 focus:opacity-100"),s&&"opacity-50"),children:a.jsx(Ye,{className:F("size-3.5",e&&"fill-current")})}),dd=({threadMessage:e,isFocused:t,onToggle:s,onToggleStar:n,isStarPending:r})=>{const o=sa(e.sentDate,"datetime"),i=Ya(e,o);return a.jsx(Ra,{message:i,onClick:s,isFocused:t,isUnread:!e.isRead,trailing:a.jsxs(a.Fragment,{children:[e.hasAttachment&&a.jsx(Bt,{className:"size-3 shrink-0 text-fg-subtle",role:"img","aria-label":"Has an attachment"}),a.jsx(Ja,{isStarred:e.hasStars,onToggleStar:n,isStarPending:r,hoverReveal:!0}),a.jsx("span",{"data-testid":"message-date",className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:o})]})})},ud=({threadMessage:e,messageData:t,isLoading:s,isError:n,error:r,onRetry:o,isFocused:i,onToggle:c,onToggleStar:d,isStarPending:v,accountId:h,showRaw:p,onToggleRaw:m,mobile:b,onReply:g,onReplyAll:u,onForward:f})=>{const x=sa(e.sentDate,"long"),S=!e.isRead,y=t?.envelope.from[0]?.flags?.trusted?.value===!0,j=t?.envelope.from[0]?.addressId,T=Ya(e,x),R=e.autoMoved||e.spamReport?a.jsx(Qc,{accountId:h,messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,autoMoved:e.autoMoved,spamReport:e.spamReport}):null;return a.jsx(Ma,{message:T,isFocused:b?!1:i,onHeaderClick:c,senderBadge:y?a.jsx(cd,{}):void 0,trailing:a.jsx("span",{"data-testid":"message-date",className:"text-2xs text-fg-subtle",children:x}),to:t?a.jsx(il,{label:"To",addresses:t.envelope.to}):null,indicators:R||!b?a.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mt-0.5",children:[R,!b&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"flex items-center justify-end gap-1",children:a.jsx(Ja,{isStarred:e.hasStars,onToggleStar:d,isStarPending:v})}),S&&a.jsx("span",{className:"size-1.5 rounded-full bg-accent","aria-label":"Unread"})]})]}):void 0,actionMenu:b?void 0:a.jsx(Vc,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,isRead:e.isRead,accountId:h,fromAddressId:j,isTrusted:y,showRaw:p,onToggleRaw:m}),actionBar:b?a.jsx(od,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,accountId:h,isRead:e.isRead,isStarred:e.hasStars,onToggleStar:d,fromAddressId:j,isTrusted:y,showRaw:p,onToggleRaw:m,onReply:g,onReplyAll:u,onForward:f}):void 0,body:s?a.jsxs("div",{className:"mt-3 animate-pulse space-y-2",children:[a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-full"}),a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-3/4"}),a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-1/2"})]}):n&&Gr(r)?a.jsx("div",{className:"mt-3",children:a.jsx(Oa,{message:"This message has been deleted"})}):n?a.jsx("div",{className:"mt-3",children:a.jsx(_e,{variant:"inline",title:"Couldn't load this message",error:r,onRetry:o})}):p?a.jsx("div",{className:"mt-3",children:a.jsx(ld,{messageId:e.messageId})}):a.jsxs("div",{className:"mt-3",children:[a.jsx(_o,{bodyParts:t?.bodyParts,messageId:e.messageId,fromAddressId:t?.envelope.from[0]?.addressId,isTrusted:y,category:qa(e.category)}),a.jsx(rd,{messageId:e.messageId,bodyParts:t?.bodyParts,hasAttachment:e.hasAttachment,className:"mt-4"})]})})},fd=({threadMessage:e,isExpanded:t,isFocused:s,onToggle:n,onToggleStar:r,isStarPending:o,accountId:i,mobile:c,onReply:d,onReplyAll:v,onForward:h})=>{const[p,m]=l.useState(!1),{data:b,isLoading:g,isError:u,error:f,refetch:x}=te({...zt({path:{messageId:e.messageId}}),enabled:t,meta:{softError:!0}});return t?a.jsx(ud,{threadMessage:e,messageData:b,isLoading:g,isError:u,error:f,onRetry:()=>x(),isFocused:s,onToggle:n,onToggleStar:r,isStarPending:o,accountId:i,showRaw:p,onToggleRaw:()=>m(S=>!S),mobile:c,onReply:d,onReplyAll:v,onForward:h}):a.jsx(dd,{threadMessage:e,isFocused:s,onToggle:n,onToggleStar:r,isStarPending:o})},md=()=>a.jsxs("div",{className:"animate-pulse p-4",children:[a.jsx("div",{className:"h-6 bg-surface-sunken rounded w-3/4 mb-5"}),a.jsx("div",{className:"space-y-4",children:Array.from({length:2}).map((e,t)=>a.jsxs("div",{className:"flex gap-3 py-3",children:[a.jsx("div",{className:"size-10 bg-surface-sunken rounded-full shrink-0"}),a.jsxs("div",{className:"flex-1",children:[a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-32 mb-2"}),a.jsx("div",{className:"h-3 bg-surface-sunken rounded w-48"})]})]},t))})]}),Pf=({threadId:e,mailboxId:t,subject:s,selectedMessageId:n,authenticity:r,onOpenIntelligence:o,onBack:i,onSwipeNext:c,onSwipePrevious:d,mobileIntelligenceOpen:v})=>{const h=Cs(),{handlers:p}=Ac({onSwipeLeft:c,onSwipeRight:d}),{accountId:m}=za(t),{data:b,isLoading:g,isError:u,error:f,refetch:x}=te({...Vn({path:{threadId:e}})}),S=l.useMemo(()=>b?.items??[],[b?.items]),y=S[S.length-1],j=l.useMemo(()=>[...S].reverse(),[S]),T=l.useRef(new Map),[R,O]=l.useState(new Set),[$,z]=l.useState(null),[L,P]=l.useState(0);l.useEffect(()=>{if(S.length>0&&e!==$){z(e);const B=new Set([S[S.length-1].threadMessageId]);if(n){const q=S.find(oe=>oe.messageId===n);q&&B.add(q.threadMessageId)}O(B),P(0)}},[e,S,$,n]);const D=l.useCallback(B=>{O(q=>{const oe=new Set(q);return oe.has(B)?oe.delete(B):oe.add(B),oe})},[]),K=l.useCallback(B=>{const q=j[B];if(!q)return;T.current.get(q.threadMessageId)?.scrollIntoView({behavior:"smooth",block:"nearest"})},[j]),k=l.useCallback(()=>{if(j.length===0)return;const B=Math.min(L+1,j.length-1);P(B),K(B)},[j.length,L,K]),M=l.useCallback(()=>{if(j.length===0)return;const B=Math.max(L-1,0);P(B),K(B)},[j.length,L,K]),I=l.useCallback(()=>{const B=j[L];B&&D(B.threadMessageId)},[j,L,D]),{data:w}=te({...xt(),staleTime:1/0}),E=w?.accounts?.[0];Ec({messages:S,expandedIds:R,threadId:e,mailboxId:t,accountId:E?.accountId});const{toggleStar:C,isPending:_,pendingMessageId:U}=Qa({threadId:e,mailboxId:t,messages:S}),W=Wo(),J=Yo(),X=n??y?.messageId,V=l.useCallback((B,q)=>{q&&J({threadId:e,messageId:q,mode:B})},[J,e]),le=l.useCallback(()=>V("reply",X),[V,X]),re=l.useCallback(()=>V("reply-all",X),[V,X]),he=l.useCallback(()=>V("forward",X),[V,X]),G=l.useRef(null),fe=W?.kind==="reply"?`${W.mode}:${W.sourceMessageId}`:void 0;if(l.useEffect(()=>{fe&&G.current?.scrollIntoView({behavior:"smooth",block:"start"})},[fe]),Zo({enabled:!g&&S.length>0&&W===void 0,bindings:[{key:"j",handler:k,preventDefault:!0},{key:"ArrowDown",handler:k,preventDefault:!0},{key:"k",handler:M,preventDefault:!0},{key:"ArrowUp",handler:M,preventDefault:!0},{key:"Enter",handler:I,preventDefault:!0},{key:"o",handler:I,preventDefault:!0},{key:"r",handler:le,preventDefault:!0},{key:"R",handler:re,noModifiers:!1,preventDefault:!0},{key:"f",handler:he,preventDefault:!0}]}),g)return a.jsx(md,{});if(u)return a.jsx("div",{className:"flex h-full items-center justify-center",children:a.jsx(_e,{title:W?"Couldn't load this conversation, so there is nothing to answer":"Couldn't load this conversation",error:f,onRetry:()=>x()})});if(S.length===0)return a.jsx("div",{className:"flex h-full items-center justify-center p-4",children:W?a.jsx(_e,{variant:"inline",title:"There is nothing here to answer",error:"This conversation has no messages left. Another mail client may have moved or deleted them."}):a.jsx(Oa,{message:"No messages in this thread"})});const ge=s||S[0]?.subject||"(No subject)",me=S.length,ce=B=>a.jsx("div",{"data-testid":"conversation-messages",children:j.map((q,oe)=>a.jsx("div",{ref:Ae=>{Ae&&T.current.set(q.threadMessageId,Ae)},children:a.jsx(fd,{threadMessage:q,isExpanded:R.has(q.threadMessageId),isFocused:oe===L,onToggle:()=>D(q.threadMessageId),onToggleStar:()=>C(q.messageId,q.hasStars),isStarPending:_&&U===q.messageId,accountId:m,mobile:B,onReply:B?()=>V("reply",q.messageId):void 0,onReplyAll:B?()=>V("reply-all",q.messageId):void 0,onForward:B?()=>V("forward",q.messageId):void 0})},q.threadMessageId))}),be=W&&a.jsx("div",{ref:G,children:W.kind==="reply"?a.jsx(yc,{surface:W}):a.jsx("div",{className:"border-b border-line bg-canvas p-4",children:a.jsx(_e,{variant:"inline",title:"That is not a way to answer a message",error:`"${W.segment}" is not reply, reply-all or forward.`})})}),xe=a.jsxs("header",{className:"border-b border-line px-5 pt-5 pb-3",children:[a.jsx("h1",{className:"max-w-2xl text-lg font-semibold leading-snug text-fg",children:ge}),a.jsxs("p",{className:"mt-1 text-2xs text-fg-subtle",children:[me," ",me===1?"message":"messages"]})]});return h?a.jsxs("article",{className:"h-full flex flex-col",children:[xe,r?.dkimMismatch&&a.jsx(jn,{authenticity:r,onOpenIntelligence:o}),a.jsxs("div",{className:"min-h-0 flex-1 overflow-auto",children:[be,ce(!1)]})]}):a.jsxs(Tl,{thread:{subject:ge,messages:[]},onBack:i??(()=>{}),intelligenceOpen:v,onToggleIntelligence:o,touchHandlers:p,children:[r?.dkimMismatch&&a.jsx(jn,{authenticity:r,onOpenIntelligence:o}),be,ce(!0)]})},pd=10,Xa=e=>({q:e?.toLowerCase()??"",limit:pd}),hd=(e,t)=>{if(!t)return;const s=t.toLowerCase();return e?.find(n=>n.normalizedEmail===s)};function gd(e){const t=new Date(e),s=new Date;return t.toDateString()===s.toDateString()?"today":ei(t,{month:"short",year:"numeric"})}function Za(e){if(!e)return!0;const[,t]=e.split("@");return t?!t.includes("."):!0}const bd="We can't verify the sender of this email, which could mean it's from an insecure source.",xd="We couldn't read this sender's address, so we can't confirm who really sent this message.";function vd(e,t){const s=e.category??"personal";return{value:Yr(s)?s:"uncategorized",overridden:t?.flags?.category?.value!=null&&t.flags.category.value!==e.category}}function yd(e,t){return{name:e.fromName??e.fromEmail??"Unknown",email:e.fromEmail??"",trust:e.senderTrust,firstSeenLabel:t?gd(t.createdAt):"unknown",inboundCount:t?.inboundCount,replyCount:t?.replyCount,addressUnverified:Za(e.fromEmail)}}function kd(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 Mn(e){if(e.fromName&&e.fromName!==e.fromEmail)return e.fromName}function jd(e){return e.length===1?e[0]:`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function wd(e,t){const s=[],n=e.displayNameCorrespondence;t&&(n===Xs.Unrelated?s.push(`The name it shows, "${t}", has nothing to do with ${e.fromDomain}.`):n===Xs.Lookalike&&s.push(`The name it shows, "${t}", only looks like ${e.fromDomain}.`));const r=Cd(e.offDomainLinkDomains);return r.length>0&&s.push(`Its links go to ${jd(r.slice(0,3))}.`),s}function Cd(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&t.length>0):[]}function Sd(e,t){const s=t>0?t:void 0;if(Za(e.fromEmail))return{verdict:"mismatch",fromDomain:"",addressUnreadable:!0,summary:xd,similarCount:s};const n=e.authenticity;if(!n)return{verdict:"caution",fromDomain:e.fromEmail?.split("@")[1]??"",summary:bd};if(!n.dkimMismatch){const v=Mn(e),h=wd(n,v);return h.length>0?{verdict:"caution",fromDomain:n.fromDomain,dkimDomain:n.dkimDomain,claimedBrand:v,summary:h.join(" ")}:{verdict:"aligned",fromDomain:n.fromDomain,dkimDomain:n.dkimDomain,summary:n.dkimDomain?`This message was signed by ${n.dkimDomain}.`:"Nothing looks unusual about this sender."}}const r=n.fromDomain,o=n.dkimDomain,i=Mn(e),c=o?`it was actually sent from ${o}`:"its signature failed to verify",d=i?`The display name claims "${i}", but ${c}${o?` — not ${r}`:""}. Real senders use their own address.`:`This message claims to be from ${r}, but ${c}.`;return{verdict:"mismatch",fromDomain:r,dkimDomain:o,claimedBrand:i,summary:d,similarCount:s}}function Nd(e,t){const s=e?.fromEmail??null,n=e?.subject??"",{data:r,error:o}=te({...ys({query:Xa(s??void 0)}),enabled:!!s,staleTime:3e4}),i=hd(r?.items,s??void 0),c=[n,s].filter(Boolean).join(" "),{data:d,isLoading:v,error:h}=te({...Wr({query:{query:c,limit:5}}),enabled:!!(e&&c.length>3),staleTime:6e4,retry:1});return{data:l.useMemo(()=>{if(!e)return null;const m=(d?.items??[]).filter(x=>x.messageId!==e.messageId).map(x=>({id:x.messageId,threadId:x.threadId,mailboxId:t!=null&&x.mailboxIds.includes(t)?t:x.mailboxIds[0]??"",fromName:x.fromName??"",subject:x.subject??"(No subject)",timeLabel:x.sentDate!=null?Xe(x.sentDate*1e3):"",matched:x.matchedChunkType})),b=yd(e,i),g=Sd(e,m.length),u=vd(e,i),f=kd(i);return{sender:b,authenticity:g,category:u,flags:f,similar:m}},[e,i,d,t]),isSimilarLoading:v,similarError:h,similarErrorIsFatal:qs(h),addressErrorIsFatal:qs(o),addressId:i?.addressId,address:i}}function Td(e,t){const s={...e??{}};for(const[n,r]of Object.entries(t))r==null?delete s[n]:s[n]={...r,setAt:r.setAt??Date.now()};return s}function Ed({addressId:e,senderEmail:t}){const s=ae(),{pushError:n}=ke(),r=Jr({query:Xa(t)}),{mutate:o,isPending:i}=ue({...Xr(),onMutate:async d=>{const v=d.body.flags??{};await s.cancelQueries({queryKey:r});const h=s.getQueryData(r);return s.setQueryData(r,p=>p&&{...p,items:p.items.map(m=>m.addressId===d.path.addressId?{...m,flags:Td(m.flags,v)}:m)}),{previous:h}},onError:(d,v,h)=>{h?.previous!==void 0&&s.setQueryData(r,h.previous),n({title:"Couldn't update sender preference",detail:Re(d),error:d})},onSettled:()=>{s.invalidateQueries({queryKey:r})}});return{updateFlags:l.useCallback(d=>{if(!e){Zr(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:d}})},[e,o,t]),isPending:i}}const Df=e=>e==="vip"?"A sender you know":e==="wellknown"?"You've emailed them before":"Passed authentication",Rd=e=>e.senderTrust!=="vip"&&e.senderTrust!=="wellknown"?!1:e.authenticity?.dkimMismatch!==!0;function Ff(e,t){e.recordEvent("rescue.candidates_surfaced",{count:String(t)})}function Of(e,t){e.recordEvent("rescue.flow_opened",{count:String(t)})}function zf(e,t){e.recordEvent("rescue.committed",{selected:String(t.selected),total:String(t.total),destination:t.toInbox?"inbox":"other"})}function Md(e,t){e.recordEvent("rescue.sent_to_junk",{count:String(t.count),senderTrust:t.senderTrust,wasRescuable:String(t.wasRescuable)})}const Id=["personal","newsletter","marketing","automated","transactional","social"],Ad=e=>e.spamReport?"notSpam":"reportSpam",$d=e=>{const{similarError:t,similarErrorIsFatal:s,isSimilarLoading:n}=e;return t&&!s?"error":n?"loading":"ready"};function Ld(){return a.jsxs("aside",{className:"flex h-full w-full flex-col bg-surface-sunken",children:[a.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-1.5 border-b border-line px-row-inset",children:[a.jsx(We,{className:"size-3.5 text-fg-subtle"}),a.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"})]}),a.jsxs("div",{className:"flex-1 animate-pulse space-y-4 p-4",children:[a.jsxs("div",{className:"space-y-2",children:[a.jsx("div",{className:"h-2.5 rounded bg-surface w-1/4"}),a.jsxs("div",{className:"flex gap-3",children:[a.jsx("div",{className:"size-10 rounded-full bg-surface shrink-0"}),a.jsxs("div",{className:"flex-1 space-y-1.5",children:[a.jsx("div",{className:"h-3 rounded bg-surface w-3/4"}),a.jsx("div",{className:"h-2.5 rounded bg-surface w-1/2"})]})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx("div",{className:"h-2.5 rounded bg-surface w-1/4"}),a.jsx("div",{className:"h-8 rounded bg-surface"})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx("div",{className:"h-2.5 rounded bg-surface w-1/4"}),a.jsx("div",{className:"flex gap-1.5 flex-wrap",children:Array.from({length:5}).map((e,t)=>a.jsx("div",{className:"h-6 w-16 rounded bg-surface"},t))})]})]})]})}function Pd({isOpen:e,current:t,onSelect:s,onCancel:n}){return e?a.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[a.jsx(to,{label:"Dismiss reclassify sender",onDismiss:n,className:"backdrop-blur-sm"}),a.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",children:[a.jsx("h2",{className:"text-lg font-semibold",children:"Reclassify this sender"}),a.jsx("p",{className:"mt-2 text-sm text-fg-muted",children:"Set a category override for future messages from this sender."}),a.jsx("div",{className:"mt-4 flex flex-col gap-1",children:Id.map(r=>a.jsxs("button",{type:"button",onClick:()=>s(r),className:`flex min-h-11 items-center justify-between rounded px-3 text-left text-sm capitalize transition-colors hover:bg-surface-raised ${r===t?"font-semibold text-accent":"text-fg"}`,children:[r,r===t&&a.jsx("span",{className:"text-2xs text-fg-subtle",children:"current"})]},r))}),a.jsx("div",{className:"mt-6 flex justify-end",children:a.jsx("button",{type:"button",onClick:n,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 Dd({thread:e,onClose:t,mailboxId:s,accountId:n,hideCloseButton:r,onAfterOptimisticRemove:o}){const{data:i,addressId:c,isSimilarLoading:d,similarError:v,similarErrorIsFatal:h}=Nd(e,s),[p,m]=l.useState(!1),b=e.fromEmail??void 0,{updateFlags:g}=Ed({addressId:c,senderEmail:b}),{reportSpam:u,notSpam:f,isReporting:x,isRestoring:S}=Ga({mailboxId:e.mailboxId,threadId:e.threadId,accountId:n,onAfterOptimisticRemove:o}),y=eo(),j=Ad(e),T=l.useCallback(()=>{f([e.messageId])},[f,e.messageId]),R=l.useCallback(()=>{Md(y,{count:1,senderTrust:e.senderTrust,wasRescuable:Rd(e)}),u([e.messageId])},[u,e,y]),O=l.useCallback(()=>{},[]),$=l.useCallback(()=>{const I=i?.flags?.vip!==!0;g({vip:{value:I}})},[i?.flags?.vip,g]),z=l.useCallback(()=>{const I=i?.flags?.muted!==!0;g({muted:{value:I}})},[i?.flags?.muted,g]),L=l.useCallback(()=>{const I=i?.flags?.unsubscribed!==!0;g({unsubscribed:{value:I}})},[i?.flags?.unsubscribed,g]),P=l.useCallback(I=>{m(!1),g({category:{value:I}})},[g]),D=c!==void 0,K={onToggleVip:D?$:void 0,onToggleMute:D?z:void 0,onToggleUnsubscribe:D?L:void 0,onReclassify:D?()=>m(!0):void 0,onNotSpam:j==="notSpam"?T:void 0,onReportSpam:j==="reportSpam"?R:void 0},k=({mailboxId:I,threadId:w,messageId:E,className:C,ariaLabel:_,children:U})=>a.jsx(ta,{to:"/mail/$mailboxId/$threadId/$messageId",params:{mailboxId:I,threadId:w,messageId:E},search:W=>W,variant:"row",className:C,"aria-label":_,children:U});if(!i)return a.jsx(Ld,{});const M=$d({similarError:v,similarErrorIsFatal:h,isSimilarLoading:d});return a.jsxs(a.Fragment,{children:[a.jsx(ja,{data:i,onClose:t,hideCloseButton:r,onShowSimilar:O,actions:K,similarState:M,similarLinkComponent:k,reportSpamPending:x,notSpamPending:S,className:"border-l-0 h-full w-full"}),a.jsx(Pd,{isOpen:p,current:i.category.value,onSelect:P,onCancel:()=>m(!1)})]})}const _f=({onClose:e,thread:t,mailboxId:s,accountId:n,hideCloseButton:r,onAfterOptimisticRemove:o})=>t?a.jsx(Dd,{thread:t,onClose:e,mailboxId:s,accountId:n,hideCloseButton:r,onAfterOptimisticRemove:o}):a.jsxs("aside",{className:"flex h-full w-full flex-col bg-surface-sunken",children:[a.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-1.5 border-b border-line px-row-inset",children:[a.jsx(We,{className:"size-3.5 text-fg-subtle"}),a.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"})]}),a.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center px-row-inset text-center",children:[a.jsx(We,{className:"size-8 text-fg-subtle"}),a.jsx("p",{className:"mt-3 text-sm text-fg-muted",children:"Intelligence"}),a.jsx("p",{className:"mt-1 text-2xs text-fg-subtle",children:"Sender trust, authenticity and similar messages will appear here."})]})]}),Fd={delete:(e,t)=>`Deleting ${e} of ${t}…`,move:(e,t)=>`Moving ${e} of ${t}…`,markRead:(e,t)=>`Marking ${e} of ${t} as read…`},er={delete:"moved to Trash",move:"moved",markRead:"marked as read"},Od={delete:"couldn't be deleted",move:"couldn't be moved",markRead:"couldn't be marked as read"},zd={delete:"Couldn't delete these messages",move:"Couldn't move these messages",markRead:"Couldn't mark these messages as read"},_d={delete:"The delete didn't finish.",move:"The move didn't finish.",markRead:"The update didn't finish."},Uf=(e,t,s)=>Fd[e](Ue(t),Ue(s)),Kf=(e,t)=>`${Ue(t)} ${er[e]}. Your mail server is still catching up.`,Bf=e=>`Stopped after ${Ue(e)}`,Qf=(e,t,s)=>`${Ue(t)} of ${Ue(s)} ${er[e]}. Nothing was sent for the rest, so they are untouched.`,Ud=(e,t)=>t>0?`Stopped after ${Ue(t)} — some messages ${Od[e]}`:zd[e],Kd=e=>_d[e],qf=e=>e==="delete"?"danger":"info",Bd=100,Qd=(e,t)=>e.kind==="move"?[t,e.destinationMailboxId]:[t],qd=({mailboxId:e,accountId:t,enabled:s,predicateKey:n,searchQuery:r})=>{const[o,i]=l.useState({kind:"idle"}),[c,d]=l.useState(void 0),[v,h]=l.useState(void 0),p=l.useRef(!1),m=l.useRef(!1),b=ae(),{pushError:g}=ke();l.useEffect(()=>{m.current||(p.current=!0),i({kind:"idle"})},[s,n]);const u=l.useRef(r);u.current=r;const f=l.useCallback($=>async z=>{const{data:L}=await Hs({path:{mailboxId:e},query:{...$,continuationToken:z,limit:Bd},throwOnError:!0});return{ids:(L.items??[]).map(P=>P.messageId),continuationToken:L.continuationToken}},[e]),x=l.useCallback(async()=>{const{data:$}=await Hs({path:{mailboxId:e},query:{...u.current,count:!0,results:!1},throwOnError:!0});if($.count===void 0)throw new Error("the search returned no count for the selection");return $.count},[e]),S=l.useCallback($=>async z=>{if($.kind==="move"){const{data:P}=await so({body:{messageIds:z,destinationMailboxId:$.destinationMailboxId},throwOnError:!0});return P}if($.kind==="markRead"){const{data:P}=await no({body:{messageIds:z,isRead:!0},throwOnError:!0});return P}const{data:L}=await ao({body:{messageIds:z},throwOnError:!0});return L},[]),y=l.useCallback($=>{we(b,je(Qd($,e))),t&&b.invalidateQueries({queryKey:Je({path:{accountId:t}})})},[b,e,t]),j=l.useCallback(()=>{p.current=!1,i({kind:"counting"}),x().then($=>{if(p.current){i({kind:"idle"});return}i({kind:"escalated",total:$})},$=>{g(Vs("Couldn't count matching messages","The count didn't finish.",$)),i({kind:"idle"})})},[x,g]),T=l.useCallback(()=>{p.current=!0},[]),R=l.useCallback(()=>{m.current||(p.current=!0,i({kind:"idle"}))},[]),O=l.useCallback(async($,z)=>{p.current=!1,m.current=!0,d($);const L=k=>h(Cc(k)),P=S($),D=f(u.current);let K;try{K=z!==void 0?await _a(z,P,L,()=>p.current):await wc(D,o.kind==="escalated"?o.total:0,P,L,()=>p.current)}finally{m.current=!1}return d(void 0),h(void 0),i({kind:"idle"}),K.error&&g(Vs(Ud($.kind,K.done),Kd($.kind),K.error)),K.done>0&&y($),K},[S,f,o,g,y]);return{phase:o,escalate:j,stop:T,clear:R,isRunning:c!==void 0,runningAction:c,progress:v,runAction:O}},Hd=120,Vd=({keyboardFocusedMessageId:e,openMessageId:t,enabled:s,open:n,delayMs:r=Hd})=>{const o=l.useRef(n);o.current=n;const i=l.useRef(void 0);l.useEffect(()=>{const c=e;if(!s){i.current=c;return}if(c===void 0||c===t)return;if(c===i.current){i.current=void 0;return}const d=setTimeout(()=>o.current(c),r);return()=>clearTimeout(d)},[s,e,t,r])},tr="This account has no Junk folder appointed, so there is nowhere to file these. Appoint one under Settings › Folders.",Gd="These are already in Junk, so there is nowhere to file them.",Wd=(e,t)=>e!==void 0&&e!==t?e:void 0,Hf=(e,t)=>{if(Wd(e,t)===void 0)return e===void 0?tr:Gd};function Yd(e,t){if(e.length!==0)return t!==void 0&&e.includes(t)?t:e[0]}const Jd={title:"",navSlot:null,titleMeta:null,searchSlot:null,searchField:null,searchResults:null,makeFilterSlot:null},hs=l.createContext(Jd),sr=()=>l.useContext(hs),nr=8,ar=e=>e==="From"||e==="FromDomain",Xd=e=>({value:e.email,label:e.displayName??e.email,...e.displayName?{hint:e.email}:{},...e.fromSelection?{source:"selected"}:{}}),Zd=e=>{const t=Da(e.email);if(t!==null)return{value:t,...e.fromSelection?{source:"selected"}:{}}},eu=(e,t)=>e.value.toLowerCase().includes(t)||(e.label??"").toLowerCase().includes(t),tu=(e,t,s)=>{if(!ar(e))return[];const n=t.trim().toLowerCase(),r=new Set,o=[];for(const i of s){if(i.email.trim()==="")continue;const c=e==="From"?Xd(i):Zd(i);if(!c)continue;const d=c.value.toLowerCase();if(!(d===""||r.has(d))&&(r.add(d),d!==n&&!(n!==""&&!eu(c,n))&&(o.push(c),o.length===nr)))break}return o},su=250,nu=2,au=(e,t,s)=>{const n=t.trim(),r=na(n,su),o=e!==void 0&&ar(e),{data:i}=te({...ys({query:{q:r,limit:nr}}),enabled:o&&r.length>=nu});if(!o||e===void 0)return[];const c=[...s.map(d=>({email:d,fromSelection:!0})),...(i?.items??[]).map(d=>({email:d.normalizedEmail,...d.displayName?{displayName:d.displayName}:{}}))];return tu(e,n,c)},rr=12,ru=e=>{const{envelope:t}=e,s=t.from[0];return{id:t.messageId,sender:s?Fa({normalizedEmail:s.normalizedEmail,displayName:s.displayName}):"Unknown",subject:t.subject??"(No subject)",date:Xe(t.date)}},ou=(e,t)=>{const s=e!==void 0&&t!==void 0,{data:n,isLoading:r}=te({...ro({path:{mailboxId:e??""},query:{...t,limit:rr}}),enabled:s,staleTime:3e4});return{messages:(n?.items??[]).map(iu),isPending:s&&r}},iu=e=>({id:e.messageId,sender:e.fromName||e.fromEmail||"Unknown",subject:e.subject??"(No subject)",date:Xe(e.sentDate)}),lu=e=>ws({queries:e.slice(0,rr).map(t=>({...zt({path:{messageId:t}}),staleTime:Number.POSITIVE_INFINITY})),combine:t=>({messages:t.map(s=>s.data).filter(s=>s!==void 0).map(ru),isPending:t.some(s=>s.isPending)})}),cu=e=>({matchOperator:"Or",literalClauses:qt(e)}),du=(e,t,s)=>{const n=ue(oo()),{mutate:r,reset:o}=n,[i,c]=l.useState(!1),d=l.useMemo(()=>Qt(s),[s]),v=l.useCallback(()=>{!e||!t||(c(!1),r({path:{accountId:e},body:Zs({anchorMessageId:t,matchOperator:"And",literalClauses:[]})}))},[e,t,r]),h=l.useCallback(()=>{c(!1),o()},[o]),p=n.data,m=p?.semanticUnavailable===!0&&!i&&d.length>0;l.useEffect(()=>{!m||!e||(c(!0),r({path:{accountId:e},body:Zs(cu(d))}))},[m,e,d,r]);const b=i||(p?.semanticUnavailable??!1),g=n.isPending||m,u=i?{matchOperator:"Or",literalClauses:qt(d)}:{...t?{anchorMessageId:t}:{},matchOperator:"And",literalClauses:[]};return{preview:v,reset:h,matchedCount:g?void 0:p?.matchedCount,messageIds:g?void 0:p?.messageIds,semanticUnavailable:b,senderFallback:i,senders:d,matchPredicate:u,isPending:g,isError:n.isError,error:n.error}},uu=()=>[Bn({path:{mailboxId:""}}),Qn({path:{mailboxId:""}}),qn()].map(e=>[{_id:e[0]._id}]),fu=e=>Ua(e)?e.pages:Ka(e)?[e]:[],mu=e=>typeof e=="object"&&e!==null&&typeof e.messageId=="string",pu=(e,t)=>{const s=new Set(t),n=new Map;for(const r of e)for(const o of fu(r))for(const i of o.items){if(!mu(i)||!s.has(i.messageId))continue;const c=i.subject?.trim();c&&n.set(i.messageId,c)}return t.map(r=>n.get(r)).filter(r=>r!==void 0)},hu=e=>{const t=ae(),s=e.join("\0");return l.useMemo(()=>{const n=uu().flatMap(r=>t.getQueriesData({queryKey:r}).map(([,o])=>o));return pu(n,e)},[t,s])},gu=new Set(["hasAttachment","isUnread","isRead","isStarred","category","before","after"]),bu=e=>gu.has(e),xu=(e,{searchHadSemanticReach:t})=>{const s=[],n=[];let r,o;for(const d of e.tokens){if(d.type==="from"){s.push({field:"From",value:d.value});continue}if(d.type==="subject"){s.push({field:"Subject",value:d.value});continue}if(d.type==="in"){r={mailboxId:d.mailboxId,label:d.value};continue}if(d.type==="account"){o=d.accountId;continue}bu(d.type)&&n.push({type:d.type,label:Jn(d)})}const i=e.freeText.trim(),c=i.length>0;return c&&s.push({field:"HasWords",value:i}),{clauses:s,matchOperator:"all",scopedOut:r,droppedFacets:n,targetAccountId:o,keptTerms:c,droppedSemantic:c&&t}},vu=(e,t,s)=>e.targetAccountId??t??s[0]?.accountId,yu=({failure:e,isStarting:t,isRunning:s,isDone:n,failedCount:r,ruleSaved:o})=>e?.kind==="restartFailed"?"backApplyRestartFailed":e?.kind==="startFailed"?o?"backApplyStartFailed":"commitFailed":n?r>0?"backApplyFailed":"backApplyComplete":e?.kind==="statusUnreadable"?"statusUnknown":t||s?"backApplyRunning":"saving",ku={clauses:[],matchOperator:"any"},ju={clauses:[],matchOperator:"all",droppedFacets:[],keptTerms:!1,droppedSemantic:!1},wu=[],ze={state:"saving",matched:0,applied:0,failed:0,failures:[]},as=(e,t)=>e.map((s,n)=>({...s,id:`${t}-${n}`})),In=(e,t,s)=>{if(e==="delete")return{kind:"delete"};if(e==="markRead")return{kind:"markRead"};const n=e==="junk"?s:t;return n?{kind:"move",destinationMailboxId:n}:void 0},rs=e=>e==="move"||e==="junk"||e==="organize",An=e=>e==="junk"?tr:"No destination was chosen, so there is nowhere to file these. Go back and pick a folder.";function Cu({verb:e,accountId:t,mailboxId:s,selection:n,selectionRestriction:r,escalated:o,escalatedProgress:i,searchConversion:c,onFinished:d,onRunEnded:v,step:h,goToStep:p,goBack:m,closeWizard:b}){const[g]=l.useState(()=>c),[u]=l.useState(()=>o),f=g!==void 0,[x,S]=l.useState(f?"properties":"selected"),y=u?"escalated":x,[j,T]=l.useState(()=>g?{clauses:as(g.clauses,"search"),matchOperator:g.matchOperator}:ku),[R,O]=l.useState(void 0),[$,z]=l.useState(void 0),[L,P]=l.useState(!1),[D,K]=l.useState(void 0),[k,M]=l.useState(void 0),[I,w]=l.useState(),E=l.useRef(!1),C=l.useRef(!1),_=l.useMemo(()=>n.map(N=>N.id),[n]),U=l.useMemo(()=>n.map(N=>N.email).filter(Boolean),[n]),W=_[0],J=hu(_),{junkMailboxId:X}=Ha(t),V=du(u?void 0:t,W,U),{preview:le}=V;l.useEffect(()=>{le()},[le]);const re=y==="similar"||y==="properties",he=l.useMemo(()=>({matchOperator:j.matchOperator==="all"?"And":"Or",literalClauses:j.clauses.map(N=>({field:N.field,value:N.value}))}),[j.clauses,j.matchOperator]),G=y==="similar"?V.matchPredicate:he,{count:fe,matchedIds:ge}=ri(re?t:void 0,G),me=lu(re?ge:[]),ce=ou(u?s:void 0,u?.searchQuery),be=u?{status:"ready",count:u.total}:re?fe:{status:"ready",count:n.length},{data:xe}=te({...vt({path:{accountId:t??""}}),enabled:!!t,staleTime:Number.POSITIVE_INFINITY}),B=Va(t),q=aa(),oe=l.useMemo(()=>oa({mailboxes:xe?.items??[],folderAppointments:B,currentMailboxId:s,translator:q}),[xe?.items,B,s,q]),{createFolderIn:Ae}=ra(t),St=oe.find(N=>N.id===j.moveMailboxId)?.label,et=oc(n.map(N=>({normalizedEmail:N.email,displayName:N.sender}))),tt=pc({match:y==="properties"&&j.clauses[0]?.value.trim()||void 0,sender:et?Fa(et):void 0,folder:St}),Q=l.useMemo(()=>({...j,name:j.name??tt}),[j,tt]),Nt=au(R?.draft.field,R?.draft.value??"",U),de=oi(t),Ce=ii(t),$e=qd({mailboxId:s??"",accountId:t,enabled:!1,predicateKey:"selection-wizard",searchQuery:{}}),{runAction:st}=$e,ne=co({verb:e,mode:y,scope:j.scope,fromSearch:f}),Z=ne[Gs(ne,h)],Le=uo(t,r),Pe=(N=>{if(N==="folder")return Le.destination;if(N==="rule")return Q.scope==="standing"||Q.scope==="until"?Le.rule:void 0})(Z)??fo(Z,Q,be),nt=l.useCallback(()=>as(mc(U,J),"seed"),[U,J]),Ke=l.useCallback(N=>{S(N),T(A=>({...A,widen:N==="similar"&&W?{anchorCount:Math.max(n.length,1)}:void 0,...N==="properties"&&A.clauses.length===0?{clauses:nt()}:{}}))},[W,n.length,nt]),at=l.useCallback(()=>{P(!0),S("properties"),T(N=>({...N,widen:void 0,clauses:as(qt(U),"sender"),matchOperator:"any"})),p("properties")},[U,p]),De=V.semanticUnavailable||V.isError;l.useEffect(()=>{Z==="match"&&(y!=="similar"||!De||L||at())},[Z,y,De,L,at]);const rt=l.useCallback(()=>{O({mode:"add",draft:{field:"From",value:""}})},[]),ot=l.useCallback(N=>{const A=j.clauses.find(Y=>Y.id===N);A&&O({mode:"edit",clauseId:N,draft:{field:A.field,value:A.value}})},[j.clauses]),it=l.useCallback(N=>{T(A=>({...A,clauses:A.clauses.filter(Y=>Y.id!==N)}))},[]),se=l.useCallback(N=>{O(A=>A&&{...A,draft:N})},[]),ve=l.useCallback(()=>{O(N=>{if(!N)return;const A=li(N.draft.field,N.draft.value),Y={...N.draft,value:A};T(Be=>({...Be,clauses:N.clauseId?Be.clauses.map(lt=>lt.id===N.clauseId?{...lt,...Y}:lt):[...Be.clauses,{id:crypto.randomUUID(),...Y}]}))})},[]),cr=l.useCallback(()=>{if(Pe){z(Z);return}z(void 0);const N=ne[Gs(ne,Z)+1];N&&p(N)},[Pe,Z,ne,p]),Gt=l.useCallback(async N=>{const A=In(e,Q.moveMailboxId,X);if(!A){M({matched:N.length,failureReason:An(e)});return}M({matched:N.length});const Y=await st(A,[...N]);M({matched:N.length,outcome:Y}),C.current&&v?.(A.kind,N.length,Y)},[e,Q.moveMailboxId,X,st,v]),Wt=l.useCallback(async()=>{if(!u)return;const N=In(e,Q.moveMailboxId,X);if(!N){M({matched:u.total,failureReason:An(e)});return}M({matched:u.total});const A=await u.run(N);M({matched:u.total,outcome:A}),C.current&&v?.(N.kind,u.total,A)},[u,e,Q.moveMailboxId,X,v]),{start:Tt}=de,{createFilterAsync:zs}=Ce,Et=l.useCallback(()=>{if(u){Wt();return}const N=ci({mode:x,ruleScope:Q.scope}),A=di({mode:x,ruleScope:Q.scope,anchorMessageId:W,clauses:Q.clauses,matchOperator:Q.matchOperator,moveMailboxId:Q.moveMailboxId,until:Q.until});if(K(N),N==="standing"||N==="temporary"){const Y=ui(A)?A:void 0;w(Y),zs(A,N,(Q.name??"").trim()).then(Be=>{Be&&Y&&Tt(Y)});return}if(N==="all-like-these"&&rs(e)){Tt(A);return}Gt(N==="just-these"?_:ge)},[u,Wt,x,Q,W,e,_,ge,zs,Tt,Gt]),dr=l.useCallback(()=>{if(Pe){z(Z);return}E.current||(E.current=!0,p("run"),Et())},[Pe,Z,p,Et]),_s=l.useCallback(N=>{const A=de.progress,Y=yu({failure:de.failure,isStarting:de.isStarting,isRunning:de.isRunning,isDone:de.isDone,failedCount:A.failedCount,ruleSaved:N});return Y==="saving"||Y==="commitFailed"||Y==="backApplyStartFailed"?{...ze,state:Y}:{state:Y,matched:A.matchedCount,applied:A.appliedCount,failed:Y==="backApplyFailed"||Y==="backApplyRestartFailed"?A.failedCount:0,failures:[]}},[de]),Us=l.useMemo(()=>{const N=new Map;for(const A of[...n,...me.messages,...ce.messages])N.set(A.id,A);return N},[n,me.messages,ce.messages]),Ks=u?i:$e.progress,Bs=l.useCallback(()=>{if(!k)return ze;const{matched:N,outcome:A,failureReason:Y}=k;if(Y!==void 0)return{...ze,state:"commitFailed",failureReason:Y};if(!A){const Qe=Ks?.done??0;return{state:"backApplyRunning",matched:Math.max(N,Qe),applied:Qe,failed:0,failures:[]}}if(!(A.cancelled||A.error!==void 0))return{state:"backApplyComplete",matched:Math.max(N,A.done),applied:A.done,failed:0,failures:[]};if(A.done===0)return{...ze,state:"commitFailed"};const lt=A.failedIds.map(Qe=>Us.get(Qe)).filter(Qe=>Qe!==void 0),hr=A.failedIds.length>0?A.failedIds.length:Math.max(N-A.done,1);return{state:"runStopped",matched:Math.max(N,A.done),applied:A.done,failed:hr,failures:lt}},[k,Ks,Us]),Fe=u?Bs():D==="standing"||D==="temporary"?Ce.isError?{...ze,state:"commitFailed"}:Ce.isSuccess?I?_s(!0):{...ze,state:"filterSaved"}:ze:D==="all-like-these"&&rs(e)?_s(!1):Bs(),ur=()=>{if(Fe.state==="statusUnknown"){de.refreshStatus();return}if(u){Wt();return}if(D==="standing"||D==="temporary"){if(Ce.isError){Ce.reset(),Et();return}I&&Tt(I);return}if(D==="all-like-these"&&rs(e)){Et();return}const N=k?.outcome?.failedIds??[];Gt(N.length>0?N:_)},fr=l.useCallback(()=>{b(ne,Z)},[b,ne,Z]),Yt=l.useCallback(()=>{C.current=!0,b(ne,Z),d()},[b,ne,Z,d]),{stop:Qs}=$e,mr=k!==void 0&&k.outcome===void 0&&k.failureReason===void 0,pr=l.useCallback(()=>{if(u){u.stop();return}Qs()},[u,Qs]);vc({shouldBlockFn:({action:N})=>N!=="BACK"?!1:(Yt(),!0),enableBeforeUnload:!1,disabled:Z!=="run"});const Jt={messages:u?ce.messages:re?me.messages:n,count:be,label:y==="selected"?"Your selection":"A sample of what matches",emptyReason:y==="similar"&&De?"notIndexed":"noMatch",loading:u?ce.isPending:re&&(be.status==="loading"||me.isPending)};return a.jsx(mo,{verb:e,steps:ne,step:Z,blockedReason:Pe,nudged:$===Z,onBack:m,onExit:Z==="run"?Yt:fr,onContinue:cr,onCommit:dr,match:{selectedCount:n.length,mode:y,accountId:Le.accountId,onModeChange:Ke,semanticUnavailable:De,semanticErrorDetail:V.error instanceof Error?V.error.message:void 0,semanticFallbackTaken:L,onSemanticFallback:at,escalatedScope:u?.scope,sample:Jt},properties:{clauses:Q.clauses,matchOperator:Q.matchOperator,onMatchOperatorChange:N=>T(A=>({...A,matchOperator:N})),clauseEdit:R,onStartAddClause:rt,onStartEditClause:ot,onRemoveClause:it,onChangeDraft:se,onSubmitClause:ve,onCancelClause:()=>O(void 0),clauseFields:fi,clauseSuggestions:Nt,conversionNotice:g?gc(g):void 0,semanticFallbackTaken:L,sample:{...Jt,label:"What this matches"}},folder:{folders:oe,mailboxId:Q.moveMailboxId,delimiter:ia(xe?.items??[]),onSelect:N=>T(A=>({...A,moveMailboxId:N})),onCreateFolder:t?Ae:void 0,restriction:Le.destination},rule:{draft:Q,onScopeChange:N=>T(A=>({...A,scope:N})),onUntilChange:N=>T(A=>({...A,until:N})),restriction:Le.rule},name:{name:Q.name??"",onNameChange:N=>T(A=>({...A,name:N})),nudged:$===Z},review:{verb:e,mode:y,selectedCount:n.length,clauses:Q.clauses,matchOperator:Q.matchOperator,folder:St,scope:Q.scope,until:Q.until,ruleName:ne.includes("name")?Q.name:void 0,escalatedScope:u?.scope,sample:Jt},run:{state:Fe.state,verb:e,scope:Q.scope,matched:Fe.matched,applied:Fe.applied,failedCount:Fe.failed,failures:Fe.failures,failureReason:Fe.failureReason,onRetry:ur,onDismiss:Yt,onCancelRun:mr?pr:void 0}})}function Vf(e){const t=io()==="search",{searchConversion:s}=sr(),{accounts:n}=ks(),{step:r,goToStep:o,goBack:i,closeWizard:c}=lo(t?"properties":"match");if(!r)return null;const d=t?s??ju:void 0;return a.jsx(Cu,{...e,...d?{verb:"organize",accountId:vu(d,e.accountId,n),selection:wu,selectionRestriction:void 0,escalated:void 0,searchConversion:d}:{},step:r,goToStep:o,goBack:i,closeWizard:c})}const Ds=l.createContext(null),Su=e=>{const t=l.useContext(Ds);return t?t.rowInteraction(e):null},Nu=()=>{const e=l.useContext(Ds);if(!e)throw new Error("useThreadListSelection must be used inside <ThreadListInteraction>");return e},Tu="[data-message-id]",Eu=e=>Array.from(e.querySelectorAll(Tu)).map(t=>t.dataset.messageId).filter(t=>t!==void 0),Ru=(e,t)=>e.length===t.length&&e.every((s,n)=>s===t[n]),Mu=e=>{const[t,s]=l.useState([]);return l.useEffect(()=>{const n=e.current;if(!n)return;const r=()=>{const i=Eu(n);s(c=>Ru(c,i)?c:i)};r();const o=new MutationObserver(r);return o.observe(n,{childList:!0,subtree:!0}),()=>o.disconnect()},[e]),t};function Gf({selectedMessageId:e,onOpen:t,onDeleteMessages:s,onSelectionVerb:n,wizardOpen:r=!1,isDeleting:o=!1,commandsRef:i,onTriageContextChange:c,children:d}){const v=Cs(),h=l.useRef(null),p=Mu(h),m=bc({orderedIds:p,isDesktop:v,initialFocusedId:e}),{focusedMessageId:b,setFocusedMessageId:g,pendingDomFocusRef:u,cursorMovedByPointerRef:f,selection:x,isMultiSelectMode:S,exitSelection:y,handleRowSelect:j}=m,{selectedIds:T,selectedCount:R,isSelected:O,toggle:$,select:z,toggleAll:L}=x,P=p.length>0&&p.every(G=>T.has(G)),D=l.useCallback(()=>{p.length>0&&L(p)},[p,L]),{intersectWith:K}=x;l.useEffect(()=>{K(p)},[K,p]),l.useEffect(()=>{const G=u.current;G!==null&&(u.current=null,h.current?.querySelector(`[data-message-id="${G}"]`)?.focus())});const k=l.useCallback(G=>{f.current=!0,g(G)},[f,g]),M=l.useCallback(G=>{v||z(G)},[v,z]),I=l.useCallback(()=>{b&&t(b)},[b,t]),w=l.useCallback(G=>t(G,{replace:!0}),[t]);Vd({keyboardFocusedMessageId:m.keyboardFocusedMessageId,openMessageId:e,enabled:v&&R===0,open:w});const[E,C]=l.useState(null),_=l.useCallback(G=>E!==null?!0:R>0?(n(G),!0):G!=="delete"||!b?!1:(C([b]),!0),[E,R,n,b]),U=l.useCallback(()=>{E!==null&&(s(E),C(null),y())},[E,s,y]),W=l.useCallback(()=>C(null),[]),J=l.useCallback(()=>R===0?!1:(y(),!0),[R,y]),X=p.length>0;l.useEffect(()=>{if(i){if(!X){i.current=null;return}return i.current={focusNext:m.focusNext,focusPrevious:m.focusPrevious,focusFirst:m.focusFirst,focusLast:m.focusLast,openFocused:I,toggleSelect:m.toggleFocusedSelection,extendSelectDown:m.extendRangeDown,extendSelectUp:m.extendRangeUp,selectAll:m.selectAllLoaded,clearSelection:J,requestVerb:_,toggleDensity:()=>{}},()=>{i.current=null}}},[i,X,m.focusNext,m.focusPrevious,m.focusFirst,m.focusLast,m.toggleFocusedSelection,m.extendRangeDown,m.extendRangeUp,m.selectAllLoaded,I,J,_]);const V=l.useMemo(()=>Array.from(T),[T]),le=E!==null;l.useEffect(()=>{c?.({focusedMessageId:b,selectedIds:V,orderedIds:p,hasList:X,blocksKeyboard:le||r})},[c,b,V,p,X,le,r]);const re=Yd(p,b),he=l.useMemo(()=>({selectedIds:T,selectedCount:R,exitSelection:y,startSelectionVerb:n,orderedIds:p,allSelected:P,toggleAllLoaded:D,rowInteraction:G=>({focused:G===b,isTabStop:G===re,isDesktop:v,onFocusRow:k,selection:{isChecked:O(G),onToggleCheck:$,onRowSelect:j,isMultiSelectMode:S,onLongPress:M}})}),[T,R,y,n,p,P,D,b,re,v,k,O,$,j,S,M]);return a.jsxs(Ds.Provider,{value:he,children:[a.jsx("div",{ref:h,className:"contents",children:d}),a.jsx(mi,{isOpen:le,title:ti(E?.length??0),description:"You can restore them from Trash later.",confirmLabel:"Move to Trash",destructive:!0,isBusy:o,onConfirm:U,onCancel:W})]})}function Wf({title:e,isDeleting:t}){const s=sr(),{selectedCount:n,exitSelection:r,startSelectionVerb:o,orderedIds:i,allSelected:c,toggleAllLoaded:d}=Nu();return a.jsx(Kl,{title:s.title||e,navSlot:s.navSlot,titleMeta:s.titleMeta,searchSlot:s.searchSlot,searchField:s.searchField,idleSlot:s.makeFilterSlot,count:n,onCancel:r,onDelete:()=>o("delete"),onMarkRead:()=>o("markRead"),isBusy:t,selectAll:i.length>0?{checked:c,indeterminate:n>0&&!c,onChange:d}:void 0})}const os=e=>{e.preventDefault(),e.stopPropagation()},Iu=(e,t)=>{const s=l.useRef(!1),n=l.useCallback(i=>{if(s.current=!1,i.button!==0)return;const c=us(i);cn(c)&&t?.(e,c)&&(os(i),s.current=!0,i.currentTarget.focus(),c.shiftKey&&window.getSelection()?.removeAllRanges())},[t,e]),r=l.useCallback(i=>{!i.ctrlKey||!t||i.preventDefault()},[t]),o=l.useCallback(i=>{if(s.current)return s.current=!1,os(i),!0;const c=us(i);return!cn(c)||!t?.(e,c)?!1:(os(i),c.shiftKey&&window.getSelection()?.removeAllRanges(),!0)},[t,e]);return{onMouseDown:n,onContextMenu:r,claimClick:o}},Au=({thread:e,active:t=!1,focused:s,isTabStop:n,density:r="comfortable",isDesktop:o,badge:i,selection:c,inListbox:d=!1,link:v,onClick:h,onFocusRow:p})=>{const m=ae(),b=e.id,g=Su(b),u=s??g?.focused??!1,f=n??g?.isTabStop??!1,x=c??g?.selection,S=p??g?.onFocusRow,y=o??g?.isDesktop??!0,j=x?.isChecked??!1,T=x?.isMultiSelectMode??!1,R=x?.onToggleCheck,O=x?.onRowSelect,$=x?.onLongPress,z=l.useCallback(C=>{C.preventDefault(),C.stopPropagation(),R?.(b)},[R,b]),L=Iu(b,O),P=l.useCallback(C=>{if(!L.claimClick(C)){if(!y){if(T){C.preventDefault(),C.stopPropagation(),R?.(b);return}h?.();return}O?.(b,us(C)),h?.()}},[L,y,T,R,O,h,b]),D=l.useCallback(()=>{$?.(b)},[$,b]),{longPressProps:K}=Cl({onLongPress:D,accessibilityDescription:j?"Deselect message":"Select message"}),k=l.useCallback(()=>{m.prefetchQuery(zt({path:{messageId:b}}))},[m,b]),M=l.useCallback(()=>{k(),S?.(b)},[k,S,b]),I=yt({"data-list-row":"","data-message-row":!0,"data-message-id":b,...d?{role:"option","aria-selected":j}:{},tabIndex:f?0:-1,onClick:P,onMouseDown:L.onMouseDown,onContextMenu:L.onContextMenu,onMouseEnter:k,onFocus:M},y||!x?{}:K),w=F(r==="compact"?Ca({active:t,focused:u}):F("group",Rs({active:t,focused:u})),"outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-inset",j&&"bg-accent-soft",!y&&"min-h-11 select-none [-webkit-touch-callout:none]"),E=r==="compact"?a.jsx(Sa,{thread:e}):a.jsx(Ms,{thread:e,badge:i,selection:x?{checked:j,alwaysVisible:T,onToggle:z}:void 0});return v===void 0?a.jsx("button",{type:"button",...I,className:w,children:E}):a.jsx(ta,{to:"/mail/$mailboxId/$threadId/$messageId",params:{...v,messageId:b},search:C=>C,variant:"row",...I,className:w,children:E})},Yf=l.memo(Au),is="Open a message first",$u="This conversation hasn't loaded yet",Jf=({hasThread:e,intelligenceOpen:t,canToggleIntelligence:s,onToggleIntelligence:n,onReply:r,onReplyAll:o,onForward:i,onDelete:c,canDelete:d,onToggleStar:v,isStarred:h,moveContext:p})=>{const[m,b]=l.useState(null),g=d??e,u=x=>()=>b(x),f=x=>x??u($u);return a.jsx(Nl,{hasThread:e,isStarred:h,onUnavailable:x=>b(is),unavailableHint:m,replyTitle:`Reply ${ct("reply")}`,replyAllTitle:`Reply all ${ct("replyAll")}`,forwardTitle:`Forward ${ct("forward")}`,deleteTitle:`Move to Trash ${ct("delete")}`,flagTitle:`Star ${ct("toggleStar")}`,onReply:f(r),onReplyAll:f(o),onForward:f(i),onDelete:g?f(c):u(is),onToggleStar:f(v),onMove:u(is),moveSlot:p?a.jsx(Ps,{accountId:p.accountId,currentMailboxId:p.currentMailboxId,onMove:p.onMove,label:"Move to mailbox"}):void 0,children:a.jsx(Sl,{open:t,enabled:s,onToggle:n})})},Lu=()=>{const e=ae();return l.useCallback(t=>{const s=Me({path:{threadId:t.threadId}}),r=e.getQueriesData({queryKey:s}).flatMap(([,o])=>o?.items.map(i=>i.messageId)??[]);return r.length>0?r:[t.messageId]},[e])},Xf=({thread:e,mailboxId:t,accountId:s,onAfterOptimisticRemove:n})=>{const r=t??e?.mailboxId,o=s??e?.accountId,{accountId:i}=za(o?void 0:r),c=o??i,d=Lu(),{deleteMessages:v}=Ls({mailboxId:r??"",threadId:e?.threadId,accountId:c,onAfterOptimisticRemove:n}),{moveMessages:h}=Vt({mailboxId:r??"",threadId:e?.threadId,accountId:c,onAfterOptimisticRemove:n}),{toggleStar:p}=Qa({threadId:e?.threadId??"",mailboxId:r??""}),m=l.useCallback(()=>{e&&v(d(e))},[e,d,v]),b=l.useCallback(u=>{e&&h(d(e),u)},[e,d,h]),g=l.useCallback(()=>{e&&p(e.messageId,e.hasStars)},[e,p]);return{mailboxId:r,accountId:c,isStarred:e?.hasStars,deleteThread:m,moveThread:b,toggleStar:g}},Zf=(e,t)=>{const{data:s}=te({...Vn({path:{threadId:e??""}}),enabled:!!e}),n=s?.items??[],r=t?n.find(i=>i.messageId===t):void 0,o=n.length>0?n[n.length-1]:void 0;return r??o},$n=(e,t,s)=>{if(!t)return null;const n=e.indexOf(t);if(n===-1)return null;const r=s==="next"?n+1:n-1;return r<0||r>=e.length?null:e[r]},em=()=>{const[e,t]=l.useState(void 0),[s,n]=l.useState([]),[r,o]=l.useState([]),i=l.useRef(null),[c,d]=l.useState(!1),[v,h]=l.useState(!1),p=l.useCallback(m=>{t(m.focusedMessageId),n(m.selectedIds),m.orderedIds&&o(m.orderedIds),d(m.hasList),h(m.blocksKeyboard)},[]);return{listCommandsRef:i,onTriageContextChange:p,focusedMessageId:e,selectedIds:s,orderedIds:r,hasList:c,blocksKeyboard:v}},tm=({context:e,orderedIds:t,selectedMessageId:s,enabled:n=!0,onClose:r,handlers:o})=>{const{listCommandsRef:i,hasList:c,blocksKeyboard:d}=e,v=l.useCallback(()=>{i.current?.clearSelection()||s&&r()},[i,s,r]);return No({enabled:n&&!d,handlers:{...c?{focusNext:()=>i.current?.focusNext(),focusPrevious:()=>i.current?.focusPrevious(),focusFirst:()=>i.current?.focusFirst(),focusLast:()=>i.current?.focusLast(),openFocused:()=>i.current?.openFocused(),toggleSelect:()=>i.current?.toggleSelect(),extendSelectDown:()=>i.current?.extendSelectDown(),extendSelectUp:()=>i.current?.extendSelectUp(),selectAll:()=>i.current?.selectAll(),toggleDensity:()=>i.current?.toggleDensity()}:{},back:v,...o}}),{goBack:v,nextMessageId:$n(t,s,"next")??void 0,previousMessageId:$n(t,s,"previous")??void 0}},Pu={sender:"sender",recipient:"recipient",subject:"subject",attachment:"attachment",body:"body",entities:"entities"};function Du(e){return Pu[e]??e}function sm(e,t){const{folder:s}=js(t,[e.mailboxId]);return{id:e.messageId,sender:e.fromName??e.fromEmail??"Unknown",...e.fromEmail?{senderEmail:e.fromEmail}:{},subject:e.subject??"(No subject)",snippet:e.snippet??"",date:Xe(e.sentDate),unread:!e.isRead,flagged:e.hasStars===!0,threadId:e.threadId,mailboxId:e.mailboxId,...s?{folder:s}:{}}}function nm(e,t){const{folder:s}=js(t,e.mailboxId?[e.mailboxId]:[]);return{id:e.id,sender:e.fromName,...e.fromEmail?{senderEmail:e.fromEmail}:{},subject:e.subject,snippet:e.snippet,date:e.timeLabel,unread:!e.isRead,flagged:e.starred===!0,...e.threadId?{threadId:e.threadId}:{},...e.mailboxId?{mailboxId:e.mailboxId}:{},...s?{folder:s}:{}}}function Fu(e,t){const{mailboxId:s,folder:n}=js(t,e.mailboxIds);return{id:e.messageId,sender:e.fromName??"Unknown",subject:e.subject??"(No subject)",snippet:"",date:e.sentDate!=null?Xe(e.sentDate*1e3):"",threadId:e.threadId,matchedChunkLabel:Du(e.matchedChunkType),score:e.score,...s?{mailboxId:s}:{},...n?{folder:n}:{}}}function am(e,t,s){const n=new Set(t),r=[];for(const o of[...e].sort((i,c)=>c.score-i.score))n.has(o.threadId)||(n.add(o.threadId),r.push(Fu(o,s)));return r}function rm(e){const t=e.authenticity?.dkimMismatch===!0;return{id:e.messageId,accountId:e.accountId,mailboxId:e.mailboxId,threadId:e.threadId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:Xe(e.sentDate),sentDate:e.sentDate,isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:qa(e.category),suspicious:t}}function om(e){return e.filter(t=>t.muted!==!0)}function im(e,t){const s=new Set,n=[];for(const r of[...e,...t])s.has(r.id)||(s.add(r.id),n.push(r));return n.sort((r,o)=>(o.sentDate??0)-(r.sentDate??0))}const Ln=[{id:"personal",label:"Personal",category:ye.personal},{id:"transactional",label:"Transactional",category:ye.transactional},{id:"newsletter",label:"Newsletter",category:ye.newsletter},{id:"marketing",label:"Marketing",category:ye.marketing},{id:"social",label:"Social",category:ye.social},{id:"automated",label:"Automated",category:ye.automated},{id:"uncategorized",label:"Unclassified",category:ye.uncategorized}];function lm(e){const t=new Map(Ln.map(n=>[n.category,[]]));for(const n of e){const r=n.category??ye.uncategorized;(t.get(r)??t.get(ye.uncategorized))?.push(n)}const s=[];for(const n of Ln){const r=t.get(n.category);r&&r.length>0&&s.push({id:n.id,label:n.label,threads:r})}return s}function cm(e,t){return e.fromName.toLowerCase().includes(t)||e.fromEmail.toLowerCase().includes(t)||e.subject.toLowerCase().includes(t)||e.snippet.toLowerCase().includes(t)}function dm(e,t){return t.every(s=>{switch(s.type){case"from":{const n=s.value.toLowerCase();return e.fromEmail.toLowerCase().includes(n)||e.fromName.toLowerCase().includes(n)}case"subject":return e.subject.toLowerCase().includes(s.value.toLowerCase());case"category":return(e.category??"uncategorized")===s.category;case"hasAttachment":return e.hasAttachment===!0;case"isUnread":return!e.isRead;case"isRead":return e.isRead===!0;case"isStarred":return e.starred===!0;case"after":return e.sentDate!=null&&e.sentDate>=s.epochSeconds*1e3;case"before":return e.sentDate!=null&&e.sentDate<s.epochSeconds*1e3;case"in":return e.mailboxId===s.mailboxId;case"account":return e.accountId===s.accountId;default:return!1}})}const or=8;function Fs(e,t){const s=Math.max(0,Math.min(t,e.length)),n=Uo(e).find(o=>s>=o.start&&s<=o.end);if(!n)return{start:s,end:s,raw:""};const r=Ko(n.raw);return r?{start:n.start,end:n.end,raw:n.raw,name:r.name,value:r.value}:{start:n.start,end:n.end,raw:n.raw}}function Ou(e,t){const s=Fs(e,t);if(s.name===void 0)return{kind:"token",query:s.raw};const n=Xn(s.name);if(n)return{kind:"value",token:n.name,source:n.values,query:s.value??""}}const zu={mailbox:"mailboxes",account:"accounts",contact:"contacts"},_u=(e,t)=>{if(e.values==="fixed")return e.options??[];const s=zu[e.values];return s?t[s]??[]:[]},Uu=(e,t)=>{if(t==="")return 1;const s=e.toLowerCase();return s.startsWith(t)?0:s.includes(t)?1:-1},gs=(e,...t)=>{let s=-1;for(const n of t){if(n===void 0)continue;const r=Uu(n,e);r<0||(s<0||r<s)&&(s=r)}return s},ir=e=>{const t=new Set;return e.filter(s=>s.rank>=0).sort((s,n)=>s.rank-n.rank).filter(s=>{const n=s.suggestion.value.toLowerCase();return t.has(n)?!1:(t.add(n),!0)}).slice(0,or).map(s=>s.suggestion)},Pn=e=>({value:`${e.name}:`,label:`${e.name}:`,hint:e.label});function Ku(e){const t=e.trim().toLowerCase();if(t==="")return Ys.map(Pn);const s=[];for(const n of Ys)if(s.push({rank:gs(t,`${n.name}:`,n.label),suggestion:Pn(n)}),n.values==="fixed")for(const r of n.options??[]){const o=Zn(n.name,r.value);s.push({rank:gs(t,o,r.label),suggestion:{value:o,label:r.label??o,hint:o}})}return ir(s)}function Bu(e,t,s){const n=t.trim().toLowerCase(),r=_u(e,s).map(o=>({rank:gs(n,o.value,o.label),suggestion:{value:Zn(e.name,o.value),label:o.label??o.value,...o.hint?{hint:o.hint}:{}}}));return ir(r)}function Qu(e,t,s={}){const n=Fs(e,t);if(n.name===void 0)return Ku(n.raw);const r=Xn(n.name);return r?Bu(r,n.value??"",s):[]}function qu(e,t,s){const n=Fs(e,t),r=!s.value.endsWith(":"),o=/\s/.test(e.slice(n.end,n.end+1)),i=r&&!o?`${s.value} `:s.value;return{query:e.slice(0,n.start)+i+e.slice(n.end),cursor:n.start+i.length+(r&&o?1:0)}}const Hu=e=>({value:e.normalizedEmail,...e.displayName?{label:e.displayName,hint:e.normalizedEmail}:{}}),Vu=250,Gu=2;function Wu({query:e,cursor:t,enabled:s}){const{accounts:n}=ks(),{mailboxesByName:r}=ea(),o=r!==void 0,i=s?Ou(e,t):void 0,c=i?.source==="contact"?i.query.trim():"",d=na(c,Vu),{data:v}=te({...ys({query:{q:d,limit:or}}),enabled:d.length>=Gu}),h=ws({queries:n.map(g=>({...vt({path:{accountId:g.accountId}}),staleTime:1/0}))}),p=l.useMemo(()=>o?To(h.map(g=>g.data?.items??[]),n):[],[o,h,n]),m=l.useMemo(()=>Eo(n),[n]),b=l.useMemo(()=>(v?.items??[]).map(Hu),[v]);return l.useMemo(()=>{if(!s)return[];const g=Qu(e,t,{mailboxes:p,accounts:m,contacts:b});return o?g:g.filter(u=>u.value!=="in:")},[s,e,t,p,m,b,o])}const lr="remit.recentSearches",Yu=5;function bs(){try{const e=localStorage.getItem(lr);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}catch{return[]}}function Dn(e){const t=e.trim();if(!t)return bs();const s=[t,...bs().filter(n=>n!==t)].slice(0,Yu);try{localStorage.setItem(lr,JSON.stringify(s))}catch{return s}return s}const Ju=e=>e.tier!=="phone"&&e.hasLiveInput&&!(e.bodyRendersCommittedResults&&e.hasCommittedQuery);function Xu(e){const{spam:t}=Ia([...e]),s=new Map;for(const r of t)r.mailboxId&&s.set(r.mailboxId,(s.get(r.mailboxId)??0)+1);let n;for(const[r,o]of s)(!n||o>n.count)&&(n={mailboxId:r,count:o});return n}function um({title:e,unreadCount:t,children:s,selectionBar:n,paneOverlay:r,footer:o,searchFilter:i,searchResults:c,searchLoading:d,relatedResults:v,relatedLoading:h,onSelectSearchResult:p,searchResultsLabel:m="Top matches",relatedResultsLabel:b="Related",searchResultsInBody:g=!1,refreshControl:u}){const{accounts:f,resultFolderIndex:x,searchQuery:S,searchInput:y,onSearchChange:j,onSearchClear:T,searchViewKey:R}=ks(),O=ea(),$=Hn(),z=po(),L=Ro(),[P,D]=l.useState(!1),[K,k]=l.useState(bs),M=ho(),I=l.useRef(R);l.useEffect(()=>{I.current!==R&&(I.current=R,D(!1))},[R]);const[w,E]=l.useState(0),[C,_]=l.useState(!1),[U,W]=l.useState(void 0),J=Wu({query:y,cursor:w,enabled:C&&y.trim().length>0}),X=l.useCallback(se=>{const ve=qu(y,w,se);j(ve.query),W({cursor:ve.cursor})},[y,w,j]),V=go({count:J.length,onAccept:se=>{const ve=J[se];ve&&X(ve)}}),{comboboxProps:le,handleKeyDown:re}=V,he=l.useMemo(()=>({comboboxProps:le,onKeyDown:re,onCaretChange:E,onFocusChange:_,...U?{caret:U}:{}}),[le,re,U]),G=V.open?a.jsx(vo,{id:V.listId,suggestions:J,activeIndex:V.activeIndex,optionId:V.optionId,onPick:X,onHighlight:V.setActiveIndex,label:"Search suggestions",className:"mx-row-inset mt-1 shrink-0"}):null,fe=y.trim().length>0,{mailboxesByName:ge,accountsByName:me}=O,ce=l.useMemo(()=>Bo(y,{mailboxesByName:ge,accountsByName:me}),[y,ge,me]),be=ce.tokens.map(se=>({label:Jn(se),onRemove:()=>j(Qo(y,se))})),xe=c??[],B=v??[],q=fe?[{id:"top",label:m,results:xe},{id:"related",label:b,results:B}]:[],Ae=!(xe.length+B.length>0)&&(d===!0||h===!0),{scope:St}=Mo(f),et=Jo({select:se=>se.matches}),tt=hi(et),Q=gi(et,St,tt?x.get(tt)?.role:void 0),Nt=Q.kind==="global"?Xu([...xe,...B]):void 0,de=Nt?{kind:"global",onScopeToSpam:()=>$({to:"/mail/$mailboxId",params:{mailboxId:Nt.mailboxId},search:{q:S||void 0}})}:Q,Ce=B.length>0,$e=l.useMemo(()=>xu(ce,{searchHadSemanticReach:Ce}),[ce,Ce]),st=fe?$e:void 0,ne=fe?{onClick:()=>{D(!1),M("properties","search")},blockedReason:hc($e)?void 0:bo($e.droppedFacets.map(se=>se.label))}:void 0,Z=ne?a.jsx(Aa,{...ne}):null,Le=Ju({tier:L,hasLiveInput:fe,hasCommittedQuery:S.trim().length>0,bodyRendersCommittedResults:g}),Os=se=>{k(Dn(y)),p?.(se)},Pe=a.jsx($a,{value:y,sections:q,loading:Ae,onSelectResult:Os,tokens:be,scope:de}),nt=n===void 0,Ke=Le?a.jsx("div",{className:"h-full overflow-y-auto",children:Pe}):null,at=Ke&&!nt?Ke:s,De=Ke&&nt?Ke:null,rt=Io(L),ot=rt&&(P||fe),it=l.useMemo(()=>({title:e,searchResults:De,makeFilterSlot:Z,searchConversion:st,navSlot:z&&!z.showNavPane&&a.jsx(H,{variant:"ghost",size:"touch",icon:a.jsx(bi,{className:"size-5"}),onClick:()=>z.openNav(),"aria-label":"Menu",className:"-ml-2 shrink-0"}),titleMeta:a.jsxs(a.Fragment,{children:[a.jsxs("span",{className:"shrink-0 text-2xs text-fg-subtle",children:[t.toLocaleString()," unread"]}),a.jsx(Ws,{}),u]}),searchSlot:rt&&!ot&&a.jsx(H,{variant:"ghost",size:"touch",icon:a.jsx(xo,{className:"size-5"}),onClick:()=>D(!0),"aria-label":"Search",className:"shrink-0"}),searchField:ot&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"min-w-0 flex-1",children:a.jsx(Gn,{value:y,onChange:j,onClear:T,globalFocusKey:!1,showClearButton:!1,suggest:he})}),a.jsx(H,{variant:"ghost",size:"touch",icon:a.jsx(Dt,{className:"size-5"}),onClick:()=>{T(),D(!1)},"aria-label":"Close search",className:"shrink-0"}),a.jsx(Ws,{})]})}),[e,t,z,rt,ot,y,j,T,he,De,Z,st,u]);if(L==="phone"&&P){const se=ve=>{k(Dn(y)),D(!1),p?.(ve)};return a.jsxs(hs.Provider,{value:it,children:[a.jsx(Ul,{value:y,onChange:j,onClear:T,onCancel:()=>{D(!1),T()},filter:i,recentSearches:K,onPickRecent:j,makeFilter:ne,sections:q,loading:Ae,onSelectResult:se,tokens:be,scope:de,suggest:he,suggestList:G}),r]})}return a.jsx(hs.Provider,{value:it,children:a.jsxs("section",{className:"relative flex h-full w-full flex-col bg-surface",children:[n?.(it),G,a.jsx("div",{className:"min-h-0 flex-1",children:at}),o,r]})})}export{Ef as $,zf as A,Df as B,Al as C,rm as D,dm as E,za as F,Lf as G,Zf as H,Ls as I,Vt as J,em as K,Xf as L,Yf as M,$f as N,Af as O,Lu as P,Qa as Q,Nd as R,Kl as S,Ed as T,Md as U,Rd as V,tm as W,Pf as X,Mf as Y,_f as Z,Jf as _,yl as a,sm as a0,am as a1,om as a2,im as a3,cm as a4,nm as a5,Ia as a6,Xu as a7,lm as a8,Tf as a9,Ju as aa,Dl as ab,Gf as ac,Cf as ad,Nu as ae,um as af,we as ag,je as ah,As as ai,bt as aj,Cl as ak,yt as al,Es as am,us as an,Sf as ao,Nf as ap,Rf as aq,Wf as ar,sr as b,Rs as c,If as d,Ha as e,xl as f,qd as g,Qf as h,Bf as i,Hf as j,Kf as k,Vd as l,vc as m,bl as n,Uf as o,qf as p,Yd as q,Vf as r,ml as s,qa as t,Iu as u,Wd as v,_c as w,Va as x,Ff as y,Of as z};