@remit/web-client-dist 0.0.384 → 0.0.385

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 (109) hide show
  1. package/assets/{BriefPane-Dw7Pe10F.js → BriefPane-DAdQLq0g.js} +1 -1
  2. package/assets/{ErrorState-xveqe4NU.js → ErrorState-wOvkM72u.js} +1 -1
  3. package/assets/{FlaggedPane-qGrQjG53.js → FlaggedPane-kvoPpzhD.js} +1 -1
  4. package/assets/{FullCompose-BdS5jMt_.js → FullCompose-BcNF5R4p.js} +1 -1
  5. package/assets/{MailListHeader-munUD_Z_.js → MailListHeader-DlgEG6TF.js} +1 -1
  6. package/assets/{MailViewChrome-BbuEwZkl.js → MailViewChrome-DZUl5LEF.js} +1 -1
  7. package/assets/{MailboxPane-CV6YxeJ6.js → MailboxPane-DOWzizn8.js} +1 -1
  8. package/assets/{NavMenuButton-DTrHcaCl.js → NavMenuButton-CYCM2eVH.js} +1 -1
  9. package/assets/{OnboardingWizard-D995ic0_.js → OnboardingWizard-CLamg4He.js} +1 -1
  10. package/assets/{OutboxPane-DU_fgjac.js → OutboxPane--inU-o6m.js} +1 -1
  11. package/assets/_mailboxId-BfhcrZGg.js +1 -0
  12. package/assets/_messageId-BKJFY7Lo.js +1 -0
  13. package/assets/_messageId-BOa-_216.js +1 -0
  14. package/assets/_messageId-GQWJk5QZ.js +1 -0
  15. package/assets/_outboxMessageId-Bj78UrWh.js +1 -0
  16. package/assets/_threadId-Bm84rvmc.js +1 -0
  17. package/assets/_threadId-Cmy_7qK7.js +1 -0
  18. package/assets/_threadId-DF6en6gV.js +1 -0
  19. package/assets/{accounts-DNuyrHHV.js → accounts-Bekaj70-.js} +1 -1
  20. package/assets/{advanced-Hl4vx2r_.js → advanced-BXc4MHoH.js} +1 -1
  21. package/assets/{appearance-DPAcHPmb.js → appearance-BxbKxsYc.js} +1 -1
  22. package/assets/{attachment-file-DsCIGE3k.js → attachment-file-CR0PW1By.js} +1 -1
  23. package/assets/{avatar-CrVNx5pM.js → avatar-1DfPRcS3.js} +1 -1
  24. package/assets/{bottom-sheet-ipETSw9E.js → bottom-sheet-DQx2Jee-.js} +1 -1
  25. package/assets/{brief-DpvvYHAg.js → brief-BIsgBS1h.js} +1 -1
  26. package/assets/brief-BX1Mu53c.js +1 -0
  27. package/assets/{browser-ponyfill-MbezRvrQ.js → browser-ponyfill-CiCvc8eU.js} +1 -1
  28. package/assets/{bug-DZ6xy-Tb.js → bug-DVIZfhcE.js} +1 -1
  29. package/assets/{circle-check-CXnX6QmC.js → circle-check-B-uZAWo0.js} +1 -1
  30. package/assets/{circle-check-big-CPc3hmuc.js → circle-check-big-Sl8zRHpX.js} +1 -1
  31. package/assets/{circle-help-Dydk2OOb.js → circle-help-DidkDhiF.js} +1 -1
  32. package/assets/{clock-Cr85zKfw.js → clock-8uDyqiCY.js} +1 -1
  33. package/assets/compose._-_outboxMessageId_-BxPKR0AZ.js +1 -0
  34. package/assets/compose._-_outboxMessageId_-DOH4nUAt.js +1 -0
  35. package/assets/compose._-_outboxMessageId_-f5sD4PUc.js +1 -0
  36. package/assets/compose._-_outboxMessageId_-gZXasZgF.js +1 -0
  37. package/assets/{confirm-dialog-DEuMA6ic.js → confirm-dialog-DQceA3_j.js} +1 -1
  38. package/assets/{download-DXwQNbLS.js → download-K5iXo_ES.js} +1 -1
  39. package/assets/{filters-DGaQenSm.js → filters-fZoYDwvH.js} +1 -1
  40. package/assets/{flagged-rPmZzncK.js → flagged-8RWypzAm.js} +1 -1
  41. package/assets/flagged-DbZUuUtn.js +1 -0
  42. package/assets/{folders-yuHkSLzK.js → folders-BF3RrsGz.js} +1 -1
  43. package/assets/index-BKtQIJsd.js +1 -0
  44. package/assets/index-BOa-_216.js +1 -0
  45. package/assets/{index-D25kY32_.js → index-Bb7aXquo.js} +3 -3
  46. package/assets/index-Bw7p5atp.js +1 -0
  47. package/assets/{index-TkI6PAgL.js → index-CL-RwCQv.js} +4 -4
  48. package/assets/index-Cf-V7Yc_.js +1 -0
  49. package/assets/index-DIi7tm-X.js +1 -0
  50. package/assets/index-DZPcVb2j.js +1 -0
  51. package/assets/index-DkjYjl8N.js +1 -0
  52. package/assets/index-GQWJk5QZ.js +1 -0
  53. package/assets/{kbd-B6SN6Hd3.js → kbd-Cuwmz-CF.js} +1 -1
  54. package/assets/{labels-yXF8oo8-.js → labels-DmXlG762.js} +1 -1
  55. package/assets/{mail-DKYXzawQ.js → mail-B1r3z0pl.js} +1 -1
  56. package/assets/{mail-CviqQaZN.js → mail-D_QZlfdW.js} +1 -1
  57. package/assets/{menu-Cv_oe3kJ.js → menu-CKfqd7Zr.js} +1 -1
  58. package/assets/{move-options-DwhS2xoZ.js → move-options-gmyuDePe.js} +1 -1
  59. package/assets/{onboarding-CxhTfLx4.js → onboarding-BSGJJ0up.js} +1 -1
  60. package/assets/outbox-DSsPN0OU.js +1 -0
  61. package/assets/{pencil-DBA1snvb.js → pencil-DH_ZI54V.js} +1 -1
  62. package/assets/{rich-text-DHzc6tlV.js → rich-text-6aA_8Tbs.js} +1 -1
  63. package/assets/{rich-text-spellcheck-worker-provider-1QQ-kq1U.js → rich-text-spellcheck-worker-provider-WIuM8Bpy.js} +1 -1
  64. package/assets/{rotate-ccw-H-YdUp-b.js → rotate-ccw-CZWAgQIB.js} +1 -1
  65. package/assets/{row-actions-BKmH_TTH.js → row-actions-DPsjh6q8.js} +1 -1
  66. package/assets/{search-scope-uzqSeOQ0.js → search-scope-D2tD8Mro.js} +1 -1
  67. package/assets/{search-token-index-D4F4WYkQ.js → search-token-index-BPaeb0nT.js} +1 -1
  68. package/assets/{search-view-CHvJBRRa.js → search-view-BRCLQBQN.js} +1 -1
  69. package/assets/{senders-BbvJ4JRX.js → senders-pGxYCZO2.js} +1 -1
  70. package/assets/settings-C-qo670s.js +1 -0
  71. package/assets/{settings-screen-wWBvhi3V.js → settings-screen-DXan7Qnj.js} +1 -1
  72. package/assets/{shield-check-C0Nfu5MF.js → shield-check-hS8zutR7.js} +1 -1
  73. package/assets/{suggested-vips-Bo5cDXcq.js → suggested-vips-C-qdzqou.js} +1 -1
  74. package/assets/{useDebouncedValue-D9IhKon-.js → useDebouncedValue-cMLhaPcO.js} +1 -1
  75. package/assets/{useFilters-DZRfaFl7.js → useFilters-CL6coSeh.js} +1 -1
  76. package/assets/{useLabels-DI4Cu-Bl.js → useLabels-VkA4O1Ty.js} +1 -1
  77. package/assets/{useMediaQuery-8XUOgNnp.js → useMediaQuery-CrSO3kMK.js} +1 -1
  78. package/assets/{useMessageBodyContent-Di1auION.js → useMessageBodyContent-BWmVC5nn.js} +1 -1
  79. package/assets/{useRefreshControl-DtdN0Hrw.js → useRefreshControl-Cw1ynDsF.js} +1 -1
  80. package/assets/{useSearchMirror-DkyBzsMg.js → useSearchMirror-DqkaJZn8.js} +1 -1
  81. package/assets/{useSearchTokenContext-DQ5NUt1n.js → useSearchTokenContext-Bjl7abMO.js} +1 -1
  82. package/assets/{useSemanticSearch-DDRAzD-l.js → useSemanticSearch-BuX7JrjR.js} +1 -1
  83. package/assets/{useSignature-BclAT-_g.js → useSignature-BXb1rM3d.js} +1 -1
  84. package/index.html +1 -1
  85. package/package.json +1 -1
  86. package/assets/_mailboxId-C33LVQvY.js +0 -1
  87. package/assets/_messageId-5sFaVJDY.js +0 -1
  88. package/assets/_messageId-8OdokxoV.js +0 -1
  89. package/assets/_messageId-Op1X5j2s.js +0 -1
  90. package/assets/_outboxMessageId-B4beCT0Y.js +0 -1
  91. package/assets/_threadId-CXBJKpkg.js +0 -1
  92. package/assets/_threadId-mpyfhyax.js +0 -1
  93. package/assets/_threadId-xROXX4Mb.js +0 -1
  94. package/assets/brief-CL5yUHRX.js +0 -1
  95. package/assets/compose._-_outboxMessageId_-BVFp9ABE.js +0 -1
  96. package/assets/compose._-_outboxMessageId_-CAvBgIBP.js +0 -1
  97. package/assets/compose._-_outboxMessageId_-Dv7NBiSF.js +0 -1
  98. package/assets/compose._-_outboxMessageId_-fGk_auJ5.js +0 -1
  99. package/assets/flagged-B7GpaxHV.js +0 -1
  100. package/assets/index-5sFaVJDY.js +0 -1
  101. package/assets/index-5wV6IfbN.js +0 -1
  102. package/assets/index-8OdokxoV.js +0 -1
  103. package/assets/index-BNehWCZu.js +0 -1
  104. package/assets/index-B_75v3AK.js +0 -1
  105. package/assets/index-BkIpfEPl.js +0 -1
  106. package/assets/index-pq-8qFaX.js +0 -1
  107. package/assets/index-rf9B-r2h.js +0 -1
  108. package/assets/outbox-By4U5HzK.js +0 -1
  109. package/assets/settings-BPD-Xefg.js +0 -1
