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