@@ -1 +1 @@
1
- import{j as r,b7 as Ss,as as kt,B as ae,S as ys,b as Re,at as Bt,r as c,C as Is,d as Cs,aU as ws,m as Je,n as Wt,s as jt,t as ks,a7 as Kt,b8 as js,b9 as Ms,I as Ts,h as Rs,T as Es,ba as As,bb as Os,bc as Ns,a5 as zs,aF as Fs,aG as Ds,g as _s,W as Mt,bd as Ls,K as Ps,q as $s,be as Bs,l as Vt,bf as Ws,z as Ks,bg as Vs,aZ as Hs}from"./index-TkI6PAgL.js";import{u as Us,p as qs,R as Qs}from"./useSearchTokenContext-DQ5NUt1n.js";import{u as Js,a as Gs,R as Ys}from"./useRefreshControl-DtdN0Hrw.js";import{C as Ht,a as Ut,c as qt,j as Xs,M as Zs,t as Qt,u as en,b as tn,d as Jt,e as Gt,f as sn,g as nn,h as on,i as rn,k as an,l as zt,n as ln,m as cn,o as dn,p as un,q as hn,S as fn,r as mn,s as gn,v as pn,w as Yt,x as xn,y as bn,z as vn,A as Sn,B as yn,D as In,E as Cn,F as wn,G as kn,H as jn,I as Mn,J as Ft,K as Dt,L as Tn,N as Rn,O as En,P as An,Q as On,R as Nn,T as zn,U as Fn,V as Dn,W as _n,X as Ln,Y as Pn,Z as Xt,_ as Zt,$ as $n,a0 as Bn,a1 as Wn,a2 as es,a3 as Kn,a4 as Vn}from"./MailListHeader-munUD_Z_.js";import{S as Hn,M as Un,a as qn,u as Qn,b as Jn}from"./MailViewChrome-BbuEwZkl.js";import{A as Tt}from"./avatar-CrVNx5pM.js";import{b as Ge,c as Gn,d as Yn}from"./format-HasNd5qT.js";import{k as Xn,n as Zn,o as Ye,p as eo,r as to,f as so,h as no,u as oo}from"./useMessageBodyContent-Di1auION.js";import{N as io}from"./NavMenuButton-DTrHcaCl.js";import{C as ro}from"./confirm-dialog-DEuMA6ic.js";import{f as ao}from"./ErrorState-xveqe4NU.js";import{a as lo}from"./useLabels-DI4Cu-Bl.js";import{a as co,D as uo,u as ho}from"./useMediaQuery-8XUOgNnp.js";import{L as fo,u as mo}from"./useSemanticSearch-DDRAzD-l.js";import{S as ut}from"./shield-check-C0Nfu5MF.js";import{B as go}from"./bottom-sheet-ipETSw9E.js";import{C as po}from"./circle-help-Dydk2OOb.js";import{C as xo}from"./circle-check-CXnX6QmC.js";import{a as bo,b as vo,f as So}from"./move-options-DwhS2xoZ.js";import{j as yo,k as Io,e as Co}from"./search-token-index-D4F4WYkQ.js";import{M as wo}from"./enums-B_igRgfI.js";import{n as ko}from"./search-query-Cr_ZXBCp.js";const jo=({children:e,onRefresh:n,isRefreshing:t})=>co(uo)?e:r.jsx(Ss,{onRefresh:n,isPullable:!t,children:e}),Mo=e=>e===1?"message":"messages";function To({count:e,onReview:n,onDismiss:t,actionLabel:s="Review & rescue"}){return r.jsx(kt,{tone:"info",variant:"soft",onDismiss:t,children:r.jsxs("div",{className:"flex flex-col gap-2",children:[r.jsxs("p",{className:"flex items-start gap-2 text-sm text-fg",children:[r.jsx(ut,{className:"mt-0.5 size-4 shrink-0 text-positive","aria-hidden":!0}),r.jsxs("span",{children:[r.jsx("span",{className:"font-semibold text-fg",children:`${e} ${Mo(e)} here`})," ","may not be spam — they're from senders we can verify."]})]}),r.jsx(ae,{variant:"primary",size:"sm",onClick:n,className:"self-start",children:s})]})})}const Ro=(e,n)=>e==="vip"?"vip":e==="unknown"&&n==="md"?"unknown-pill":"hidden",ts=({senderTrust:e,size:n="sm",className:t})=>{const s=Ro(e,n);return s==="vip"?r.jsx(ys,{className:Re("text-warning shrink-0",n==="sm"&&"size-3.5",n==="md"&&"size-4",t),"aria-label":"VIP sender","data-testid":"sender-trust-vip"}):s==="unknown-pill"?r.jsx("span",{className:Re("inline-flex items-center rounded border border-dashed border-fg-subtle/40 font-medium uppercase tracking-wide text-fg-muted/80 shrink-0","px-2 py-0.5 text-xs",t),title:"First message from this sender","aria-label":"First message from this sender","data-testid":"sender-trust-unknown",children:"new"}):null};function Eo({candidate:e,selected:n,onToggle:t,hideSender:s=!1}){const{senderName:o,senderAddress:i,subject:l,snippet:a,trustReason:u,trustSubReason:d,senderTrust:f}=e;return r.jsxs("label",{className:Re("flex w-full cursor-pointer items-start gap-3 px-3 py-2.5 text-left transition-colors",s&&"pl-11",n?"bg-positive/10":"bg-surface hover:bg-surface-sunken"),children:[r.jsx(Ht,{className:"mt-0.5",checked:n,onChange:t,"aria-label":`${n?"Deselect":"Select"} ${s?l:`message from ${o}`}`}),!s&&r.jsx(Tt,{name:o,email:i,size:"sm"}),r.jsxs("span",{className:"min-w-0 flex-1",children:[!s&&r.jsxs("span",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"truncate text-sm font-medium text-fg",children:o}),f&&r.jsx(ts,{senderTrust:f,size:"sm"}),r.jsx("span",{className:"truncate text-2xs text-fg-subtle",children:i})]}),r.jsx("span",{className:"block truncate text-sm text-fg-muted",children:l}),r.jsx("span",{className:"block line-clamp-1 text-xs text-fg-subtle",children:a}),!s&&r.jsxs("span",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[r.jsxs(Bt,{tone:"positive",children:[r.jsx(ut,{className:"size-3","aria-hidden":!0}),u]}),r.jsx("span",{className:"text-2xs text-fg-subtle",children:d})]})]})]})}const Ao=e=>{const n=new Map,t=[];for(const s of e){const o=(s.senderAddress||s.senderName).toLowerCase(),i=n.get(o);if(i){i.messages.push(s);continue}n.set(o,{key:o,senderName:s.senderName,senderAddress:s.senderAddress,trustReason:s.trustReason,trustSubReason:s.trustSubReason,senderTrust:s.senderTrust,messages:[s]}),t.push(o)}return t.map(s=>n.get(s)).sort((s,o)=>o.messages.length-s.messages.length)},Oo=(e,n)=>{const t=e.messages.filter(s=>n.has(s.id)).length;return t===0?"none":t===e.messages.length?"all":"some"},_t=e=>e===1?"message":"messages";function No({group:e,selected:n,onToggleGroup:t,onToggleMessage:s}){const[o,i]=c.useState(!1),l=Oo(e,n),a=e.messages.length,u=o?Is:Cs;return r.jsxs("div",{className:Re(l!=="none"?"bg-positive/10":"bg-surface"),children:[r.jsxs("div",{className:"flex w-full items-start gap-3 px-3 py-2.5",children:[r.jsx(Ht,{className:"mt-0.5",checked:l==="all",indeterminate:l==="some",onChange:()=>t(e,l!=="all"),"aria-label":`${l==="all"?"Deselect":"Select"} all ${a} ${_t(a)} from ${e.senderName}`}),r.jsx(Tt,{name:e.senderName,email:e.senderAddress,size:"sm"}),r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"truncate text-sm font-medium text-fg",children:e.senderName}),e.senderTrust&&r.jsx(ts,{senderTrust:e.senderTrust,size:"sm"}),r.jsx("span",{className:"truncate text-2xs text-fg-subtle",children:e.senderAddress})]}),r.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[r.jsxs(Bt,{tone:"positive",children:[r.jsx(ut,{className:"size-3","aria-hidden":!0}),e.trustReason]}),r.jsx("span",{className:"text-2xs text-fg-subtle",children:e.trustSubReason})]})]}),r.jsxs("button",{type:"button",onClick:()=>i(d=>!d),"aria-expanded":o,className:"flex shrink-0 items-center gap-1 rounded-md px-1.5 py-1 text-2xs text-fg-muted transition-colors hover:bg-surface-sunken hover:text-fg",children:[`${a} ${_t(a)}`,r.jsx(u,{className:"size-3.5","aria-hidden":!0})]})]}),o&&r.jsx("div",{className:"divide-y divide-line border-t border-line",children:e.messages.map(d=>r.jsx(Eo,{candidate:d,selected:n.has(d.id),onToggle:()=>s(d.id),hideSender:!0},d.id))})]})}const Rt=e=>e===1?"message":"messages",zo=(e,n)=>`Moves ${e===1?"this message":`these ${e} ${Rt(e)}`} out of Spam to ${n} now. Nothing later.`,wt=(e,n)=>e.find(t=>t.id===n)?.label??"Inbox";function Fo(){return r.jsx(kt,{tone:"info",variant:"soft",children:r.jsx("p",{className:"text-2xs text-fg-muted",children:"We list a message here only when we can confirm the sender is who they say — usually someone you've emailed before, write to often, or a service that consistently checks out. We never guess from words in the subject. Anything we can't confirm stays in Spam."})})}function Do({candidates:e,selected:n,onToggle:t,onToggleGroup:s,onSelectAll:o,onSelectNone:i,onContinue:l,onCancel:a}){const[u,d]=c.useState(!1),f=n.size,m=c.useMemo(()=>Ao(e),[e]);return r.jsxs("div",{className:"flex min-h-0 flex-col",children:[r.jsxs("div",{className:"px-row-inset pb-2 pt-1",children:[r.jsxs("div",{className:"flex items-start justify-between gap-2",children:[r.jsxs("h2",{className:"flex items-center gap-2 text-sm font-semibold text-fg",children:[r.jsx(ut,{className:"size-4 text-positive","aria-hidden":!0}),"Rescue from Spam"]}),r.jsx(ae,{variant:"ghost",size:"sm",icon:r.jsx(po,{className:"size-3.5"}),onClick:()=>d(g=>!g),className:"-mr-1.5 -mt-0.5",children:"Why these?"})]}),r.jsx("p",{className:"mt-1 text-2xs text-fg-subtle",children:"These look safe — from senders we can verify. Uncheck any sender that belongs in Spam, or open a sender to pick individual messages."}),u&&r.jsx("div",{className:"mt-2",children:r.jsx(Fo,{})})]}),r.jsxs("div",{className:"flex items-center justify-between px-row-inset pb-1.5",children:[r.jsx("span",{className:"text-2xs font-medium text-fg-muted",children:`${f} of ${e.length} selected · ${m.length} ${m.length===1?"sender":"senders"}`}),r.jsxs("span",{className:"flex gap-1",children:[r.jsx(ae,{variant:"ghost",size:"sm",onClick:o,children:"Select all"}),r.jsx(ae,{variant:"ghost",size:"sm",onClick:i,children:"Select none"})]})]}),r.jsx("div",{className:"min-h-0 flex-1 divide-y divide-line overflow-y-auto border-y border-line",children:m.map(g=>r.jsx(No,{group:g,selected:n,onToggleGroup:s,onToggleMessage:t},g.key))}),r.jsxs("div",{className:"space-y-2 border-t border-line bg-surface px-row-inset py-3",children:[r.jsx(ae,{variant:"primary",onClick:l,className:"h-11 w-full font-semibold",children:`Continue with ${f} ${Rt(f)}`}),r.jsx(ae,{variant:"ghost",onClick:a,className:"h-11 w-full",children:"Cancel"})]})]})}function _o({count:e,folders:n,delimiter:t,destination:s,onPick:o,onMove:i,onBack:l}){const[a,u]=c.useState(!1);return r.jsxs("div",{className:"flex min-h-0 flex-col",children:[r.jsxs("div",{className:"px-row-inset pb-2 pt-1",children:[r.jsx("h2",{className:"text-sm font-semibold text-fg",children:"Where should they go?"}),r.jsx("p",{className:"mt-1 text-2xs text-fg-subtle",children:"Pick a folder, then we move them out of Spam."})]}),r.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-y-auto px-row-inset py-2",children:a?r.jsx("div",{className:"flex min-h-0 flex-1 overflow-hidden rounded-xl border border-line bg-surface",children:r.jsx(ws,{folders:n,selectedId:s,delimiter:t,onSelect:o,onCancel:()=>u(!1)})}):r.jsxs("div",{className:"rounded-xl border border-line bg-surface-sunken p-3",children:[r.jsx("p",{className:"text-2xs text-fg-subtle",children:"Destination"}),r.jsx("p",{className:"mt-0.5 text-sm font-medium text-fg",children:wt(n,s)}),r.jsx(ae,{variant:"ghost",size:"sm",onClick:()=>u(!0),className:"mt-2 px-0",children:"Move to a different folder"})]})}),r.jsxs("div",{className:"space-y-2 border-t border-line bg-surface px-row-inset py-3",children:[r.jsx("p",{className:"text-2xs text-fg-subtle",children:zo(e,wt(n,s))}),r.jsx(ae,{variant:"primary",onClick:i,className:"h-11 w-full font-semibold",children:`Move ${e} out of Spam`}),r.jsx(ae,{variant:"ghost",onClick:l,className:"h-11 w-full",children:"Back"})]})]})}function Lo({count:e,destinationLabel:n,onClose:t}){return r.jsxs("div",{className:"flex min-h-0 flex-col",children:[r.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 px-row-inset py-10 text-center",children:[r.jsx(xo,{className:"size-10 text-positive","aria-hidden":!0}),r.jsx("p",{className:"text-base font-semibold text-fg",children:`Moved ${e} ${Rt(e)} out of Spam.`}),r.jsx("p",{className:"text-2xs text-fg-subtle",children:`You'll find them in ${n}.`})]}),r.jsx("div",{className:"border-t border-line bg-surface px-row-inset py-3",children:r.jsx(ae,{variant:"primary",onClick:t,className:"h-11 w-full font-semibold",children:"Done"})})]})}function Po({open:e,candidates:n,defaultDestinationId:t,availableFolders:s,delimiter:o,onConfirmMove:i,onCancel:l}){const[a,u]=c.useState("review"),[d,f]=c.useState(()=>e?new Set(n.map(C=>C.id)):new Set),[m,g]=c.useState(t),[b,y]=c.useState(0),w=c.useRef(!1);c.useEffect(()=>{e&&!w.current&&(u("review"),f(new Set(n.map(C=>C.id))),g(t),y(0)),w.current=e},[e,n,t]);const M=d.size,p=C=>{f(j=>{const N=new Set(j);return N.has(C)?N.delete(C):N.add(C),N})},x=(C,j)=>{f(N=>{const A=new Set(N);for(const z of C.messages)j?A.add(z.id):A.delete(z.id);return A})},k=()=>{const C=Array.from(d);y(C.length),i(C,m),u("done")};return r.jsxs(go,{open:e,onClose:l,dismissLabel:"Close rescue",children:[a==="review"&&r.jsx(Do,{candidates:n,selected:d,onToggle:p,onToggleGroup:x,onSelectAll:()=>f(new Set(n.map(C=>C.id))),onSelectNone:()=>f(new Set),onContinue:()=>u("destination"),onCancel:l}),a==="destination"&&r.jsx(_o,{count:M,folders:s,delimiter:o,destination:m,onPick:g,onMove:k,onBack:()=>u("review")}),a==="done"&&r.jsx(Lo,{count:b,destinationLabel:wt(s,m),onClose:l})]})}function $o(e){const n=e.toAddresses.join(", ");return{id:e.outboxMessageId,accountId:e.accountId,fromName:e.fromName??e.fromAddress??"Me",fromEmail:e.fromAddress??"",subject:e.subject??"(No subject)",snippet:n?`To: ${n}`:"(No recipients)",timeLabel:Ge(e.updatedAt),isRead:!0}}function Bo(e){return{id:e.messageId,accountId:e.accountId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:Ge(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0}}function Wo({outboxMessages:e,accountId:n,imapThreads:t}){const s=e.filter(l=>l.status==="draft"&&l.accountId===n).map($o),o=t.map(Bo),i=[];return s.length>0&&i.push({id:"remit-drafts",label:"Not yet sent (Remit)",threads:s}),o.length>0&&i.push({id:"imap-drafts",label:"On the server",threads:o}),i}const Ko=({label:e,count:n})=>r.jsxs("div",{className:"sticky top-0 z-10 flex items-baseline justify-between border-b border-line bg-surface-sunken px-row-inset py-1",children:[r.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e}),r.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:n})]}),Vo=({row:e,isSelected:n,onOpen:t,onDelete:s,isDeleting:o})=>r.jsxs("button",{type:"button",onClick:()=>t(e.id),className:Re("group",qt({active:n})),children:[r.jsx(Rs,{className:"size-7 shrink-0 text-fg-muted mt-0.5"}),r.jsx(Ut,{thread:e}),r.jsx("div",{className:"flex items-center gap-1 shrink-0",children:r.jsx("button",{type:"button",onClick:i=>{i.stopPropagation(),s(e.id)},disabled:o,className:"p-1.5 rounded-md text-fg-muted hover:text-danger hover:bg-surface-raised transition-colors opacity-0 group-hover:opacity-100 focus:opacity-100",title:"Delete draft",children:r.jsx(Es,{className:"size-3.5"})})})]}),Ho=({row:e,isSelected:n,onOpen:t})=>{const s=!e.isRead;return r.jsxs("button",{type:"button",onClick:()=>t(e.id),className:Re("group",qt({active:n})),children:[s&&r.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),r.jsx(Tt,{name:e.fromName,email:e.fromEmail,size:"sm"}),r.jsx(Ut,{thread:e})]})};function Uo({mailboxId:e,accountId:n,selectedMessageId:t,imapThreads:s,title:o,unreadCount:i}){const l=Xn(),a=Zn(),u=Je(),d=Ye(),f=Wt(),{data:m}=jt(ks()),g=c.useMemo(()=>Wo({outboxMessages:m?.items??[],accountId:n,imapThreads:s}),[m?.items,n,s]),b=Kt({...Ms(),onSuccess:()=>{f.invalidateQueries({queryKey:js()})}}),y=p=>{b.mutate({path:{outboxMessageId:p}})},w=p=>{const x=s.find(k=>k.messageId===p)?.threadId;x&&u({to:"/mail/$mailboxId/$threadId/$messageId",params:{mailboxId:e,threadId:x,messageId:p},search:k=>k,hash:d})},M=g.length===0;return r.jsxs("section",{className:"flex h-full w-full flex-col bg-surface",children:[r.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[r.jsx(io,{}),r.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:o}),(i??0)>0&&r.jsxs("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:[i," unread"]})]}),r.jsx("div",{className:"flex-1 overflow-y-auto",children:M?r.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-2 text-center px-4",children:[r.jsx(Ts,{className:"size-8 text-fg-subtle"}),r.jsx("p",{className:"text-sm font-medium text-fg",children:"No drafts"}),r.jsx("p",{className:"text-xs text-fg-subtle",children:"Messages you start composing will appear here."})]}):g.map(p=>r.jsxs("div",{children:[p.label&&r.jsx(Ko,{label:p.label,count:p.threads.length}),r.jsx("div",{className:"divide-y divide-line",children:p.threads.map(x=>p.id==="remit-drafts"?r.jsx(Vo,{row:x,isSelected:x.id===l,onOpen:a,onDelete:y,isDeleting:b.isPending},x.id):r.jsx(Ho,{row:x,isSelected:x.id===t,onOpen:w},x.id))})]},p.id))})]})}function qo(e,n,t){const s=new Array(e);return new Proxy(s,{get(o,i,l){if(typeof i=="string"){const a=i.charCodeAt(0);if(a>=48&&a<=57){const u=+i;if(Number.isInteger(u)&&u>=0&&u<e){let d=o[u];if(!d){const f=n[u*2];d=o[u]={index:u,key:t(u),start:f,size:n[u*2+1],end:f+n[u*2+1],lane:0}}return d}}if(i==="length")return e}return Reflect.get(o,i,l)}})}function Le(e,n,t){let s=t.initialDeps??[],o,i=!0;function l(){const a=e();return(a.length!==s.length||a.some((d,f)=>s[f]!==d))&&(s=a,o=n(...a),t?.onChange&&!(i&&t.skipInitialOnChange)&&t.onChange(o),i=!1),o}return l.updateDeps=a=>{s=a},l}function Lt(e,n){if(e===void 0)throw new Error("Unexpected undefined");return e}const Qo=(e,n)=>Math.abs(e-n)<1.01,Jo=(e,n,t)=>{let s;return function(...o){e.clearTimeout(s),s=e.setTimeout(()=>n.apply(this,o),t)}};let Qe;const It=()=>{if(Qe!==void 0)return Qe;if(typeof navigator>"u")return Qe=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return Qe=!0;const e=navigator.maxTouchPoints;return Qe=navigator.platform==="MacIntel"&&e!==void 0&&e>0},Pt=e=>{const{offsetWidth:n,offsetHeight:t}=e;return{width:n,height:t}},Go=e=>e,Yo=e=>{const n=Math.max(e.startIndex-e.overscan,0),s=Math.min(e.endIndex+e.overscan,e.count-1)-n+1,o=new Array(s);for(let i=0;i<s;i++)o[i]=n+i;return o},Xo=(e,n)=>{const t=e.scrollElement;if(!t)return;const s=e.targetWindow;if(!s)return;const o=l=>{const{width:a,height:u}=l;n({width:Math.round(a),height:Math.round(u)})};if(o(Pt(t)),!s.ResizeObserver)return()=>{};const i=new s.ResizeObserver(l=>{const a=()=>{const u=l[0];if(u?.borderBoxSize){const d=u.borderBoxSize[0];if(d){o({width:d.inlineSize,height:d.blockSize});return}}o(Pt(t))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(a):a()});return i.observe(t,{box:"border-box"}),()=>{i.unobserve(t)}},dt={passive:!0},Zo=typeof window>"u"?!0:"onscrollend"in window,ei=(e,n,t)=>{const s=e.scrollElement;if(!s)return;const o=e.targetWindow;if(!o)return;const i=e.options.useScrollendEvent&&Zo;let l=0;const a=i?null:Jo(o,()=>n(l,!1),e.options.isScrollingResetDelay),u=m=>()=>{l=t(s),a?.(),n(l,m)},d=u(!0),f=u(!1);return s.addEventListener("scroll",d,dt),i&&s.addEventListener("scrollend",f,dt),()=>{s.removeEventListener("scroll",d),i&&s.removeEventListener("scrollend",f)}},ti=(e,n)=>ei(e,n,t=>{const{horizontal:s,isRtl:o}=e.options;return s?t.scrollLeft*(o&&-1||1):t.scrollTop}),si=(e,n,t)=>{if(t.options.useCachedMeasurements){const s=t.indexFromElement(e),o=t.options.getItemKey(s);return t.itemSizeCache.get(o)??t.options.estimateSize(s)}if(n?.borderBoxSize){const s=n.borderBoxSize[0];if(s)return Math.round(s[t.options.horizontal?"inlineSize":"blockSize"])}if(!n){const s=t.indexFromElement(e),o=t.options.getItemKey(s),i=t.itemSizeCache.get(o);if(i!==void 0)return i}return e[t.options.horizontal?"offsetWidth":"offsetHeight"]},ni=(e,{adjustments:n=0,behavior:t},s)=>{var o,i;(i=(o=s.scrollElement)==null?void 0:o.scrollTo)==null||i.call(o,{[s.options.horizontal?"left":"top"]:e+n,behavior:t})},oi=ni;class ii{constructor(n){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this._flatMeasurements=null,this.itemSizeCache=new Map,this.itemSizeCacheVersion=0,this.laneAssignments=new Map,this.pendingMin=null,this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.pendingScrollAnchor=null,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._intendedScrollOffset=null,this.elementsCache=new Map,this.now=()=>{var t,s,o;return((o=(s=(t=this.targetWindow)==null?void 0:t.performance)==null?void 0:s.now)==null?void 0:o.call(s))??Date.now()},this.observer=(()=>{let t=null;const s=()=>t||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:t=new this.targetWindow.ResizeObserver(o=>{o.forEach(i=>{const l=()=>{const a=i.target,u=this.indexFromElement(a);if(!a.isConnected){this.observer.unobserve(a);for(const[d,f]of this.elementsCache)if(f===a){this.elementsCache.delete(d);break}return}this.shouldMeasureDuringScroll(u)&&this.resizeItem(u,this.options.measureElement(a,i,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(l):l()})}));return{disconnect:()=>{var o;(o=s())==null||o.disconnect(),t=null},observe:o=>{var i;return(i=s())==null?void 0:i.observe(o,{box:"border-box"})},unobserve:o=>{var i;return(i=s())==null?void 0:i.unobserve(o)}}})(),this.range=null,this.setOptions=t=>{var s,o;const i={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:Go,rangeExtractor:Yo,onChange:()=>{},measureElement:si,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,anchorTo:"start",followOnAppend:!1,scrollEndThreshold:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:"estimate",useCachedMeasurements:!1};for(const g in t){const b=t[g];b!==void 0&&(i[g]=b)}const l=this.options;let a=null,u=null,d=!1;if(l!==void 0&&l.enabled&&i.enabled&&i.anchorTo==="end"&&this.scrollElement!==null){const g=l.count,b=i.count,y=this.getMeasurements(),w=g>0?((s=y[0])==null?void 0:s.key)??l.getItemKey(0):null,M=g>0?((o=y[g-1])==null?void 0:o.key)??l.getItemKey(g-1):null;if(b!==g||g>0&&b>0&&(i.getItemKey(0)!==w||i.getItemKey(b-1)!==M)){d=!0;const k=g>0?this.getVirtualItemForOffset(this.getScrollOffset())??y[0]:null;k&&(a=[k.key,this.getScrollOffset()-k.start]);const C=i.followOnAppend===!0?"auto":i.followOnAppend||null;C&&b>g&&this.isAtEnd(l.scrollEndThreshold)&&(g===0||i.getItemKey(b-1)!==M)&&(u=C)}}this.options=i,d&&(this.pendingMin=0,this.itemSizeCacheVersion++);let f=!1,m=0;if(a&&this.scrollOffset!==null){const[g,b]=a,y=this.getMeasurements(),{count:w,getItemKey:M}=this.options;let p=0;for(;p<w&&M(p)!==g;)p++;if(p<w){const x=y[p];if(x){const k=x.start+b;k!==this.scrollOffset&&(m=k-this.scrollOffset,this.scrollOffset=k,f=!0)}}}(f||u)&&(this.pendingScrollAnchor=[f?a[0]:null,f?a[1]:0,u,m])},this.notify=t=>{var s,o;(o=(s=this.options).onChange)==null||o.call(s,this,t)},this.maybeNotify=Le(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),t=>{this.notify(t)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(t=>t()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var t;const s=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==s){if(this.cleanup(),!s){this.maybeNotify();return}if(this.scrollElement=s,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((t=this.scrollElement)==null?void 0:t.window)??null,this.elementsCache.forEach(i=>{this.observer.observe(i)}),this.unsubs.push(this.options.observeElementRect(this,i=>{this.scrollRect=i,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(i,l)=>{if(l&&this._intendedScrollOffset===null&&i===this.scrollOffset)return;this._intendedScrollOffset!==null&&Math.abs(i-this._intendedScrollOffset)<1.5&&(i=this._intendedScrollOffset),this._intendedScrollOffset=null,this.scrollAdjustments=0;const a=this.getScrollOffset();this.scrollDirection=l?a===i?this.scrollDirection:a<i?"forward":"backward":null,this.scrollOffset=i,this.isScrolling=l,this._flushIosDeferredIfReady(),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),"addEventListener"in this.scrollElement){const i=this.scrollElement,l=()=>{this._iosTouching=!0,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)},a=()=>{this._iosTouching=!1,!(!It()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};i.addEventListener("touchstart",l,dt),i.addEventListener("touchend",a,dt),this.unsubs.push(()=>{i.removeEventListener("touchstart",l),i.removeEventListener("touchend",a),this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)})}this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}const o=this.pendingScrollAnchor;if(this.pendingScrollAnchor=null,o&&this.scrollElement&&this.options.enabled){const[i,l,a,u]=o;i!==null&&!a&&(It()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?u!==0&&(this._iosDeferredAdjustment+=u):this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})),a&&this.scrollToEnd({behavior:a})}},this._flushIosDeferredIfReady=()=>{if(this._iosDeferredAdjustment===0||this.isScrolling||this._iosTouching||this._iosJustTouchEnded)return;const t=this.getScrollOffset(),s=this.getMaxScrollOffset();if(t<0||t>s)return;const o=this._iosDeferredAdjustment;this._iosDeferredAdjustment=0,this._scrollToOffset(t,{adjustments:this.scrollAdjustments+=o,behavior:void 0})},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset=="function"?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getMeasurementOptions=Le(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode,this.options.gap],(t,s,o,i,l,a,u,d)=>(this.prevLanes!==void 0&&this.prevLanes!==a&&(this.lanesChangedFlag=!0),this.prevLanes=a,this.pendingMin=null,{count:t,paddingStart:s,scrollMargin:o,getItemKey:i,enabled:l,lanes:a,laneAssignmentMode:u,gap:d}),{key:!1}),this.getMeasurements=Le(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:t,paddingStart:s,scrollMargin:o,getItemKey:i,enabled:l,lanes:a,laneAssignmentMode:u,gap:d},f)=>{const m=this.itemSizeCache;if(!l)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>t)for(const p of this.laneAssignments.keys())p>=t&&this.laneAssignments.delete(p);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMin=null),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(p=>{this.itemSizeCache.set(p.key,p.size)}));const g=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===t&&(this.lanesSettling=!1),a===1){const p=t*2;let x=this._flatMeasurements;if(!x||x.length<p){const j=new Float64Array(p);x&&g>0&&j.set(x.subarray(0,g*2)),x=j,this._flatMeasurements=x}let k;if(g===0)k=s+o;else{const j=g-1;k=x[j*2]+x[j*2+1]+d}for(let j=g;j<t;j++){const N=i(j),A=m.get(N),z=typeof A=="number"?A:this.options.estimateSize(j);x[j*2]=k,x[j*2+1]=z,k+=z+d}const C=qo(t,x,i);return this.measurementsCache=C,C}const b=this.measurementsCache.slice(0,g),y=new Array(a).fill(void 0),w=new Float64Array(a);let M=0;for(let p=0;p<g;p++){const x=b[p];x&&(y[x.lane]===void 0&&M++,y[x.lane]=p,w[x.lane]=x.end)}for(let p=g;p<t;p++){const x=i(p),k=this.laneAssignments.get(p);let C,j;const N=u==="estimate"||m.has(x);if(k!==void 0&&this.options.lanes>1){C=k;const E=y[C],L=E!==void 0?b[E]:void 0;j=L?L.end+d:s+o}else if(M===a){let E=0,L=w[0],he=y[0];for(let F=1;F<a;F++){const ee=w[F];(ee<L||ee===L&&y[F]<he)&&(E=F,L=ee,he=y[F])}C=E,j=L+d,N&&this.laneAssignments.set(p,C)}else C=p%this.options.lanes,j=s+o,N&&this.laneAssignments.set(p,C);const A=m.get(x),z=typeof A=="number"?A:this.options.estimateSize(p),Z=j+z;b[p]={index:p,start:j,size:z,end:Z,key:x,lane:C},y[C]===void 0&&M++,y[C]=p,w[C]=Z}return this.measurementsCache=b,b},{key:!1,debug:()=>this.options.debug}),this.calculateRange=Le(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(t,s,o,i)=>t.length===0||s===0?(this.range=null,null):(this.range=ai(t,s,o,i,i===1&&this._flatMeasurements!=null?this._flatMeasurements:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=Le(()=>{let t=null,s=null;const o=this.calculateRange();return o&&(t=o.startIndex,s=o.endIndex),this.maybeNotify.updateDeps([this.isScrolling,t,s]),[this.options.rangeExtractor,this.options.overscan,this.options.count,t,s]},(t,s,o,i,l)=>i===null||l===null?[]:t({startIndex:i,endIndex:l,overscan:s,count:o}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=t=>{const s=this.options.indexAttribute,o=t.getAttribute(s);return o?parseInt(o,10):(console.warn(`Missing attribute name '${s}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=t=>{var s;if(!this.scrollState||this.scrollState.behavior!=="smooth")return!0;const o=this.scrollState.index??((s=this.getVirtualItemForOffset(this.scrollState.lastTargetOffset))==null?void 0:s.index);if(o!==void 0&&this.range){const i=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),l=Math.max(0,o-i),a=Math.min(this.options.count-1,o+i);return t>=l&&t<=a}return!0},this.measureElement=t=>{if(!t){this.elementsCache.forEach((l,a)=>{l.isConnected||(this.observer.unobserve(l),this.elementsCache.delete(a))});return}const s=this.indexFromElement(t),o=this.options.getItemKey(s),i=this.elementsCache.get(o);i!==t&&(i&&this.observer.unobserve(i),this.observer.observe(t),this.elementsCache.set(o,t)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(s)&&this.resizeItem(s,this.options.measureElement(t,void 0,this))},this.resizeItem=(t,s)=>{var o,i;if(t<0||t>=this.options.count)return;let l,a,u;const d=this._flatMeasurements;if(this.options.lanes===1&&d!==null)u=this.options.getItemKey(t),a=d[t*2],l=d[t*2+1];else{const g=this.measurementsCache[t];if(!g)return;u=g.key,a=g.start,l=g.size}const f=this.itemSizeCache.get(u)??l,m=s-f;if(m!==0){const g=this.options.anchorTo==="end"&&((o=this.scrollState)==null?void 0:o.behavior)!=="smooth"&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,b=g?this.getTotalSize():0,y=((i=this.scrollState)==null?void 0:i.behavior)!=="smooth"&&(this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[t]??{index:t,key:u,start:a,size:l,end:a+l,lane:0},m,this):a<this.getScrollOffset()+this.scrollAdjustments&&(!this.itemSizeCache.has(u)||this.scrollDirection!=="backward"));(this.pendingMin===null||t<this.pendingMin)&&(this.pendingMin=t),this.itemSizeCache.set(u,s),this.itemSizeCacheVersion++,g?this.applyScrollAdjustment(this.getTotalSize()-b):y&&this.applyScrollAdjustment(m),this.notify(!1)}},this.getVirtualItems=Le(()=>[this.getVirtualIndexes(),this.getMeasurements()],(t,s)=>{const o=[];for(let i=0,l=t.length;i<l;i++){const a=t[i],u=s[a];o.push(u)}return o},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=t=>{const s=this.getMeasurements();if(s.length===0)return;const o=this._flatMeasurements,i=this.options.lanes===1&&o!=null,l=ss(0,s.length-1,i?a=>o[a*2]:a=>Lt(s[a]).start,t);return Lt(s[l])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if("scrollHeight"in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{const t=this.scrollElement.document.documentElement;return this.options.horizontal?t.scrollWidth-this.scrollElement.innerWidth:t.scrollHeight-this.scrollElement.innerHeight}},this.getVirtualDistanceFromEnd=()=>Math.max(this.getTotalSize()-this.getSize()-this.getScrollOffset(),0),this.getDistanceFromEnd=()=>Math.max(this.getMaxScrollOffset()-this.getScrollOffset(),0),this.isAtEnd=(t=this.options.scrollEndThreshold)=>this.getDistanceFromEnd()<=t,this.getOffsetForAlignment=(t,s,o=0)=>{if(!this.scrollElement)return 0;const i=this.getSize(),l=this.getScrollOffset();s==="auto"&&(s=t>=l+i?"end":"start"),s==="center"?t+=(o-i)/2:s==="end"&&(t-=i);const a=this.getMaxScrollOffset();return Math.max(Math.min(a,t),0)},this.getOffsetForIndex=(t,s="auto")=>{t=Math.max(0,Math.min(t,this.options.count-1));const o=this.getSize(),i=this.getScrollOffset(),l=this.measurementsCache[t];if(!l)return;if(s==="auto")if(l.end>=i+o-this.options.scrollPaddingEnd)s="end";else if(l.start<=i+this.options.scrollPaddingStart)s="start";else return[i,s];if(s==="end"&&t===this.options.count-1)return[this.getMaxScrollOffset(),s];const a=s==="end"?l.end+this.options.scrollPaddingEnd:l.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(a,s,l.size),s]},this.scrollToOffset=(t,{align:s="start",behavior:o="auto"}={})=>{const i=this.getOffsetForAlignment(t,s),l=this.now();this.scrollState={index:null,align:s,behavior:o,startedAt:l,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:o}),this.scheduleScrollReconcile()},this.scrollToIndex=(t,{align:s="auto",behavior:o="auto"}={})=>{t=Math.max(0,Math.min(t,this.options.count-1));const i=this.getOffsetForIndex(t,s);if(!i)return;const[l,a]=i,u=this.now();this.scrollState={index:t,align:a,behavior:o,startedAt:u,lastTargetOffset:l,stableFrames:0},this._scrollToOffset(l,{adjustments:void 0,behavior:o}),this.scheduleScrollReconcile()},this.scrollBy=(t,{behavior:s="auto"}={})=>{const o=this.getScrollOffset()+t,i=this.now();this.scrollState={index:null,align:"start",behavior:s,startedAt:i,lastTargetOffset:o,stableFrames:0},this._scrollToOffset(o,{adjustments:void 0,behavior:s}),this.scheduleScrollReconcile()},this.scrollToEnd=({behavior:t="auto"}={})=>{if(this.options.count>0){this.scrollToIndex(this.options.count-1,{align:"end",behavior:t});return}this.scrollToOffset(Math.max(this.getTotalSize()-this.getSize(),0),{behavior:t})},this.getTotalSize=()=>{var t;const s=this.getMeasurements();let o;if(s.length===0)o=this.options.paddingStart;else if(this.options.lanes===1){const i=s.length-1,l=this._flatMeasurements;l!=null?o=l[i*2]+l[i*2+1]:o=((t=s[i])==null?void 0:t.end)??0}else{const i=Array(this.options.lanes).fill(null);let l=s.length-1;for(;l>=0&&i.some(a=>a===null);){const a=s[l];i[a.lane]===null&&(i[a.lane]=a.end),l--}o=Math.max(...i.filter(a=>a!==null))}return Math.max(o-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{const t=[];if(this.itemSizeCache.size===0)return t;const s=this.getMeasurements();for(const o of s)o&&this.itemSizeCache.has(o.key)&&t.push({index:o.index,key:o.key,start:o.start,size:o.size,end:o.end,lane:o.lane});return t},this._scrollToOffset=(t,{adjustments:s,behavior:o})=>{this._intendedScrollOffset=t+(s??0),this.options.scrollToFn(t,{behavior:o,adjustments:s},this)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(n)}applyScrollAdjustment(n,t){n!==0&&(It()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?this._iosDeferredAdjustment+=n:(this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=n,behavior:t}),this.scrollOffset!==null&&(this.scrollOffset+=this.scrollAdjustments,this.scrollAdjustments=0)))}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId==null&&(this.rafId=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}))}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}const s=this.scrollState.index!=null?this.getOffsetForIndex(this.scrollState.index,this.scrollState.align):void 0,o=s?s[0]:this.scrollState.lastTargetOffset,i=1,l=o!==this.scrollState.lastTargetOffset;if(!l&&Qo(o,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=i){this.getScrollOffset()!==o&&this._scrollToOffset(o,{adjustments:void 0,behavior:"auto"}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,l){const a=this.getSize()||600,u=Math.abs(o-this.getScrollOffset()),d=this.scrollState.behavior==="smooth"&&u>a;this.scrollState.lastTargetOffset=o,d||(this.scrollState.behavior="auto"),this._scrollToOffset(o,{adjustments:void 0,behavior:d?"smooth":"auto"})}this.scheduleScrollReconcile()}}const ss=(e,n,t,s)=>{for(;e<=n;){const o=(e+n)/2|0,i=t(o);if(i<s)e=o+1;else if(i>s)n=o-1;else return o}return e>0?e-1:0};function ri(e,n,t){let s=0;for(;s<=n;){const o=(s+n)/2|0,i=e[o*2];if(i<t)s=o+1;else if(i>t)n=o-1;else return o}return s>0?s-1:0}function ai(e,n,t,s,o){const i=e.length-1;if(e.length<=s)return{startIndex:0,endIndex:i};if(s===1&&o!==null){const d=ri(o,i,t);let f=d;const m=t+n;for(;f<i&&o[f*2]+o[f*2+1]<m;)f++;return{startIndex:d,endIndex:f}}let a=ss(0,i,d=>e[d].start,t),u=a;if(s===1)for(;u<i&&e[u].end<t+n;)u++;else if(s>1){const d=Array(s).fill(0);for(;u<i&&d.some(m=>m<t+n);){const m=e[u];d[m.lane]=m.end,u++}const f=Array(s).fill(t+n);for(;a>=0&&f.some(m=>m>=t);){const m=e[a];f[m.lane]=m.start,a--}a=Math.max(0,a-a%s),u=Math.min(i,u+(s-1-u%s))}return{startIndex:a,endIndex:u}}const Ct=typeof document<"u"?c.useLayoutEffect:c.useEffect;function li({useFlushSync:e=!0,directDomUpdates:n=!1,directDomUpdatesMode:t="transform",...s}){const o=c.useReducer(d=>d+1,0)[1],i=c.useRef({enabled:n,mode:t,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});i.current.enabled=n,i.current.mode=t;const l=d=>{const f=i.current;if(!f.enabled||!f.container)return;const m=d.getTotalSize();if(m!==f.lastSize){f.lastSize=m;const p=d.options.horizontal?"width":"height";f.container.style[p]=`${m}px`}const g=!!d.options.horizontal,b=f.mode==="transform",y=g?"left":"top",w=d.options.scrollMargin,M=d.getVirtualItems();for(const p of M){const x=p.start-w,k=d.elementsCache.get(p.key);k&&f.lastPositions.get(k)!==x&&(f.lastPositions.set(k,x),b?k.style.transform=g?`translate3d(${x}px, 0, 0)`:`translate3d(0, ${x}px, 0)`:k.style[y]=`${x}px`)}},a={...s,onChange:(d,f)=>{var m;const g=i.current;let b=!0;if(g.enabled){l(d);const y=d.range,w=g.prevRange;b=!w||w.isScrolling!==d.isScrolling||w.startIndex!==y?.startIndex||w.endIndex!==y?.endIndex,b&&(g.prevRange=y?{startIndex:y.startIndex,endIndex:y.endIndex,isScrolling:d.isScrolling}:null)}b&&(e&&f?As.flushSync(o):o()),(m=s.onChange)==null||m.call(s,d,f)}},[u]=c.useState(()=>{const d=new ii(a);return Object.assign(d,{containerRef:f=>{const m=i.current;if(m.container=f,m.lastSize=null,f&&m.enabled){const g=d.getTotalSize();m.lastSize=g;const b=d.options.horizontal?"width":"height";f.style[b]=`${g}px`}}})});return u.setOptions(a),Ct(()=>u._didMount(),[]),Ct(()=>u._willUpdate()),Ct(()=>{l(u)}),u}function ci(e){return li({observeElementRect:Xo,observeElementOffset:ti,scrollToFn:oi,...e})}const Et=e=>e.query?`matching "${e.query}"`:e.from?`from "${e.from}"`:"matching your search",di=e=>`Select all ${Et(e)}`,ui=(e,n)=>`All ${Gn(n)} ${Et(e)} selected`,hi=({verb:e,confirmingDelete:n,hasSelection:t,junkMailboxId:s,currentMailboxId:o,deletableMessageId:i})=>{if(n)return{kind:"withheld"};if(e==="junk"){const l=Xs(s,o);if(l!==void 0)return{kind:"unavailable",reason:l}}return t?{kind:"openWizard"}:e!=="delete"||i===void 0?{kind:"declined"}:{kind:"confirmDelete",messageId:i}},fi=(e,n,t)=>e==="BACK"&&n&&t===void 0,mi=(e,n)=>({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:Ge(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Qt(e.category),messageCount:n,suspicious:e.authenticity?.dkimMismatch===!0,labels:e.labels}),gi=({thread:e,mailboxId:n,isSelected:t,isFocused:s,isTabStop:o,onFocusRow:i,isChecked:l,onToggleCheck:a,onRowSelect:u,messageCount:d,isMultiSelectMode:f,onLongPress:m,isDesktop:g,density:b})=>r.jsx(Zs,{thread:mi(e,d),link:{mailboxId:n,threadId:e.threadId},inListbox:!0,active:t,focused:s,isTabStop:o,density:b,isDesktop:g,onFocusRow:i,selection:{isChecked:l,onToggleCheck:a,onRowSelect:u,isMultiSelectMode:f,onLongPress:m}}),pi=c.memo(gi),xi=e=>{const n=e.authenticity?.dkimMismatch===!0;return{id:e.messageId,accountId:e.accountId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:Ge(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Qt(e.category),suspicious:n}},bi=({thread:e,mailboxId:n,isSelected:t,isFocused:s,isTabStop:o,onFocusRow:i,isChecked:l,onToggleCheck:a,onRowSelect:u,isMultiSelectMode:d,onLongPress:f,isDesktop:m,onDelete:g,onToggleRead:b,density:y})=>{const[w,M]=c.useState("none"),p=Je(),x=Ye(),k=c.useCallback(z=>{navigator.vibrate?.(10),z==="trailing"?g(e.messageId):b(e.messageId,e.isRead),M("none")},[g,b,e.messageId,e.isRead]),C=c.useCallback(()=>{f(e.messageId)},[f,e.messageId]),j=c.useCallback(()=>{a(e.messageId)},[a,e.messageId]),N=c.useCallback(()=>{p({to:"/mail/$mailboxId/$threadId/$messageId",params:{mailboxId:n,threadId:e.threadId,messageId:e.messageId},search:z=>z,hash:x})},[p,x,n,e.threadId,e.messageId]),A=en(e.messageId,u);return m||d?r.jsx(pi,{thread:e,mailboxId:n,isSelected:t,isFocused:s,isTabStop:o,onFocusRow:i,isChecked:l,onToggleCheck:a,onRowSelect:u,isMultiSelectMode:d,onLongPress:f,isDesktop:m,density:y}):r.jsx("div",{role:"presentation",onPointerDownCapture:A.onMouseDown,onClickCapture:A.claimClick,onContextMenu:A.onContextMenu,children:r.jsx(Hn,{thread:xi(e),selectionMode:!1,checked:!1,active:t,peek:w,onPeek:M,onToggleCheck:j,onLongPress:C,onOpen:N,onAct:k})})},vi=72,Si=32,yi=5,ns="remit:list-density",Ii=()=>{try{const e=localStorage.getItem(ns);if(e==="compact"||e==="comfortable")return e}catch{}return"comfortable"},Ci=({query:e})=>r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-line bg-surface-sunken/30",children:[r.jsx(_s,{className:"size-4 text-fg-muted"}),r.jsxs("span",{className:"text-sm text-fg-muted",children:["Results for “",e,"”"]})]}),wi=({mailboxId:e,threads:n,selectedMessageId:t,isLoading:s,isError:o=!1,error:i,onRetry:l,searchQuery:a,searchPredicate:u,onDeleteMessages:d,isDeleting:f=!1,isMoving:m=!1,onLoadMore:g,hasMore:b=!1,isLoadingMore:y=!1,accountId:w,listTitle:M,listMeta:p,listFilter:x,listScopeLabel:k,onTriageContextChange:C,commandsRef:j,hideHeader:N=!1})=>{const A=c.useRef(null),z=Je(),Z=Ye(),E=ho(),L=Os(),{verb:he,start:F,startFromSearch:ee}=L,Ee=Ns(),se=!!a?.trim(),Y=tn(),{labels:Ae}=lo(w),{pushError:ne}=zs(),[T,P]=c.useState(t),[Se,fe]=c.useState(),O=c.useCallback(h=>{fe(v=>v===h?v:void 0),P(h)},[]),[me,Oe]=c.useState(Ii),ye=c.useCallback(()=>{Oe(h=>{const v=h==="comfortable"?"compact":"comfortable";try{localStorage.setItem(ns,v)}catch{}return v})},[]),{toggleReadFor:Ie}=Jt({mailboxId:e}),{junkMailboxId:ge}=Gt(w),Pe=Yt(ge,e),{trashMailboxId:$e,isLoading:H}=sn(w),$=H?"unknown":$e===e?"permanent":"trash",{selectedIds:U,selectedCount:K,hasSelection:oe,isSelected:D,toggle:X,select:pe,clearSelection:Xe,selectRange:Ne,setAnchor:Be,selectAll:ie,toggleAll:ft,intersectWith:Ze}=nn(),Ce=pn(K,E),[R,ze]=c.useState(null),Fe=se&&!!u,et=`${e}|${JSON.stringify(u??{})}`,I=on({mailboxId:e,accountId:w,enabled:Fe,predicateKey:et,searchQuery:u??{}}),mt=c.useCallback((h,v,Q)=>{if(Q.error===void 0){if(Q.cancelled){ne({severity:"warning",title:an(Q.done),detail:rn(h,Q.done,v)});return}ne({severity:"info",title:zt(h,Q.done)})}},[ne]),We=I.phase.kind,we=I.clear,V=c.useCallback(()=>{We==="escalated"&&we(),Xe()},[Xe,we,We]),[le,tt]=c.useState(null),xe=c.useRef(null),ce=c.useRef(!1),ke=c.useRef(null),be=!s&&n.length>0,Ke=R!==null,te=ci({count:n.length,getScrollElement:()=>A.current,estimateSize:()=>me==="compact"?Si:vi,overscan:yi}),Ve=t?n.findIndex(h=>h.messageId===t):-1,q=T?n.findIndex(h=>h.messageId===T):-1,re=c.useCallback(h=>{if(h<0||h>=n.length)return;const v=n[h];if(Ce){X(v.messageId);return}xe.current=v.messageId,ce.current=!1,fe(v.messageId),P(v.messageId)},[n,Ce,X]),He=c.useCallback(()=>{if(n.length===0)return;const h=q<0?0:Math.min(q+1,n.length-1);re(h)},[n.length,q,re]),Ue=c.useCallback(()=>{if(n.length===0)return;const h=q<=0?0:q-1;re(h)},[n.length,q,re]),ve=c.useCallback(()=>re(0),[re]),je=c.useCallback(()=>re(n.length-1),[re,n.length]),Me=c.useCallback(()=>{T&&X(T)},[T,X]),B=c.useMemo(()=>n.map(h=>h.messageId),[n]),gt=c.useMemo(()=>{const h=[];for(const v of n)U.has(v.messageId)&&h.push({id:v.messageId,sender:v.fromName??v.fromEmail??"Unknown",email:v.fromEmail??"",subject:v.subject??"(No subject)",date:Ge(v.sentDate)});return h},[n,U]),pt=c.useCallback((h,v)=>v.shiftKey?(Ne(B,h,T),!0):v.metaKey||v.ctrlKey?(X(h),!0):(V(),Be(h),!1),[B,T,Ne,X,V,Be]),de=c.useCallback(h=>{!d||h.length===0||(ke.current=T??null,ze(h))},[d,T]),De=c.useCallback(h=>{const v=ln(B,T,h);v!==void 0&&(Ne(B,v),xe.current=v,ce.current=!1,fe(void 0),P(v))},[B,T,Ne]),st=c.useCallback(()=>De(-1),[De]),nt=c.useCallback(()=>De(1),[De]),ot=c.useCallback(()=>{B.length>0&&ie(B)},[B,ie]),it=c.useCallback(h=>{const v=hi({verb:h,confirmingDelete:R!==null,hasSelection:oe,junkMailboxId:ge,currentMailboxId:e,deletableMessageId:d?T:void 0});return v.kind==="openWizard"?(F(h),!0):v.kind==="confirmDelete"?(de([v.messageId]),!0):v.kind==="unavailable"?(ne({severity:"warning",title:v.reason}),!0):v.kind==="withheld"},[R,d,oe,ge,e,F,T,de,ne]),ue=c.useCallback((h,v)=>{const Q=n.find(J=>J.messageId===h)?.threadId;Q&&z({to:"/mail/$mailboxId/$threadId/$messageId",params:{mailboxId:e,threadId:Q,messageId:h},search:J=>J,hash:Z,replace:v?.replace})},[z,Z,e,n]),rt=c.useCallback(()=>{T&&ue(T)},[T,ue]),Te=c.useCallback(h=>ue(h,{replace:!0}),[ue]);cn({keyboardFocusedMessageId:Se,openMessageId:t,enabled:E&&K===0,open:Te});const _e=I.phase.kind==="escalated"?{scope:Et(u??{}),total:I.phase.total,searchQuery:u??{},run:h=>I.runAction(h),stop:I.stop}:void 0,at=c.useCallback(()=>{if(!R)return;const h=R;if(h.length===0){ze(null);return}const v=new Set(h),Q=n.findIndex(G=>v.has(G.messageId));let J;for(let G=Q+1;G<n.length;G++)if(!v.has(n[G].messageId)){J=n[G].messageId;break}if(J===void 0){for(let G=Q-1;G>=0;G--)if(!v.has(n[G].messageId)){J=n[G].messageId;break}}d?.(h),V(),ke.current=null,ze(null),J!==void 0&&(xe.current=J,ce.current=!1,O(J),E&&ue(J,{replace:!0})),E||tt(zt("delete",h.length))},[R,n,d,V,ue,E,O]),xt=c.useCallback(()=>{const h=ke.current;ke.current=null,ze(null),h!==null&&(xe.current=h,ce.current=!1,O(h))},[O]),qe=c.useMemo(()=>{if(K===0)return;const h=new Set;for(const v of n)U.has(v.messageId)&&h.add(v.accountConfigId);if(h.size>1)return"Move only works within one account — clear selection or pick messages from a single account"},[K,U,n]),bt=c.useCallback(()=>{if(_e){ee();return}F("organize")},[_e,ee,F]),lt=c.useCallback(h=>{d?.([h])},[d]),vt=c.useCallback((h,v)=>{Ie([h],!v)},[Ie]),S=c.useCallback(h=>{E||pe(h)},[E,pe]),_=c.useCallback(()=>{if(I.isRunning||I.phase.kind==="counting"){I.stop();return}V()},[I,V]),W=c.useCallback(()=>{I.clear()},[I]);c.useEffect(()=>{if(ce.current||!E&&t)return;const h=q>=0?q:Ve;h>=0&&te.scrollToIndex(h,{align:"auto"})},[q,Ve,te,E,t]),c.useEffect(()=>{t&&(ce.current=!1,O(t))},[t,O]),c.useEffect(()=>{T&&(n.some(h=>h.messageId===T)||O(n[0]?.messageId))},[n,T,O]),c.useEffect(()=>{C?.({focusedMessageId:T,selectedIds:Array.from(U),hasList:be,blocksKeyboard:Ke||L.isOpen})},[T,U,be,Ke,L.isOpen,C]);const At=c.useRef(C);At.current=C,c.useEffect(()=>()=>At.current?.({focusedMessageId:void 0,selectedIds:[],hasList:!1,blocksKeyboard:!1}),[]),c.useEffect(()=>{I.phase.kind!=="idle"||I.isRunning||Ze(n.map(h=>h.messageId))},[n,Ze,I.phase,I.isRunning]);const Ot=c.useRef(e);c.useEffect(()=>{Ot.current!==e&&(Ot.current=e,V())},[e,V]),dn({shouldBlockFn:({action:h})=>fi(h,oe,Ee)?(V(),!0):!1,enableBeforeUnload:!1,disabled:!oe||Ee!==void 0}),c.useEffect(()=>{const h=A.current;if(!h||!b||!g)return;const v=()=>{if(y)return;const{scrollTop:Q,scrollHeight:J,clientHeight:G}=h;Q+G>=J-200&&g()};return h.addEventListener("scroll",v,{passive:!0}),v(),()=>h.removeEventListener("scroll",v)},[b,y,g]),c.useEffect(()=>{const h=xe.current;if(!h)return;const v=A.current?.querySelector(`[data-message-id="${h}"]`);v&&(xe.current=null,v.focus({preventScroll:!0}))}),c.useEffect(()=>{if(j){if(!be){j.current=null;return}return j.current={focusNext:He,focusPrevious:Ue,focusFirst:ve,focusLast:je,openFocused:rt,toggleSelect:Me,extendSelectDown:nt,extendSelectUp:st,selectAll:ot,clearSelection:()=>oe?(V(),!0):!1,requestVerb:it,toggleDensity:ye},()=>{j.current=null}}},[j,be,He,Ue,ve,je,rt,Me,nt,st,ot,oe,V,it,ye]);const Nt=s?"loading":o?"error":n.length===0?"empty":"ready",as=o?ao(i):void 0,ls=c.useCallback(()=>{const h=Fs(Ds());window.open(h,"_blank","noopener,noreferrer")},[]),cs=[{id:"inbox",threads:[]}],St=B.length>0&&B.every(h=>U.has(h)),ds=Fe&&b&&St&&!f&&!m&&I.phase.kind==="idle"&&!I.isRunning,us=f||m||I.isRunning,yt=I.phase.kind==="escalated"?I.phase.total:K,hs=I.runningAction?un(I.runningAction.kind,I.progress?.done??0,I.progress?.total??yt):I.phase.kind==="counting"?"Counting matches…":I.phase.kind==="escalated"?ui(u??{},I.phase.total):void 0,fs=I.phase.kind!=="escalated"&&B.length>0?{checked:St,indeterminate:K>0&&!St,onChange:()=>ft(B)}:void 0,ms=I.runningAction?{value:I.progress?.done??0,max:I.progress?.total??yt,tone:hn(I.runningAction.kind)}:void 0,gs=(I.phase.kind==="counting"?{tone:"info",text:"",action:{label:"Stop",onClick:I.stop}}:I.phase.kind==="escalated"&&!I.isRunning?{tone:"info",text:"",action:{label:"Clear selection",onClick:W}}:ds?{tone:"info",text:"",action:{label:di(u??{}),onClick:I.escalate}}:void 0)??(qe?{tone:"warning",text:qe}:void 0),ps=r.jsx(fn,{title:Y.title||M,navSlot:Y.navSlot,titleMeta:Y.titleMeta,searchSlot:Y.searchSlot,searchField:Y.searchField,idleSlot:Y.makeFilterSlot,count:yt,onCancel:_,onDelete:()=>F("delete"),onMove:()=>F("move"),onOrganize:bt,onJunk:Pe?()=>F("junk"):void 0,onMarkRead:()=>F("markRead"),overflowSlot:w&&e&&K>0&&Ae.length>0?r.jsx(fo,{accountId:w,mailboxId:e,messageIds:Array.from(U)}):void 0,isBusy:us,isCounting:I.phase.kind==="counting",selectAll:fs,statusLabel:hs,progress:ms,notice:gs}),xs=mn(B,T),bs=c.useCallback(h=>{ce.current=!0,O(h)},[O]),vs=r.jsxs(r.Fragment,{children:[se&&a&&r.jsx(Ci,{query:a}),r.jsxs("div",{ref:A,role:"listbox","aria-multiselectable":!0,"aria-label":M,className:"flex-1 overflow-y-auto",children:[r.jsx("div",{role:"presentation",className:"relative w-full",style:{height:`${te.getTotalSize()}px`},children:te.getVirtualItems().map(h=>{const v=n[h.index];return r.jsx("div",{role:"presentation","data-index":h.index,ref:te.measureElement,className:Re("absolute left-0 top-0 w-full border-b border-line",I.isRunning&&"pointer-events-none opacity-50"),style:{transform:`translateY(${h.start}px)`},children:r.jsx(bi,{thread:v,mailboxId:e,isSelected:t===v.messageId,isFocused:T===v.messageId,isTabStop:xs===v.messageId,onFocusRow:bs,isChecked:D(v.messageId),onToggleCheck:X,onRowSelect:pt,isMultiSelectMode:Ce,onLongPress:S,isDesktop:E,onDelete:lt,onToggleRead:vt,density:me})},h.key)})}),y&&r.jsx(Un,{})]})]});return r.jsxs(r.Fragment,{children:[le&&!E&&r.jsx(kt,{tone:"success",variant:"soft",className:"m-2 rounded-md",onDismiss:()=>tt(null),children:le}),r.jsx(qn,{listTitle:M,listMeta:p,sections:cs,flatList:!0,listState:Y.searchResults?"ready":Nt,searchQuery:se?a:void 0,listFilter:x,listScopeLabel:k,errorMessage:as,onRetry:l,onReportError:ls,density:me,selectedThreadId:t,onSelectThread:h=>ue(h),isDesktop:E,hideHeader:N,selectionBar:ps,listBody:Y.searchResults??(Nt==="ready"?vs:void 0)}),r.jsx(ro,{isOpen:R!==null,...Yn(R?.length??0,$),destructive:!0,isBusy:f||$==="unknown",onConfirm:at,onCancel:xt}),r.jsx(gn,{verb:he,accountId:w,mailboxId:e,selection:gt,selectionRestriction:qe?"spansAccounts":void 0,escalated:_e,escalatedProgress:I.progress,onFinished:V,onRunEnded:mt})]})},ki=e=>Ps({path:{accountId:e}}),ji=e=>{const n=Wt(),t=Mt(),s=Kt({...Ls(),onSuccess:()=>{t.recordEvent("sync.triggered"),n.invalidateQueries({queryKey:ki(e)})}});return{trigger:()=>{s.mutate({path:{accountId:e}})},triggerAsync:()=>s.mutateAsync({path:{accountId:e}}),isPending:s.isPending,error:s.error,reset:s.reset}},Mi=({accountId:e,children:n})=>{const{triggerAsync:t,isPending:s}=ji(e);return r.jsx(jo,{onRefresh:t,isRefreshing:s,children:n})};function Ti({accountId:e,currentMailboxId:n,candidates:t,onMove:s,children:o}){const[i,l]=c.useState(!1),a=Mt(),u=bo(),{inboxMailboxId:d}=xn(e),f=bn(e),{data:m}=jt({...$s({path:{accountId:e}}),staleTime:1/0}),g=c.useMemo(()=>vo({mailboxes:m?.items??[],folderAppointments:f,currentMailboxId:n,translator:u}),[m?.items,f,n,u]),b=c.useMemo(()=>d||(g.find(x=>x.label.toLowerCase()==="inbox")?.id??g.find(x=>!x.isCurrent)?.id??""),[d,g]),y=c.useRef(!1);c.useEffect(()=>{y.current||(y.current=!0,vn(a,t.length))},[a,t.length]);const w=c.useCallback(()=>{Sn(a,t.length),l(!0)},[a,t.length]),M=c.useCallback((p,x)=>{yn(a,{selected:p.length,total:t.length,toInbox:x===d}),s(p,x)},[a,t.length,d,s]);return r.jsxs("div",{className:"relative flex h-full min-h-0 flex-col",children:[r.jsx("div",{className:"shrink-0 px-row-inset pt-2",children:r.jsx(To,{count:t.length,onReview:w})}),r.jsx("div",{className:"min-h-0 flex-1",children:o}),r.jsx(Po,{open:i,candidates:t,defaultDestinationId:b,availableFolders:g,delimiter:So(m?.items??[]),onConfirmMove:M,onCancel:()=>l(!1)})]})}const Ri="We can verify this sender";function Ei(e){const{data:n}=jt({...Bs({path:{mailboxId:e??""},query:{senderTrust:["vip","wellknown"],dkimMismatch:!1,results:!0,limit:500}}),enabled:!!e,staleTime:6e4});return{candidates:(n?.items??[]).map(s=>({id:s.messageId,senderName:s.fromName||s.fromEmail||"Unknown sender",senderAddress:s.fromEmail??"",subject:s.subject||"(no subject)",snippet:s.snippet??"",trustReason:Ri,trustSubReason:In(s.senderTrust),senderTrust:s.senderTrust}))}}const Ai=e=>{const n=new Set,t=[];for(const s of e)n.has(s.threadMessageId)||(n.add(s.threadMessageId),t.push(s));return t},Oi={unread:"unread",flagged:"starred",attachment:"attachments"},Ni=new Set(Object.values(wo)),os=e=>Ni.has(e),zi=e=>os(e.category)||e.attributes.size>0,Fi=e=>{const n={};os(e.category)&&(n.category=[e.category]);for(const t of e.attributes){const s=Oi[t];s&&(n[s]=!0)}return n},Di=e=>(e.senderTrust?.length??0)>0||e.dkimMismatch!==void 0?"loaded-pages":"whole-folder",_i=["category","unread","starred","attachments"],$t=e=>JSON.stringify(_i.map(n=>e?.[n]??null)),Li=e=>{if(!Array.isArray(e))return;const[n]=e;if(typeof n!="object"||n===null)return;const t=n.query;if(!(typeof t!="object"||t===null))return t},Pi=(e,n)=>{const t=Li(e);return t?$t(t)===$t(n):!1},ct=e=>e[0],$i=e=>{const n=ct(e.filter(a=>a.type==="from").map(a=>a.value)),t=ct(e.filter(a=>a.type==="subject").map(a=>a.value)),s=ct(e.filter(a=>a.type==="category").map(a=>a.category)),o=ct(e.filter(a=>a.type==="isUnread"||a.type==="isRead").map(a=>a.type==="isUnread")),i=e.some(a=>a.type==="isStarred")?!0:void 0,l=e.some(a=>a.type==="hasAttachment")?!0:void 0;return{...n!==void 0?{from:n}:{},...t!==void 0?{subject:t}:{},...s!==void 0?{category:[s]}:{},...o!==void 0?{unread:o}:{},...i!==void 0?{starred:i}:{},...l!==void 0?{attachments:l}:{}}},Bi=(e,n)=>{switch(n.type){case"from":return e.from?.toLowerCase()===n.value.toLowerCase();case"subject":return e.subject?.toLowerCase()===n.value.toLowerCase();case"category":return e.category?.length===1&&e.category[0]===n.category;case"isUnread":return e.unread===!0;case"isRead":return e.unread===!1;case"isStarred":return e.starred===!0;case"hasAttachment":return e.attachments===!0;case"before":case"after":case"in":case"account":return!1}};function Wi(e,n={}){const t=$i(e),s={...t,...n};return{params:t,residual:e.filter(o=>!Bi(s,o))}}function Ki(e,n,t){if(n.length===0)return e;const s=[...n];return e.filter(o=>{const i=Cn(o);return wn({...i,accountId:i.accountId??t},s)})}const Vi=50,Hi=new Map(es().categories.filter(e=>e.id!=="all").map(e=>[e.id,e.label])),is=c.createContext(null);function ht(){const e=c.useContext(is);if(!e)throw new Error("MailboxPane.* must be used inside <MailboxPane>");return e}function Ui({mailboxId:e,thread:n,children:t}){const s=Je(),o=Ye(),i=n?.threadId,l=n?.messageId,a=Mt(),{accounts:u,searchQuery:d,intelligenceOpen:f,onToggleIntelligence:m}=Vt(),g=Us(),b=ko(d),y=b.length>0,{freeText:w,tokens:M}=qs(b,g),[p,x]=c.useState("all"),[k,C]=c.useState(new Set),j=c.useMemo(()=>({category:p,attributes:k}),[p,k]),N=c.useMemo(()=>Fi(j),[j]),A=y||zi(j),{params:z,residual:Z}=Wi(M,N),E={order:"desc",limit:Vi,...w?{query:w}:{},...z,...N},L={category:E.category,unread:E.unread,starred:E.starred,attachments:E.attachments},he=A?Ws({path:{mailboxId:e},query:E}):Ks({path:{mailboxId:e},query:{order:"desc"}}),{data:F,isLoading:ee,isError:Ee,error:se,refetch:Y,fetchNextPage:Ae,hasNextPage:ne,isFetchingNextPage:T}=Qn({queryKey:he,queryFn:async({pageParam:S})=>{if(A){const{data:W}=await Vs({path:{mailboxId:e},query:{...E,continuationToken:S},throwOnError:!0});return W}const{data:_}=await Hs({path:{mailboxId:e},query:{order:"desc",continuationToken:S},throwOnError:!0});return _},initialPageParam:void 0,getNextPageParam:S=>S.continuationToken,placeholderData:(S,_)=>Pi(_?.queryKey,L)?S:void 0}),{accountId:P,isLoading:Se}=kn(e),fe=yo({accounts:u}),O=Ki(jn(Ai(F?.pages.flatMap(S=>S.items??[])??[])),Z,P),me=c.useCallback(S=>{x(S)},[]),Oe=c.useCallback(S=>{C(_=>{const W=new Set(_);return W.has(S)?W.delete(S):W.add(S),W})},[]),ye=c.useCallback(()=>{x("all"),C(new Set)},[]),Ie=Hi.get(p),ge=Ie?{label:Ie,reach:Z.length>0?"loaded-pages":Di(E),onClear:ye}:void 0,Pe=i?O.find(S=>S.messageId===l)??O.find(S=>S.threadId===i):void 0,$e=Mn(i,l),H=Pe??$e,$=l??H?.messageId,U=c.useMemo(()=>{if(i)return{threadId:i,mailboxId:H?.mailboxId??e,subject:H?.subject,messageId:$,authenticity:H?.authenticity}},[i,H,$,e]),K=c.useCallback(()=>{s({to:"/mail/$mailboxId",params:{mailboxId:e},search:S=>S,hash:o})},[e,s,o]),oe=c.useCallback(S=>{s({to:"/mail/$mailboxId/$threadId/$messageId",params:{mailboxId:e,...S},search:_=>_,hash:o})},[e,s,o]),D=c.useCallback(S=>{$&&S.includes($)&&K()},[$,K]),{deleteMessages:X,isPending:pe}=Ft({mailboxId:e,onAfterOptimisticRemove:D}),{moveMessages:Xe,isPending:Ne}=Dt({mailboxId:e,accountId:P,onAfterOptimisticRemove:D}),Be=Tn(),{listCommandsRef:ie,onTriageContextChange:ft,focusedMessageId:Ze,selectedIds:Ce}=Be,R=O.find(S=>S.messageId===Ze)??H,ze=Io({accounts:u})??0,Fe=Rn({thread:H,mailboxId:e,accountId:P,onAfterOptimisticRemove:D}),{draftsMailboxId:et}=En(P),I=et!==void 0&&et===e,{archiveMailboxId:mt}=An(P),We=On(),we=eo(),V=c.useMemo(()=>to(we,i,$),[we,i,$]),le=c.useMemo(()=>{if(R)return S=>we({threadId:R.threadId,messageId:R.messageId,mode:S})},[we,R]),tt=so(),xe=no(),ce=oo(),ke=c.useCallback(S=>S?We(S):[],[We]),{toggleStar:be}=Nn({threadId:R?.threadId??"",mailboxId:e}),{toggleReadFor:Ke}=Jt({mailboxId:e,accountId:P}),{junkMailboxId:te}=Gt(P),Ve=te!=null&&te===e,q=Yt(te,e),{candidates:re}=Ei(Ve?te:void 0),{moveMessages:He}=Dt({mailboxId:e,threadId:R?.threadId,accountId:P,onAfterOptimisticRemove:D}),{deleteMessages:Ue}=Ft({mailboxId:e,threadId:R?.threadId,onAfterOptimisticRemove:D}),{addressId:ve,address:je}=zn(R),{updateFlags:Me}=Fn({addressId:ve,senderEmail:R?.fromEmail??void 0}),B=c.useCallback(()=>le?.("reply"),[le]),gt=c.useCallback(()=>le?.("reply-all"),[le]),pt=c.useCallback(()=>le?.("forward"),[le]),de=c.useCallback(()=>ke(R),[ke,R]),De=c.useCallback(()=>{if(ie.current?.requestVerb("delete"))return;const S=de();S.length>0&&Ue(S)},[ie,de,Ue]),st=c.useCallback(()=>{if(ie.current?.requestVerb("junk")||!q)return;const S=de();S.length!==0&&(Dn(a,{count:S.length,senderTrust:R?.senderTrust??"unknown",wasRescuable:R?_n(R):!1}),He(S,q))},[ie,q,de,He,a,R]),nt=c.useCallback(()=>{if(Ce.length>0){const S=!(R?.hasStars??!1),_=new Set(Ce);for(const W of O)_.has(W.messageId)&&W.hasStars!==S&&be(W.messageId,W.hasStars);return}R&&be(R.messageId,R.hasStars)},[Ce,O,R,be]),ot=c.useCallback(()=>{if(ie.current?.requestVerb("markRead"))return;const S=de();if(S.length===0)return;const _=!(R?.isRead??!1);Ke(S,_)},[ie,de,R,Ke]),it=c.useCallback(()=>{if(!ve)return;const S=je?.flags?.muted?.value!==!0;Me({muted:{value:S}})},[ve,je,Me]),ue=c.useCallback(()=>{if(!ve)return;const S=je?.flags?.vip?.value!==!0;Me({vip:{value:S}})},[ve,je,Me]),rt=c.useCallback(()=>{f||m()},[f,m]),Te=c.useCallback(S=>{s({to:S})},[s]),_e=I?"drafts":mt===e?"archive":te===e?"junk":"inbox",at=c.useRef("");c.useEffect(()=>{const S=at.current;at.current=b,b.length>0&&S.length===0&&a.recordEvent("search.submitted",{mailboxType:_e})},[b,_e,a]);const{goBack:xt,nextMessageId:qe,previousMessageId:bt}=Ln({context:Be,orderedIds:O.map(S=>S.messageId),selectedMessageId:$,enabled:!tt&&!xe,onClose:K,handlers:{reply:B,replyAll:gt,forward:pt,delete:De,toggleStar:nt,toggleRead:ot,muteSender:it,blockSender:rt,vipSender:ue,markJunk:st,toggleIntelligence:H?m:void 0,compose:ce,goBrief:()=>Te("/mail/brief"),goInbox:()=>Te("/mail/brief"),goSent:()=>Te("/mail/brief"),goFlagged:()=>Te("/mail/flagged"),goSettings:()=>Te("/settings")}}),lt=S=>{if(!S)return;const _=O.find(W=>W.messageId===S);return _?{threadId:_.threadId,messageId:S}:void 0},vt={mailboxId:e,selectedMessageId:$,selectedThread:H,conversation:U,onOpenThread:oe,threads:O,isLoading:ee,isError:Ee,error:se,mailboxAccountId:P,mailboxAccountLoading:Se,mailboxName:fe,unreadCount:ze,isDraftsMailbox:I,isSpamFolder:Ve,rescueCandidates:re,filterCategory:p,filterAttributes:k,onSelectFilterCategory:me,onToggleFilterAttribute:Oe,onClearFilters:ye,listFilter:ge,intelligenceOpen:f,onToggleIntelligence:m,handleDeselectIfRemoved:D,searchPredicate:y&&Z.length===0?E:void 0,onDeleteMessages:X,onMoveMessages:Xe,isDeleting:pe,isMoving:Ne,onLoadMore:Ae,hasMore:ne,isLoadingMore:T,onTriageContextChange:ft,listCommandsRef:ie,onRetry:()=>Y(),onReply:V,onToolbarDelete:Fe.deleteThread,onToolbarStar:Fe.toggleStar,onToolbarMove:Fe.moveThread,onBack:xt,nextThread:lt(qe),previousThread:lt(bt)};return r.jsx(is.Provider,{value:vt,children:t})}function rs(){const{mailboxId:e,selectedMessageId:n,threads:t,isLoading:s,isError:o,error:i,onDeleteMessages:l,onMoveMessages:a,isDeleting:u,isMoving:d,onLoadMore:f,hasMore:m,isLoadingMore:g,mailboxAccountId:b,mailboxName:y,unreadCount:w,isDraftsMailbox:M,isSpamFolder:p,rescueCandidates:x,onTriageContextChange:k,listCommandsRef:C,onRetry:j,filterCategory:N,filterAttributes:A,onSelectFilterCategory:z,onToggleFilterAttribute:Z,onClearFilters:E,listFilter:L,searchPredicate:he}=ht(),{searchQuery:F,searchInput:ee,accounts:Ee,resultFolderIndex:se}=Vt(),Y=Co(),Ae=Je(),ne=Ye(),T=y??"Inbox",P=c.useMemo(()=>es(),[]),Se=c.useMemo(()=>b?[b]:[],[b]),{hasNewMail:fe}=Js(),{state:O,errorMessage:me,refresh:Oe}=Gs(Se,{onSettled:j}),ye=c.useMemo(()=>r.jsx(Ys,{state:O,onRefresh:Oe,label:`Refresh ${T}`,errorMessage:me,hasUpdate:fe(Se)}),[O,Oe,T,me,fe,Se]),Ie=c.useMemo(()=>t.map(D=>Kn(D,se)),[t,se]),{hits:ge,isLoading:Pe}=mo({mailboxId:e,filterCategory:N}),$e=c.useMemo(()=>Vn(ge,t.map(D=>D.threadId),se),[ge,t,se]),H=c.useCallback(D=>{const X=D.threadId??t.find(pe=>pe.messageId===D.id)?.threadId;X&&Ae({to:"/mail/$mailboxId/$threadId/$messageId",params:{mailboxId:D.mailboxId??e,threadId:X,messageId:D.id},search:pe=>({...pe,q:ee||void 0}),hash:ne})},[e,Ae,ne,ee,t]);if(M&&b)return r.jsx(Uo,{mailboxId:e,accountId:b,selectedMessageId:n,imapThreads:t,title:y??"Drafts",unreadCount:w??void 0});const $=r.jsx(wi,{mailboxId:e,threads:t,selectedMessageId:n,isLoading:s,isError:o,error:i,onRetry:j,searchQuery:F,searchPredicate:he,onDeleteMessages:l,isDeleting:u,isMoving:d,onLoadMore:f,hasMore:m,isLoadingMore:g,accountId:b,listTitle:T,listFilter:L,listScopeLabel:T,hideHeader:!0,onTriageContextChange:k,commandsRef:C}),U=Ee[0]?.accountId,K=Y==="phone"&&U?r.jsx(Mi,{accountId:U,children:$}):$,oe=p&&x.length>0&&b?r.jsx(Ti,{accountId:b,currentMailboxId:e,candidates:x,onMove:a,children:K}):K;return r.jsx(Jn,{title:T,unreadCount:w,preset:P,selectedCategory:N,activeFilters:A,onSelectCategory:z,onToggleFilter:Z,onClearFilters:E,searchResults:Ie,searchLoading:s,relatedResults:$e,relatedLoading:Pe,onSelectSearchResult:H,searchResultsInBody:!0,refreshControl:ye,children:oe})}function qi(){const{mailboxId:e,mailboxAccountId:n,mailboxAccountLoading:t,selectedThread:s,conversation:o,onReply:i,onToolbarDelete:l,onToolbarStar:a,onToolbarMove:u,handleDeselectIfRemoved:d}=ht(),f=!!o,m=Bn(o?.threadId),g=c.useRef(null),{railFits:b,openRail:y}=m;c.useEffect(()=>{if(!b)return;const M=s?.messageId??null;M&&g.current!==M&&s?.authenticity?.dkimMismatch&&(g.current=M,y())},[b,y,s?.messageId,s?.authenticity?.dkimMismatch]);const w=o?r.jsx(Xt,{threadId:o.threadId,mailboxId:o.mailboxId,subject:o.subject,selectedMessageId:o.messageId,authenticity:o.authenticity,onOpenIntelligence:m.open}):r.jsx(Qs,{});return r.jsxs(r.Fragment,{children:[r.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[r.jsx(Wn,{hasThread:f,messageId:o?.messageId,intelligenceOpen:m.isShowing,canToggleIntelligence:m.canToggle,onToggleIntelligence:m.toggle,onReply:i?()=>i("reply"):void 0,onReplyAll:i?()=>i("reply-all"):void 0,onForward:i?()=>i("forward"):void 0,onDelete:f?l:void 0,onToggleStar:f?a:void 0,isStarred:s?.hasStars,moveContext:f&&n?{accountId:n,currentMailboxId:e,onMove:u}:void 0,moveContextLoading:t}),r.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:w})]}),r.jsx(Zt,{isOpen:m.drawerOpen,onClose:m.closeDrawer,thread:s,mailboxId:e,accountId:n,onAfterOptimisticRemove:d})]})}function Qi(){const{mailboxId:e,mailboxAccountId:n,selectedThread:t,onToggleIntelligence:s,handleDeselectIfRemoved:o}=ht();return r.jsx($n,{onClose:s,thread:t,mailboxId:e,accountId:n,onAfterOptimisticRemove:o})}function Ji(){const{mailboxId:e,mailboxAccountId:n,selectedThread:t,conversation:s,onOpenThread:o,onBack:i,nextThread:l,previousThread:a,handleDeselectIfRemoved:u}=ht(),d=Pn(s?.threadId??null);return s?r.jsxs(r.Fragment,{children:[r.jsx(Xt,{threadId:s.threadId,mailboxId:s.mailboxId,subject:s.subject,selectedMessageId:s.messageId,authenticity:s.authenticity,onBack:i,onOpenIntelligence:d.toggle,onSwipeNext:l?()=>o(l):void 0,onSwipePrevious:a?()=>o(a):void 0,mobileIntelligenceOpen:d.isOpen}),r.jsx(Zt,{isOpen:d.isOpen,onClose:d.close,thread:t,mailboxId:e,accountId:n,onAfterOptimisticRemove:u})]}):r.jsx(rs,{})}const Sr=Object.assign(Ui,{List:rs,Reading:qi,Intelligence:Qi,Phone:Ji});export{Sr as M};
1
+ import{j as r,b7 as Ss,as as kt,B as ae,S as ys,b as Re,at as Bt,r as c,C as Is,d as Cs,aU as ws,m as Je,n as Wt,s as jt,t as ks,a7 as Kt,b8 as js,b9 as Ms,I as Ts,h as Rs,T as Es,ba as As,bb as Os,bc as Ns,a5 as zs,aF as Fs,aG as Ds,g as _s,W as Mt,bd as Ls,K as Ps,q as $s,be as Bs,l as Vt,bf as Ws,z as Ks,bg as Vs,aZ as Hs}from"./index-CL-RwCQv.js";import{u as Us,p as qs,R as Qs}from"./useSearchTokenContext-Bjl7abMO.js";import{u as Js,a as Gs,R as Ys}from"./useRefreshControl-Cw1ynDsF.js";import{C as Ht,a as Ut,c as qt,j as Xs,M as Zs,t as Qt,u as en,b as tn,d as Jt,e as Gt,f as sn,g as nn,h as on,i as rn,k as an,l as zt,n as ln,m as cn,o as dn,p as un,q as hn,S as fn,r as mn,s as gn,v as pn,w as Yt,x as xn,y as bn,z as vn,A as Sn,B as yn,D as In,E as Cn,F as wn,G as kn,H as jn,I as Mn,J as Ft,K as Dt,L as Tn,N as Rn,O as En,P as An,Q as On,R as Nn,T as zn,U as Fn,V as Dn,W as _n,X as Ln,Y as Pn,Z as Xt,_ as Zt,$ as $n,a0 as Bn,a1 as Wn,a2 as es,a3 as Kn,a4 as Vn}from"./MailListHeader-DlgEG6TF.js";import{S as Hn,M as Un,a as qn,u as Qn,b as Jn}from"./MailViewChrome-DZUl5LEF.js";import{A as Tt}from"./avatar-1DfPRcS3.js";import{b as Ge,c as Gn,d as Yn}from"./format-HasNd5qT.js";import{k as Xn,n as Zn,o as Ye,p as eo,r as to,f as so,h as no,u as oo}from"./useMessageBodyContent-BWmVC5nn.js";import{N as io}from"./NavMenuButton-CYCM2eVH.js";import{C as ro}from"./confirm-dialog-DQceA3_j.js";import{f as ao}from"./ErrorState-wOvkM72u.js";import{a as lo}from"./useLabels-VkA4O1Ty.js";import{a as co,D as uo,u as ho}from"./useMediaQuery-CrSO3kMK.js";import{L as fo,u as mo}from"./useSemanticSearch-BuX7JrjR.js";import{S as ut}from"./shield-check-hS8zutR7.js";import{B as go}from"./bottom-sheet-DQx2Jee-.js";import{C as po}from"./circle-help-DidkDhiF.js";import{C as xo}from"./circle-check-B-uZAWo0.js";import{a as bo,b as vo,f as So}from"./move-options-gmyuDePe.js";import{j as yo,k as Io,e as Co}from"./search-token-index-BPaeb0nT.js";import{M as wo}from"./enums-B_igRgfI.js";import{n as ko}from"./search-query-Cr_ZXBCp.js";const jo=({children:e,onRefresh:n,isRefreshing:t})=>co(uo)?e:r.jsx(Ss,{onRefresh:n,isPullable:!t,children:e}),Mo=e=>e===1?"message":"messages";function To({count:e,onReview:n,onDismiss:t,actionLabel:s="Review & rescue"}){return r.jsx(kt,{tone:"info",variant:"soft",onDismiss:t,children:r.jsxs("div",{className:"flex flex-col gap-2",children:[r.jsxs("p",{className:"flex items-start gap-2 text-sm text-fg",children:[r.jsx(ut,{className:"mt-0.5 size-4 shrink-0 text-positive","aria-hidden":!0}),r.jsxs("span",{children:[r.jsx("span",{className:"font-semibold text-fg",children:`${e} ${Mo(e)} here`})," ","may not be spam — they're from senders we can verify."]})]}),r.jsx(ae,{variant:"primary",size:"sm",onClick:n,className:"self-start",children:s})]})})}const Ro=(e,n)=>e==="vip"?"vip":e==="unknown"&&n==="md"?"unknown-pill":"hidden",ts=({senderTrust:e,size:n="sm",className:t})=>{const s=Ro(e,n);return s==="vip"?r.jsx(ys,{className:Re("text-warning shrink-0",n==="sm"&&"size-3.5",n==="md"&&"size-4",t),"aria-label":"VIP sender","data-testid":"sender-trust-vip"}):s==="unknown-pill"?r.jsx("span",{className:Re("inline-flex items-center rounded border border-dashed border-fg-subtle/40 font-medium uppercase tracking-wide text-fg-muted/80 shrink-0","px-2 py-0.5 text-xs",t),title:"First message from this sender","aria-label":"First message from this sender","data-testid":"sender-trust-unknown",children:"new"}):null};function Eo({candidate:e,selected:n,onToggle:t,hideSender:s=!1}){const{senderName:o,senderAddress:i,subject:l,snippet:a,trustReason:u,trustSubReason:d,senderTrust:f}=e;return r.jsxs("label",{className:Re("flex w-full cursor-pointer items-start gap-3 px-3 py-2.5 text-left transition-colors",s&&"pl-11",n?"bg-positive/10":"bg-surface hover:bg-surface-sunken"),children:[r.jsx(Ht,{className:"mt-0.5",checked:n,onChange:t,"aria-label":`${n?"Deselect":"Select"} ${s?l:`message from ${o}`}`}),!s&&r.jsx(Tt,{name:o,email:i,size:"sm"}),r.jsxs("span",{className:"min-w-0 flex-1",children:[!s&&r.jsxs("span",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"truncate text-sm font-medium text-fg",children:o}),f&&r.jsx(ts,{senderTrust:f,size:"sm"}),r.jsx("span",{className:"truncate text-2xs text-fg-subtle",children:i})]}),r.jsx("span",{className:"block truncate text-sm text-fg-muted",children:l}),r.jsx("span",{className:"block line-clamp-1 text-xs text-fg-subtle",children:a}),!s&&r.jsxs("span",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[r.jsxs(Bt,{tone:"positive",children:[r.jsx(ut,{className:"size-3","aria-hidden":!0}),u]}),r.jsx("span",{className:"text-2xs text-fg-subtle",children:d})]})]})]})}const Ao=e=>{const n=new Map,t=[];for(const s of e){const o=(s.senderAddress||s.senderName).toLowerCase(),i=n.get(o);if(i){i.messages.push(s);continue}n.set(o,{key:o,senderName:s.senderName,senderAddress:s.senderAddress,trustReason:s.trustReason,trustSubReason:s.trustSubReason,senderTrust:s.senderTrust,messages:[s]}),t.push(o)}return t.map(s=>n.get(s)).sort((s,o)=>o.messages.length-s.messages.length)},Oo=(e,n)=>{const t=e.messages.filter(s=>n.has(s.id)).length;return t===0?"none":t===e.messages.length?"all":"some"},_t=e=>e===1?"message":"messages";function No({group:e,selected:n,onToggleGroup:t,onToggleMessage:s}){const[o,i]=c.useState(!1),l=Oo(e,n),a=e.messages.length,u=o?Is:Cs;return r.jsxs("div",{className:Re(l!=="none"?"bg-positive/10":"bg-surface"),children:[r.jsxs("div",{className:"flex w-full items-start gap-3 px-3 py-2.5",children:[r.jsx(Ht,{className:"mt-0.5",checked:l==="all",indeterminate:l==="some",onChange:()=>t(e,l!=="all"),"aria-label":`${l==="all"?"Deselect":"Select"} all ${a} ${_t(a)} from ${e.senderName}`}),r.jsx(Tt,{name:e.senderName,email:e.senderAddress,size:"sm"}),r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"truncate text-sm font-medium text-fg",children:e.senderName}),e.senderTrust&&r.jsx(ts,{senderTrust:e.senderTrust,size:"sm"}),r.jsx("span",{className:"truncate text-2xs text-fg-subtle",children:e.senderAddress})]}),r.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[r.jsxs(Bt,{tone:"positive",children:[r.jsx(ut,{className:"size-3","aria-hidden":!0}),e.trustReason]}),r.jsx("span",{className:"text-2xs text-fg-subtle",children:e.trustSubReason})]})]}),r.jsxs("button",{type:"button",onClick:()=>i(d=>!d),"aria-expanded":o,className:"flex shrink-0 items-center gap-1 rounded-md px-1.5 py-1 text-2xs text-fg-muted transition-colors hover:bg-surface-sunken hover:text-fg",children:[`${a} ${_t(a)}`,r.jsx(u,{className:"size-3.5","aria-hidden":!0})]})]}),o&&r.jsx("div",{className:"divide-y divide-line border-t border-line",children:e.messages.map(d=>r.jsx(Eo,{candidate:d,selected:n.has(d.id),onToggle:()=>s(d.id),hideSender:!0},d.id))})]})}const Rt=e=>e===1?"message":"messages",zo=(e,n)=>`Moves ${e===1?"this message":`these ${e} ${Rt(e)}`} out of Spam to ${n} now. Nothing later.`,wt=(e,n)=>e.find(t=>t.id===n)?.label??"Inbox";function Fo(){return r.jsx(kt,{tone:"info",variant:"soft",children:r.jsx("p",{className:"text-2xs text-fg-muted",children:"We list a message here only when we can confirm the sender is who they say — usually someone you've emailed before, write to often, or a service that consistently checks out. We never guess from words in the subject. Anything we can't confirm stays in Spam."})})}function Do({candidates:e,selected:n,onToggle:t,onToggleGroup:s,onSelectAll:o,onSelectNone:i,onContinue:l,onCancel:a}){const[u,d]=c.useState(!1),f=n.size,m=c.useMemo(()=>Ao(e),[e]);return r.jsxs("div",{className:"flex min-h-0 flex-col",children:[r.jsxs("div",{className:"px-row-inset pb-2 pt-1",children:[r.jsxs("div",{className:"flex items-start justify-between gap-2",children:[r.jsxs("h2",{className:"flex items-center gap-2 text-sm font-semibold text-fg",children:[r.jsx(ut,{className:"size-4 text-positive","aria-hidden":!0}),"Rescue from Spam"]}),r.jsx(ae,{variant:"ghost",size:"sm",icon:r.jsx(po,{className:"size-3.5"}),onClick:()=>d(g=>!g),className:"-mr-1.5 -mt-0.5",children:"Why these?"})]}),r.jsx("p",{className:"mt-1 text-2xs text-fg-subtle",children:"These look safe — from senders we can verify. Uncheck any sender that belongs in Spam, or open a sender to pick individual messages."}),u&&r.jsx("div",{className:"mt-2",children:r.jsx(Fo,{})})]}),r.jsxs("div",{className:"flex items-center justify-between px-row-inset pb-1.5",children:[r.jsx("span",{className:"text-2xs font-medium text-fg-muted",children:`${f} of ${e.length} selected · ${m.length} ${m.length===1?"sender":"senders"}`}),r.jsxs("span",{className:"flex gap-1",children:[r.jsx(ae,{variant:"ghost",size:"sm",onClick:o,children:"Select all"}),r.jsx(ae,{variant:"ghost",size:"sm",onClick:i,children:"Select none"})]})]}),r.jsx("div",{className:"min-h-0 flex-1 divide-y divide-line overflow-y-auto border-y border-line",children:m.map(g=>r.jsx(No,{group:g,selected:n,onToggleGroup:s,onToggleMessage:t},g.key))}),r.jsxs("div",{className:"space-y-2 border-t border-line bg-surface px-row-inset py-3",children:[r.jsx(ae,{variant:"primary",onClick:l,className:"h-11 w-full font-semibold",children:`Continue with ${f} ${Rt(f)}`}),r.jsx(ae,{variant:"ghost",onClick:a,className:"h-11 w-full",children:"Cancel"})]})]})}function _o({count:e,folders:n,delimiter:t,destination:s,onPick:o,onMove:i,onBack:l}){const[a,u]=c.useState(!1);return r.jsxs("div",{className:"flex min-h-0 flex-col",children:[r.jsxs("div",{className:"px-row-inset pb-2 pt-1",children:[r.jsx("h2",{className:"text-sm font-semibold text-fg",children:"Where should they go?"}),r.jsx("p",{className:"mt-1 text-2xs text-fg-subtle",children:"Pick a folder, then we move them out of Spam."})]}),r.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-y-auto px-row-inset py-2",children:a?r.jsx("div",{className:"flex min-h-0 flex-1 overflow-hidden rounded-xl border border-line bg-surface",children:r.jsx(ws,{folders:n,selectedId:s,delimiter:t,onSelect:o,onCancel:()=>u(!1)})}):r.jsxs("div",{className:"rounded-xl border border-line bg-surface-sunken p-3",children:[r.jsx("p",{className:"text-2xs text-fg-subtle",children:"Destination"}),r.jsx("p",{className:"mt-0.5 text-sm font-medium text-fg",children:wt(n,s)}),r.jsx(ae,{variant:"ghost",size:"sm",onClick:()=>u(!0),className:"mt-2 px-0",children:"Move to a different folder"})]})}),r.jsxs("div",{className:"space-y-2 border-t border-line bg-surface px-row-inset py-3",children:[r.jsx("p",{className:"text-2xs text-fg-subtle",children:zo(e,wt(n,s))}),r.jsx(ae,{variant:"primary",onClick:i,className:"h-11 w-full font-semibold",children:`Move ${e} out of Spam`}),r.jsx(ae,{variant:"ghost",onClick:l,className:"h-11 w-full",children:"Back"})]})]})}function Lo({count:e,destinationLabel:n,onClose:t}){return r.jsxs("div",{className:"flex min-h-0 flex-col",children:[r.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 px-row-inset py-10 text-center",children:[r.jsx(xo,{className:"size-10 text-positive","aria-hidden":!0}),r.jsx("p",{className:"text-base font-semibold text-fg",children:`Moved ${e} ${Rt(e)} out of Spam.`}),r.jsx("p",{className:"text-2xs text-fg-subtle",children:`You'll find them in ${n}.`})]}),r.jsx("div",{className:"border-t border-line bg-surface px-row-inset py-3",children:r.jsx(ae,{variant:"primary",onClick:t,className:"h-11 w-full font-semibold",children:"Done"})})]})}function Po({open:e,candidates:n,defaultDestinationId:t,availableFolders:s,delimiter:o,onConfirmMove:i,onCancel:l}){const[a,u]=c.useState("review"),[d,f]=c.useState(()=>e?new Set(n.map(C=>C.id)):new Set),[m,g]=c.useState(t),[b,y]=c.useState(0),w=c.useRef(!1);c.useEffect(()=>{e&&!w.current&&(u("review"),f(new Set(n.map(C=>C.id))),g(t),y(0)),w.current=e},[e,n,t]);const M=d.size,p=C=>{f(j=>{const N=new Set(j);return N.has(C)?N.delete(C):N.add(C),N})},x=(C,j)=>{f(N=>{const A=new Set(N);for(const z of C.messages)j?A.add(z.id):A.delete(z.id);return A})},k=()=>{const C=Array.from(d);y(C.length),i(C,m),u("done")};return r.jsxs(go,{open:e,onClose:l,dismissLabel:"Close rescue",children:[a==="review"&&r.jsx(Do,{candidates:n,selected:d,onToggle:p,onToggleGroup:x,onSelectAll:()=>f(new Set(n.map(C=>C.id))),onSelectNone:()=>f(new Set),onContinue:()=>u("destination"),onCancel:l}),a==="destination"&&r.jsx(_o,{count:M,folders:s,delimiter:o,destination:m,onPick:g,onMove:k,onBack:()=>u("review")}),a==="done"&&r.jsx(Lo,{count:b,destinationLabel:wt(s,m),onClose:l})]})}function $o(e){const n=e.toAddresses.join(", ");return{id:e.outboxMessageId,accountId:e.accountId,fromName:e.fromName??e.fromAddress??"Me",fromEmail:e.fromAddress??"",subject:e.subject??"(No subject)",snippet:n?`To: ${n}`:"(No recipients)",timeLabel:Ge(e.updatedAt),isRead:!0}}function Bo(e){return{id:e.messageId,accountId:e.accountId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:Ge(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0}}function Wo({outboxMessages:e,accountId:n,imapThreads:t}){const s=e.filter(l=>l.status==="draft"&&l.accountId===n).map($o),o=t.map(Bo),i=[];return s.length>0&&i.push({id:"remit-drafts",label:"Not yet sent (Remit)",threads:s}),o.length>0&&i.push({id:"imap-drafts",label:"On the server",threads:o}),i}const Ko=({label:e,count:n})=>r.jsxs("div",{className:"sticky top-0 z-10 flex items-baseline justify-between border-b border-line bg-surface-sunken px-row-inset py-1",children:[r.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e}),r.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:n})]}),Vo=({row:e,isSelected:n,onOpen:t,onDelete:s,isDeleting:o})=>r.jsxs("button",{type:"button",onClick:()=>t(e.id),className:Re("group",qt({active:n})),children:[r.jsx(Rs,{className:"size-7 shrink-0 text-fg-muted mt-0.5"}),r.jsx(Ut,{thread:e}),r.jsx("div",{className:"flex items-center gap-1 shrink-0",children:r.jsx("button",{type:"button",onClick:i=>{i.stopPropagation(),s(e.id)},disabled:o,className:"p-1.5 rounded-md text-fg-muted hover:text-danger hover:bg-surface-raised transition-colors opacity-0 group-hover:opacity-100 focus:opacity-100",title:"Delete draft",children:r.jsx(Es,{className:"size-3.5"})})})]}),Ho=({row:e,isSelected:n,onOpen:t})=>{const s=!e.isRead;return r.jsxs("button",{type:"button",onClick:()=>t(e.id),className:Re("group",qt({active:n})),children:[s&&r.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),r.jsx(Tt,{name:e.fromName,email:e.fromEmail,size:"sm"}),r.jsx(Ut,{thread:e})]})};function Uo({mailboxId:e,accountId:n,selectedMessageId:t,imapThreads:s,title:o,unreadCount:i}){const l=Xn(),a=Zn(),u=Je(),d=Ye(),f=Wt(),{data:m}=jt(ks()),g=c.useMemo(()=>Wo({outboxMessages:m?.items??[],accountId:n,imapThreads:s}),[m?.items,n,s]),b=Kt({...Ms(),onSuccess:()=>{f.invalidateQueries({queryKey:js()})}}),y=p=>{b.mutate({path:{outboxMessageId:p}})},w=p=>{const x=s.find(k=>k.messageId===p)?.threadId;x&&u({to:"/mail/$mailboxId/$threadId/$messageId",params:{mailboxId:e,threadId:x,messageId:p},search:k=>k,hash:d})},M=g.length===0;return r.jsxs("section",{className:"flex h-full w-full flex-col bg-surface",children:[r.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[r.jsx(io,{}),r.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:o}),(i??0)>0&&r.jsxs("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:[i," unread"]})]}),r.jsx("div",{className:"flex-1 overflow-y-auto",children:M?r.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-2 text-center px-4",children:[r.jsx(Ts,{className:"size-8 text-fg-subtle"}),r.jsx("p",{className:"text-sm font-medium text-fg",children:"No drafts"}),r.jsx("p",{className:"text-xs text-fg-subtle",children:"Messages you start composing will appear here."})]}):g.map(p=>r.jsxs("div",{children:[p.label&&r.jsx(Ko,{label:p.label,count:p.threads.length}),r.jsx("div",{className:"divide-y divide-line",children:p.threads.map(x=>p.id==="remit-drafts"?r.jsx(Vo,{row:x,isSelected:x.id===l,onOpen:a,onDelete:y,isDeleting:b.isPending},x.id):r.jsx(Ho,{row:x,isSelected:x.id===t,onOpen:w},x.id))})]},p.id))})]})}function qo(e,n,t){const s=new Array(e);return new Proxy(s,{get(o,i,l){if(typeof i=="string"){const a=i.charCodeAt(0);if(a>=48&&a<=57){const u=+i;if(Number.isInteger(u)&&u>=0&&u<e){let d=o[u];if(!d){const f=n[u*2];d=o[u]={index:u,key:t(u),start:f,size:n[u*2+1],end:f+n[u*2+1],lane:0}}return d}}if(i==="length")return e}return Reflect.get(o,i,l)}})}function Le(e,n,t){let s=t.initialDeps??[],o,i=!0;function l(){const a=e();return(a.length!==s.length||a.some((d,f)=>s[f]!==d))&&(s=a,o=n(...a),t?.onChange&&!(i&&t.skipInitialOnChange)&&t.onChange(o),i=!1),o}return l.updateDeps=a=>{s=a},l}function Lt(e,n){if(e===void 0)throw new Error("Unexpected undefined");return e}const Qo=(e,n)=>Math.abs(e-n)<1.01,Jo=(e,n,t)=>{let s;return function(...o){e.clearTimeout(s),s=e.setTimeout(()=>n.apply(this,o),t)}};let Qe;const It=()=>{if(Qe!==void 0)return Qe;if(typeof navigator>"u")return Qe=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return Qe=!0;const e=navigator.maxTouchPoints;return Qe=navigator.platform==="MacIntel"&&e!==void 0&&e>0},Pt=e=>{const{offsetWidth:n,offsetHeight:t}=e;return{width:n,height:t}},Go=e=>e,Yo=e=>{const n=Math.max(e.startIndex-e.overscan,0),s=Math.min(e.endIndex+e.overscan,e.count-1)-n+1,o=new Array(s);for(let i=0;i<s;i++)o[i]=n+i;return o},Xo=(e,n)=>{const t=e.scrollElement;if(!t)return;const s=e.targetWindow;if(!s)return;const o=l=>{const{width:a,height:u}=l;n({width:Math.round(a),height:Math.round(u)})};if(o(Pt(t)),!s.ResizeObserver)return()=>{};const i=new s.ResizeObserver(l=>{const a=()=>{const u=l[0];if(u?.borderBoxSize){const d=u.borderBoxSize[0];if(d){o({width:d.inlineSize,height:d.blockSize});return}}o(Pt(t))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(a):a()});return i.observe(t,{box:"border-box"}),()=>{i.unobserve(t)}},dt={passive:!0},Zo=typeof window>"u"?!0:"onscrollend"in window,ei=(e,n,t)=>{const s=e.scrollElement;if(!s)return;const o=e.targetWindow;if(!o)return;const i=e.options.useScrollendEvent&&Zo;let l=0;const a=i?null:Jo(o,()=>n(l,!1),e.options.isScrollingResetDelay),u=m=>()=>{l=t(s),a?.(),n(l,m)},d=u(!0),f=u(!1);return s.addEventListener("scroll",d,dt),i&&s.addEventListener("scrollend",f,dt),()=>{s.removeEventListener("scroll",d),i&&s.removeEventListener("scrollend",f)}},ti=(e,n)=>ei(e,n,t=>{const{horizontal:s,isRtl:o}=e.options;return s?t.scrollLeft*(o&&-1||1):t.scrollTop}),si=(e,n,t)=>{if(t.options.useCachedMeasurements){const s=t.indexFromElement(e),o=t.options.getItemKey(s);return t.itemSizeCache.get(o)??t.options.estimateSize(s)}if(n?.borderBoxSize){const s=n.borderBoxSize[0];if(s)return Math.round(s[t.options.horizontal?"inlineSize":"blockSize"])}if(!n){const s=t.indexFromElement(e),o=t.options.getItemKey(s),i=t.itemSizeCache.get(o);if(i!==void 0)return i}return e[t.options.horizontal?"offsetWidth":"offsetHeight"]},ni=(e,{adjustments:n=0,behavior:t},s)=>{var o,i;(i=(o=s.scrollElement)==null?void 0:o.scrollTo)==null||i.call(o,{[s.options.horizontal?"left":"top"]:e+n,behavior:t})},oi=ni;class ii{constructor(n){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this._flatMeasurements=null,this.itemSizeCache=new Map,this.itemSizeCacheVersion=0,this.laneAssignments=new Map,this.pendingMin=null,this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.pendingScrollAnchor=null,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._intendedScrollOffset=null,this.elementsCache=new Map,this.now=()=>{var t,s,o;return((o=(s=(t=this.targetWindow)==null?void 0:t.performance)==null?void 0:s.now)==null?void 0:o.call(s))??Date.now()},this.observer=(()=>{let t=null;const s=()=>t||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:t=new this.targetWindow.ResizeObserver(o=>{o.forEach(i=>{const l=()=>{const a=i.target,u=this.indexFromElement(a);if(!a.isConnected){this.observer.unobserve(a);for(const[d,f]of this.elementsCache)if(f===a){this.elementsCache.delete(d);break}return}this.shouldMeasureDuringScroll(u)&&this.resizeItem(u,this.options.measureElement(a,i,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(l):l()})}));return{disconnect:()=>{var o;(o=s())==null||o.disconnect(),t=null},observe:o=>{var i;return(i=s())==null?void 0:i.observe(o,{box:"border-box"})},unobserve:o=>{var i;return(i=s())==null?void 0:i.unobserve(o)}}})(),this.range=null,this.setOptions=t=>{var s,o;const i={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:Go,rangeExtractor:Yo,onChange:()=>{},measureElement:si,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,anchorTo:"start",followOnAppend:!1,scrollEndThreshold:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:"estimate",useCachedMeasurements:!1};for(const g in t){const b=t[g];b!==void 0&&(i[g]=b)}const l=this.options;let a=null,u=null,d=!1;if(l!==void 0&&l.enabled&&i.enabled&&i.anchorTo==="end"&&this.scrollElement!==null){const g=l.count,b=i.count,y=this.getMeasurements(),w=g>0?((s=y[0])==null?void 0:s.key)??l.getItemKey(0):null,M=g>0?((o=y[g-1])==null?void 0:o.key)??l.getItemKey(g-1):null;if(b!==g||g>0&&b>0&&(i.getItemKey(0)!==w||i.getItemKey(b-1)!==M)){d=!0;const k=g>0?this.getVirtualItemForOffset(this.getScrollOffset())??y[0]:null;k&&(a=[k.key,this.getScrollOffset()-k.start]);const C=i.followOnAppend===!0?"auto":i.followOnAppend||null;C&&b>g&&this.isAtEnd(l.scrollEndThreshold)&&(g===0||i.getItemKey(b-1)!==M)&&(u=C)}}this.options=i,d&&(this.pendingMin=0,this.itemSizeCacheVersion++);let f=!1,m=0;if(a&&this.scrollOffset!==null){const[g,b]=a,y=this.getMeasurements(),{count:w,getItemKey:M}=this.options;let p=0;for(;p<w&&M(p)!==g;)p++;if(p<w){const x=y[p];if(x){const k=x.start+b;k!==this.scrollOffset&&(m=k-this.scrollOffset,this.scrollOffset=k,f=!0)}}}(f||u)&&(this.pendingScrollAnchor=[f?a[0]:null,f?a[1]:0,u,m])},this.notify=t=>{var s,o;(o=(s=this.options).onChange)==null||o.call(s,this,t)},this.maybeNotify=Le(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),t=>{this.notify(t)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(t=>t()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var t;const s=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==s){if(this.cleanup(),!s){this.maybeNotify();return}if(this.scrollElement=s,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((t=this.scrollElement)==null?void 0:t.window)??null,this.elementsCache.forEach(i=>{this.observer.observe(i)}),this.unsubs.push(this.options.observeElementRect(this,i=>{this.scrollRect=i,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(i,l)=>{if(l&&this._intendedScrollOffset===null&&i===this.scrollOffset)return;this._intendedScrollOffset!==null&&Math.abs(i-this._intendedScrollOffset)<1.5&&(i=this._intendedScrollOffset),this._intendedScrollOffset=null,this.scrollAdjustments=0;const a=this.getScrollOffset();this.scrollDirection=l?a===i?this.scrollDirection:a<i?"forward":"backward":null,this.scrollOffset=i,this.isScrolling=l,this._flushIosDeferredIfReady(),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),"addEventListener"in this.scrollElement){const i=this.scrollElement,l=()=>{this._iosTouching=!0,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)},a=()=>{this._iosTouching=!1,!(!It()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};i.addEventListener("touchstart",l,dt),i.addEventListener("touchend",a,dt),this.unsubs.push(()=>{i.removeEventListener("touchstart",l),i.removeEventListener("touchend",a),this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)})}this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}const o=this.pendingScrollAnchor;if(this.pendingScrollAnchor=null,o&&this.scrollElement&&this.options.enabled){const[i,l,a,u]=o;i!==null&&!a&&(It()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?u!==0&&(this._iosDeferredAdjustment+=u):this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})),a&&this.scrollToEnd({behavior:a})}},this._flushIosDeferredIfReady=()=>{if(this._iosDeferredAdjustment===0||this.isScrolling||this._iosTouching||this._iosJustTouchEnded)return;const t=this.getScrollOffset(),s=this.getMaxScrollOffset();if(t<0||t>s)return;const o=this._iosDeferredAdjustment;this._iosDeferredAdjustment=0,this._scrollToOffset(t,{adjustments:this.scrollAdjustments+=o,behavior:void 0})},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset=="function"?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getMeasurementOptions=Le(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode,this.options.gap],(t,s,o,i,l,a,u,d)=>(this.prevLanes!==void 0&&this.prevLanes!==a&&(this.lanesChangedFlag=!0),this.prevLanes=a,this.pendingMin=null,{count:t,paddingStart:s,scrollMargin:o,getItemKey:i,enabled:l,lanes:a,laneAssignmentMode:u,gap:d}),{key:!1}),this.getMeasurements=Le(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:t,paddingStart:s,scrollMargin:o,getItemKey:i,enabled:l,lanes:a,laneAssignmentMode:u,gap:d},f)=>{const m=this.itemSizeCache;if(!l)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>t)for(const p of this.laneAssignments.keys())p>=t&&this.laneAssignments.delete(p);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMin=null),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(p=>{this.itemSizeCache.set(p.key,p.size)}));const g=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===t&&(this.lanesSettling=!1),a===1){const p=t*2;let x=this._flatMeasurements;if(!x||x.length<p){const j=new Float64Array(p);x&&g>0&&j.set(x.subarray(0,g*2)),x=j,this._flatMeasurements=x}let k;if(g===0)k=s+o;else{const j=g-1;k=x[j*2]+x[j*2+1]+d}for(let j=g;j<t;j++){const N=i(j),A=m.get(N),z=typeof A=="number"?A:this.options.estimateSize(j);x[j*2]=k,x[j*2+1]=z,k+=z+d}const C=qo(t,x,i);return this.measurementsCache=C,C}const b=this.measurementsCache.slice(0,g),y=new Array(a).fill(void 0),w=new Float64Array(a);let M=0;for(let p=0;p<g;p++){const x=b[p];x&&(y[x.lane]===void 0&&M++,y[x.lane]=p,w[x.lane]=x.end)}for(let p=g;p<t;p++){const x=i(p),k=this.laneAssignments.get(p);let C,j;const N=u==="estimate"||m.has(x);if(k!==void 0&&this.options.lanes>1){C=k;const E=y[C],L=E!==void 0?b[E]:void 0;j=L?L.end+d:s+o}else if(M===a){let E=0,L=w[0],he=y[0];for(let F=1;F<a;F++){const ee=w[F];(ee<L||ee===L&&y[F]<he)&&(E=F,L=ee,he=y[F])}C=E,j=L+d,N&&this.laneAssignments.set(p,C)}else C=p%this.options.lanes,j=s+o,N&&this.laneAssignments.set(p,C);const A=m.get(x),z=typeof A=="number"?A:this.options.estimateSize(p),Z=j+z;b[p]={index:p,start:j,size:z,end:Z,key:x,lane:C},y[C]===void 0&&M++,y[C]=p,w[C]=Z}return this.measurementsCache=b,b},{key:!1,debug:()=>this.options.debug}),this.calculateRange=Le(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(t,s,o,i)=>t.length===0||s===0?(this.range=null,null):(this.range=ai(t,s,o,i,i===1&&this._flatMeasurements!=null?this._flatMeasurements:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=Le(()=>{let t=null,s=null;const o=this.calculateRange();return o&&(t=o.startIndex,s=o.endIndex),this.maybeNotify.updateDeps([this.isScrolling,t,s]),[this.options.rangeExtractor,this.options.overscan,this.options.count,t,s]},(t,s,o,i,l)=>i===null||l===null?[]:t({startIndex:i,endIndex:l,overscan:s,count:o}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=t=>{const s=this.options.indexAttribute,o=t.getAttribute(s);return o?parseInt(o,10):(console.warn(`Missing attribute name '${s}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=t=>{var s;if(!this.scrollState||this.scrollState.behavior!=="smooth")return!0;const o=this.scrollState.index??((s=this.getVirtualItemForOffset(this.scrollState.lastTargetOffset))==null?void 0:s.index);if(o!==void 0&&this.range){const i=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),l=Math.max(0,o-i),a=Math.min(this.options.count-1,o+i);return t>=l&&t<=a}return!0},this.measureElement=t=>{if(!t){this.elementsCache.forEach((l,a)=>{l.isConnected||(this.observer.unobserve(l),this.elementsCache.delete(a))});return}const s=this.indexFromElement(t),o=this.options.getItemKey(s),i=this.elementsCache.get(o);i!==t&&(i&&this.observer.unobserve(i),this.observer.observe(t),this.elementsCache.set(o,t)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(s)&&this.resizeItem(s,this.options.measureElement(t,void 0,this))},this.resizeItem=(t,s)=>{var o,i;if(t<0||t>=this.options.count)return;let l,a,u;const d=this._flatMeasurements;if(this.options.lanes===1&&d!==null)u=this.options.getItemKey(t),a=d[t*2],l=d[t*2+1];else{const g=this.measurementsCache[t];if(!g)return;u=g.key,a=g.start,l=g.size}const f=this.itemSizeCache.get(u)??l,m=s-f;if(m!==0){const g=this.options.anchorTo==="end"&&((o=this.scrollState)==null?void 0:o.behavior)!=="smooth"&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,b=g?this.getTotalSize():0,y=((i=this.scrollState)==null?void 0:i.behavior)!=="smooth"&&(this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[t]??{index:t,key:u,start:a,size:l,end:a+l,lane:0},m,this):a<this.getScrollOffset()+this.scrollAdjustments&&(!this.itemSizeCache.has(u)||this.scrollDirection!=="backward"));(this.pendingMin===null||t<this.pendingMin)&&(this.pendingMin=t),this.itemSizeCache.set(u,s),this.itemSizeCacheVersion++,g?this.applyScrollAdjustment(this.getTotalSize()-b):y&&this.applyScrollAdjustment(m),this.notify(!1)}},this.getVirtualItems=Le(()=>[this.getVirtualIndexes(),this.getMeasurements()],(t,s)=>{const o=[];for(let i=0,l=t.length;i<l;i++){const a=t[i],u=s[a];o.push(u)}return o},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=t=>{const s=this.getMeasurements();if(s.length===0)return;const o=this._flatMeasurements,i=this.options.lanes===1&&o!=null,l=ss(0,s.length-1,i?a=>o[a*2]:a=>Lt(s[a]).start,t);return Lt(s[l])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if("scrollHeight"in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{const t=this.scrollElement.document.documentElement;return this.options.horizontal?t.scrollWidth-this.scrollElement.innerWidth:t.scrollHeight-this.scrollElement.innerHeight}},this.getVirtualDistanceFromEnd=()=>Math.max(this.getTotalSize()-this.getSize()-this.getScrollOffset(),0),this.getDistanceFromEnd=()=>Math.max(this.getMaxScrollOffset()-this.getScrollOffset(),0),this.isAtEnd=(t=this.options.scrollEndThreshold)=>this.getDistanceFromEnd()<=t,this.getOffsetForAlignment=(t,s,o=0)=>{if(!this.scrollElement)return 0;const i=this.getSize(),l=this.getScrollOffset();s==="auto"&&(s=t>=l+i?"end":"start"),s==="center"?t+=(o-i)/2:s==="end"&&(t-=i);const a=this.getMaxScrollOffset();return Math.max(Math.min(a,t),0)},this.getOffsetForIndex=(t,s="auto")=>{t=Math.max(0,Math.min(t,this.options.count-1));const o=this.getSize(),i=this.getScrollOffset(),l=this.measurementsCache[t];if(!l)return;if(s==="auto")if(l.end>=i+o-this.options.scrollPaddingEnd)s="end";else if(l.start<=i+this.options.scrollPaddingStart)s="start";else return[i,s];if(s==="end"&&t===this.options.count-1)return[this.getMaxScrollOffset(),s];const a=s==="end"?l.end+this.options.scrollPaddingEnd:l.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(a,s,l.size),s]},this.scrollToOffset=(t,{align:s="start",behavior:o="auto"}={})=>{const i=this.getOffsetForAlignment(t,s),l=this.now();this.scrollState={index:null,align:s,behavior:o,startedAt:l,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:o}),this.scheduleScrollReconcile()},this.scrollToIndex=(t,{align:s="auto",behavior:o="auto"}={})=>{t=Math.max(0,Math.min(t,this.options.count-1));const i=this.getOffsetForIndex(t,s);if(!i)return;const[l,a]=i,u=this.now();this.scrollState={index:t,align:a,behavior:o,startedAt:u,lastTargetOffset:l,stableFrames:0},this._scrollToOffset(l,{adjustments:void 0,behavior:o}),this.scheduleScrollReconcile()},this.scrollBy=(t,{behavior:s="auto"}={})=>{const o=this.getScrollOffset()+t,i=this.now();this.scrollState={index:null,align:"start",behavior:s,startedAt:i,lastTargetOffset:o,stableFrames:0},this._scrollToOffset(o,{adjustments:void 0,behavior:s}),this.scheduleScrollReconcile()},this.scrollToEnd=({behavior:t="auto"}={})=>{if(this.options.count>0){this.scrollToIndex(this.options.count-1,{align:"end",behavior:t});return}this.scrollToOffset(Math.max(this.getTotalSize()-this.getSize(),0),{behavior:t})},this.getTotalSize=()=>{var t;const s=this.getMeasurements();let o;if(s.length===0)o=this.options.paddingStart;else if(this.options.lanes===1){const i=s.length-1,l=this._flatMeasurements;l!=null?o=l[i*2]+l[i*2+1]:o=((t=s[i])==null?void 0:t.end)??0}else{const i=Array(this.options.lanes).fill(null);let l=s.length-1;for(;l>=0&&i.some(a=>a===null);){const a=s[l];i[a.lane]===null&&(i[a.lane]=a.end),l--}o=Math.max(...i.filter(a=>a!==null))}return Math.max(o-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{const t=[];if(this.itemSizeCache.size===0)return t;const s=this.getMeasurements();for(const o of s)o&&this.itemSizeCache.has(o.key)&&t.push({index:o.index,key:o.key,start:o.start,size:o.size,end:o.end,lane:o.lane});return t},this._scrollToOffset=(t,{adjustments:s,behavior:o})=>{this._intendedScrollOffset=t+(s??0),this.options.scrollToFn(t,{behavior:o,adjustments:s},this)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(n)}applyScrollAdjustment(n,t){n!==0&&(It()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?this._iosDeferredAdjustment+=n:(this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=n,behavior:t}),this.scrollOffset!==null&&(this.scrollOffset+=this.scrollAdjustments,this.scrollAdjustments=0)))}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId==null&&(this.rafId=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}))}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}const s=this.scrollState.index!=null?this.getOffsetForIndex(this.scrollState.index,this.scrollState.align):void 0,o=s?s[0]:this.scrollState.lastTargetOffset,i=1,l=o!==this.scrollState.lastTargetOffset;if(!l&&Qo(o,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=i){this.getScrollOffset()!==o&&this._scrollToOffset(o,{adjustments:void 0,behavior:"auto"}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,l){const a=this.getSize()||600,u=Math.abs(o-this.getScrollOffset()),d=this.scrollState.behavior==="smooth"&&u>a;this.scrollState.lastTargetOffset=o,d||(this.scrollState.behavior="auto"),this._scrollToOffset(o,{adjustments:void 0,behavior:d?"smooth":"auto"})}this.scheduleScrollReconcile()}}const ss=(e,n,t,s)=>{for(;e<=n;){const o=(e+n)/2|0,i=t(o);if(i<s)e=o+1;else if(i>s)n=o-1;else return o}return e>0?e-1:0};function ri(e,n,t){let s=0;for(;s<=n;){const o=(s+n)/2|0,i=e[o*2];if(i<t)s=o+1;else if(i>t)n=o-1;else return o}return s>0?s-1:0}function ai(e,n,t,s,o){const i=e.length-1;if(e.length<=s)return{startIndex:0,endIndex:i};if(s===1&&o!==null){const d=ri(o,i,t);let f=d;const m=t+n;for(;f<i&&o[f*2]+o[f*2+1]<m;)f++;return{startIndex:d,endIndex:f}}let a=ss(0,i,d=>e[d].start,t),u=a;if(s===1)for(;u<i&&e[u].end<t+n;)u++;else if(s>1){const d=Array(s).fill(0);for(;u<i&&d.some(m=>m<t+n);){const m=e[u];d[m.lane]=m.end,u++}const f=Array(s).fill(t+n);for(;a>=0&&f.some(m=>m>=t);){const m=e[a];f[m.lane]=m.start,a--}a=Math.max(0,a-a%s),u=Math.min(i,u+(s-1-u%s))}return{startIndex:a,endIndex:u}}const Ct=typeof document<"u"?c.useLayoutEffect:c.useEffect;function li({useFlushSync:e=!0,directDomUpdates:n=!1,directDomUpdatesMode:t="transform",...s}){const o=c.useReducer(d=>d+1,0)[1],i=c.useRef({enabled:n,mode:t,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});i.current.enabled=n,i.current.mode=t;const l=d=>{const f=i.current;if(!f.enabled||!f.container)return;const m=d.getTotalSize();if(m!==f.lastSize){f.lastSize=m;const p=d.options.horizontal?"width":"height";f.container.style[p]=`${m}px`}const g=!!d.options.horizontal,b=f.mode==="transform",y=g?"left":"top",w=d.options.scrollMargin,M=d.getVirtualItems();for(const p of M){const x=p.start-w,k=d.elementsCache.get(p.key);k&&f.lastPositions.get(k)!==x&&(f.lastPositions.set(k,x),b?k.style.transform=g?`translate3d(${x}px, 0, 0)`:`translate3d(0, ${x}px, 0)`:k.style[y]=`${x}px`)}},a={...s,onChange:(d,f)=>{var m;const g=i.current;let b=!0;if(g.enabled){l(d);const y=d.range,w=g.prevRange;b=!w||w.isScrolling!==d.isScrolling||w.startIndex!==y?.startIndex||w.endIndex!==y?.endIndex,b&&(g.prevRange=y?{startIndex:y.startIndex,endIndex:y.endIndex,isScrolling:d.isScrolling}:null)}b&&(e&&f?As.flushSync(o):o()),(m=s.onChange)==null||m.call(s,d,f)}},[u]=c.useState(()=>{const d=new ii(a);return Object.assign(d,{containerRef:f=>{const m=i.current;if(m.container=f,m.lastSize=null,f&&m.enabled){const g=d.getTotalSize();m.lastSize=g;const b=d.options.horizontal?"width":"height";f.style[b]=`${g}px`}}})});return u.setOptions(a),Ct(()=>u._didMount(),[]),Ct(()=>u._willUpdate()),Ct(()=>{l(u)}),u}function ci(e){return li({observeElementRect:Xo,observeElementOffset:ti,scrollToFn:oi,...e})}const Et=e=>e.query?`matching "${e.query}"`:e.from?`from "${e.from}"`:"matching your search",di=e=>`Select all ${Et(e)}`,ui=(e,n)=>`All ${Gn(n)} ${Et(e)} selected`,hi=({verb:e,confirmingDelete:n,hasSelection:t,junkMailboxId:s,currentMailboxId:o,deletableMessageId:i})=>{if(n)return{kind:"withheld"};if(e==="junk"){const l=Xs(s,o);if(l!==void 0)return{kind:"unavailable",reason:l}}return t?{kind:"openWizard"}:e!=="delete"||i===void 0?{kind:"declined"}:{kind:"confirmDelete",messageId:i}},fi=(e,n,t)=>e==="BACK"&&n&&t===void 0,mi=(e,n)=>({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:Ge(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Qt(e.category),messageCount:n,suspicious:e.authenticity?.dkimMismatch===!0,labels:e.labels}),gi=({thread:e,mailboxId:n,isSelected:t,isFocused:s,isTabStop:o,onFocusRow:i,isChecked:l,onToggleCheck:a,onRowSelect:u,messageCount:d,isMultiSelectMode:f,onLongPress:m,isDesktop:g,density:b})=>r.jsx(Zs,{thread:mi(e,d),link:{mailboxId:n,threadId:e.threadId},inListbox:!0,active:t,focused:s,isTabStop:o,density:b,isDesktop:g,onFocusRow:i,selection:{isChecked:l,onToggleCheck:a,onRowSelect:u,isMultiSelectMode:f,onLongPress:m}}),pi=c.memo(gi),xi=e=>{const n=e.authenticity?.dkimMismatch===!0;return{id:e.messageId,accountId:e.accountId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:Ge(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Qt(e.category),suspicious:n}},bi=({thread:e,mailboxId:n,isSelected:t,isFocused:s,isTabStop:o,onFocusRow:i,isChecked:l,onToggleCheck:a,onRowSelect:u,isMultiSelectMode:d,onLongPress:f,isDesktop:m,onDelete:g,onToggleRead:b,density:y})=>{const[w,M]=c.useState("none"),p=Je(),x=Ye(),k=c.useCallback(z=>{navigator.vibrate?.(10),z==="trailing"?g(e.messageId):b(e.messageId,e.isRead),M("none")},[g,b,e.messageId,e.isRead]),C=c.useCallback(()=>{f(e.messageId)},[f,e.messageId]),j=c.useCallback(()=>{a(e.messageId)},[a,e.messageId]),N=c.useCallback(()=>{p({to:"/mail/$mailboxId/$threadId/$messageId",params:{mailboxId:n,threadId:e.threadId,messageId:e.messageId},search:z=>z,hash:x})},[p,x,n,e.threadId,e.messageId]),A=en(e.messageId,u);return m||d?r.jsx(pi,{thread:e,mailboxId:n,isSelected:t,isFocused:s,isTabStop:o,onFocusRow:i,isChecked:l,onToggleCheck:a,onRowSelect:u,isMultiSelectMode:d,onLongPress:f,isDesktop:m,density:y}):r.jsx("div",{role:"presentation",onPointerDownCapture:A.onMouseDown,onClickCapture:A.claimClick,onContextMenu:A.onContextMenu,children:r.jsx(Hn,{thread:xi(e),selectionMode:!1,checked:!1,active:t,peek:w,onPeek:M,onToggleCheck:j,onLongPress:C,onOpen:N,onAct:k})})},vi=72,Si=32,yi=5,ns="remit:list-density",Ii=()=>{try{const e=localStorage.getItem(ns);if(e==="compact"||e==="comfortable")return e}catch{}return"comfortable"},Ci=({query:e})=>r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-line bg-surface-sunken/30",children:[r.jsx(_s,{className:"size-4 text-fg-muted"}),r.jsxs("span",{className:"text-sm text-fg-muted",children:["Results for “",e,"”"]})]}),wi=({mailboxId:e,threads:n,selectedMessageId:t,isLoading:s,isError:o=!1,error:i,onRetry:l,searchQuery:a,searchPredicate:u,onDeleteMessages:d,isDeleting:f=!1,isMoving:m=!1,onLoadMore:g,hasMore:b=!1,isLoadingMore:y=!1,accountId:w,listTitle:M,listMeta:p,listFilter:x,listScopeLabel:k,onTriageContextChange:C,commandsRef:j,hideHeader:N=!1})=>{const A=c.useRef(null),z=Je(),Z=Ye(),E=ho(),L=Os(),{verb:he,start:F,startFromSearch:ee}=L,Ee=Ns(),se=!!a?.trim(),Y=tn(),{labels:Ae}=lo(w),{pushError:ne}=zs(),[T,P]=c.useState(t),[Se,fe]=c.useState(),O=c.useCallback(h=>{fe(v=>v===h?v:void 0),P(h)},[]),[me,Oe]=c.useState(Ii),ye=c.useCallback(()=>{Oe(h=>{const v=h==="comfortable"?"compact":"comfortable";try{localStorage.setItem(ns,v)}catch{}return v})},[]),{toggleReadFor:Ie}=Jt({mailboxId:e}),{junkMailboxId:ge}=Gt(w),Pe=Yt(ge,e),{trashMailboxId:$e,isLoading:H}=sn(w),$=H?"unknown":$e===e?"permanent":"trash",{selectedIds:U,selectedCount:K,hasSelection:oe,isSelected:D,toggle:X,select:pe,clearSelection:Xe,selectRange:Ne,setAnchor:Be,selectAll:ie,toggleAll:ft,intersectWith:Ze}=nn(),Ce=pn(K,E),[R,ze]=c.useState(null),Fe=se&&!!u,et=`${e}|${JSON.stringify(u??{})}`,I=on({mailboxId:e,accountId:w,enabled:Fe,predicateKey:et,searchQuery:u??{}}),mt=c.useCallback((h,v,Q)=>{if(Q.error===void 0){if(Q.cancelled){ne({severity:"warning",title:an(Q.done),detail:rn(h,Q.done,v)});return}ne({severity:"info",title:zt(h,Q.done)})}},[ne]),We=I.phase.kind,we=I.clear,V=c.useCallback(()=>{We==="escalated"&&we(),Xe()},[Xe,we,We]),[le,tt]=c.useState(null),xe=c.useRef(null),ce=c.useRef(!1),ke=c.useRef(null),be=!s&&n.length>0,Ke=R!==null,te=ci({count:n.length,getScrollElement:()=>A.current,estimateSize:()=>me==="compact"?Si:vi,overscan:yi}),Ve=t?n.findIndex(h=>h.messageId===t):-1,q=T?n.findIndex(h=>h.messageId===T):-1,re=c.useCallback(h=>{if(h<0||h>=n.length)return;const v=n[h];if(Ce){X(v.messageId);return}xe.current=v.messageId,ce.current=!1,fe(v.messageId),P(v.messageId)},[n,Ce,X]),He=c.useCallback(()=>{if(n.length===0)return;const h=q<0?0:Math.min(q+1,n.length-1);re(h)},[n.length,q,re]),Ue=c.useCallback(()=>{if(n.length===0)return;const h=q<=0?0:q-1;re(h)},[n.length,q,re]),ve=c.useCallback(()=>re(0),[re]),je=c.useCallback(()=>re(n.length-1),[re,n.length]),Me=c.useCallback(()=>{T&&X(T)},[T,X]),B=c.useMemo(()=>n.map(h=>h.messageId),[n]),gt=c.useMemo(()=>{const h=[];for(const v of n)U.has(v.messageId)&&h.push({id:v.messageId,sender:v.fromName??v.fromEmail??"Unknown",email:v.fromEmail??"",subject:v.subject??"(No subject)",date:Ge(v.sentDate)});return h},[n,U]),pt=c.useCallback((h,v)=>v.shiftKey?(Ne(B,h,T),!0):v.metaKey||v.ctrlKey?(X(h),!0):(V(),Be(h),!1),[B,T,Ne,X,V,Be]),de=c.useCallback(h=>{!d||h.length===0||(ke.current=T??null,ze(h))},[d,T]),De=c.useCallback(h=>{const v=ln(B,T,h);v!==void 0&&(Ne(B,v),xe.current=v,ce.current=!1,fe(void 0),P(v))},[B,T,Ne]),st=c.useCallback(()=>De(-1),[De]),nt=c.useCallback(()=>De(1),[De]),ot=c.useCallback(()=>{B.length>0&&ie(B)},[B,ie]),it=c.useCallback(h=>{const v=hi({verb:h,confirmingDelete:R!==null,hasSelection:oe,junkMailboxId:ge,currentMailboxId:e,deletableMessageId:d?T:void 0});return v.kind==="openWizard"?(F(h),!0):v.kind==="confirmDelete"?(de([v.messageId]),!0):v.kind==="unavailable"?(ne({severity:"warning",title:v.reason}),!0):v.kind==="withheld"},[R,d,oe,ge,e,F,T,de,ne]),ue=c.useCallback((h,v)=>{const Q=n.find(J=>J.messageId===h)?.threadId;Q&&z({to:"/mail/$mailboxId/$threadId/$messageId",params:{mailboxId:e,threadId:Q,messageId:h},search:J=>J,hash:Z,replace:v?.replace})},[z,Z,e,n]),rt=c.useCallback(()=>{T&&ue(T)},[T,ue]),Te=c.useCallback(h=>ue(h,{replace:!0}),[ue]);cn({keyboardFocusedMessageId:Se,openMessageId:t,enabled:E&&K===0,open:Te});const _e=I.phase.kind==="escalated"?{scope:Et(u??{}),total:I.phase.total,searchQuery:u??{},run:h=>I.runAction(h),stop:I.stop}:void 0,at=c.useCallback(()=>{if(!R)return;const h=R;if(h.length===0){ze(null);return}const v=new Set(h),Q=n.findIndex(G=>v.has(G.messageId));let J;for(let G=Q+1;G<n.length;G++)if(!v.has(n[G].messageId)){J=n[G].messageId;break}if(J===void 0){for(let G=Q-1;G>=0;G--)if(!v.has(n[G].messageId)){J=n[G].messageId;break}}d?.(h),V(),ke.current=null,ze(null),J!==void 0&&(xe.current=J,ce.current=!1,O(J),E&&ue(J,{replace:!0})),E||tt(zt("delete",h.length))},[R,n,d,V,ue,E,O]),xt=c.useCallback(()=>{const h=ke.current;ke.current=null,ze(null),h!==null&&(xe.current=h,ce.current=!1,O(h))},[O]),qe=c.useMemo(()=>{if(K===0)return;const h=new Set;for(const v of n)U.has(v.messageId)&&h.add(v.accountConfigId);if(h.size>1)return"Move only works within one account — clear selection or pick messages from a single account"},[K,U,n]),bt=c.useCallback(()=>{if(_e){ee();return}F("organize")},[_e,ee,F]),lt=c.useCallback(h=>{d?.([h])},[d]),vt=c.useCallback((h,v)=>{Ie([h],!v)},[Ie]),S=c.useCallback(h=>{E||pe(h)},[E,pe]),_=c.useCallback(()=>{if(I.isRunning||I.phase.kind==="counting"){I.stop();return}V()},[I,V]),W=c.useCallback(()=>{I.clear()},[I]);c.useEffect(()=>{if(ce.current||!E&&t)return;const h=q>=0?q:Ve;h>=0&&te.scrollToIndex(h,{align:"auto"})},[q,Ve,te,E,t]),c.useEffect(()=>{t&&(ce.current=!1,O(t))},[t,O]),c.useEffect(()=>{T&&(n.some(h=>h.messageId===T)||O(n[0]?.messageId))},[n,T,O]),c.useEffect(()=>{C?.({focusedMessageId:T,selectedIds:Array.from(U),hasList:be,blocksKeyboard:Ke||L.isOpen})},[T,U,be,Ke,L.isOpen,C]);const At=c.useRef(C);At.current=C,c.useEffect(()=>()=>At.current?.({focusedMessageId:void 0,selectedIds:[],hasList:!1,blocksKeyboard:!1}),[]),c.useEffect(()=>{I.phase.kind!=="idle"||I.isRunning||Ze(n.map(h=>h.messageId))},[n,Ze,I.phase,I.isRunning]);const Ot=c.useRef(e);c.useEffect(()=>{Ot.current!==e&&(Ot.current=e,V())},[e,V]),dn({shouldBlockFn:({action:h})=>fi(h,oe,Ee)?(V(),!0):!1,enableBeforeUnload:!1,disabled:!oe||Ee!==void 0}),c.useEffect(()=>{const h=A.current;if(!h||!b||!g)return;const v=()=>{if(y)return;const{scrollTop:Q,scrollHeight:J,clientHeight:G}=h;Q+G>=J-200&&g()};return h.addEventListener("scroll",v,{passive:!0}),v(),()=>h.removeEventListener("scroll",v)},[b,y,g]),c.useEffect(()=>{const h=xe.current;if(!h)return;const v=A.current?.querySelector(`[data-message-id="${h}"]`);v&&(xe.current=null,v.focus({preventScroll:!0}))}),c.useEffect(()=>{if(j){if(!be){j.current=null;return}return j.current={focusNext:He,focusPrevious:Ue,focusFirst:ve,focusLast:je,openFocused:rt,toggleSelect:Me,extendSelectDown:nt,extendSelectUp:st,selectAll:ot,clearSelection:()=>oe?(V(),!0):!1,requestVerb:it,toggleDensity:ye},()=>{j.current=null}}},[j,be,He,Ue,ve,je,rt,Me,nt,st,ot,oe,V,it,ye]);const Nt=s?"loading":o?"error":n.length===0?"empty":"ready",as=o?ao(i):void 0,ls=c.useCallback(()=>{const h=Fs(Ds());window.open(h,"_blank","noopener,noreferrer")},[]),cs=[{id:"inbox",threads:[]}],St=B.length>0&&B.every(h=>U.has(h)),ds=Fe&&b&&St&&!f&&!m&&I.phase.kind==="idle"&&!I.isRunning,us=f||m||I.isRunning,yt=I.phase.kind==="escalated"?I.phase.total:K,hs=I.runningAction?un(I.runningAction.kind,I.progress?.done??0,I.progress?.total??yt):I.phase.kind==="counting"?"Counting matches…":I.phase.kind==="escalated"?ui(u??{},I.phase.total):void 0,fs=I.phase.kind!=="escalated"&&B.length>0?{checked:St,indeterminate:K>0&&!St,onChange:()=>ft(B)}:void 0,ms=I.runningAction?{value:I.progress?.done??0,max:I.progress?.total??yt,tone:hn(I.runningAction.kind)}:void 0,gs=(I.phase.kind==="counting"?{tone:"info",text:"",action:{label:"Stop",onClick:I.stop}}:I.phase.kind==="escalated"&&!I.isRunning?{tone:"info",text:"",action:{label:"Clear selection",onClick:W}}:ds?{tone:"info",text:"",action:{label:di(u??{}),onClick:I.escalate}}:void 0)??(qe?{tone:"warning",text:qe}:void 0),ps=r.jsx(fn,{title:Y.title||M,navSlot:Y.navSlot,titleMeta:Y.titleMeta,searchSlot:Y.searchSlot,searchField:Y.searchField,idleSlot:Y.makeFilterSlot,count:yt,onCancel:_,onDelete:()=>F("delete"),onMove:()=>F("move"),onOrganize:bt,onJunk:Pe?()=>F("junk"):void 0,onMarkRead:()=>F("markRead"),overflowSlot:w&&e&&K>0&&Ae.length>0?r.jsx(fo,{accountId:w,mailboxId:e,messageIds:Array.from(U)}):void 0,isBusy:us,isCounting:I.phase.kind==="counting",selectAll:fs,statusLabel:hs,progress:ms,notice:gs}),xs=mn(B,T),bs=c.useCallback(h=>{ce.current=!0,O(h)},[O]),vs=r.jsxs(r.Fragment,{children:[se&&a&&r.jsx(Ci,{query:a}),r.jsxs("div",{ref:A,role:"listbox","aria-multiselectable":!0,"aria-label":M,className:"flex-1 overflow-y-auto",children:[r.jsx("div",{role:"presentation",className:"relative w-full",style:{height:`${te.getTotalSize()}px`},children:te.getVirtualItems().map(h=>{const v=n[h.index];return r.jsx("div",{role:"presentation","data-index":h.index,ref:te.measureElement,className:Re("absolute left-0 top-0 w-full border-b border-line",I.isRunning&&"pointer-events-none opacity-50"),style:{transform:`translateY(${h.start}px)`},children:r.jsx(bi,{thread:v,mailboxId:e,isSelected:t===v.messageId,isFocused:T===v.messageId,isTabStop:xs===v.messageId,onFocusRow:bs,isChecked:D(v.messageId),onToggleCheck:X,onRowSelect:pt,isMultiSelectMode:Ce,onLongPress:S,isDesktop:E,onDelete:lt,onToggleRead:vt,density:me})},h.key)})}),y&&r.jsx(Un,{})]})]});return r.jsxs(r.Fragment,{children:[le&&!E&&r.jsx(kt,{tone:"success",variant:"soft",className:"m-2 rounded-md",onDismiss:()=>tt(null),children:le}),r.jsx(qn,{listTitle:M,listMeta:p,sections:cs,flatList:!0,listState:Y.searchResults?"ready":Nt,searchQuery:se?a:void 0,listFilter:x,listScopeLabel:k,errorMessage:as,onRetry:l,onReportError:ls,density:me,selectedThreadId:t,onSelectThread:h=>ue(h),isDesktop:E,hideHeader:N,selectionBar:ps,listBody:Y.searchResults??(Nt==="ready"?vs:void 0)}),r.jsx(ro,{isOpen:R!==null,...Yn(R?.length??0,$),destructive:!0,isBusy:f||$==="unknown",onConfirm:at,onCancel:xt}),r.jsx(gn,{verb:he,accountId:w,mailboxId:e,selection:gt,selectionRestriction:qe?"spansAccounts":void 0,escalated:_e,escalatedProgress:I.progress,onFinished:V,onRunEnded:mt})]})},ki=e=>Ps({path:{accountId:e}}),ji=e=>{const n=Wt(),t=Mt(),s=Kt({...Ls(),onSuccess:()=>{t.recordEvent("sync.triggered"),n.invalidateQueries({queryKey:ki(e)})}});return{trigger:()=>{s.mutate({path:{accountId:e}})},triggerAsync:()=>s.mutateAsync({path:{accountId:e}}),isPending:s.isPending,error:s.error,reset:s.reset}},Mi=({accountId:e,children:n})=>{const{triggerAsync:t,isPending:s}=ji(e);return r.jsx(jo,{onRefresh:t,isRefreshing:s,children:n})};function Ti({accountId:e,currentMailboxId:n,candidates:t,onMove:s,children:o}){const[i,l]=c.useState(!1),a=Mt(),u=bo(),{inboxMailboxId:d}=xn(e),f=bn(e),{data:m}=jt({...$s({path:{accountId:e}}),staleTime:1/0}),g=c.useMemo(()=>vo({mailboxes:m?.items??[],folderAppointments:f,currentMailboxId:n,translator:u}),[m?.items,f,n,u]),b=c.useMemo(()=>d||(g.find(x=>x.label.toLowerCase()==="inbox")?.id??g.find(x=>!x.isCurrent)?.id??""),[d,g]),y=c.useRef(!1);c.useEffect(()=>{y.current||(y.current=!0,vn(a,t.length))},[a,t.length]);const w=c.useCallback(()=>{Sn(a,t.length),l(!0)},[a,t.length]),M=c.useCallback((p,x)=>{yn(a,{selected:p.length,total:t.length,toInbox:x===d}),s(p,x)},[a,t.length,d,s]);return r.jsxs("div",{className:"relative flex h-full min-h-0 flex-col",children:[r.jsx("div",{className:"shrink-0 px-row-inset pt-2",children:r.jsx(To,{count:t.length,onReview:w})}),r.jsx("div",{className:"min-h-0 flex-1",children:o}),r.jsx(Po,{open:i,candidates:t,defaultDestinationId:b,availableFolders:g,delimiter:So(m?.items??[]),onConfirmMove:M,onCancel:()=>l(!1)})]})}const Ri="We can verify this sender";function Ei(e){const{data:n}=jt({...Bs({path:{mailboxId:e??""},query:{senderTrust:["vip","wellknown"],dkimMismatch:!1,results:!0,limit:500}}),enabled:!!e,staleTime:6e4});return{candidates:(n?.items??[]).map(s=>({id:s.messageId,senderName:s.fromName||s.fromEmail||"Unknown sender",senderAddress:s.fromEmail??"",subject:s.subject||"(no subject)",snippet:s.snippet??"",trustReason:Ri,trustSubReason:In(s.senderTrust),senderTrust:s.senderTrust}))}}const Ai=e=>{const n=new Set,t=[];for(const s of e)n.has(s.threadMessageId)||(n.add(s.threadMessageId),t.push(s));return t},Oi={unread:"unread",flagged:"starred",attachment:"attachments"},Ni=new Set(Object.values(wo)),os=e=>Ni.has(e),zi=e=>os(e.category)||e.attributes.size>0,Fi=e=>{const n={};os(e.category)&&(n.category=[e.category]);for(const t of e.attributes){const s=Oi[t];s&&(n[s]=!0)}return n},Di=e=>(e.senderTrust?.length??0)>0||e.dkimMismatch!==void 0?"loaded-pages":"whole-folder",_i=["category","unread","starred","attachments"],$t=e=>JSON.stringify(_i.map(n=>e?.[n]??null)),Li=e=>{if(!Array.isArray(e))return;const[n]=e;if(typeof n!="object"||n===null)return;const t=n.query;if(!(typeof t!="object"||t===null))return t},Pi=(e,n)=>{const t=Li(e);return t?$t(t)===$t(n):!1},ct=e=>e[0],$i=e=>{const n=ct(e.filter(a=>a.type==="from").map(a=>a.value)),t=ct(e.filter(a=>a.type==="subject").map(a=>a.value)),s=ct(e.filter(a=>a.type==="category").map(a=>a.category)),o=ct(e.filter(a=>a.type==="isUnread"||a.type==="isRead").map(a=>a.type==="isUnread")),i=e.some(a=>a.type==="isStarred")?!0:void 0,l=e.some(a=>a.type==="hasAttachment")?!0:void 0;return{...n!==void 0?{from:n}:{},...t!==void 0?{subject:t}:{},...s!==void 0?{category:[s]}:{},...o!==void 0?{unread:o}:{},...i!==void 0?{starred:i}:{},...l!==void 0?{attachments:l}:{}}},Bi=(e,n)=>{switch(n.type){case"from":return e.from?.toLowerCase()===n.value.toLowerCase();case"subject":return e.subject?.toLowerCase()===n.value.toLowerCase();case"category":return e.category?.length===1&&e.category[0]===n.category;case"isUnread":return e.unread===!0;case"isRead":return e.unread===!1;case"isStarred":return e.starred===!0;case"hasAttachment":return e.attachments===!0;case"before":case"after":case"in":case"account":return!1}};function Wi(e,n={}){const t=$i(e),s={...t,...n};return{params:t,residual:e.filter(o=>!Bi(s,o))}}function Ki(e,n,t){if(n.length===0)return e;const s=[...n];return e.filter(o=>{const i=Cn(o);return wn({...i,accountId:i.accountId??t},s)})}const Vi=50,Hi=new Map(es().categories.filter(e=>e.id!=="all").map(e=>[e.id,e.label])),is=c.createContext(null);function ht(){const e=c.useContext(is);if(!e)throw new Error("MailboxPane.* must be used inside <MailboxPane>");return e}function Ui({mailboxId:e,thread:n,children:t}){const s=Je(),o=Ye(),i=n?.threadId,l=n?.messageId,a=Mt(),{accounts:u,searchQuery:d,intelligenceOpen:f,onToggleIntelligence:m}=Vt(),g=Us(),b=ko(d),y=b.length>0,{freeText:w,tokens:M}=qs(b,g),[p,x]=c.useState("all"),[k,C]=c.useState(new Set),j=c.useMemo(()=>({category:p,attributes:k}),[p,k]),N=c.useMemo(()=>Fi(j),[j]),A=y||zi(j),{params:z,residual:Z}=Wi(M,N),E={order:"desc",limit:Vi,...w?{query:w}:{},...z,...N},L={category:E.category,unread:E.unread,starred:E.starred,attachments:E.attachments},he=A?Ws({path:{mailboxId:e},query:E}):Ks({path:{mailboxId:e},query:{order:"desc"}}),{data:F,isLoading:ee,isError:Ee,error:se,refetch:Y,fetchNextPage:Ae,hasNextPage:ne,isFetchingNextPage:T}=Qn({queryKey:he,queryFn:async({pageParam:S})=>{if(A){const{data:W}=await Vs({path:{mailboxId:e},query:{...E,continuationToken:S},throwOnError:!0});return W}const{data:_}=await Hs({path:{mailboxId:e},query:{order:"desc",continuationToken:S},throwOnError:!0});return _},initialPageParam:void 0,getNextPageParam:S=>S.continuationToken,placeholderData:(S,_)=>Pi(_?.queryKey,L)?S:void 0}),{accountId:P,isLoading:Se}=kn(e),fe=yo({accounts:u}),O=Ki(jn(Ai(F?.pages.flatMap(S=>S.items??[])??[])),Z,P),me=c.useCallback(S=>{x(S)},[]),Oe=c.useCallback(S=>{C(_=>{const W=new Set(_);return W.has(S)?W.delete(S):W.add(S),W})},[]),ye=c.useCallback(()=>{x("all"),C(new Set)},[]),Ie=Hi.get(p),ge=Ie?{label:Ie,reach:Z.length>0?"loaded-pages":Di(E),onClear:ye}:void 0,Pe=i?O.find(S=>S.messageId===l)??O.find(S=>S.threadId===i):void 0,$e=Mn(i,l),H=Pe??$e,$=l??H?.messageId,U=c.useMemo(()=>{if(i)return{threadId:i,mailboxId:H?.mailboxId??e,subject:H?.subject,messageId:$,authenticity:H?.authenticity}},[i,H,$,e]),K=c.useCallback(()=>{s({to:"/mail/$mailboxId",params:{mailboxId:e},search:S=>S,hash:o})},[e,s,o]),oe=c.useCallback(S=>{s({to:"/mail/$mailboxId/$threadId/$messageId",params:{mailboxId:e,...S},search:_=>_,hash:o})},[e,s,o]),D=c.useCallback(S=>{$&&S.includes($)&&K()},[$,K]),{deleteMessages:X,isPending:pe}=Ft({mailboxId:e,onAfterOptimisticRemove:D}),{moveMessages:Xe,isPending:Ne}=Dt({mailboxId:e,accountId:P,onAfterOptimisticRemove:D}),Be=Tn(),{listCommandsRef:ie,onTriageContextChange:ft,focusedMessageId:Ze,selectedIds:Ce}=Be,R=O.find(S=>S.messageId===Ze)??H,ze=Io({accounts:u})??0,Fe=Rn({thread:H,mailboxId:e,accountId:P,onAfterOptimisticRemove:D}),{draftsMailboxId:et}=En(P),I=et!==void 0&&et===e,{archiveMailboxId:mt}=An(P),We=On(),we=eo(),V=c.useMemo(()=>to(we,i,$),[we,i,$]),le=c.useMemo(()=>{if(R)return S=>we({threadId:R.threadId,messageId:R.messageId,mode:S})},[we,R]),tt=so(),xe=no(),ce=oo(),ke=c.useCallback(S=>S?We(S):[],[We]),{toggleStar:be}=Nn({threadId:R?.threadId??"",mailboxId:e}),{toggleReadFor:Ke}=Jt({mailboxId:e,accountId:P}),{junkMailboxId:te}=Gt(P),Ve=te!=null&&te===e,q=Yt(te,e),{candidates:re}=Ei(Ve?te:void 0),{moveMessages:He}=Dt({mailboxId:e,threadId:R?.threadId,accountId:P,onAfterOptimisticRemove:D}),{deleteMessages:Ue}=Ft({mailboxId:e,threadId:R?.threadId,onAfterOptimisticRemove:D}),{addressId:ve,address:je}=zn(R),{updateFlags:Me}=Fn({addressId:ve,senderEmail:R?.fromEmail??void 0}),B=c.useCallback(()=>le?.("reply"),[le]),gt=c.useCallback(()=>le?.("reply-all"),[le]),pt=c.useCallback(()=>le?.("forward"),[le]),de=c.useCallback(()=>ke(R),[ke,R]),De=c.useCallback(()=>{if(ie.current?.requestVerb("delete"))return;const S=de();S.length>0&&Ue(S)},[ie,de,Ue]),st=c.useCallback(()=>{if(ie.current?.requestVerb("junk")||!q)return;const S=de();S.length!==0&&(Dn(a,{count:S.length,senderTrust:R?.senderTrust??"unknown",wasRescuable:R?_n(R):!1}),He(S,q))},[ie,q,de,He,a,R]),nt=c.useCallback(()=>{if(Ce.length>0){const S=!(R?.hasStars??!1),_=new Set(Ce);for(const W of O)_.has(W.messageId)&&W.hasStars!==S&&be(W.messageId,W.hasStars);return}R&&be(R.messageId,R.hasStars)},[Ce,O,R,be]),ot=c.useCallback(()=>{if(ie.current?.requestVerb("markRead"))return;const S=de();if(S.length===0)return;const _=!(R?.isRead??!1);Ke(S,_)},[ie,de,R,Ke]),it=c.useCallback(()=>{if(!ve)return;const S=je?.flags?.muted?.value!==!0;Me({muted:{value:S}})},[ve,je,Me]),ue=c.useCallback(()=>{if(!ve)return;const S=je?.flags?.vip?.value!==!0;Me({vip:{value:S}})},[ve,je,Me]),rt=c.useCallback(()=>{f||m()},[f,m]),Te=c.useCallback(S=>{s({to:S})},[s]),_e=I?"drafts":mt===e?"archive":te===e?"junk":"inbox",at=c.useRef("");c.useEffect(()=>{const S=at.current;at.current=b,b.length>0&&S.length===0&&a.recordEvent("search.submitted",{mailboxType:_e})},[b,_e,a]);const{goBack:xt,nextMessageId:qe,previousMessageId:bt}=Ln({context:Be,orderedIds:O.map(S=>S.messageId),selectedMessageId:$,enabled:!tt&&!xe,onClose:K,handlers:{reply:B,replyAll:gt,forward:pt,delete:De,toggleStar:nt,toggleRead:ot,muteSender:it,blockSender:rt,vipSender:ue,markJunk:st,toggleIntelligence:H?m:void 0,compose:ce,goBrief:()=>Te("/mail/brief"),goInbox:()=>Te("/mail/brief"),goSent:()=>Te("/mail/brief"),goFlagged:()=>Te("/mail/flagged"),goSettings:()=>Te("/settings")}}),lt=S=>{if(!S)return;const _=O.find(W=>W.messageId===S);return _?{threadId:_.threadId,messageId:S}:void 0},vt={mailboxId:e,selectedMessageId:$,selectedThread:H,conversation:U,onOpenThread:oe,threads:O,isLoading:ee,isError:Ee,error:se,mailboxAccountId:P,mailboxAccountLoading:Se,mailboxName:fe,unreadCount:ze,isDraftsMailbox:I,isSpamFolder:Ve,rescueCandidates:re,filterCategory:p,filterAttributes:k,onSelectFilterCategory:me,onToggleFilterAttribute:Oe,onClearFilters:ye,listFilter:ge,intelligenceOpen:f,onToggleIntelligence:m,handleDeselectIfRemoved:D,searchPredicate:y&&Z.length===0?E:void 0,onDeleteMessages:X,onMoveMessages:Xe,isDeleting:pe,isMoving:Ne,onLoadMore:Ae,hasMore:ne,isLoadingMore:T,onTriageContextChange:ft,listCommandsRef:ie,onRetry:()=>Y(),onReply:V,onToolbarDelete:Fe.deleteThread,onToolbarStar:Fe.toggleStar,onToolbarMove:Fe.moveThread,onBack:xt,nextThread:lt(qe),previousThread:lt(bt)};return r.jsx(is.Provider,{value:vt,children:t})}function rs(){const{mailboxId:e,selectedMessageId:n,threads:t,isLoading:s,isError:o,error:i,onDeleteMessages:l,onMoveMessages:a,isDeleting:u,isMoving:d,onLoadMore:f,hasMore:m,isLoadingMore:g,mailboxAccountId:b,mailboxName:y,unreadCount:w,isDraftsMailbox:M,isSpamFolder:p,rescueCandidates:x,onTriageContextChange:k,listCommandsRef:C,onRetry:j,filterCategory:N,filterAttributes:A,onSelectFilterCategory:z,onToggleFilterAttribute:Z,onClearFilters:E,listFilter:L,searchPredicate:he}=ht(),{searchQuery:F,searchInput:ee,accounts:Ee,resultFolderIndex:se}=Vt(),Y=Co(),Ae=Je(),ne=Ye(),T=y??"Inbox",P=c.useMemo(()=>es(),[]),Se=c.useMemo(()=>b?[b]:[],[b]),{hasNewMail:fe}=Js(),{state:O,errorMessage:me,refresh:Oe}=Gs(Se,{onSettled:j}),ye=c.useMemo(()=>r.jsx(Ys,{state:O,onRefresh:Oe,label:`Refresh ${T}`,errorMessage:me,hasUpdate:fe(Se)}),[O,Oe,T,me,fe,Se]),Ie=c.useMemo(()=>t.map(D=>Kn(D,se)),[t,se]),{hits:ge,isLoading:Pe}=mo({mailboxId:e,filterCategory:N}),$e=c.useMemo(()=>Vn(ge,t.map(D=>D.threadId),se),[ge,t,se]),H=c.useCallback(D=>{const X=D.threadId??t.find(pe=>pe.messageId===D.id)?.threadId;X&&Ae({to:"/mail/$mailboxId/$threadId/$messageId",params:{mailboxId:D.mailboxId??e,threadId:X,messageId:D.id},search:pe=>({...pe,q:ee||void 0}),hash:ne})},[e,Ae,ne,ee,t]);if(M&&b)return r.jsx(Uo,{mailboxId:e,accountId:b,selectedMessageId:n,imapThreads:t,title:y??"Drafts",unreadCount:w??void 0});const $=r.jsx(wi,{mailboxId:e,threads:t,selectedMessageId:n,isLoading:s,isError:o,error:i,onRetry:j,searchQuery:F,searchPredicate:he,onDeleteMessages:l,isDeleting:u,isMoving:d,onLoadMore:f,hasMore:m,isLoadingMore:g,accountId:b,listTitle:T,listFilter:L,listScopeLabel:T,hideHeader:!0,onTriageContextChange:k,commandsRef:C}),U=Ee[0]?.accountId,K=Y==="phone"&&U?r.jsx(Mi,{accountId:U,children:$}):$,oe=p&&x.length>0&&b?r.jsx(Ti,{accountId:b,currentMailboxId:e,candidates:x,onMove:a,children:K}):K;return r.jsx(Jn,{title:T,unreadCount:w,preset:P,selectedCategory:N,activeFilters:A,onSelectCategory:z,onToggleFilter:Z,onClearFilters:E,searchResults:Ie,searchLoading:s,relatedResults:$e,relatedLoading:Pe,onSelectSearchResult:H,searchResultsInBody:!0,refreshControl:ye,children:oe})}function qi(){const{mailboxId:e,mailboxAccountId:n,mailboxAccountLoading:t,selectedThread:s,conversation:o,onReply:i,onToolbarDelete:l,onToolbarStar:a,onToolbarMove:u,handleDeselectIfRemoved:d}=ht(),f=!!o,m=Bn(o?.threadId),g=c.useRef(null),{railFits:b,openRail:y}=m;c.useEffect(()=>{if(!b)return;const M=s?.messageId??null;M&&g.current!==M&&s?.authenticity?.dkimMismatch&&(g.current=M,y())},[b,y,s?.messageId,s?.authenticity?.dkimMismatch]);const w=o?r.jsx(Xt,{threadId:o.threadId,mailboxId:o.mailboxId,subject:o.subject,selectedMessageId:o.messageId,authenticity:o.authenticity,onOpenIntelligence:m.open}):r.jsx(Qs,{});return r.jsxs(r.Fragment,{children:[r.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[r.jsx(Wn,{hasThread:f,messageId:o?.messageId,intelligenceOpen:m.isShowing,canToggleIntelligence:m.canToggle,onToggleIntelligence:m.toggle,onReply:i?()=>i("reply"):void 0,onReplyAll:i?()=>i("reply-all"):void 0,onForward:i?()=>i("forward"):void 0,onDelete:f?l:void 0,onToggleStar:f?a:void 0,isStarred:s?.hasStars,moveContext:f&&n?{accountId:n,currentMailboxId:e,onMove:u}:void 0,moveContextLoading:t}),r.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:w})]}),r.jsx(Zt,{isOpen:m.drawerOpen,onClose:m.closeDrawer,thread:s,mailboxId:e,accountId:n,onAfterOptimisticRemove:d})]})}function Qi(){const{mailboxId:e,mailboxAccountId:n,selectedThread:t,onToggleIntelligence:s,handleDeselectIfRemoved:o}=ht();return r.jsx($n,{onClose:s,thread:t,mailboxId:e,accountId:n,onAfterOptimisticRemove:o})}function Ji(){const{mailboxId:e,mailboxAccountId:n,selectedThread:t,conversation:s,onOpenThread:o,onBack:i,nextThread:l,previousThread:a,handleDeselectIfRemoved:u}=ht(),d=Pn(s?.threadId??null);return s?r.jsxs(r.Fragment,{children:[r.jsx(Xt,{threadId:s.threadId,mailboxId:s.mailboxId,subject:s.subject,selectedMessageId:s.messageId,authenticity:s.authenticity,onBack:i,onOpenIntelligence:d.toggle,onSwipeNext:l?()=>o(l):void 0,onSwipePrevious:a?()=>o(a):void 0,mobileIntelligenceOpen:d.isOpen}),r.jsx(Zt,{isOpen:d.isOpen,onClose:d.close,thread:t,mailboxId:e,accountId:n,onAfterOptimisticRemove:u})]}):r.jsx(rs,{})}const Sr=Object.assign(Ui,{List:rs,Reading:qi,Intelligence:Qi,Phone:Ji});export{Sr as M};
@@ -1 +1 @@
1
- import{i as n,j as a,B as o}from"./index-TkI6PAgL.js";import{M as e}from"./menu-Cv_oe3kJ.js";function i(){const s=n();return!s||s.showNavPane?null:a.jsx(o,{variant:"ghost",size:"sm",icon:a.jsx(e,{className:"size-4"}),onClick:s.openNav,"aria-label":"Open folders",className:"-ml-1 shrink-0"})}export{i as N};
1
+ import{i as n,j as a,B as o}from"./index-CL-RwCQv.js";import{M as e}from"./menu-CKfqd7Zr.js";function i(){const s=n();return!s||s.showNavPane?null:a.jsx(o,{variant:"ghost",size:"sm",icon:a.jsx(e,{className:"size-4"}),onClick:s.openNav,"aria-label":"Open folders",className:"-ml-1 shrink-0"})}export{i as N};
@@ -1 +1 @@
1
- import{c as re,j as e,b as z,ac as V,ag as oe,r as i,at as he,aw as A,ad as F,n as xe,a7 as X,V as fe,ab as ye,s as Q,ax as Y,Q as ne,B as C,af as D,aa as ge,ae as ve,as as q,ap as be,I as je}from"./index-TkI6PAgL.js";import{K as Se}from"./kbd-B6SN6Hd3.js";import{c as we}from"./account-form-helpers-DhckT_PN.js";import{M as ke}from"./mail-DKYXzawQ.js";const K=re("AtSign",[["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["path",{d:"M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8",key:"7n84p3"}]]);const Ce=re("Server",[["rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2",key:"ngkwjq"}],["rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2",key:"iecqi9"}],["line",{x1:"6",x2:"6.01",y1:"6",y2:"6",key:"16zg32"}],["line",{x1:"6",x2:"6.01",y1:"18",y2:"18",key:"nzw8ys"}]]);function Ne({url:t}){return e.jsxs("p",{className:"text-2xs text-fg-subtle",children:["Stored encrypted, used only to connect to your mail server."," ",t?e.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"text-accent underline",children:"How to create an app password"}):e.jsx("span",{children:"Check your provider's help for app password instructions."})]})}function Ee({raised:t,className:o,...s}){return e.jsx("div",{className:z("rounded-sm border border-line bg-surface",t?"bg-surface-raised shadow-sm":"",o),...s})}function J({value:t,defaultValue:o,onValueChange:s,...a}){return s?e.jsxs(V,{value:t,onChange:n=>s(n.target.value),...a,children:[e.jsx("option",{value:"tls",children:"TLS/SSL"}),e.jsx("option",{value:"starttls",children:"STARTTLS"}),e.jsx("option",{value:"none",children:"None (insecure)"})]}):e.jsxs(V,{defaultValue:o??t,...a,children:[e.jsx("option",{value:"tls",children:"TLS/SSL"}),e.jsx("option",{value:"starttls",children:"STARTTLS"}),e.jsx("option",{value:"none",children:"None (insecure)"})]})}function G(t){return{tls:t==="tls",startTls:t==="starttls"}}function Te({steps:t,activeStep:o}){return e.jsx("ol",{className:"flex items-center gap-1",children:t.map((s,a)=>{const n=a<o,r=a===o;return e.jsxs("li",{className:"flex items-center gap-1",children:[a>0&&e.jsx("span",{className:"h-px w-5 bg-line","aria-hidden":!0}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:z("flex size-5 items-center justify-center rounded-full text-2xs font-semibold tabular-nums",n&&"bg-accent text-accent-fg",r&&"bg-accent-soft text-accent ring-1 ring-accent",!n&&!r&&"bg-surface-sunken text-fg-subtle"),children:n?e.jsx(oe,{className:"size-3"}):a+1}),e.jsx("span",{className:z("hidden text-2xs sm:inline",r?"font-medium text-fg":"text-fg-subtle"),children:s})]})]},s)})})}function L({steps:t,activeStep:o,title:s,subtitle:a,children:n,footer:r,hideSteps:u}){return e.jsxs("div",{className:"flex min-h-dvh w-full flex-col items-center overflow-y-auto bg-canvas pb-[max(2rem,env(safe-area-inset-bottom,0px))] pl-[max(2rem,env(safe-area-inset-left,0px))] pr-[max(2rem,env(safe-area-inset-right,0px))] pt-[max(2rem,env(safe-area-inset-top,0px))] font-sans text-fg sm:pt-[30vh]",children:[!u&&e.jsx("div",{className:"mb-5 w-full max-w-xl",children:e.jsx(Te,{steps:t,activeStep:o})}),e.jsxs(Ee,{raised:!0,className:"w-full max-w-xl",children:[e.jsxs("div",{className:"px-5 pt-5",children:[e.jsx("h1",{className:"text-xl font-semibold text-fg",children:s}),a&&e.jsx("p",{className:"mt-1 text-sm text-fg-muted",children:a})]}),e.jsx("div",{className:"px-5 py-5",children:n}),r&&e.jsx("div",{className:"flex items-center justify-between gap-3 border-t border-line px-5 py-3",children:r})]})]})}const Pe="Coming soon — use IMAP for now.";function W({name:t,description:o,icon:s,comingSoon:a,selected:n,onSelect:r}){const[u,h]=i.useState(!1),c=()=>{if(r){r();return}a&&h(!0)};return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("button",{type:"button",onClick:c,"aria-disabled":a||void 0,className:z("flex flex-col items-start gap-2 rounded-sm border p-3 text-left transition-colors",n?"border-accent-2 bg-accent-2-soft":"border-line bg-surface hover:border-line-strong",a&&"opacity-55"),children:[e.jsx("span",{className:z("text-fg-muted",n&&"text-accent-2"),children:s}),e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-semibold text-fg",children:t}),a&&e.jsx("span",{className:"rounded-full bg-surface-sunken px-1.5 py-0.5 text-2xs text-fg-subtle",children:"soon"})]}),e.jsx("span",{className:"text-xs text-fg-subtle",children:o})]}),u&&e.jsx("p",{className:"text-2xs text-fg-subtle",children:Pe})]})}function Z({legend:t,badge:o,host:s,port:a,security:n,readOnly:r,onHostChange:u,onPortChange:h,onSecurityChange:c,hostPlaceholder:v,portPlaceholder:j}){const S=i.useId(),y=i.useId(),w=i.useId();return e.jsxs("fieldset",{children:[e.jsxs("legend",{className:"flex items-center gap-2 text-sm font-semibold text-fg",children:[t,o&&e.jsx(he,{tone:o.tone,children:o.label})]}),e.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-3 sm:grid-cols-[1fr_6rem_8rem] sm:gap-2",children:[e.jsxs("div",{children:[e.jsx(A,{htmlFor:S,children:"Host"}),u?e.jsx(F,{id:S,readOnly:r,value:s,onChange:x=>u(x.target.value),placeholder:v}):e.jsx(F,{id:S,readOnly:r,defaultValue:s,placeholder:v})]}),e.jsxs("div",{children:[e.jsx(A,{htmlFor:y,children:"Port"}),h?e.jsx(F,{id:y,readOnly:r,value:a,onChange:x=>h(x.target.value),placeholder:j}):e.jsx(F,{id:y,readOnly:r,defaultValue:a,placeholder:j})]}),e.jsxs("div",{children:[e.jsx(A,{htmlFor:w,children:"Security"}),c?e.jsx(J,{id:w,value:n,onValueChange:c}):e.jsx(J,{id:w,defaultValue:n})]})]})]})}function _({label:t,detail:o,state:s}){return e.jsxs("div",{className:"flex items-start gap-3 py-2",children:[e.jsxs("span",{className:z("mt-0.5 flex size-5 shrink-0 items-center justify-center rounded-full text-2xs",s==="ok"&&"bg-positive text-accent-fg",s==="failed"&&"bg-danger text-accent-fg",s==="running"&&"border border-accent text-accent",s==="pending"&&"border border-line text-fg-subtle"),children:[s==="ok"&&e.jsx(oe,{className:"size-3"}),s==="failed"&&"!",s==="running"&&e.jsx("span",{className:"size-2 animate-pulse rounded-full bg-accent"})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:z("text-sm",s==="failed"?"font-medium text-danger":"text-fg"),children:t}),o&&e.jsx("div",{className:"mt-0.5 text-xs text-fg-subtle",children:o})]})]})}const Ie=(t,o)=>{const s=i.useRef(o);s.current=o,i.useEffect(()=>{if(!t)return;const a=()=>{document.visibilityState==="visible"&&s.current()};return document.addEventListener("visibilitychange",a),window.addEventListener("pageshow",a),()=>{document.removeEventListener("visibilitychange",a),window.removeEventListener("pageshow",a)}},[t])},Ae={"gmail.com":{imap:{host:"imap.gmail.com",port:993,security:"tls"},smtp:{host:"smtp.gmail.com",port:587,security:"starttls"},source:"provider-table"},"googlemail.com":{imap:{host:"imap.gmail.com",port:993,security:"tls"},smtp:{host:"smtp.gmail.com",port:587,security:"starttls"},source:"provider-table"},"outlook.com":{imap:{host:"outlook.office365.com",port:993,security:"tls"},smtp:{host:"smtp.office365.com",port:587,security:"starttls"},source:"provider-table"},"hotmail.com":{imap:{host:"outlook.office365.com",port:993,security:"tls"},smtp:{host:"smtp.office365.com",port:587,security:"starttls"},source:"provider-table"},"live.com":{imap:{host:"outlook.office365.com",port:993,security:"tls"},smtp:{host:"smtp.office365.com",port:587,security:"starttls"},source:"provider-table"},"msn.com":{imap:{host:"outlook.office365.com",port:993,security:"tls"},smtp:{host:"smtp.office365.com",port:587,security:"starttls"},source:"provider-table"},"icloud.com":{imap:{host:"imap.mail.me.com",port:993,security:"tls"},smtp:{host:"smtp.mail.me.com",port:587,security:"starttls"},source:"provider-table"},"me.com":{imap:{host:"imap.mail.me.com",port:993,security:"tls"},smtp:{host:"smtp.mail.me.com",port:587,security:"starttls"},source:"provider-table"},"mac.com":{imap:{host:"imap.mail.me.com",port:993,security:"tls"},smtp:{host:"smtp.mail.me.com",port:587,security:"starttls"},source:"provider-table"},"fastmail.com":{imap:{host:"imap.fastmail.com",port:993,security:"tls"},smtp:{host:"smtp.fastmail.com",port:465,security:"tls"},source:"provider-table"},"fastmail.fm":{imap:{host:"imap.fastmail.com",port:993,security:"tls"},smtp:{host:"smtp.fastmail.com",port:465,security:"tls"},source:"provider-table"},"yahoo.com":{imap:{host:"imap.mail.yahoo.com",port:993,security:"tls"},smtp:{host:"smtp.mail.yahoo.com",port:465,security:"tls"},source:"provider-table"},"yahoo.co.uk":{imap:{host:"imap.mail.yahoo.com",port:993,security:"tls"},smtp:{host:"smtp.mail.yahoo.com",port:465,security:"tls"},source:"provider-table"},"ymail.com":{imap:{host:"imap.mail.yahoo.com",port:993,security:"tls"},smtp:{host:"smtp.mail.yahoo.com",port:465,security:"tls"},source:"provider-table"},"aol.com":{imap:{host:"imap.aol.com",port:993,security:"tls"},smtp:{host:"smtp.aol.com",port:465,security:"tls"},source:"provider-table"},"zoho.com":{imap:{host:"imap.zoho.com",port:993,security:"tls"},smtp:{host:"smtp.zoho.com",port:465,security:"tls"},source:"provider-table"},"gmx.com":{imap:{host:"imap.gmx.com",port:993,security:"tls"},smtp:{host:"smtp.gmx.com",port:587,security:"starttls"},source:"provider-table"},"gmx.net":{imap:{host:"imap.gmx.net",port:993,security:"tls"},smtp:{host:"mail.gmx.net",port:587,security:"starttls"},source:"provider-table"},"gmx.de":{imap:{host:"imap.gmx.net",port:993,security:"tls"},smtp:{host:"mail.gmx.net",port:587,security:"starttls"},source:"provider-table"},"web.de":{imap:{host:"imap.web.de",port:993,security:"tls"},smtp:{host:"smtp.web.de",port:587,security:"starttls"},source:"provider-table"},"mail.com":{imap:{host:"imap.mail.com",port:993,security:"tls"},smtp:{host:"smtp.mail.com",port:465,security:"tls"},source:"provider-table"},"hey.com":{imap:{host:"imap.hey.com",port:993,security:"tls"},smtp:{host:"smtp.hey.com",port:465,security:"tls"},source:"provider-table"},"tutanota.com":{imap:{host:"mail.tutanota.com",port:993,security:"tls"},smtp:{host:"mail.tutanota.com",port:465,security:"tls"},source:"provider-table"},"tuta.io":{imap:{host:"mail.tutanota.com",port:993,security:"tls"},smtp:{host:"mail.tutanota.com",port:465,security:"tls"},source:"provider-table"},"posteo.de":{imap:{host:"posteo.de",port:993,security:"tls"},smtp:{host:"posteo.de",port:465,security:"tls"},source:"provider-table"},"runbox.com":{imap:{host:"imap.runbox.com",port:993,security:"tls"},smtp:{host:"smtp.runbox.com",port:587,security:"starttls"},source:"provider-table"},"mailbox.org":{imap:{host:"imap.mailbox.org",port:993,security:"tls"},smtp:{host:"smtp.mailbox.org",port:465,security:"tls"},source:"provider-table"},"hushmail.com":{imap:{host:"imap.hushmail.com",port:993,security:"tls"},smtp:{host:"smtp.hushmail.com",port:465,security:"tls"},source:"provider-table"}},Le={"gmail.com":"https://support.google.com/accounts/answer/185833","googlemail.com":"https://support.google.com/accounts/answer/185833","yahoo.com":"https://help.yahoo.com/kb/generate-manage-third-party-passwords-sln15241.html","icloud.com":"https://support.apple.com/en-us/102654","me.com":"https://support.apple.com/en-us/102654","mac.com":"https://support.apple.com/en-us/102654","fastmail.com":"https://www.fastmail.help/hc/en-us/articles/360058752854","fastmail.fm":"https://www.fastmail.help/hc/en-us/articles/360058752854","outlook.com":"https://support.microsoft.com/en-us/account-billing/manage-app-passwords-for-two-step-verification-d6dc8c6d-4bf7-4851-ad95-6d07799387e9","hotmail.com":"https://support.microsoft.com/en-us/account-billing/manage-app-passwords-for-two-step-verification-d6dc8c6d-4bf7-4851-ad95-6d07799387e9","zoho.com":"https://help.zoho.com/portal/en/kb/zoho-mail/client-configuration/imap-access/articles/zoho-mail-app-passwords"};function ae(t){try{const s=new DOMParser().parseFromString(t,"application/xml");if(s.querySelector("parsererror"))return null;const a=s.querySelectorAll("incomingServer[type='imap']"),n=s.querySelectorAll("outgoingServer[type='smtp']");if(!a.length||!n.length)return null;const r=a[0],u=n[0],h=r.querySelector("hostname")?.textContent?.trim(),c=r.querySelector("port")?.textContent?.trim(),v=r.querySelector("socketType")?.textContent?.trim().toUpperCase(),j=u.querySelector("hostname")?.textContent?.trim(),S=u.querySelector("port")?.textContent?.trim(),y=u.querySelector("socketType")?.textContent?.trim().toUpperCase();if(!h||!c||!j||!S)return null;const w=x=>x==="SSL"||x==="TLS"||x==="SSL/TLS"?"tls":x==="STARTTLS"?"starttls":"none";return{imap:{host:h,port:Number.parseInt(c,10),security:w(v)},smtp:{host:j,port:Number.parseInt(S,10),security:w(y)},source:"mozilla-autoconfig"}}catch{return null}}async function Me(t,o){try{const s=`https://autoconfig.thunderbird.net/v1.1/${t}`,a=await fetch(s,{signal:o});if(!a.ok)return null;const n=await a.text(),r=ae(n);return r||null}catch{return null}}async function Fe(t,o){try{const s=`https://autoconfig.${t}/mail/config-v1.1.xml`,a=await fetch(s,{signal:o});if(!a.ok)return null;const n=await a.text(),r=ae(n);return r?{...r,source:"domain-autoconfig"}:null}catch{return null}}function Re(t){return{imap:{host:`imap.${t}`,port:993,security:"tls"},smtp:{host:`smtp.${t}`,port:587,security:"starttls"},source:"heuristic"}}async function Oe(t,o=1500){const s=t.indexOf("@");if(s===-1)return null;const a=t.slice(s+1).toLowerCase();if(!a)return null;const n=Ae[a];if(n)return n;const r=new AbortController,u=setTimeout(()=>r.abort(),o);try{const h=await Me(a,r.signal);if(h)return h;const c=await Fe(a,r.signal);if(c)return c}finally{clearTimeout(u)}return Re(a)}function ze(t){const o=t.indexOf("@");return o===-1?"Looking up server settings…":`Looking up settings for ${t.slice(o+1)}…`}function ie(t){const o=t.indexOf("@");if(o===-1)return;const s=t.slice(o+1).toLowerCase();return Le[s]}const ce=[{id:"icloud",label:"iCloud",username:"full-email",imap:{host:"imap.mail.me.com",port:993,security:"tls"},smtp:{host:"smtp.mail.me.com",port:587,security:"starttls"},passwordHelp:{text:"iCloud requires an app-specific password, not your Apple ID password. Generate one under Sign-In & Security → App-Specific Passwords.",url:"https://support.apple.com/en-us/102654"}},{id:"yahoo",label:"Yahoo",username:"full-email",imap:{host:"imap.mail.yahoo.com",port:993,security:"tls"},smtp:{host:"smtp.mail.yahoo.com",port:465,security:"tls"},passwordHelp:{text:"Yahoo requires an app password, not your login password. Generate one under Account Security.",url:"https://help.yahoo.com/kb/generate-manage-third-party-passwords-sln15241.html"}},{id:"aol",label:"AOL",username:"full-email",imap:{host:"imap.aol.com",port:993,security:"tls"},smtp:{host:"smtp.aol.com",port:465,security:"tls"},passwordHelp:{text:"AOL requires an app password, not your login password. Generate one under Account Security.",url:"https://login.aol.com/account/security"}},{id:"fastmail",label:"Fastmail",username:"full-email",imap:{host:"imap.fastmail.com",port:993,security:"tls"},smtp:{host:"smtp.fastmail.com",port:465,security:"tls"},passwordHelp:{text:"Fastmail requires an app password, not your login password. Create one under Settings → Privacy & Security → App passwords.",url:"https://www.fastmail.help/hc/en-us/articles/360058752854"}}];function ee(t){return ce.find(o=>o.id===t)}const _e={"icloud.com":"icloud","me.com":"icloud","mac.com":"icloud","yahoo.com":"yahoo","yahoo.co.uk":"yahoo","ymail.com":"yahoo","aol.com":"aol","fastmail.com":"fastmail","fastmail.fm":"fastmail"};function He(t){const o=t.indexOf("@");if(o===-1)return"";const s=t.slice(o+1).toLowerCase();return _e[s]??""}const M=["Connector","Address","Servers","Credentials","Test","Sync"],R={connector:0,address:1,servers:2,credentials:3,test:4,sync:5},te={host:"",port:993,security:"tls"},se={host:"",port:587,security:"starttls"};function $e({onStart:t}){return i.useEffect(()=>{const o=s=>{s.key==="Enter"&&t()};return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[t]),e.jsx(L,{steps:M,activeStep:0,hideSteps:!0,title:"Welcome to Remit",subtitle:"One inbox for all your mail, with context about every message.",footer:e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-2xs text-fg-subtle",children:[e.jsx(Se,{children:"Enter"})," to continue"]}),e.jsx(C,{variant:"primary",onClick:t,children:"Add your first account"})]}),children:e.jsxs("div",{className:"flex flex-col items-start py-5",children:[e.jsx("span",{className:"flex size-14 items-center justify-center rounded-md bg-accent-soft",children:e.jsx(ke,{className:"size-7 text-accent"})}),e.jsx("p",{className:"mt-5 max-w-sm text-sm leading-relaxed text-fg-muted",children:"Remit syncs your existing mailboxes and tells you who is really writing to you — sender history, authenticity checks, and similar messages, right next to every email."})]})})}function De({onContinue:t,onMicrosoft:o,onBack:s,showBack:a}){const[n,r]=i.useState("imap");i.useEffect(()=>{const h=c=>{c.key==="Enter"&&(n==="microsoft"?o():t()),c.key==="Escape"&&s()};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[t,o,s,n]);const u=()=>{n==="microsoft"?o():t()};return e.jsx(L,{steps:M,activeStep:R.connector,title:"How does this account connect?",subtitle:"Choose a sign-in method. IMAP works with any provider.",footer:e.jsxs(e.Fragment,{children:[a?e.jsx(C,{variant:"ghost",onClick:s,children:"Back"}):e.jsx("span",{}),e.jsx(C,{variant:"primary",onClick:u,children:n==="microsoft"?"Continue with Microsoft":"Continue with IMAP"})]}),children:e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-3",children:[e.jsx(W,{name:"IMAP / SMTP",description:"Any mail provider — Fastmail, iCloud, your own server.",icon:e.jsx(Ce,{className:"size-5"}),selected:n==="imap",onSelect:()=>r("imap")}),e.jsx(W,{name:"Gmail",description:"Sign in with Google. No app passwords.",icon:e.jsx(K,{className:"size-5"}),comingSoon:!0}),e.jsx(W,{name:"Outlook / Microsoft 365",description:"Sign in with Microsoft. Works with Outlook.com and work accounts.",icon:e.jsx(je,{className:"size-5"}),selected:n==="microsoft",onSelect:()=>r("microsoft")})]})})}function qe({onBack:t,onConnected:o}){const[s,a]=i.useState(""),[n,r]=i.useState(null),[u,h]=i.useState(!1),[c,v]=i.useState(!1),j=i.useRef(!0);i.useEffect(()=>(j.current=!0,()=>{j.current=!1}),[]);const S=i.useRef(new Set),{refetch:y}=Q(ne()),w=X({...be(),onSuccess:p=>{j.current&&(h(!0),window.location.assign(p.authorizationUrl))},onError:p=>{v(!1),r(p instanceof Error?p.message:"Failed to start sign-in")}});Ie(u,i.useCallback(()=>{v(!1),y().then(({data:p,isError:m})=>{if(!j.current)return;if(m||!p){r("Couldn't check whether the sign-in finished. Open Settings › Accounts to see whether the account is connected.");return}r(null);const N=p.accounts.find(b=>!S.current.has(b.accountId));N&&o(N.accountId)})},[y,o]));const x=c||w.isPending,f=()=>{x||(r(null),v(!0),y().then(({data:p,isError:m})=>{if(j.current){if(m||!p){v(!1),r("Couldn't read this instance's accounts, so sign-in can't be tracked. Check your connection and try again.");return}S.current=new Set(p.accounts.map(N=>N.accountId)),w.mutate({body:{email:s.trim()||void 0}})}}))},l=i.useRef(f);return l.current=f,i.useEffect(()=>{const p=m=>{m.key==="Enter"&&l.current(),m.key==="Escape"&&t()};return window.addEventListener("keydown",p),()=>window.removeEventListener("keydown",p)},[t]),e.jsx(L,{steps:M,activeStep:R.connector,title:"Sign in with Microsoft",subtitle:"You'll be redirected to Microsoft to sign in securely.",footer:e.jsxs(e.Fragment,{children:[e.jsx(C,{variant:"ghost",onClick:t,children:"Back"}),e.jsx(C,{variant:"primary",onClick:f,disabled:x,icon:x?e.jsx(D,{className:"size-4 animate-spin"}):void 0,children:x?"Redirecting…":u?"Start over":"Sign in with Microsoft"})]}),children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(A,{htmlFor:"microsoft-email",children:"Email address (optional)"}),e.jsx(F,{id:"microsoft-email",icon:e.jsx(K,{className:"size-4"}),placeholder:"you@outlook.com",value:s,onChange:p=>a(p.target.value),type:"email",autoComplete:"email"}),e.jsx("p",{className:"mt-1.5 text-2xs text-fg-subtle",children:"Pre-fills the Microsoft sign-in form. Leave blank to choose on the Microsoft page."})]}),u&&e.jsx(q,{tone:"info",children:"Waiting for Microsoft. Finish signing in — this window carries on the moment the account is connected, wherever you finished."}),n&&e.jsx(q,{tone:"danger",children:n})]})})}function Ge({initialEmail:t,initialDisplayName:o,onContinue:s,onBack:a}){const[n,r]=i.useState(t),[u,h]=i.useState(o),[c,v]=i.useState(!1),[j,S]=i.useState(""),[y,w]=i.useState(null),x=i.useCallback(async()=>{const f=n.trim();if(!f.includes("@")||!f.includes(".")){w("Enter a valid email address.");return}w(null),v(!0),S(ze(f));try{const l=await Oe(f);s(f,u.trim(),l)}finally{v(!1)}},[n,u,s]);return i.useEffect(()=>{const f=l=>{l.key==="Enter"&&!c&&x(),l.key==="Escape"&&a()};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[x,c,a]),e.jsx(L,{steps:M,activeStep:R.address,title:"What's the email address?",subtitle:"We'll detect the server settings for you.",footer:e.jsxs(e.Fragment,{children:[e.jsx(C,{variant:"ghost",onClick:a,children:"Back"}),e.jsx(C,{variant:"primary",disabled:c,onClick:()=>{x()},children:"Continue"})]}),children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(A,{htmlFor:"onboarding-email",children:"Email address"}),e.jsx(F,{id:"onboarding-email",icon:e.jsx(K,{className:"size-4"}),placeholder:"you@example.com",value:n,onChange:f=>{r(f.target.value),w(null)},type:"email",autoComplete:"email"})]}),e.jsxs("div",{children:[e.jsx(A,{htmlFor:"onboarding-display-name",children:"Display name (optional)"}),e.jsx(F,{id:"onboarding-display-name",placeholder:"Alice",value:u,onChange:f=>h(f.target.value)}),e.jsx("p",{className:"mt-1.5 text-2xs text-fg-subtle",children:"What to call this account in Remit. Leave blank to use a name derived from the address."})]}),c&&e.jsxs("div",{className:"mt-3 flex items-center gap-2 text-xs text-fg-muted",children:[e.jsx(D,{className:"size-3.5 animate-spin text-accent"}),j]}),y&&!c&&e.jsx("div",{className:"mt-3",children:e.jsx(q,{tone:"danger",children:y})})]})})}function Be({email:t,imapConfig:o,smtpConfig:s,discovered:a,onContinue:n,onBack:r,onChange:u}){const[h,c]=i.useState(o),[v,j]=i.useState(s),[S,y]=i.useState(()=>He(t)),[w,x]=i.useState(!1),[f,l]=i.useState(null),p=ee(S),m=p!==void 0&&!w,N=i.useCallback(g=>{y(g),x(!1),l(null);const d=ee(g);d&&(c({host:d.imap.host,port:d.imap.port,security:d.imap.security}),j({host:d.smtp.host,port:d.smtp.port,security:d.smtp.security}))},[]);i.useEffect(()=>{u(h,v)},[h,v,u]);const b=h.host.trim()!=="",k=i.useCallback(()=>{if(!b){l("Enter the IMAP host.");return}l(null),n()},[b,n]);i.useEffect(()=>{const g=d=>{d.key==="Enter"&&k(),d.key==="Escape"&&r()};return window.addEventListener("keydown",g),()=>window.removeEventListener("keydown",g)},[k,r]);const T=t.split("@")[1]??"your domain",O=p?"Pick your provider to fill in the right settings — or choose Custom to enter them by hand.":a?"Found via autodiscovery — adjust anything that looks off.":`We couldn't detect settings for ${T} — enter them manually.`,P=m?{label:"preset",tone:"neutral"}:!p&&a?{label:"detected",tone:"positive"}:void 0,I=p?.passwordHelp.url??ie(t);return e.jsx(L,{steps:M,activeStep:R.servers,title:"Confirm server settings",subtitle:O,footer:e.jsxs(e.Fragment,{children:[e.jsx(C,{variant:"ghost",onClick:r,children:"Back"}),e.jsx(C,{variant:"primary",onClick:k,children:"Continue"})]}),children:e.jsxs("div",{className:"space-y-5",children:[f&&e.jsx(q,{tone:"danger",children:f}),e.jsxs("div",{children:[e.jsx(A,{htmlFor:"provider-select",children:"Provider"}),e.jsxs(V,{id:"provider-select",value:S,onChange:g=>N(g.target.value),children:[e.jsx("option",{value:"",children:"Custom / other"}),ce.map(g=>e.jsx("option",{value:g.id,children:g.label},g.id))]}),p&&e.jsx("p",{className:"mt-1 text-2xs text-fg-subtle",children:m?e.jsxs(e.Fragment,{children:["Server settings are pre-filled for ",p.label," and locked."," ",e.jsx("button",{type:"button",className:"text-accent underline",onClick:()=>x(!0),children:"Advanced"})," ","lets you edit them by hand."]}):e.jsxs(e.Fragment,{children:["Editing ",p.label,"'s settings by hand."]})})]}),e.jsx(Z,{legend:"IMAP — incoming",badge:P,readOnly:m,host:h.host,port:String(h.port),security:h.security,hostPlaceholder:"imap.example.com",portPlaceholder:"993",onHostChange:g=>{c(d=>({...d,host:g})),l(null)},onPortChange:g=>c(d=>({...d,port:Number(g)})),onSecurityChange:g=>c(d=>({...d,security:g}))}),e.jsx("p",{className:"text-2xs text-fg-subtle",children:"Sending (SMTP) is optional — leave it blank to set up a receive-only account and add sending later in Settings."}),e.jsx(Z,{legend:"SMTP — outgoing (optional)",badge:P,readOnly:m,host:v.host,port:String(v.port),security:v.security,hostPlaceholder:"smtp.example.com",portPlaceholder:"587",onHostChange:g=>{j(d=>({...d,host:g})),l(null)},onPortChange:g=>j(d=>({...d,port:Number(g)})),onSecurityChange:g=>j(d=>({...d,security:g}))}),p&&e.jsxs("p",{className:"text-2xs text-fg-subtle",children:[p.passwordHelp.text," ",I&&e.jsx("a",{href:I,target:"_blank",rel:"noopener noreferrer",className:"text-accent underline",children:"Get an app password"})]})]})})}function Ue({email:t,username:o,password:s,onContinue:a,onBack:n,onChange:r}){const[u,h]=i.useState(o||t),[c,v]=i.useState(s),[j,S]=i.useState(null),y=t.split("@")[1]??"",w=ie(t),x=u.trim()!==""&&c.trim()!=="";i.useEffect(()=>{r(u,c)},[u,c,r]);const f=i.useCallback(()=>{if(!x){S("Enter your username and password.");return}S(null),a()},[x,a]);return i.useEffect(()=>{const l=p=>{p.key==="Enter"&&f(),p.key==="Escape"&&n()};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[f,n]),e.jsx(L,{steps:M,activeStep:R.credentials,title:`Sign in to ${y||"your mail server"}`,subtitle:"Many providers require an app password instead of your normal one.",footer:e.jsxs(e.Fragment,{children:[e.jsx(C,{variant:"ghost",onClick:n,children:"Back"}),e.jsx(C,{variant:"primary",onClick:f,children:"Test connection"})]}),children:e.jsxs("div",{className:"space-y-3",children:[j&&e.jsx("div",{className:"rounded-md bg-danger-soft px-3 py-2 text-sm text-danger",children:j}),e.jsxs("div",{children:[e.jsx(A,{htmlFor:"credentials-username",children:"Username"}),e.jsx(F,{id:"credentials-username",value:u,onChange:l=>{h(l.target.value),S(null)},autoComplete:"username"})]}),e.jsxs("div",{children:[e.jsx(A,{htmlFor:"credentials-password",children:"Password or app password"}),e.jsx(ve,{id:"credentials-password",value:c,onChange:l=>{v(l.target.value),S(null)},autoComplete:"current-password"})]}),e.jsx(Ne,{url:w})]})})}function We({email:t,imapConfig:o,smtpConfig:s,username:a,password:n,onSuccess:r,onBackToCredentials:u,onBackToServers:h}){const[c,v]=i.useState({imapState:"running",smtpState:"pending",phase:"running"}),[j,S]=i.useState(0),y=s.host.trim()!=="",w=G(o.security),x=G(s.security),f=X({...ge()});i.useEffect(()=>{let m=!1;const N=[];return v({imapState:"running",smtpState:"pending",phase:"running"}),f.mutate({body:{username:a,password:n,imapHost:o.host,imapPort:o.port,imapTls:w.tls,imapStartTls:w.startTls,smtpHost:s.host,smtpPort:s.port,smtpTls:x.tls,smtpStartTls:x.startTls}},{onSuccess:b=>{if(m)return;const k=b.imapSuccess,T=y?b.smtpSuccess:!0;v({imapState:k?"ok":"failed",smtpState:y?"running":"ok",imapDetail:k?`Connected — ${o.host}:${o.port}`:b.imapError,phase:"running"}),N.push(window.setTimeout(()=>{if(m)return;const O=I=>{const g=I?.toLowerCase()??"";return g.includes("auth")||g.includes("login")||g.includes("535")||g.includes("credential")},P=!k&&O(b.imapError)||k&&y&&!b.smtpSuccess&&O(b.smtpError);v({imapState:k?"ok":"failed",smtpState:y?b.smtpSuccess?"ok":"failed":"ok",imapDetail:k?`Connected — ${o.host}:${o.port}`:b.imapError,smtpDetail:y?b.smtpSuccess?`Connected — ${s.host}:${s.port}`:b.smtpError:"Not set up — receive-only",rawError:k?y&&!b.smtpSuccess?b.smtpError:void 0:b.imapError,phase:k&&T?"success":P?"auth-failure":"network-failure"}),k&&T&&N.push(window.setTimeout(()=>{m||r()},800))},400))},onError:b=>{if(m)return;const k=b instanceof Error?b.message:"Connection failed";v({imapState:"failed",smtpState:"failed",imapDetail:k,smtpDetail:k,rawError:k,phase:"network-failure"})}}),()=>{m=!0;for(const b of N)window.clearTimeout(b)}},[j]);const{phase:l}=c;i.useEffect(()=>{const m=N=>{N.key==="Escape"&&(l==="auth-failure"?u():l==="network-failure"&&h())};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[l,u,h]);const p=l==="auth-failure"?e.jsxs(e.Fragment,{children:[e.jsx(C,{variant:"ghost",onClick:u,children:"Back to credentials"}),e.jsx(C,{variant:"primary",onClick:()=>S(m=>m+1),children:"Retry"})]}):l==="network-failure"?e.jsxs(e.Fragment,{children:[e.jsx(C,{variant:"ghost",onClick:h,children:"Back to servers"}),e.jsx(C,{variant:"primary",onClick:()=>S(m=>m+1),children:"Retry"})]}):l==="success"?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-2xs text-fg-subtle",children:"Connection verified"}),e.jsx(C,{variant:"primary",onClick:r,children:"Start syncing"})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-2xs text-fg-subtle",children:"Testing…"}),e.jsx("span",{})]});return e.jsx(L,{steps:M,activeStep:R.test,title:"Testing the connection",subtitle:`Checking ${t}`,footer:p,children:e.jsxs("div",{className:"divide-y divide-line",children:[e.jsx(_,{label:`IMAP — ${o.host}:${o.port}`,detail:c.imapDetail,state:c.imapState}),e.jsx(_,{label:y?`SMTP — ${s.host}:${s.port}`:"SMTP — sending",detail:y?c.smtpDetail:"Not set up — you can add sending later in Settings",state:c.smtpState}),(l==="auth-failure"||l==="network-failure")&&c.rawError&&e.jsxs("div",{className:"py-3",children:[l==="auth-failure"&&e.jsx("p",{className:"mb-2 text-xs text-fg-muted",children:"Check your password — many providers require an app password."}),e.jsx("code",{className:"block rounded bg-surface-sunken px-2.5 py-2 text-2xs text-fg-muted",children:c.rawError})]})]})})}const Ve=2e4;function Qe({email:t,displayName:o,imapConfig:s,smtpConfig:a,username:n,password:r,onGoToInbox:u}){const h=xe(),[c,v]=i.useState(null),[j,S]=i.useState(null),y=i.useRef(!1),w=G(s.security),x=G(a.security),f=X({...ye(),onSuccess:E=>{v(E.accountId),h.invalidateQueries({queryKey:fe()})},onError:E=>{S(E instanceof Error?E.message:"Failed to create account")}});i.useEffect(()=>{if(y.current)return;y.current=!0;const E=a.host.trim()!=="",H=we({imapHost:s.host,smtpHost:a.host,smtpPort:a.port}),$=E?H??{smtpHost:a.host,smtpPort:a.port,smtpTls:x.tls,smtpStartTls:x.startTls}:null;f.mutate({body:{email:t,displayName:o||void 0,username:n!==t?n:void 0,password:r,imapHost:s.host,imapPort:s.port,imapTls:w.tls,imapStartTls:w.startTls,smtpHost:$?.smtpHost||void 0,smtpPort:$?.smtpPort||void 0,smtpTls:$?.smtpTls??!1,smtpStartTls:$?.smtpStartTls??!1}})},[]);const{data:l,isError:p}=Q({...Y({path:{accountId:c??""}}),enabled:!!c,refetchInterval:E=>{const H=E.state.data?.syncPhase;return H==="complete"||H==="error"?!1:2e3}}),m=l?.syncPhase==="error",{data:N}=Q({...ne(),enabled:!!c&&m}),b=N?.accounts.find(E=>E.accountId===c)?.lastError,k=l?.mailboxes.find(E=>E.fullPath==="INBOX"||E.fullPath==="Inbox"),T=l?.mailboxCountTotal??0,O=l?.mailboxCountSynced??0,P=k?.messagesTotal??0,I=k?.messagesSynced??0,g=P>0?I/P:0,d=l?.syncPhase,le=m?"failed":d==="idle"||d===void 0||d==="discovering_mailboxes"?"running":T>0?"ok":"running",B=m?"failed":!d||d==="idle"||d==="discovering_mailboxes"?"pending":d==="syncing_inbox"||d==="syncing_others"?"running":"ok",U=m?"failed":!d||d==="idle"||d==="discovering_mailboxes"||d==="syncing_inbox"?"pending":d==="syncing_others"?"running":"ok",me=I>0||k?.phase==="complete"||d==="complete"||m,[ue,de]=i.useState(!1);i.useEffect(()=>{if(!c)return;const E=setTimeout(()=>de(!0),Ve);return()=>clearTimeout(E)},[c]);const pe=!!c&&(me||p||ue);return j?e.jsx(L,{steps:M,activeStep:R.sync,title:"Couldn't create account",subtitle:"Something went wrong saving your account.",footer:e.jsxs(e.Fragment,{children:[e.jsx("span",{}),e.jsx(C,{variant:"primary",onClick:()=>{y.current=!1,S(null),f.mutate({body:{email:t,displayName:o||void 0,username:n!==t?n:void 0,password:r,imapHost:s.host,imapPort:s.port,imapTls:w.tls,imapStartTls:w.startTls,smtpHost:a.host||void 0,smtpPort:a.port||void 0,smtpTls:x.tls,smtpStartTls:x.startTls}})},children:"Retry"})]}),children:e.jsx("code",{className:"block rounded bg-surface-sunken px-2.5 py-2 text-2xs text-fg-muted",children:j})}):e.jsx(L,{steps:M,activeStep:R.sync,title:`Syncing ${t}`,subtitle:"Newest mail first — you can start reading right away.",footer:e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-2xs text-fg-subtle",children:"Sync continues in the background"}),pe?e.jsx(C,{variant:"primary",onClick:()=>c&&u(c),children:"Go to inbox"}):e.jsx(C,{variant:"primary",disabled:!0,icon:e.jsx(D,{className:"size-3.5 animate-spin"}),children:"Getting your mail…"})]}),children:f.isPending?e.jsxs("div",{className:"flex items-center gap-2 py-4 text-sm text-fg-muted",children:[e.jsx(D,{className:"size-4 animate-spin text-accent"}),"Creating your account…"]}):e.jsxs("div",{className:"space-y-3",children:[P>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-baseline justify-between text-xs",children:[e.jsx("span",{className:"font-medium text-fg",children:"INBOX"}),e.jsxs("span",{className:"text-fg-subtle tabular-nums",children:[I.toLocaleString()," / ",P.toLocaleString()," ","messages"]})]}),e.jsx("div",{className:"mt-1 h-1.5 overflow-hidden rounded-full bg-surface-sunken",children:e.jsx("div",{className:"h-full rounded-full bg-accent transition-all duration-500",style:{width:`${Math.max(2,g*100)}%`}})})]}),e.jsxs("div",{className:"divide-y divide-line",children:[e.jsx(_,{label:"Mailboxes discovered",detail:T>0?`${T} mailbox${T===1?"":"es"} found`:"Discovering…",state:le}),e.jsx(_,{label:"INBOX",detail:B==="ok"?`${I.toLocaleString()} messages synced`:B==="running"?"Syncing newest first…":"Queued",state:B}),O>1||d==="syncing_others"||d==="complete"?e.jsx(_,{label:"Other mailboxes",detail:U==="ok"?`${O-1} mailboxes synced`:U==="running"?"Syncing…":"Queued",state:U}):null]}),m&&e.jsxs("div",{className:"mt-2 space-y-2",children:[e.jsxs("p",{className:"text-xs text-danger",children:["Sync stalled. The account is still active —"," ",e.jsx("button",{type:"button",className:"underline",onClick:()=>{h.invalidateQueries({queryKey:Y({path:{accountId:c??""}}).queryKey})},children:"retry"})]}),b&&e.jsx("code",{className:"block rounded bg-surface-sunken px-2.5 py-2 text-2xs text-fg-muted",children:b})]})]})})}function Ze({skipWelcome:t=!1,onComplete:o,onCancel:s}){const[a,n]=i.useState(t?"connector":"welcome"),[r,u]=i.useState({email:"",displayName:"",imapConfig:te,smtpConfig:se,username:"",password:"",discoveryResult:null,discovered:!1,createdAccountId:null}),h=i.useCallback(()=>n("connector"),[]),c=i.useCallback(()=>n("address"),[]),v=i.useCallback(()=>n("microsoft-email"),[]),j=i.useCallback(()=>{t?s?.():n("welcome")},[t,s]),S=i.useCallback((l,p,m)=>{let N=te,b=se,k=!1;m&&(k=m.source!=="heuristic",N={host:m.imap.host,port:m.imap.port,security:m.imap.security},b={host:m.smtp.host,port:m.smtp.port,security:m.smtp.security}),u(T=>({...T,email:l,displayName:p,imapConfig:N,smtpConfig:b,discoveryResult:m,discovered:k,username:l})),n("servers")},[]),y=i.useCallback((l,p)=>{u(m=>({...m,imapConfig:l,smtpConfig:p}))},[]),w=i.useCallback((l,p)=>{u(m=>({...m,username:l,password:p}))},[]),x=i.useCallback(()=>n("sync"),[]),f=i.useCallback(l=>{o(l)},[o]);switch(a){case"welcome":return e.jsx($e,{onStart:h});case"connector":return e.jsx(De,{onContinue:c,onMicrosoft:v,onBack:j,showBack:!t});case"microsoft-email":return e.jsx(qe,{onBack:()=>n("connector"),onConnected:f});case"address":return e.jsx(Ge,{initialEmail:r.email,initialDisplayName:r.displayName,onContinue:S,onBack:()=>n("connector")});case"servers":return e.jsx(Be,{email:r.email,imapConfig:r.imapConfig,smtpConfig:r.smtpConfig,discovered:r.discovered,onContinue:()=>n("credentials"),onBack:()=>n("address"),onChange:y});case"credentials":return e.jsx(Ue,{email:r.email,username:r.username,password:r.password,onContinue:()=>n("test"),onBack:()=>n("servers"),onChange:w});case"test":return e.jsx(We,{email:r.email,imapConfig:r.imapConfig,smtpConfig:r.smtpConfig,username:r.username,password:r.password,onSuccess:x,onBackToCredentials:()=>n("credentials"),onBackToServers:()=>n("servers")});case"sync":return e.jsx(Qe,{email:r.email,displayName:r.displayName,imapConfig:r.imapConfig,smtpConfig:r.smtpConfig,username:r.username,password:r.password,onGoToInbox:f})}}export{Ze as O,ce as P,ee as g,G as s,Ie as u};
1
+ import{c as re,j as e,b as z,ac as V,ag as oe,r as i,at as he,aw as A,ad as F,n as xe,a7 as X,V as fe,ab as ye,s as Q,ax as Y,Q as ne,B as C,af as D,aa as ge,ae as ve,as as q,ap as be,I as je}from"./index-CL-RwCQv.js";import{K as Se}from"./kbd-Cuwmz-CF.js";import{c as we}from"./account-form-helpers-DhckT_PN.js";import{M as ke}from"./mail-B1r3z0pl.js";const K=re("AtSign",[["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["path",{d:"M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8",key:"7n84p3"}]]);const Ce=re("Server",[["rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2",key:"ngkwjq"}],["rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2",key:"iecqi9"}],["line",{x1:"6",x2:"6.01",y1:"6",y2:"6",key:"16zg32"}],["line",{x1:"6",x2:"6.01",y1:"18",y2:"18",key:"nzw8ys"}]]);function Ne({url:t}){return e.jsxs("p",{className:"text-2xs text-fg-subtle",children:["Stored encrypted, used only to connect to your mail server."," ",t?e.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"text-accent underline",children:"How to create an app password"}):e.jsx("span",{children:"Check your provider's help for app password instructions."})]})}function Ee({raised:t,className:o,...s}){return e.jsx("div",{className:z("rounded-sm border border-line bg-surface",t?"bg-surface-raised shadow-sm":"",o),...s})}function J({value:t,defaultValue:o,onValueChange:s,...a}){return s?e.jsxs(V,{value:t,onChange:n=>s(n.target.value),...a,children:[e.jsx("option",{value:"tls",children:"TLS/SSL"}),e.jsx("option",{value:"starttls",children:"STARTTLS"}),e.jsx("option",{value:"none",children:"None (insecure)"})]}):e.jsxs(V,{defaultValue:o??t,...a,children:[e.jsx("option",{value:"tls",children:"TLS/SSL"}),e.jsx("option",{value:"starttls",children:"STARTTLS"}),e.jsx("option",{value:"none",children:"None (insecure)"})]})}function G(t){return{tls:t==="tls",startTls:t==="starttls"}}function Te({steps:t,activeStep:o}){return e.jsx("ol",{className:"flex items-center gap-1",children:t.map((s,a)=>{const n=a<o,r=a===o;return e.jsxs("li",{className:"flex items-center gap-1",children:[a>0&&e.jsx("span",{className:"h-px w-5 bg-line","aria-hidden":!0}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:z("flex size-5 items-center justify-center rounded-full text-2xs font-semibold tabular-nums",n&&"bg-accent text-accent-fg",r&&"bg-accent-soft text-accent ring-1 ring-accent",!n&&!r&&"bg-surface-sunken text-fg-subtle"),children:n?e.jsx(oe,{className:"size-3"}):a+1}),e.jsx("span",{className:z("hidden text-2xs sm:inline",r?"font-medium text-fg":"text-fg-subtle"),children:s})]})]},s)})})}function L({steps:t,activeStep:o,title:s,subtitle:a,children:n,footer:r,hideSteps:u}){return e.jsxs("div",{className:"flex min-h-dvh w-full flex-col items-center overflow-y-auto bg-canvas pb-[max(2rem,env(safe-area-inset-bottom,0px))] pl-[max(2rem,env(safe-area-inset-left,0px))] pr-[max(2rem,env(safe-area-inset-right,0px))] pt-[max(2rem,env(safe-area-inset-top,0px))] font-sans text-fg sm:pt-[30vh]",children:[!u&&e.jsx("div",{className:"mb-5 w-full max-w-xl",children:e.jsx(Te,{steps:t,activeStep:o})}),e.jsxs(Ee,{raised:!0,className:"w-full max-w-xl",children:[e.jsxs("div",{className:"px-5 pt-5",children:[e.jsx("h1",{className:"text-xl font-semibold text-fg",children:s}),a&&e.jsx("p",{className:"mt-1 text-sm text-fg-muted",children:a})]}),e.jsx("div",{className:"px-5 py-5",children:n}),r&&e.jsx("div",{className:"flex items-center justify-between gap-3 border-t border-line px-5 py-3",children:r})]})]})}const Pe="Coming soon — use IMAP for now.";function W({name:t,description:o,icon:s,comingSoon:a,selected:n,onSelect:r}){const[u,h]=i.useState(!1),c=()=>{if(r){r();return}a&&h(!0)};return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("button",{type:"button",onClick:c,"aria-disabled":a||void 0,className:z("flex flex-col items-start gap-2 rounded-sm border p-3 text-left transition-colors",n?"border-accent-2 bg-accent-2-soft":"border-line bg-surface hover:border-line-strong",a&&"opacity-55"),children:[e.jsx("span",{className:z("text-fg-muted",n&&"text-accent-2"),children:s}),e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-semibold text-fg",children:t}),a&&e.jsx("span",{className:"rounded-full bg-surface-sunken px-1.5 py-0.5 text-2xs text-fg-subtle",children:"soon"})]}),e.jsx("span",{className:"text-xs text-fg-subtle",children:o})]}),u&&e.jsx("p",{className:"text-2xs text-fg-subtle",children:Pe})]})}function Z({legend:t,badge:o,host:s,port:a,security:n,readOnly:r,onHostChange:u,onPortChange:h,onSecurityChange:c,hostPlaceholder:v,portPlaceholder:j}){const S=i.useId(),y=i.useId(),w=i.useId();return e.jsxs("fieldset",{children:[e.jsxs("legend",{className:"flex items-center gap-2 text-sm font-semibold text-fg",children:[t,o&&e.jsx(he,{tone:o.tone,children:o.label})]}),e.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-3 sm:grid-cols-[1fr_6rem_8rem] sm:gap-2",children:[e.jsxs("div",{children:[e.jsx(A,{htmlFor:S,children:"Host"}),u?e.jsx(F,{id:S,readOnly:r,value:s,onChange:x=>u(x.target.value),placeholder:v}):e.jsx(F,{id:S,readOnly:r,defaultValue:s,placeholder:v})]}),e.jsxs("div",{children:[e.jsx(A,{htmlFor:y,children:"Port"}),h?e.jsx(F,{id:y,readOnly:r,value:a,onChange:x=>h(x.target.value),placeholder:j}):e.jsx(F,{id:y,readOnly:r,defaultValue:a,placeholder:j})]}),e.jsxs("div",{children:[e.jsx(A,{htmlFor:w,children:"Security"}),c?e.jsx(J,{id:w,value:n,onValueChange:c}):e.jsx(J,{id:w,defaultValue:n})]})]})]})}function _({label:t,detail:o,state:s}){return e.jsxs("div",{className:"flex items-start gap-3 py-2",children:[e.jsxs("span",{className:z("mt-0.5 flex size-5 shrink-0 items-center justify-center rounded-full text-2xs",s==="ok"&&"bg-positive text-accent-fg",s==="failed"&&"bg-danger text-accent-fg",s==="running"&&"border border-accent text-accent",s==="pending"&&"border border-line text-fg-subtle"),children:[s==="ok"&&e.jsx(oe,{className:"size-3"}),s==="failed"&&"!",s==="running"&&e.jsx("span",{className:"size-2 animate-pulse rounded-full bg-accent"})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:z("text-sm",s==="failed"?"font-medium text-danger":"text-fg"),children:t}),o&&e.jsx("div",{className:"mt-0.5 text-xs text-fg-subtle",children:o})]})]})}const Ie=(t,o)=>{const s=i.useRef(o);s.current=o,i.useEffect(()=>{if(!t)return;const a=()=>{document.visibilityState==="visible"&&s.current()};return document.addEventListener("visibilitychange",a),window.addEventListener("pageshow",a),()=>{document.removeEventListener("visibilitychange",a),window.removeEventListener("pageshow",a)}},[t])},Ae={"gmail.com":{imap:{host:"imap.gmail.com",port:993,security:"tls"},smtp:{host:"smtp.gmail.com",port:587,security:"starttls"},source:"provider-table"},"googlemail.com":{imap:{host:"imap.gmail.com",port:993,security:"tls"},smtp:{host:"smtp.gmail.com",port:587,security:"starttls"},source:"provider-table"},"outlook.com":{imap:{host:"outlook.office365.com",port:993,security:"tls"},smtp:{host:"smtp.office365.com",port:587,security:"starttls"},source:"provider-table"},"hotmail.com":{imap:{host:"outlook.office365.com",port:993,security:"tls"},smtp:{host:"smtp.office365.com",port:587,security:"starttls"},source:"provider-table"},"live.com":{imap:{host:"outlook.office365.com",port:993,security:"tls"},smtp:{host:"smtp.office365.com",port:587,security:"starttls"},source:"provider-table"},"msn.com":{imap:{host:"outlook.office365.com",port:993,security:"tls"},smtp:{host:"smtp.office365.com",port:587,security:"starttls"},source:"provider-table"},"icloud.com":{imap:{host:"imap.mail.me.com",port:993,security:"tls"},smtp:{host:"smtp.mail.me.com",port:587,security:"starttls"},source:"provider-table"},"me.com":{imap:{host:"imap.mail.me.com",port:993,security:"tls"},smtp:{host:"smtp.mail.me.com",port:587,security:"starttls"},source:"provider-table"},"mac.com":{imap:{host:"imap.mail.me.com",port:993,security:"tls"},smtp:{host:"smtp.mail.me.com",port:587,security:"starttls"},source:"provider-table"},"fastmail.com":{imap:{host:"imap.fastmail.com",port:993,security:"tls"},smtp:{host:"smtp.fastmail.com",port:465,security:"tls"},source:"provider-table"},"fastmail.fm":{imap:{host:"imap.fastmail.com",port:993,security:"tls"},smtp:{host:"smtp.fastmail.com",port:465,security:"tls"},source:"provider-table"},"yahoo.com":{imap:{host:"imap.mail.yahoo.com",port:993,security:"tls"},smtp:{host:"smtp.mail.yahoo.com",port:465,security:"tls"},source:"provider-table"},"yahoo.co.uk":{imap:{host:"imap.mail.yahoo.com",port:993,security:"tls"},smtp:{host:"smtp.mail.yahoo.com",port:465,security:"tls"},source:"provider-table"},"ymail.com":{imap:{host:"imap.mail.yahoo.com",port:993,security:"tls"},smtp:{host:"smtp.mail.yahoo.com",port:465,security:"tls"},source:"provider-table"},"aol.com":{imap:{host:"imap.aol.com",port:993,security:"tls"},smtp:{host:"smtp.aol.com",port:465,security:"tls"},source:"provider-table"},"zoho.com":{imap:{host:"imap.zoho.com",port:993,security:"tls"},smtp:{host:"smtp.zoho.com",port:465,security:"tls"},source:"provider-table"},"gmx.com":{imap:{host:"imap.gmx.com",port:993,security:"tls"},smtp:{host:"smtp.gmx.com",port:587,security:"starttls"},source:"provider-table"},"gmx.net":{imap:{host:"imap.gmx.net",port:993,security:"tls"},smtp:{host:"mail.gmx.net",port:587,security:"starttls"},source:"provider-table"},"gmx.de":{imap:{host:"imap.gmx.net",port:993,security:"tls"},smtp:{host:"mail.gmx.net",port:587,security:"starttls"},source:"provider-table"},"web.de":{imap:{host:"imap.web.de",port:993,security:"tls"},smtp:{host:"smtp.web.de",port:587,security:"starttls"},source:"provider-table"},"mail.com":{imap:{host:"imap.mail.com",port:993,security:"tls"},smtp:{host:"smtp.mail.com",port:465,security:"tls"},source:"provider-table"},"hey.com":{imap:{host:"imap.hey.com",port:993,security:"tls"},smtp:{host:"smtp.hey.com",port:465,security:"tls"},source:"provider-table"},"tutanota.com":{imap:{host:"mail.tutanota.com",port:993,security:"tls"},smtp:{host:"mail.tutanota.com",port:465,security:"tls"},source:"provider-table"},"tuta.io":{imap:{host:"mail.tutanota.com",port:993,security:"tls"},smtp:{host:"mail.tutanota.com",port:465,security:"tls"},source:"provider-table"},"posteo.de":{imap:{host:"posteo.de",port:993,security:"tls"},smtp:{host:"posteo.de",port:465,security:"tls"},source:"provider-table"},"runbox.com":{imap:{host:"imap.runbox.com",port:993,security:"tls"},smtp:{host:"smtp.runbox.com",port:587,security:"starttls"},source:"provider-table"},"mailbox.org":{imap:{host:"imap.mailbox.org",port:993,security:"tls"},smtp:{host:"smtp.mailbox.org",port:465,security:"tls"},source:"provider-table"},"hushmail.com":{imap:{host:"imap.hushmail.com",port:993,security:"tls"},smtp:{host:"smtp.hushmail.com",port:465,security:"tls"},source:"provider-table"}},Le={"gmail.com":"https://support.google.com/accounts/answer/185833","googlemail.com":"https://support.google.com/accounts/answer/185833","yahoo.com":"https://help.yahoo.com/kb/generate-manage-third-party-passwords-sln15241.html","icloud.com":"https://support.apple.com/en-us/102654","me.com":"https://support.apple.com/en-us/102654","mac.com":"https://support.apple.com/en-us/102654","fastmail.com":"https://www.fastmail.help/hc/en-us/articles/360058752854","fastmail.fm":"https://www.fastmail.help/hc/en-us/articles/360058752854","outlook.com":"https://support.microsoft.com/en-us/account-billing/manage-app-passwords-for-two-step-verification-d6dc8c6d-4bf7-4851-ad95-6d07799387e9","hotmail.com":"https://support.microsoft.com/en-us/account-billing/manage-app-passwords-for-two-step-verification-d6dc8c6d-4bf7-4851-ad95-6d07799387e9","zoho.com":"https://help.zoho.com/portal/en/kb/zoho-mail/client-configuration/imap-access/articles/zoho-mail-app-passwords"};function ae(t){try{const s=new DOMParser().parseFromString(t,"application/xml");if(s.querySelector("parsererror"))return null;const a=s.querySelectorAll("incomingServer[type='imap']"),n=s.querySelectorAll("outgoingServer[type='smtp']");if(!a.length||!n.length)return null;const r=a[0],u=n[0],h=r.querySelector("hostname")?.textContent?.trim(),c=r.querySelector("port")?.textContent?.trim(),v=r.querySelector("socketType")?.textContent?.trim().toUpperCase(),j=u.querySelector("hostname")?.textContent?.trim(),S=u.querySelector("port")?.textContent?.trim(),y=u.querySelector("socketType")?.textContent?.trim().toUpperCase();if(!h||!c||!j||!S)return null;const w=x=>x==="SSL"||x==="TLS"||x==="SSL/TLS"?"tls":x==="STARTTLS"?"starttls":"none";return{imap:{host:h,port:Number.parseInt(c,10),security:w(v)},smtp:{host:j,port:Number.parseInt(S,10),security:w(y)},source:"mozilla-autoconfig"}}catch{return null}}async function Me(t,o){try{const s=`https://autoconfig.thunderbird.net/v1.1/${t}`,a=await fetch(s,{signal:o});if(!a.ok)return null;const n=await a.text(),r=ae(n);return r||null}catch{return null}}async function Fe(t,o){try{const s=`https://autoconfig.${t}/mail/config-v1.1.xml`,a=await fetch(s,{signal:o});if(!a.ok)return null;const n=await a.text(),r=ae(n);return r?{...r,source:"domain-autoconfig"}:null}catch{return null}}function Re(t){return{imap:{host:`imap.${t}`,port:993,security:"tls"},smtp:{host:`smtp.${t}`,port:587,security:"starttls"},source:"heuristic"}}async function Oe(t,o=1500){const s=t.indexOf("@");if(s===-1)return null;const a=t.slice(s+1).toLowerCase();if(!a)return null;const n=Ae[a];if(n)return n;const r=new AbortController,u=setTimeout(()=>r.abort(),o);try{const h=await Me(a,r.signal);if(h)return h;const c=await Fe(a,r.signal);if(c)return c}finally{clearTimeout(u)}return Re(a)}function ze(t){const o=t.indexOf("@");return o===-1?"Looking up server settings…":`Looking up settings for ${t.slice(o+1)}…`}function ie(t){const o=t.indexOf("@");if(o===-1)return;const s=t.slice(o+1).toLowerCase();return Le[s]}const ce=[{id:"icloud",label:"iCloud",username:"full-email",imap:{host:"imap.mail.me.com",port:993,security:"tls"},smtp:{host:"smtp.mail.me.com",port:587,security:"starttls"},passwordHelp:{text:"iCloud requires an app-specific password, not your Apple ID password. Generate one under Sign-In & Security → App-Specific Passwords.",url:"https://support.apple.com/en-us/102654"}},{id:"yahoo",label:"Yahoo",username:"full-email",imap:{host:"imap.mail.yahoo.com",port:993,security:"tls"},smtp:{host:"smtp.mail.yahoo.com",port:465,security:"tls"},passwordHelp:{text:"Yahoo requires an app password, not your login password. Generate one under Account Security.",url:"https://help.yahoo.com/kb/generate-manage-third-party-passwords-sln15241.html"}},{id:"aol",label:"AOL",username:"full-email",imap:{host:"imap.aol.com",port:993,security:"tls"},smtp:{host:"smtp.aol.com",port:465,security:"tls"},passwordHelp:{text:"AOL requires an app password, not your login password. Generate one under Account Security.",url:"https://login.aol.com/account/security"}},{id:"fastmail",label:"Fastmail",username:"full-email",imap:{host:"imap.fastmail.com",port:993,security:"tls"},smtp:{host:"smtp.fastmail.com",port:465,security:"tls"},passwordHelp:{text:"Fastmail requires an app password, not your login password. Create one under Settings → Privacy & Security → App passwords.",url:"https://www.fastmail.help/hc/en-us/articles/360058752854"}}];function ee(t){return ce.find(o=>o.id===t)}const _e={"icloud.com":"icloud","me.com":"icloud","mac.com":"icloud","yahoo.com":"yahoo","yahoo.co.uk":"yahoo","ymail.com":"yahoo","aol.com":"aol","fastmail.com":"fastmail","fastmail.fm":"fastmail"};function He(t){const o=t.indexOf("@");if(o===-1)return"";const s=t.slice(o+1).toLowerCase();return _e[s]??""}const M=["Connector","Address","Servers","Credentials","Test","Sync"],R={connector:0,address:1,servers:2,credentials:3,test:4,sync:5},te={host:"",port:993,security:"tls"},se={host:"",port:587,security:"starttls"};function $e({onStart:t}){return i.useEffect(()=>{const o=s=>{s.key==="Enter"&&t()};return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[t]),e.jsx(L,{steps:M,activeStep:0,hideSteps:!0,title:"Welcome to Remit",subtitle:"One inbox for all your mail, with context about every message.",footer:e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-2xs text-fg-subtle",children:[e.jsx(Se,{children:"Enter"})," to continue"]}),e.jsx(C,{variant:"primary",onClick:t,children:"Add your first account"})]}),children:e.jsxs("div",{className:"flex flex-col items-start py-5",children:[e.jsx("span",{className:"flex size-14 items-center justify-center rounded-md bg-accent-soft",children:e.jsx(ke,{className:"size-7 text-accent"})}),e.jsx("p",{className:"mt-5 max-w-sm text-sm leading-relaxed text-fg-muted",children:"Remit syncs your existing mailboxes and tells you who is really writing to you — sender history, authenticity checks, and similar messages, right next to every email."})]})})}function De({onContinue:t,onMicrosoft:o,onBack:s,showBack:a}){const[n,r]=i.useState("imap");i.useEffect(()=>{const h=c=>{c.key==="Enter"&&(n==="microsoft"?o():t()),c.key==="Escape"&&s()};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[t,o,s,n]);const u=()=>{n==="microsoft"?o():t()};return e.jsx(L,{steps:M,activeStep:R.connector,title:"How does this account connect?",subtitle:"Choose a sign-in method. IMAP works with any provider.",footer:e.jsxs(e.Fragment,{children:[a?e.jsx(C,{variant:"ghost",onClick:s,children:"Back"}):e.jsx("span",{}),e.jsx(C,{variant:"primary",onClick:u,children:n==="microsoft"?"Continue with Microsoft":"Continue with IMAP"})]}),children:e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-3",children:[e.jsx(W,{name:"IMAP / SMTP",description:"Any mail provider — Fastmail, iCloud, your own server.",icon:e.jsx(Ce,{className:"size-5"}),selected:n==="imap",onSelect:()=>r("imap")}),e.jsx(W,{name:"Gmail",description:"Sign in with Google. No app passwords.",icon:e.jsx(K,{className:"size-5"}),comingSoon:!0}),e.jsx(W,{name:"Outlook / Microsoft 365",description:"Sign in with Microsoft. Works with Outlook.com and work accounts.",icon:e.jsx(je,{className:"size-5"}),selected:n==="microsoft",onSelect:()=>r("microsoft")})]})})}function qe({onBack:t,onConnected:o}){const[s,a]=i.useState(""),[n,r]=i.useState(null),[u,h]=i.useState(!1),[c,v]=i.useState(!1),j=i.useRef(!0);i.useEffect(()=>(j.current=!0,()=>{j.current=!1}),[]);const S=i.useRef(new Set),{refetch:y}=Q(ne()),w=X({...be(),onSuccess:p=>{j.current&&(h(!0),window.location.assign(p.authorizationUrl))},onError:p=>{v(!1),r(p instanceof Error?p.message:"Failed to start sign-in")}});Ie(u,i.useCallback(()=>{v(!1),y().then(({data:p,isError:m})=>{if(!j.current)return;if(m||!p){r("Couldn't check whether the sign-in finished. Open Settings › Accounts to see whether the account is connected.");return}r(null);const N=p.accounts.find(b=>!S.current.has(b.accountId));N&&o(N.accountId)})},[y,o]));const x=c||w.isPending,f=()=>{x||(r(null),v(!0),y().then(({data:p,isError:m})=>{if(j.current){if(m||!p){v(!1),r("Couldn't read this instance's accounts, so sign-in can't be tracked. Check your connection and try again.");return}S.current=new Set(p.accounts.map(N=>N.accountId)),w.mutate({body:{email:s.trim()||void 0}})}}))},l=i.useRef(f);return l.current=f,i.useEffect(()=>{const p=m=>{m.key==="Enter"&&l.current(),m.key==="Escape"&&t()};return window.addEventListener("keydown",p),()=>window.removeEventListener("keydown",p)},[t]),e.jsx(L,{steps:M,activeStep:R.connector,title:"Sign in with Microsoft",subtitle:"You'll be redirected to Microsoft to sign in securely.",footer:e.jsxs(e.Fragment,{children:[e.jsx(C,{variant:"ghost",onClick:t,children:"Back"}),e.jsx(C,{variant:"primary",onClick:f,disabled:x,icon:x?e.jsx(D,{className:"size-4 animate-spin"}):void 0,children:x?"Redirecting…":u?"Start over":"Sign in with Microsoft"})]}),children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(A,{htmlFor:"microsoft-email",children:"Email address (optional)"}),e.jsx(F,{id:"microsoft-email",icon:e.jsx(K,{className:"size-4"}),placeholder:"you@outlook.com",value:s,onChange:p=>a(p.target.value),type:"email",autoComplete:"email"}),e.jsx("p",{className:"mt-1.5 text-2xs text-fg-subtle",children:"Pre-fills the Microsoft sign-in form. Leave blank to choose on the Microsoft page."})]}),u&&e.jsx(q,{tone:"info",children:"Waiting for Microsoft. Finish signing in — this window carries on the moment the account is connected, wherever you finished."}),n&&e.jsx(q,{tone:"danger",children:n})]})})}function Ge({initialEmail:t,initialDisplayName:o,onContinue:s,onBack:a}){const[n,r]=i.useState(t),[u,h]=i.useState(o),[c,v]=i.useState(!1),[j,S]=i.useState(""),[y,w]=i.useState(null),x=i.useCallback(async()=>{const f=n.trim();if(!f.includes("@")||!f.includes(".")){w("Enter a valid email address.");return}w(null),v(!0),S(ze(f));try{const l=await Oe(f);s(f,u.trim(),l)}finally{v(!1)}},[n,u,s]);return i.useEffect(()=>{const f=l=>{l.key==="Enter"&&!c&&x(),l.key==="Escape"&&a()};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[x,c,a]),e.jsx(L,{steps:M,activeStep:R.address,title:"What's the email address?",subtitle:"We'll detect the server settings for you.",footer:e.jsxs(e.Fragment,{children:[e.jsx(C,{variant:"ghost",onClick:a,children:"Back"}),e.jsx(C,{variant:"primary",disabled:c,onClick:()=>{x()},children:"Continue"})]}),children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(A,{htmlFor:"onboarding-email",children:"Email address"}),e.jsx(F,{id:"onboarding-email",icon:e.jsx(K,{className:"size-4"}),placeholder:"you@example.com",value:n,onChange:f=>{r(f.target.value),w(null)},type:"email",autoComplete:"email"})]}),e.jsxs("div",{children:[e.jsx(A,{htmlFor:"onboarding-display-name",children:"Display name (optional)"}),e.jsx(F,{id:"onboarding-display-name",placeholder:"Alice",value:u,onChange:f=>h(f.target.value)}),e.jsx("p",{className:"mt-1.5 text-2xs text-fg-subtle",children:"What to call this account in Remit. Leave blank to use a name derived from the address."})]}),c&&e.jsxs("div",{className:"mt-3 flex items-center gap-2 text-xs text-fg-muted",children:[e.jsx(D,{className:"size-3.5 animate-spin text-accent"}),j]}),y&&!c&&e.jsx("div",{className:"mt-3",children:e.jsx(q,{tone:"danger",children:y})})]})})}function Be({email:t,imapConfig:o,smtpConfig:s,discovered:a,onContinue:n,onBack:r,onChange:u}){const[h,c]=i.useState(o),[v,j]=i.useState(s),[S,y]=i.useState(()=>He(t)),[w,x]=i.useState(!1),[f,l]=i.useState(null),p=ee(S),m=p!==void 0&&!w,N=i.useCallback(g=>{y(g),x(!1),l(null);const d=ee(g);d&&(c({host:d.imap.host,port:d.imap.port,security:d.imap.security}),j({host:d.smtp.host,port:d.smtp.port,security:d.smtp.security}))},[]);i.useEffect(()=>{u(h,v)},[h,v,u]);const b=h.host.trim()!=="",k=i.useCallback(()=>{if(!b){l("Enter the IMAP host.");return}l(null),n()},[b,n]);i.useEffect(()=>{const g=d=>{d.key==="Enter"&&k(),d.key==="Escape"&&r()};return window.addEventListener("keydown",g),()=>window.removeEventListener("keydown",g)},[k,r]);const T=t.split("@")[1]??"your domain",O=p?"Pick your provider to fill in the right settings — or choose Custom to enter them by hand.":a?"Found via autodiscovery — adjust anything that looks off.":`We couldn't detect settings for ${T} — enter them manually.`,P=m?{label:"preset",tone:"neutral"}:!p&&a?{label:"detected",tone:"positive"}:void 0,I=p?.passwordHelp.url??ie(t);return e.jsx(L,{steps:M,activeStep:R.servers,title:"Confirm server settings",subtitle:O,footer:e.jsxs(e.Fragment,{children:[e.jsx(C,{variant:"ghost",onClick:r,children:"Back"}),e.jsx(C,{variant:"primary",onClick:k,children:"Continue"})]}),children:e.jsxs("div",{className:"space-y-5",children:[f&&e.jsx(q,{tone:"danger",children:f}),e.jsxs("div",{children:[e.jsx(A,{htmlFor:"provider-select",children:"Provider"}),e.jsxs(V,{id:"provider-select",value:S,onChange:g=>N(g.target.value),children:[e.jsx("option",{value:"",children:"Custom / other"}),ce.map(g=>e.jsx("option",{value:g.id,children:g.label},g.id))]}),p&&e.jsx("p",{className:"mt-1 text-2xs text-fg-subtle",children:m?e.jsxs(e.Fragment,{children:["Server settings are pre-filled for ",p.label," and locked."," ",e.jsx("button",{type:"button",className:"text-accent underline",onClick:()=>x(!0),children:"Advanced"})," ","lets you edit them by hand."]}):e.jsxs(e.Fragment,{children:["Editing ",p.label,"'s settings by hand."]})})]}),e.jsx(Z,{legend:"IMAP — incoming",badge:P,readOnly:m,host:h.host,port:String(h.port),security:h.security,hostPlaceholder:"imap.example.com",portPlaceholder:"993",onHostChange:g=>{c(d=>({...d,host:g})),l(null)},onPortChange:g=>c(d=>({...d,port:Number(g)})),onSecurityChange:g=>c(d=>({...d,security:g}))}),e.jsx("p",{className:"text-2xs text-fg-subtle",children:"Sending (SMTP) is optional — leave it blank to set up a receive-only account and add sending later in Settings."}),e.jsx(Z,{legend:"SMTP — outgoing (optional)",badge:P,readOnly:m,host:v.host,port:String(v.port),security:v.security,hostPlaceholder:"smtp.example.com",portPlaceholder:"587",onHostChange:g=>{j(d=>({...d,host:g})),l(null)},onPortChange:g=>j(d=>({...d,port:Number(g)})),onSecurityChange:g=>j(d=>({...d,security:g}))}),p&&e.jsxs("p",{className:"text-2xs text-fg-subtle",children:[p.passwordHelp.text," ",I&&e.jsx("a",{href:I,target:"_blank",rel:"noopener noreferrer",className:"text-accent underline",children:"Get an app password"})]})]})})}function Ue({email:t,username:o,password:s,onContinue:a,onBack:n,onChange:r}){const[u,h]=i.useState(o||t),[c,v]=i.useState(s),[j,S]=i.useState(null),y=t.split("@")[1]??"",w=ie(t),x=u.trim()!==""&&c.trim()!=="";i.useEffect(()=>{r(u,c)},[u,c,r]);const f=i.useCallback(()=>{if(!x){S("Enter your username and password.");return}S(null),a()},[x,a]);return i.useEffect(()=>{const l=p=>{p.key==="Enter"&&f(),p.key==="Escape"&&n()};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[f,n]),e.jsx(L,{steps:M,activeStep:R.credentials,title:`Sign in to ${y||"your mail server"}`,subtitle:"Many providers require an app password instead of your normal one.",footer:e.jsxs(e.Fragment,{children:[e.jsx(C,{variant:"ghost",onClick:n,children:"Back"}),e.jsx(C,{variant:"primary",onClick:f,children:"Test connection"})]}),children:e.jsxs("div",{className:"space-y-3",children:[j&&e.jsx("div",{className:"rounded-md bg-danger-soft px-3 py-2 text-sm text-danger",children:j}),e.jsxs("div",{children:[e.jsx(A,{htmlFor:"credentials-username",children:"Username"}),e.jsx(F,{id:"credentials-username",value:u,onChange:l=>{h(l.target.value),S(null)},autoComplete:"username"})]}),e.jsxs("div",{children:[e.jsx(A,{htmlFor:"credentials-password",children:"Password or app password"}),e.jsx(ve,{id:"credentials-password",value:c,onChange:l=>{v(l.target.value),S(null)},autoComplete:"current-password"})]}),e.jsx(Ne,{url:w})]})})}function We({email:t,imapConfig:o,smtpConfig:s,username:a,password:n,onSuccess:r,onBackToCredentials:u,onBackToServers:h}){const[c,v]=i.useState({imapState:"running",smtpState:"pending",phase:"running"}),[j,S]=i.useState(0),y=s.host.trim()!=="",w=G(o.security),x=G(s.security),f=X({...ge()});i.useEffect(()=>{let m=!1;const N=[];return v({imapState:"running",smtpState:"pending",phase:"running"}),f.mutate({body:{username:a,password:n,imapHost:o.host,imapPort:o.port,imapTls:w.tls,imapStartTls:w.startTls,smtpHost:s.host,smtpPort:s.port,smtpTls:x.tls,smtpStartTls:x.startTls}},{onSuccess:b=>{if(m)return;const k=b.imapSuccess,T=y?b.smtpSuccess:!0;v({imapState:k?"ok":"failed",smtpState:y?"running":"ok",imapDetail:k?`Connected — ${o.host}:${o.port}`:b.imapError,phase:"running"}),N.push(window.setTimeout(()=>{if(m)return;const O=I=>{const g=I?.toLowerCase()??"";return g.includes("auth")||g.includes("login")||g.includes("535")||g.includes("credential")},P=!k&&O(b.imapError)||k&&y&&!b.smtpSuccess&&O(b.smtpError);v({imapState:k?"ok":"failed",smtpState:y?b.smtpSuccess?"ok":"failed":"ok",imapDetail:k?`Connected — ${o.host}:${o.port}`:b.imapError,smtpDetail:y?b.smtpSuccess?`Connected — ${s.host}:${s.port}`:b.smtpError:"Not set up — receive-only",rawError:k?y&&!b.smtpSuccess?b.smtpError:void 0:b.imapError,phase:k&&T?"success":P?"auth-failure":"network-failure"}),k&&T&&N.push(window.setTimeout(()=>{m||r()},800))},400))},onError:b=>{if(m)return;const k=b instanceof Error?b.message:"Connection failed";v({imapState:"failed",smtpState:"failed",imapDetail:k,smtpDetail:k,rawError:k,phase:"network-failure"})}}),()=>{m=!0;for(const b of N)window.clearTimeout(b)}},[j]);const{phase:l}=c;i.useEffect(()=>{const m=N=>{N.key==="Escape"&&(l==="auth-failure"?u():l==="network-failure"&&h())};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[l,u,h]);const p=l==="auth-failure"?e.jsxs(e.Fragment,{children:[e.jsx(C,{variant:"ghost",onClick:u,children:"Back to credentials"}),e.jsx(C,{variant:"primary",onClick:()=>S(m=>m+1),children:"Retry"})]}):l==="network-failure"?e.jsxs(e.Fragment,{children:[e.jsx(C,{variant:"ghost",onClick:h,children:"Back to servers"}),e.jsx(C,{variant:"primary",onClick:()=>S(m=>m+1),children:"Retry"})]}):l==="success"?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-2xs text-fg-subtle",children:"Connection verified"}),e.jsx(C,{variant:"primary",onClick:r,children:"Start syncing"})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-2xs text-fg-subtle",children:"Testing…"}),e.jsx("span",{})]});return e.jsx(L,{steps:M,activeStep:R.test,title:"Testing the connection",subtitle:`Checking ${t}`,footer:p,children:e.jsxs("div",{className:"divide-y divide-line",children:[e.jsx(_,{label:`IMAP — ${o.host}:${o.port}`,detail:c.imapDetail,state:c.imapState}),e.jsx(_,{label:y?`SMTP — ${s.host}:${s.port}`:"SMTP — sending",detail:y?c.smtpDetail:"Not set up — you can add sending later in Settings",state:c.smtpState}),(l==="auth-failure"||l==="network-failure")&&c.rawError&&e.jsxs("div",{className:"py-3",children:[l==="auth-failure"&&e.jsx("p",{className:"mb-2 text-xs text-fg-muted",children:"Check your password — many providers require an app password."}),e.jsx("code",{className:"block rounded bg-surface-sunken px-2.5 py-2 text-2xs text-fg-muted",children:c.rawError})]})]})})}const Ve=2e4;function Qe({email:t,displayName:o,imapConfig:s,smtpConfig:a,username:n,password:r,onGoToInbox:u}){const h=xe(),[c,v]=i.useState(null),[j,S]=i.useState(null),y=i.useRef(!1),w=G(s.security),x=G(a.security),f=X({...ye(),onSuccess:E=>{v(E.accountId),h.invalidateQueries({queryKey:fe()})},onError:E=>{S(E instanceof Error?E.message:"Failed to create account")}});i.useEffect(()=>{if(y.current)return;y.current=!0;const E=a.host.trim()!=="",H=we({imapHost:s.host,smtpHost:a.host,smtpPort:a.port}),$=E?H??{smtpHost:a.host,smtpPort:a.port,smtpTls:x.tls,smtpStartTls:x.startTls}:null;f.mutate({body:{email:t,displayName:o||void 0,username:n!==t?n:void 0,password:r,imapHost:s.host,imapPort:s.port,imapTls:w.tls,imapStartTls:w.startTls,smtpHost:$?.smtpHost||void 0,smtpPort:$?.smtpPort||void 0,smtpTls:$?.smtpTls??!1,smtpStartTls:$?.smtpStartTls??!1}})},[]);const{data:l,isError:p}=Q({...Y({path:{accountId:c??""}}),enabled:!!c,refetchInterval:E=>{const H=E.state.data?.syncPhase;return H==="complete"||H==="error"?!1:2e3}}),m=l?.syncPhase==="error",{data:N}=Q({...ne(),enabled:!!c&&m}),b=N?.accounts.find(E=>E.accountId===c)?.lastError,k=l?.mailboxes.find(E=>E.fullPath==="INBOX"||E.fullPath==="Inbox"),T=l?.mailboxCountTotal??0,O=l?.mailboxCountSynced??0,P=k?.messagesTotal??0,I=k?.messagesSynced??0,g=P>0?I/P:0,d=l?.syncPhase,le=m?"failed":d==="idle"||d===void 0||d==="discovering_mailboxes"?"running":T>0?"ok":"running",B=m?"failed":!d||d==="idle"||d==="discovering_mailboxes"?"pending":d==="syncing_inbox"||d==="syncing_others"?"running":"ok",U=m?"failed":!d||d==="idle"||d==="discovering_mailboxes"||d==="syncing_inbox"?"pending":d==="syncing_others"?"running":"ok",me=I>0||k?.phase==="complete"||d==="complete"||m,[ue,de]=i.useState(!1);i.useEffect(()=>{if(!c)return;const E=setTimeout(()=>de(!0),Ve);return()=>clearTimeout(E)},[c]);const pe=!!c&&(me||p||ue);return j?e.jsx(L,{steps:M,activeStep:R.sync,title:"Couldn't create account",subtitle:"Something went wrong saving your account.",footer:e.jsxs(e.Fragment,{children:[e.jsx("span",{}),e.jsx(C,{variant:"primary",onClick:()=>{y.current=!1,S(null),f.mutate({body:{email:t,displayName:o||void 0,username:n!==t?n:void 0,password:r,imapHost:s.host,imapPort:s.port,imapTls:w.tls,imapStartTls:w.startTls,smtpHost:a.host||void 0,smtpPort:a.port||void 0,smtpTls:x.tls,smtpStartTls:x.startTls}})},children:"Retry"})]}),children:e.jsx("code",{className:"block rounded bg-surface-sunken px-2.5 py-2 text-2xs text-fg-muted",children:j})}):e.jsx(L,{steps:M,activeStep:R.sync,title:`Syncing ${t}`,subtitle:"Newest mail first — you can start reading right away.",footer:e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-2xs text-fg-subtle",children:"Sync continues in the background"}),pe?e.jsx(C,{variant:"primary",onClick:()=>c&&u(c),children:"Go to inbox"}):e.jsx(C,{variant:"primary",disabled:!0,icon:e.jsx(D,{className:"size-3.5 animate-spin"}),children:"Getting your mail…"})]}),children:f.isPending?e.jsxs("div",{className:"flex items-center gap-2 py-4 text-sm text-fg-muted",children:[e.jsx(D,{className:"size-4 animate-spin text-accent"}),"Creating your account…"]}):e.jsxs("div",{className:"space-y-3",children:[P>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-baseline justify-between text-xs",children:[e.jsx("span",{className:"font-medium text-fg",children:"INBOX"}),e.jsxs("span",{className:"text-fg-subtle tabular-nums",children:[I.toLocaleString()," / ",P.toLocaleString()," ","messages"]})]}),e.jsx("div",{className:"mt-1 h-1.5 overflow-hidden rounded-full bg-surface-sunken",children:e.jsx("div",{className:"h-full rounded-full bg-accent transition-all duration-500",style:{width:`${Math.max(2,g*100)}%`}})})]}),e.jsxs("div",{className:"divide-y divide-line",children:[e.jsx(_,{label:"Mailboxes discovered",detail:T>0?`${T} mailbox${T===1?"":"es"} found`:"Discovering…",state:le}),e.jsx(_,{label:"INBOX",detail:B==="ok"?`${I.toLocaleString()} messages synced`:B==="running"?"Syncing newest first…":"Queued",state:B}),O>1||d==="syncing_others"||d==="complete"?e.jsx(_,{label:"Other mailboxes",detail:U==="ok"?`${O-1} mailboxes synced`:U==="running"?"Syncing…":"Queued",state:U}):null]}),m&&e.jsxs("div",{className:"mt-2 space-y-2",children:[e.jsxs("p",{className:"text-xs text-danger",children:["Sync stalled. The account is still active —"," ",e.jsx("button",{type:"button",className:"underline",onClick:()=>{h.invalidateQueries({queryKey:Y({path:{accountId:c??""}}).queryKey})},children:"retry"})]}),b&&e.jsx("code",{className:"block rounded bg-surface-sunken px-2.5 py-2 text-2xs text-fg-muted",children:b})]})]})})}function Ze({skipWelcome:t=!1,onComplete:o,onCancel:s}){const[a,n]=i.useState(t?"connector":"welcome"),[r,u]=i.useState({email:"",displayName:"",imapConfig:te,smtpConfig:se,username:"",password:"",discoveryResult:null,discovered:!1,createdAccountId:null}),h=i.useCallback(()=>n("connector"),[]),c=i.useCallback(()=>n("address"),[]),v=i.useCallback(()=>n("microsoft-email"),[]),j=i.useCallback(()=>{t?s?.():n("welcome")},[t,s]),S=i.useCallback((l,p,m)=>{let N=te,b=se,k=!1;m&&(k=m.source!=="heuristic",N={host:m.imap.host,port:m.imap.port,security:m.imap.security},b={host:m.smtp.host,port:m.smtp.port,security:m.smtp.security}),u(T=>({...T,email:l,displayName:p,imapConfig:N,smtpConfig:b,discoveryResult:m,discovered:k,username:l})),n("servers")},[]),y=i.useCallback((l,p)=>{u(m=>({...m,imapConfig:l,smtpConfig:p}))},[]),w=i.useCallback((l,p)=>{u(m=>({...m,username:l,password:p}))},[]),x=i.useCallback(()=>n("sync"),[]),f=i.useCallback(l=>{o(l)},[o]);switch(a){case"welcome":return e.jsx($e,{onStart:h});case"connector":return e.jsx(De,{onContinue:c,onMicrosoft:v,onBack:j,showBack:!t});case"microsoft-email":return e.jsx(qe,{onBack:()=>n("connector"),onConnected:f});case"address":return e.jsx(Ge,{initialEmail:r.email,initialDisplayName:r.displayName,onContinue:S,onBack:()=>n("connector")});case"servers":return e.jsx(Be,{email:r.email,imapConfig:r.imapConfig,smtpConfig:r.smtpConfig,discovered:r.discovered,onContinue:()=>n("credentials"),onBack:()=>n("address"),onChange:y});case"credentials":return e.jsx(Ue,{email:r.email,username:r.username,password:r.password,onContinue:()=>n("test"),onBack:()=>n("servers"),onChange:w});case"test":return e.jsx(We,{email:r.email,imapConfig:r.imapConfig,smtpConfig:r.smtpConfig,username:r.username,password:r.password,onSuccess:x,onBackToCredentials:()=>n("credentials"),onBackToServers:()=>n("servers")});case"sync":return e.jsx(Qe,{email:r.email,displayName:r.displayName,imapConfig:r.imapConfig,smtpConfig:r.smtpConfig,username:r.username,password:r.password,onGoToInbox:f})}}export{Ze as O,ce as P,ee as g,G as s,Ie as u};