@remit/web-client-dist 0.0.389 → 0.0.391
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-DHqXVPU1.js → BriefPane-gQae7FXu.js} +1 -1
- package/assets/{ErrorState-GVRl41CW.js → ErrorState-Bn1oQw8C.js} +1 -1
- package/assets/FlaggedPane-BAR4Ky6a.js +1 -0
- package/assets/{FullCompose-CunpGx1b.js → FullCompose-Cv3MK_3g.js} +1 -1
- package/assets/MailListHeader-DznCndIp.js +7 -0
- package/assets/{MailViewChrome-DNibq_9G.js → MailViewChrome-BEuukQ7E.js} +1 -1
- package/assets/MailboxPane-B7nqvLl3.js +1 -0
- package/assets/{NavMenuButton-TEE1--Yt.js → NavMenuButton-C65lZ8kj.js} +1 -1
- package/assets/{OnboardingWizard-DOGTDfZJ.js → OnboardingWizard-DsaHOR6q.js} +1 -1
- package/assets/{OutboxPane-ieYQoIhx.js → OutboxPane-Dyude9Tx.js} +1 -1
- package/assets/_mailboxId-Bcy-ZIMZ.js +1 -0
- package/assets/_messageId-BjtpUAiY.js +1 -0
- package/assets/_messageId-BrvrVTJO.js +1 -0
- package/assets/_messageId-DJUXd-ym.js +1 -0
- package/assets/_outboxMessageId-DLssBq50.js +1 -0
- package/assets/_threadId-CFGu0I1L.js +1 -0
- package/assets/_threadId-CG2yKDxi.js +1 -0
- package/assets/_threadId-DSvp6fr6.js +1 -0
- package/assets/{accounts-BB_YAGOL.js → accounts-DhyjISyA.js} +1 -1
- package/assets/{advanced-BKBBGGkA.js → advanced-BbgHlWGx.js} +1 -1
- package/assets/{appearance-BifGV7LC.js → appearance-R-T_LOKS.js} +1 -1
- package/assets/{attachment-file-3nQeOYEl.js → attachment-file-BLDkIwOJ.js} +1 -1
- package/assets/{avatar-CMmsLmyy.js → avatar-DN2GOVwx.js} +1 -1
- package/assets/{bottom-sheet-CWgSrS8P.js → bottom-sheet-BOV1XlmK.js} +1 -1
- package/assets/{brief-CzJIeuHg.js → brief-CVhL20Be.js} +1 -1
- package/assets/brief-NWAyMRhx.js +1 -0
- package/assets/{browser-ponyfill-CujCJVgN.js → browser-ponyfill-D32B93-O.js} +1 -1
- package/assets/{bug-C02aRzzI.js → bug-CFJvh78a.js} +1 -1
- package/assets/{circle-check-D1WgdSWg.js → circle-check-B1axZLsr.js} +1 -1
- package/assets/{circle-check-big-RhLkzWwq.js → circle-check-big-vqvQydJO.js} +1 -1
- package/assets/{circle-help-B4Km6qS2.js → circle-help-BJY9-zHE.js} +1 -1
- package/assets/{clock-C9PA6FBa.js → clock-aSLlxPRI.js} +1 -1
- package/assets/compose._-_outboxMessageId_-B-I9TQKF.js +1 -0
- package/assets/compose._-_outboxMessageId_-C371nzzR.js +1 -0
- package/assets/compose._-_outboxMessageId_-DLU-kxsZ.js +1 -0
- package/assets/compose._-_outboxMessageId_-u4OuMRxE.js +1 -0
- package/assets/{confirm-dialog-Da6hnSM3.js → confirm-dialog-BZchyNni.js} +1 -1
- package/assets/{download-rjhaAxaF.js → download-DmAkhhMn.js} +1 -1
- package/assets/{filters-DPtYEotN.js → filters-zSfon7Fz.js} +1 -1
- package/assets/flagged-DbwD456Q.js +1 -0
- package/assets/{flagged-CGrZEuHu.js → flagged-TX_K_SDH.js} +1 -1
- package/assets/{folders-C0R1Y4OK.js → folders-xljDMDdm.js} +1 -1
- package/assets/format-D7umvejg.js +1 -0
- package/assets/{help-copy-9GDhU54q.js → help-copy-9gZWDIuu.js} +1 -1
- package/assets/index-BEQek0iA.js +1 -0
- package/assets/{index-DWTQFAld.js → index-BKi_1Qmh.js} +4 -4
- package/assets/index-BrvrVTJO.js +1 -0
- package/assets/index-BtjFK1Tg.js +1 -0
- package/assets/index-CFu6hexv.js +1 -0
- package/assets/index-CHI5ffeH.js +1 -0
- package/assets/index-CHkPTaHx.js +1 -0
- package/assets/index-CJB0i5Fm.js +1 -0
- package/assets/{index-BA8nKa3G.js → index-DGOEldLQ.js} +3 -3
- package/assets/index-DJUXd-ym.js +1 -0
- package/assets/{kbd-D5PH_Yeh.js → kbd-CaLtMuEp.js} +1 -1
- package/assets/{labels-CvGPNnzi.js → labels-BIvrEn-w.js} +1 -1
- package/assets/{mail-BkQ3qfkO.js → mail-BhxrrdBx.js} +1 -1
- package/assets/{mail-CVYovHhd.js → mail-DV0uERxL.js} +1 -1
- package/assets/{menu-axuokLb8.js → menu-3dLcSCcM.js} +1 -1
- package/assets/{move-options-bACz3EKO.js → move-options-yXxXVQoL.js} +1 -1
- package/assets/{onboarding-Czxb8_g9.js → onboarding-C6hRcHAf.js} +1 -1
- package/assets/outbox-BYoYn006.js +1 -0
- package/assets/{pencil-BMKOgHR8.js → pencil-C-ZGjBY2.js} +1 -1
- package/assets/{rich-text-DkCI7aTE.js → rich-text-DoN_jZV_.js} +1 -1
- package/assets/{rich-text-spellcheck-worker-provider-CLSscphk.js → rich-text-spellcheck-worker-provider-CA4LOlq5.js} +1 -1
- package/assets/{rotate-ccw-BTLQy92s.js → rotate-ccw-ChFcYBoM.js} +1 -1
- package/assets/{row-actions-CzeVDOjC.js → row-actions-B1y94-E_.js} +1 -1
- package/assets/{search-scope-CYOn5umZ.js → search-scope-Ci5AdKCU.js} +1 -1
- package/assets/{search-token-index-Cs8Ftd9n.js → search-token-index-CBTVc3D8.js} +1 -1
- package/assets/{search-view-D_vEtzm8.js → search-view-B0zvV-Pg.js} +1 -1
- package/assets/{senders-BQLYGOyT.js → senders-CQIXGOVn.js} +1 -1
- package/assets/settings-DRp3tzum.js +1 -0
- package/assets/{settings-screen-vHPARR-S.js → settings-screen-BQgI79gc.js} +1 -1
- package/assets/{shield-check-DvqZopQi.js → shield-check-bHOnFfMN.js} +1 -1
- package/assets/{suggested-vips-CR_Hbf_l.js → suggested-vips-mSU92pmk.js} +1 -1
- package/assets/{useDebouncedValue-BCcQLHTX.js → useDebouncedValue-DVdVjbNi.js} +1 -1
- package/assets/{useFilters-BZTwmiUR.js → useFilters-CX8meUa-.js} +1 -1
- package/assets/{useLabels-qZXTLOTI.js → useLabels-kXlhZvsf.js} +1 -1
- package/assets/{useMediaQuery-BJ0bdm27.js → useMediaQuery-BS2MwPdz.js} +1 -1
- package/assets/{useMessageBodyContent-Cq8ZI8TG.js → useMessageBodyContent-_8vqUkeq.js} +1 -1
- package/assets/{useRefreshControl-CbLU7po8.js → useRefreshControl-DH6HghkG.js} +1 -1
- package/assets/{useSearchMirror-D8Nl0zF5.js → useSearchMirror-C__UTrT9.js} +1 -1
- package/assets/{useSearchTokenContext-pDlDcPcA.js → useSearchTokenContext-SHA9xnEZ.js} +1 -1
- package/assets/{useSemanticSearch-Beo5Ak7n.js → useSemanticSearch-DvBxUHMv.js} +1 -1
- package/assets/{useSignature-BYfjpUlQ.js → useSignature-C2iDHQnY.js} +1 -1
- package/index.html +1 -1
- package/package.json +1 -1
- package/assets/FlaggedPane-DKUFnO_I.js +0 -1
- package/assets/MailListHeader-DJihnNAN.js +0 -7
- package/assets/MailboxPane-DeGxB8Qf.js +0 -1
- package/assets/_mailboxId-DTtJ_RCS.js +0 -1
- package/assets/_messageId-BJ8f8FrH.js +0 -1
- package/assets/_messageId-C22pps5X.js +0 -1
- package/assets/_messageId-D-ubN05n.js +0 -1
- package/assets/_outboxMessageId-Rnms2OF-.js +0 -1
- package/assets/_threadId-CfwHf-ER.js +0 -1
- package/assets/_threadId-CkP863ki.js +0 -1
- package/assets/_threadId-Cn9vPnDJ.js +0 -1
- package/assets/brief-_ObMXcNH.js +0 -1
- package/assets/compose._-_outboxMessageId_-DGVI8xL9.js +0 -1
- package/assets/compose._-_outboxMessageId_-DxEWhOy_.js +0 -1
- package/assets/compose._-_outboxMessageId_-Q1XXeaqV.js +0 -1
- package/assets/compose._-_outboxMessageId_-jEOT1d7O.js +0 -1
- package/assets/flagged-ClS4NYnh.js +0 -1
- package/assets/format-HasNd5qT.js +0 -1
- package/assets/index-8wk_Fxi1.js +0 -1
- package/assets/index-9pBWBQiy.js +0 -1
- package/assets/index-BJ8f8FrH.js +0 -1
- package/assets/index-BOlqAdG5.js +0 -1
- package/assets/index-C22pps5X.js +0 -1
- package/assets/index-CLhxHvEn.js +0 -1
- package/assets/index-COgtU5wB.js +0 -1
- package/assets/index-DAQVTV7Y.js +0 -1
- package/assets/outbox-ig-gKQn5.js +0 -1
- package/assets/settings-_lAt5ro4.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as a,af as Ke,S as Xe,bh as es,l as G,bb as ss,m as oe,r as o,s as ae,bi as ne,q as ts,bj as as,bk as ns,bl as os,e as Re,bm as rs}from"./index-DWTQFAld.js";import{s as Te,a as is,b as we,u as ls,p as cs,R as ds}from"./useSearchTokenContext-pDlDcPcA.js";import{a5 as ve,E as ye,a6 as us,a7 as ms,F as fs,a8 as Se,a9 as hs,aa as gs,ab as xs,a4 as ps,ac as Is,ad as bs,ae as vs,M as ys,af as Ss,ag as Cs,ah as js,e as Rs,w as Ts,ai as ws,s as Ms,S as ks,I as Fs,N as Ce,L as Ns,J as As,d as Os,X as Bs,Y as Ls,Z as Me,_ as ke,$ as Ds,a0 as Es,a1 as Ps}from"./MailListHeader-DJihnNAN.js";import{u as qs,a as zs,R as Qs,i as Hs,b as _s}from"./useRefreshControl-CbLU7po8.js";import{e as $s,c as Ws,R as Us}from"./search-token-index-Cs8Ftd9n.js";import{a as Vs}from"./useLabels-qZXTLOTI.js";import{u as Ys}from"./useMediaQuery-BJ0bdm27.js";import{u as Gs,L as Js}from"./useSemanticSearch-Beo5Ak7n.js";import{o as Zs,f as Ks,h as Xs,p as et,r as st}from"./useMessageBodyContent-Cq8ZI8TG.js";function tt({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(Ke,{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:at(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 at({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 Fe=[{id:"unread",name:"is",value:"unread"},{id:"attachment",name:"has",value:"attachment"}],Ne="category",nt={unclassified:"uncategorized"},$=e=>is(e).map(s=>s.raw),_=e=>e.join(" "),re=e=>{const s=we(e);if(s)return Fe.find(n=>n.name===s.name&&n.value===s.value.toLowerCase())?.id},ie=e=>{const s=we(e);if(!s||s.name!==Ne)return;const n=s.value.toLowerCase(),r=nt[n];if(r)return r;if(!(!es(n)||n==="all"))return n},Ae=e=>Fe.find(s=>s.id===e),Oe=e=>Ae(e)!==void 0,ot=e=>{const s=new Set;for(const n of $(e)){const r=re(n);r&&s.add(r)}return s},rt=e=>{let s="all";for(const n of $(e)){const r=ie(n);r&&(s=r)}return s},it=(e,s)=>{const n=Ae(s);if(!n)return;const r=$(e),d=r.filter(l=>re(l)!==s);return d.length<r.length?_(d):_([...r,Te(n.name,n.value)])},lt=(e,s)=>{const n=$(e).filter(r=>!ie(r));return _(s==="all"?n:[...n,Te(Ne,s)])},ct=e=>_($(e).filter(s=>!re(s)&&!ie(s))),Be=e=>e.trim().length>0,dt=e=>{if(!Be(e.query))return e.ownFilters;const s=new Set(ot(e.query));for(const n of e.ownFilters)Oe(n)||s.add(n);return s},ut=e=>Be(e.query)?rt(e.query):e.ownCategory,mt=(e,s)=>e.createdAt!==s.createdAt?e.createdAt-s.createdAt:e.accountId.localeCompare(s.accountId),ft=e=>[...e].sort(mt),ht=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))}),gt=({accountEmail:e})=>{const s=oe();return a.jsxs("div",{className:"flex items-center gap-2 px-row-inset py-2 border-b border-line bg-danger-soft/40 text-xs text-danger",children:[a.jsx(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"})]})},xt=(e,s)=>{if(s.size===0)return{};const n=new Set,r=new Set;for(const l of e)s.has(l.id)&&(l.accountId&&n.add(l.accountId),l.mailboxId&&r.add(l.mailboxId));if(n.size>1)return{restriction:"spansAccounts",moveDisabledHint:"Move only works within one account — clear selection or pick messages from a single account"};const d=n.size===1?[...n][0]:void 0;return r.size>1?{accountId:d,restriction:"spansFolders",moveDisabledHint:`Move only works within one folder — this selection spans ${r.size} folders`}:{accountId:d,mailboxId:r.size===1?[...r][0]:void 0}};function pt({header:e,rows:s,wizard:n,children:r}){const{selectedIds:d,selectedCount:l,exitSelection:f,orderedIds:u,allSelected:h,toggleAllLoaded:S}=js(),p=o.useMemo(()=>xt(s,d),[s,d]),{junkMailboxId:I}=Rs(p.accountId),{labels:b}=Vs(p.accountId),N=o.useMemo(()=>Array.from(d),[d]),D=o.useMemo(()=>s.filter(x=>d.has(x.id)).map(x=>({id:x.id,sender:x.fromName,email:x.fromEmail,subject:x.subject,date:x.timeLabel})),[s,d]),m=Ts(I,p.mailboxId),v=o.useMemo(()=>u.length>0?{checked:h,indeterminate:l>0&&!h,onChange:S}:void 0,[u.length,h,l,S]),A=p.moveDisabledHint?{tone:"warning",text:p.moveDisabledHint}:void 0,C=x=>a.jsx(ks,{title:x.title,navSlot:x.navSlot,titleMeta:x.titleMeta,searchSlot:x.searchSlot,searchField:x.searchField,idleSlot:x.makeFilterSlot,count:l,onCancel:f,onDelete:()=>n.start("delete"),onMove:()=>n.start("move"),onOrganize:()=>n.start("organize"),onJunk:m?()=>n.start("junk"):void 0,onMarkRead:()=>n.start("markRead"),overflowSlot:p.accountId&&p.mailboxId&&l>0&&b.length>0?a.jsx(Js,{accountId:p.accountId,mailboxId:p.mailboxId,messageIds:N}):void 0,selectAll:v,notice:A});return a.jsx(ws,{...e,selectionBar:C,paneOverlay:a.jsx(Ms,{verb:n.verb,accountId:p.accountId,mailboxId:p.mailboxId,selection:D,selectionRestriction:p.restriction,onFinished:f}),children:r})}function It({accounts:e,selectedMessageId:s,onOpenThread:n,commandsRef:r,onTriageContextChange:d,onDeleteMessages:l}){const{searchQuery:f,searchInput:u,resultFolderIndex:h,onSearchChange:S}=G(),p=ls(),I=Ys(),b=$s(),N=ss(),D=oe(),m=o.useMemo(()=>ft(e.filter(t=>!t.muted?.value)),[e]),[v,A]=o.useState("all"),[C,x]=o.useState("all"),[W,E]=o.useState(new Set),[Z,j]=o.useState(!1),P=o.useCallback(t=>{E(i=>{const c=new Set(i);return c.has(t)?c.delete(t):c.add(t),c})},[]),U=o.useCallback(()=>E(new Set),[]),T=u.trim().length>0,R=o.useMemo(()=>dt({query:u,ownFilters:W}),[u,W]),w=o.useMemo(()=>ut({query:u,ownCategory:C}),[u,C]),O=o.useCallback(t=>{if(!T||!Oe(t)){P(t);return}const i=it(u,t);i!==void 0&&S(i)},[T,u,S,P]),q=o.useCallback(t=>{if(!T){x(t);return}S(lt(u,t))},[T,u,S]),z=o.useCallback(()=>{x("all"),A("all"),U(),T&&S(ct(u))},[T,u,S,U]),{data:B,isLoading:Q,isError:g,refetch:L}=ae({...ne(),staleTime:6e4}),M=Ws({queries:m.map(t=>({...ts({path:{accountId:t.accountId}}),staleTime:1/0,meta:{softError:!0}}))}),V=o.useMemo(()=>{const t=new Map;for(let i=0;i<m.length;i++){const c=m[i].accountId,Ge=(M[i]?.data?.items??[]).reduce((Je,Ze)=>Je+(Ze.unseenCount??0),0);t.set(c,Ge)}return t},[m,M]),Ee=o.useMemo(()=>m.filter((t,i)=>{const c=M[i];return c?.isError?!as(c.error):!1}),[m,M]),{freeText:k,tokens:K}=cs(f.trim().toLowerCase(),p),{data:le,isFetching:Pe}=ae({...ne({query:{query:k,limit:ht}}),enabled:k.length>0,staleTime:3e4}),y=o.useMemo(()=>{const t=ve(B?.items??[]).map(ye);return(k?us(t.filter(c=>ms(c,k)),ve(le?.items??[]).map(ye)):t).filter(c=>(v==="all"||c.accountId===v)&&fs(c,K))},[B,le,v,k,K]),{bodyRows:ce,briefSpamOffer:X}=o.useMemo(()=>{if(!k)return{bodyRows:y,briefSpamOffer:void 0};const t=y.map(F=>Se(F,h)),{spam:i}=hs(t);if(i.length===0)return{bodyRows:y,briefSpamOffer:void 0};const c=new Set(i.map(F=>F.id));return{bodyRows:y.filter(F=>!c.has(F.id)),briefSpamOffer:gs(t)}},[y,k,h]),de=o.useMemo(()=>xs(ce),[ce]),ue=o.useCallback((t,i)=>{const c=y.find(F=>F.id===t)?.threadId;c&&n?.({threadId:c,messageId:t},i)},[y,n]),qe=o.useCallback(t=>{const i=t.threadId??y.find(c=>c.id===t.id)?.threadId;i&&n?.({threadId:i,messageId:t.id})},[y,n]),ee=o.useMemo(()=>m.length<=1?[]:[{id:"all",label:"All",active:v==="all"},...m.map(t=>({id:t.accountId,label:t.email.split("@")[0]??t.email,count:V.get(t.accountId),active:v===t.accountId}))],[m,V,v]),H=o.useMemo(()=>e.filter(t=>t.muted?.value).length,[e]),ze=o.useMemo(()=>Array.from(V.values()).reduce((t,i)=>t+i,0),[V]),se=o.useMemo(()=>m.map(t=>t.accountId),[m]),{hasNewMail:me}=qs(),{state:fe,errorMessage:he,refresh:ge}=zs(se,{onSettled:()=>L()}),Qe=o.useMemo(()=>a.jsx(Qs,{state:fe,onRefresh:ge,label:"Refresh daily brief",errorMessage:he,hasUpdate:me(se)}),[fe,ge,he,me,se]),te=o.useMemo(()=>y.filter(t=>(w==="all"||t.category===w)&&ns(t,R)).map(t=>Se(t,h)),[y,w,R,h]),{hits:xe,isLoading:He}=Gs(),_e=o.useMemo(()=>{const t=new Map;for(const c of B?.items??[])t.set(c.messageId,c.threadId);const i=te.map(c=>t.get(c.id)).filter(c=>c!=null);return ps(xe,i,h)},[xe,te,B,h]),$e=o.useMemo(()=>{const t=Is(ee.map(i=>({id:i.id,label:i.label,count:i.count,active:i.active})));return{categories:t.categories,filters:t.filters,sources:t.sources,sourcesNote:H>0?`+${H} muted`:void 0,selectedCategory:w,activeFilters:R,expanded:Z,onExpandedChange:j,onSelectCategory:i=>q(i),onSelectSource:A,onToggleFilter:i=>O(i),onClear:z}},[ee,H,w,R,Z,O,q,z]),pe=de.length===0&&v==="all"&&k.length===0&&K.length===0,We=o.useMemo(()=>m.map(t=>t.accountId),[m]),Ue=o.useMemo(()=>m.some(t=>Hs(t.syncPhase)),[m]),Y=_s(We,pe||Ue),Ie=a.jsxs("div",{className:"h-full overflow-y-auto",children:[a.jsx(je,{}),a.jsx(je,{})]}),be=!Q&&!g&&!pe,Ve=bs({tier:b,hasLiveInput:T,hasCommittedQuery:f.trim().length>0,bodyRendersCommittedResults:!0}),Ye=be?a.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[X&&a.jsx(vs,{count:X.count,onScopeToSpam:()=>D({to:"/mail/$mailboxId",params:{mailboxId:X.mailboxId},search:{q:f||void 0}})}),a.jsx("div",{className:"min-h-0 flex-1",children:a.jsx(os,{sections:de,briefCategory:w,Row:ys,selectedThreadId:s,onSelectThread:ue,onSelectBriefCategory:q,sources:ee,sourcesNote:H>0?`+${H} muted`:void 0,onSelectSource:A,activeFilters:R,onToggleFilter:O,onClearFilters:z})})]}):Q?Ie:g?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:()=>L(),className:"flex items-center gap-1 text-accent underline text-xs",children:[a.jsx(Us,{className:"size-3.5"}),"Try again"]})]}):Y.resolved?a.jsx(tt,{sync:Y.syncing?{synced:Y.synced,total:Y.total}:void 0}):Ie;return a.jsx(rs,{hasSheet:be&&!Ve,children:a.jsx(Ss,{selectedMessageId:s,onOpen:ue,onDeleteMessages:l,onSelectionVerb:N.start,wizardOpen:N.isOpen,commandsRef:r,onTriageContextChange:d,children:a.jsx(pt,{wizard:N,header:{title:"Daily brief",unreadCount:ze,footer:I?a.jsx(Cs,{}):void 0,searchFilter:$e,searchResults:te,searchLoading:Q||Pe,relatedResults:_e,relatedLoading:He,onSelectSearchResult:qe,searchResultsInBody:!0,refreshControl:Qe},rows:y,children:a.jsxs("div",{className:"flex h-full flex-col",children:[Ee.map(t=>a.jsx(gt,{accountEmail:t.email,accountId:t.accountId},t.accountId)),a.jsx("div",{className:"min-h-0 flex-1",children:Ye})]})})})})}const Le=o.createContext(null);function J(){const e=o.useContext(Le);if(!e)throw new Error("BriefPane.* must be used inside <BriefPane>");return e}function bt({thread:e,children:s}){const n=oe(),r=Zs(),{searchInput:d}=G(),l=e?.threadId,f=e?.messageId,{data:u}=ae({...ne(),staleTime:6e4}),h=o.useMemo(()=>u?.items??[],[u]),S=o.useMemo(()=>{if(l)return h.find(g=>g.messageId===f)??h.find(g=>g.threadId===l)},[h,l,f]),p=Fs(l,f),I=S??p,b=f??I?.messageId,N=o.useMemo(()=>{if(l)return{threadId:l,mailboxId:I?.mailboxId??"",subject:I?.subject,messageId:b,authenticity:I?.authenticity}},[l,I,b]),D=o.useCallback((g,L)=>{n({to:"/mail/brief/$threadId/$messageId",params:g,replace:L?.replace,search:M=>({...M,q:d||void 0}),hash:r})},[n,r,d]),m=o.useCallback(()=>{n({to:"/mail/brief",search:g=>g,hash:r})},[n,r]),v=o.useCallback(g=>{b&&g.includes(b)&&m()},[b,m]),A=Ce({thread:I,onAfterOptimisticRemove:v}),C=Ns(),{deleteMessages:x}=As({mailboxId:I?.mailboxId??"",messages:h,onAfterOptimisticRemove:v}),{toggleReadFor:W}=Os({mailboxId:I?.mailboxId??"",messages:h}),E=C.focusedMessageId,j=o.useMemo(()=>h.find(g=>g.messageId===E),[h,E])??I,P=Ce({thread:j}),U=Ks(),T=Xs(),R=et(),w=o.useMemo(()=>st(R,l,b),[R,l,b]),O=o.useMemo(()=>{if(j)return g=>R({threadId:j.threadId,messageId:j.messageId,mode:g})},[R,j]),{nextMessageId:q,previousMessageId:z}=Bs({context:C,orderedIds:C.orderedIds,selectedMessageId:b,enabled:!U&&!T,onClose:m,handlers:{reply:()=>O?.("reply"),replyAll:()=>O?.("reply-all"),forward:()=>O?.("forward"),delete:()=>{C.listCommandsRef.current?.requestVerb("delete")||P.deleteThread()},toggleStar:P.toggleStar,toggleRead:()=>{C.listCommandsRef.current?.requestVerb("markRead")||j&&W([j.messageId],!j.isRead)},goFlagged:()=>n({to:"/mail/flagged"}),goSettings:()=>n({to:"/settings"})}}),B=o.useCallback(g=>{if(!g)return;const L=h.find(M=>M.messageId===g);return L?{threadId:L.threadId,messageId:g}:void 0},[h]),Q={selectedMessageId:b,selectedThread:I,conversation:N,onOpenThread:D,onCloseThread:m,nextThread:B(q),previousThread:B(z),actions:A,onReply:w,triage:C,onDeleteMessages:x,handleDeselectIfRemoved:v};return a.jsx(Le.Provider,{value:Q,children:s})}function De(){const{selectedMessageId:e,onOpenThread:s,triage:n,onDeleteMessages:r}=J(),{accounts:d}=G();return a.jsx(It,{accounts:d,selectedMessageId:e,onOpenThread:s,commandsRef:n.listCommandsRef,onTriageContextChange:n.onTriageContextChange,onDeleteMessages:r})}function vt(){const{conversation:e,selectedThread:s,actions:n,onReply:r,handleDeselectIfRemoved:d}=J(),l=!!e,f=Es(e?.threadId);return a.jsxs(a.Fragment,{children:[a.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[a.jsx(Ps,{hasThread:l,intelligenceOpen:f.isShowing,canToggleIntelligence:f.canToggle,onToggleIntelligence:f.toggle,onReply:r?()=>r("reply"):void 0,onReplyAll:r?()=>r("reply-all"):void 0,onForward:r?()=>r("forward"):void 0,onDelete:l?n.deleteThread:void 0,onToggleStar:l?n.toggleStar:void 0,isStarred:n.isStarred,moveContext:l&&n.accountId&&n.mailboxId?{accountId:n.accountId,currentMailboxId:n.mailboxId,onMove:n.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,onOpenIntelligence:f.open}):a.jsx(ds,{})})]}),a.jsx(ke,{isOpen:f.drawerOpen,onClose:f.closeDrawer,thread:s,mailboxId:s?.mailboxId,accountId:s?.accountId,onAfterOptimisticRemove:d})]})}function yt(){const{selectedThread:e,handleDeselectIfRemoved:s}=J(),{onToggleIntelligence:n}=G();return a.jsx(Ds,{onClose:n,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId,onAfterOptimisticRemove:s})}function St(){const{selectedThread:e,conversation:s,onOpenThread:n,onCloseThread:r,nextThread:d,previousThread:l,handleDeselectIfRemoved:f}=J(),u=Ls(s?.threadId??null);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.toggle,onSwipeNext:d?()=>n(d):void 0,onSwipePrevious:l?()=>n(l):void 0,mobileIntelligenceOpen:u.isOpen}),a.jsx(ke,{isOpen:u.isOpen,onClose:u.close,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId,onAfterOptimisticRemove:f})]}):a.jsx("div",{className:"h-full",children:a.jsx(De,{})})}const At=Object.assign(bt,{List:De,Reading:vt,Intelligence:yt,Phone:St});export{At as B};
|
|
1
|
+
import{j as a,af as Ke,S as Xe,bh as es,l as G,bb as ss,m as oe,r as o,s as ae,bi as ne,q as ts,bj as as,bk as ns,bl as os,e as Re,bm as rs}from"./index-BKi_1Qmh.js";import{s as Te,a as is,b as we,u as ls,p as cs,R as ds}from"./useSearchTokenContext-SHA9xnEZ.js";import{a5 as ve,E as ye,a6 as us,a7 as ms,F as fs,a8 as Se,a9 as hs,aa as gs,ab as xs,a4 as ps,ac as Is,ad as bs,ae as vs,M as ys,af as Ss,ag as Cs,ah as js,e as Rs,v as Ts,ai as ws,q as Ms,S as ks,I as Fs,N as Ce,L as Ns,J as As,d as Os,X as Bs,Y as Ls,Z as Me,_ as ke,$ as Ds,a0 as Es,a1 as Ps}from"./MailListHeader-DznCndIp.js";import{u as qs,a as zs,R as Qs,i as Hs,b as _s}from"./useRefreshControl-DH6HghkG.js";import{e as $s,c as Ws,R as Us}from"./search-token-index-CBTVc3D8.js";import{a as Vs}from"./useLabels-kXlhZvsf.js";import{u as Ys}from"./useMediaQuery-BS2MwPdz.js";import{u as Gs,L as Js}from"./useSemanticSearch-DvBxUHMv.js";import{o as Zs,f as Ks,h as Xs,p as et,r as st}from"./useMessageBodyContent-_8vqUkeq.js";function tt({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(Ke,{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:at(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 at({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 Fe=[{id:"unread",name:"is",value:"unread"},{id:"attachment",name:"has",value:"attachment"}],Ne="category",nt={unclassified:"uncategorized"},$=e=>is(e).map(s=>s.raw),_=e=>e.join(" "),re=e=>{const s=we(e);if(s)return Fe.find(n=>n.name===s.name&&n.value===s.value.toLowerCase())?.id},ie=e=>{const s=we(e);if(!s||s.name!==Ne)return;const n=s.value.toLowerCase(),r=nt[n];if(r)return r;if(!(!es(n)||n==="all"))return n},Ae=e=>Fe.find(s=>s.id===e),Oe=e=>Ae(e)!==void 0,ot=e=>{const s=new Set;for(const n of $(e)){const r=re(n);r&&s.add(r)}return s},rt=e=>{let s="all";for(const n of $(e)){const r=ie(n);r&&(s=r)}return s},it=(e,s)=>{const n=Ae(s);if(!n)return;const r=$(e),d=r.filter(l=>re(l)!==s);return d.length<r.length?_(d):_([...r,Te(n.name,n.value)])},lt=(e,s)=>{const n=$(e).filter(r=>!ie(r));return _(s==="all"?n:[...n,Te(Ne,s)])},ct=e=>_($(e).filter(s=>!re(s)&&!ie(s))),Be=e=>e.trim().length>0,dt=e=>{if(!Be(e.query))return e.ownFilters;const s=new Set(ot(e.query));for(const n of e.ownFilters)Oe(n)||s.add(n);return s},ut=e=>Be(e.query)?rt(e.query):e.ownCategory,mt=(e,s)=>e.createdAt!==s.createdAt?e.createdAt-s.createdAt:e.accountId.localeCompare(s.accountId),ft=e=>[...e].sort(mt),ht=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))}),gt=({accountEmail:e})=>{const s=oe();return a.jsxs("div",{className:"flex items-center gap-2 px-row-inset py-2 border-b border-line bg-danger-soft/40 text-xs text-danger",children:[a.jsx(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"})]})},xt=(e,s)=>{if(s.size===0)return{};const n=new Set,r=new Set;for(const l of e)s.has(l.id)&&(l.accountId&&n.add(l.accountId),l.mailboxId&&r.add(l.mailboxId));if(n.size>1)return{restriction:"spansAccounts",moveDisabledHint:"Move only works within one account — clear selection or pick messages from a single account"};const d=n.size===1?[...n][0]:void 0;return r.size>1?{accountId:d,restriction:"spansFolders",moveDisabledHint:`Move only works within one folder — this selection spans ${r.size} folders`}:{accountId:d,mailboxId:r.size===1?[...r][0]:void 0}};function pt({header:e,rows:s,wizard:n,children:r}){const{selectedIds:d,selectedCount:l,exitSelection:f,orderedIds:u,allSelected:h,toggleAllLoaded:S}=js(),p=o.useMemo(()=>xt(s,d),[s,d]),{junkMailboxId:I}=Rs(p.accountId),{labels:b}=Vs(p.accountId),N=o.useMemo(()=>Array.from(d),[d]),D=o.useMemo(()=>s.filter(x=>d.has(x.id)).map(x=>({id:x.id,sender:x.fromName,email:x.fromEmail,subject:x.subject,date:x.timeLabel})),[s,d]),m=Ts(I,p.mailboxId),v=o.useMemo(()=>u.length>0?{checked:h,indeterminate:l>0&&!h,onChange:S}:void 0,[u.length,h,l,S]),A=p.moveDisabledHint?{tone:"warning",text:p.moveDisabledHint}:void 0,C=x=>a.jsx(ks,{title:x.title,navSlot:x.navSlot,titleMeta:x.titleMeta,searchSlot:x.searchSlot,searchField:x.searchField,idleSlot:x.makeFilterSlot,count:l,onCancel:f,onDelete:()=>n.start("delete"),onMove:()=>n.start("move"),onOrganize:()=>n.start("organize"),onJunk:m?()=>n.start("junk"):void 0,onMarkRead:()=>n.start("markRead"),overflowSlot:p.accountId&&p.mailboxId&&l>0&&b.length>0?a.jsx(Js,{accountId:p.accountId,mailboxId:p.mailboxId,messageIds:N}):void 0,selectAll:v,notice:A});return a.jsx(ws,{...e,selectionBar:C,paneOverlay:a.jsx(Ms,{verb:n.verb,accountId:p.accountId,mailboxId:p.mailboxId,selection:D,selectionRestriction:p.restriction,onFinished:f}),children:r})}function It({accounts:e,selectedMessageId:s,onOpenThread:n,commandsRef:r,onTriageContextChange:d,onDeleteMessages:l}){const{searchQuery:f,searchInput:u,resultFolderIndex:h,onSearchChange:S}=G(),p=ls(),I=Ys(),b=$s(),N=ss(),D=oe(),m=o.useMemo(()=>ft(e.filter(t=>!t.muted?.value)),[e]),[v,A]=o.useState("all"),[C,x]=o.useState("all"),[W,E]=o.useState(new Set),[Z,j]=o.useState(!1),P=o.useCallback(t=>{E(i=>{const c=new Set(i);return c.has(t)?c.delete(t):c.add(t),c})},[]),U=o.useCallback(()=>E(new Set),[]),T=u.trim().length>0,R=o.useMemo(()=>dt({query:u,ownFilters:W}),[u,W]),w=o.useMemo(()=>ut({query:u,ownCategory:C}),[u,C]),O=o.useCallback(t=>{if(!T||!Oe(t)){P(t);return}const i=it(u,t);i!==void 0&&S(i)},[T,u,S,P]),q=o.useCallback(t=>{if(!T){x(t);return}S(lt(u,t))},[T,u,S]),z=o.useCallback(()=>{x("all"),A("all"),U(),T&&S(ct(u))},[T,u,S,U]),{data:B,isLoading:Q,isError:g,refetch:L}=ae({...ne(),staleTime:6e4}),M=Ws({queries:m.map(t=>({...ts({path:{accountId:t.accountId}}),staleTime:1/0,meta:{softError:!0}}))}),V=o.useMemo(()=>{const t=new Map;for(let i=0;i<m.length;i++){const c=m[i].accountId,Ge=(M[i]?.data?.items??[]).reduce((Je,Ze)=>Je+(Ze.unseenCount??0),0);t.set(c,Ge)}return t},[m,M]),Ee=o.useMemo(()=>m.filter((t,i)=>{const c=M[i];return c?.isError?!as(c.error):!1}),[m,M]),{freeText:k,tokens:K}=cs(f.trim().toLowerCase(),p),{data:le,isFetching:Pe}=ae({...ne({query:{query:k,limit:ht}}),enabled:k.length>0,staleTime:3e4}),y=o.useMemo(()=>{const t=ve(B?.items??[]).map(ye);return(k?us(t.filter(c=>ms(c,k)),ve(le?.items??[]).map(ye)):t).filter(c=>(v==="all"||c.accountId===v)&&fs(c,K))},[B,le,v,k,K]),{bodyRows:ce,briefSpamOffer:X}=o.useMemo(()=>{if(!k)return{bodyRows:y,briefSpamOffer:void 0};const t=y.map(F=>Se(F,h)),{spam:i}=hs(t);if(i.length===0)return{bodyRows:y,briefSpamOffer:void 0};const c=new Set(i.map(F=>F.id));return{bodyRows:y.filter(F=>!c.has(F.id)),briefSpamOffer:gs(t)}},[y,k,h]),de=o.useMemo(()=>xs(ce),[ce]),ue=o.useCallback((t,i)=>{const c=y.find(F=>F.id===t)?.threadId;c&&n?.({threadId:c,messageId:t},i)},[y,n]),qe=o.useCallback(t=>{const i=t.threadId??y.find(c=>c.id===t.id)?.threadId;i&&n?.({threadId:i,messageId:t.id})},[y,n]),ee=o.useMemo(()=>m.length<=1?[]:[{id:"all",label:"All",active:v==="all"},...m.map(t=>({id:t.accountId,label:t.email.split("@")[0]??t.email,count:V.get(t.accountId),active:v===t.accountId}))],[m,V,v]),H=o.useMemo(()=>e.filter(t=>t.muted?.value).length,[e]),ze=o.useMemo(()=>Array.from(V.values()).reduce((t,i)=>t+i,0),[V]),se=o.useMemo(()=>m.map(t=>t.accountId),[m]),{hasNewMail:me}=qs(),{state:fe,errorMessage:he,refresh:ge}=zs(se,{onSettled:()=>L()}),Qe=o.useMemo(()=>a.jsx(Qs,{state:fe,onRefresh:ge,label:"Refresh daily brief",errorMessage:he,hasUpdate:me(se)}),[fe,ge,he,me,se]),te=o.useMemo(()=>y.filter(t=>(w==="all"||t.category===w)&&ns(t,R)).map(t=>Se(t,h)),[y,w,R,h]),{hits:xe,isLoading:He}=Gs(),_e=o.useMemo(()=>{const t=new Map;for(const c of B?.items??[])t.set(c.messageId,c.threadId);const i=te.map(c=>t.get(c.id)).filter(c=>c!=null);return ps(xe,i,h)},[xe,te,B,h]),$e=o.useMemo(()=>{const t=Is(ee.map(i=>({id:i.id,label:i.label,count:i.count,active:i.active})));return{categories:t.categories,filters:t.filters,sources:t.sources,sourcesNote:H>0?`+${H} muted`:void 0,selectedCategory:w,activeFilters:R,expanded:Z,onExpandedChange:j,onSelectCategory:i=>q(i),onSelectSource:A,onToggleFilter:i=>O(i),onClear:z}},[ee,H,w,R,Z,O,q,z]),pe=de.length===0&&v==="all"&&k.length===0&&K.length===0,We=o.useMemo(()=>m.map(t=>t.accountId),[m]),Ue=o.useMemo(()=>m.some(t=>Hs(t.syncPhase)),[m]),Y=_s(We,pe||Ue),Ie=a.jsxs("div",{className:"h-full overflow-y-auto",children:[a.jsx(je,{}),a.jsx(je,{})]}),be=!Q&&!g&&!pe,Ve=bs({tier:b,hasLiveInput:T,hasCommittedQuery:f.trim().length>0,bodyRendersCommittedResults:!0}),Ye=be?a.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[X&&a.jsx(vs,{count:X.count,onScopeToSpam:()=>D({to:"/mail/$mailboxId",params:{mailboxId:X.mailboxId},search:{q:f||void 0}})}),a.jsx("div",{className:"min-h-0 flex-1",children:a.jsx(os,{sections:de,briefCategory:w,Row:ys,selectedThreadId:s,onSelectThread:ue,onSelectBriefCategory:q,sources:ee,sourcesNote:H>0?`+${H} muted`:void 0,onSelectSource:A,activeFilters:R,onToggleFilter:O,onClearFilters:z})})]}):Q?Ie:g?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:()=>L(),className:"flex items-center gap-1 text-accent underline text-xs",children:[a.jsx(Us,{className:"size-3.5"}),"Try again"]})]}):Y.resolved?a.jsx(tt,{sync:Y.syncing?{synced:Y.synced,total:Y.total}:void 0}):Ie;return a.jsx(rs,{hasSheet:be&&!Ve,children:a.jsx(Ss,{selectedMessageId:s,rows:y,onOpen:ue,onDeleteMessages:l,onSelectionVerb:N.start,wizardOpen:N.isOpen,commandsRef:r,onTriageContextChange:d,children:a.jsx(pt,{wizard:N,header:{title:"Daily brief",unreadCount:ze,footer:I?a.jsx(Cs,{}):void 0,searchFilter:$e,searchResults:te,searchLoading:Q||Pe,relatedResults:_e,relatedLoading:He,onSelectSearchResult:qe,searchResultsInBody:!0,refreshControl:Qe},rows:y,children:a.jsxs("div",{className:"flex h-full flex-col",children:[Ee.map(t=>a.jsx(gt,{accountEmail:t.email,accountId:t.accountId},t.accountId)),a.jsx("div",{className:"min-h-0 flex-1",children:Ye})]})})})})}const Le=o.createContext(null);function J(){const e=o.useContext(Le);if(!e)throw new Error("BriefPane.* must be used inside <BriefPane>");return e}function bt({thread:e,children:s}){const n=oe(),r=Zs(),{searchInput:d}=G(),l=e?.threadId,f=e?.messageId,{data:u}=ae({...ne(),staleTime:6e4}),h=o.useMemo(()=>u?.items??[],[u]),S=o.useMemo(()=>{if(l)return h.find(g=>g.messageId===f)??h.find(g=>g.threadId===l)},[h,l,f]),p=Fs(l,f),I=S??p,b=f??I?.messageId,N=o.useMemo(()=>{if(l)return{threadId:l,mailboxId:I?.mailboxId??"",subject:I?.subject,messageId:b,authenticity:I?.authenticity}},[l,I,b]),D=o.useCallback((g,L)=>{n({to:"/mail/brief/$threadId/$messageId",params:g,replace:L?.replace,search:M=>({...M,q:d||void 0}),hash:r})},[n,r,d]),m=o.useCallback(()=>{n({to:"/mail/brief",search:g=>g,hash:r})},[n,r]),v=o.useCallback(g=>{b&&g.includes(b)&&m()},[b,m]),A=Ce({thread:I,onAfterOptimisticRemove:v}),C=Ns(),{deleteMessages:x}=As({mailboxId:I?.mailboxId??"",messages:h,onAfterOptimisticRemove:v}),{toggleReadFor:W}=Os({mailboxId:I?.mailboxId??"",messages:h}),E=C.focusedMessageId,j=o.useMemo(()=>h.find(g=>g.messageId===E),[h,E])??I,P=Ce({thread:j}),U=Ks(),T=Xs(),R=et(),w=o.useMemo(()=>st(R,l,b),[R,l,b]),O=o.useMemo(()=>{if(j)return g=>R({threadId:j.threadId,messageId:j.messageId,mode:g})},[R,j]),{nextMessageId:q,previousMessageId:z}=Bs({context:C,orderedIds:C.orderedIds,selectedMessageId:b,enabled:!U&&!T,onClose:m,handlers:{reply:()=>O?.("reply"),replyAll:()=>O?.("reply-all"),forward:()=>O?.("forward"),delete:()=>{C.listCommandsRef.current?.requestVerb("delete")||P.deleteThread()},toggleStar:P.toggleStar,toggleRead:()=>{C.listCommandsRef.current?.requestVerb("markRead")||j&&W([j.messageId],!j.isRead)},goFlagged:()=>n({to:"/mail/flagged"}),goSettings:()=>n({to:"/settings"})}}),B=o.useCallback(g=>{if(!g)return;const L=h.find(M=>M.messageId===g);return L?{threadId:L.threadId,messageId:g}:void 0},[h]),Q={selectedMessageId:b,selectedThread:I,conversation:N,onOpenThread:D,onCloseThread:m,nextThread:B(q),previousThread:B(z),actions:A,onReply:w,triage:C,onDeleteMessages:x,handleDeselectIfRemoved:v};return a.jsx(Le.Provider,{value:Q,children:s})}function De(){const{selectedMessageId:e,onOpenThread:s,triage:n,onDeleteMessages:r}=J(),{accounts:d}=G();return a.jsx(It,{accounts:d,selectedMessageId:e,onOpenThread:s,commandsRef:n.listCommandsRef,onTriageContextChange:n.onTriageContextChange,onDeleteMessages:r})}function vt(){const{conversation:e,selectedThread:s,actions:n,onReply:r,handleDeselectIfRemoved:d}=J(),l=!!e,f=Es(e?.threadId);return a.jsxs(a.Fragment,{children:[a.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[a.jsx(Ps,{hasThread:l,intelligenceOpen:f.isShowing,canToggleIntelligence:f.canToggle,onToggleIntelligence:f.toggle,onReply:r?()=>r("reply"):void 0,onReplyAll:r?()=>r("reply-all"):void 0,onForward:r?()=>r("forward"):void 0,onDelete:l?n.deleteThread:void 0,onToggleStar:l?n.toggleStar:void 0,isStarred:n.isStarred,moveContext:l&&n.accountId&&n.mailboxId?{accountId:n.accountId,currentMailboxId:n.mailboxId,onMove:n.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,onOpenIntelligence:f.open}):a.jsx(ds,{})})]}),a.jsx(ke,{isOpen:f.drawerOpen,onClose:f.closeDrawer,thread:s,mailboxId:s?.mailboxId,accountId:s?.accountId,onAfterOptimisticRemove:d})]})}function yt(){const{selectedThread:e,handleDeselectIfRemoved:s}=J(),{onToggleIntelligence:n}=G();return a.jsx(Ds,{onClose:n,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId,onAfterOptimisticRemove:s})}function St(){const{selectedThread:e,conversation:s,onOpenThread:n,onCloseThread:r,nextThread:d,previousThread:l,handleDeselectIfRemoved:f}=J(),u=Ls(s?.threadId??null);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.toggle,onSwipeNext:d?()=>n(d):void 0,onSwipePrevious:l?()=>n(l):void 0,mobileIntelligenceOpen:u.isOpen}),a.jsx(ke,{isOpen:u.isOpen,onClose:u.close,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId,onAfterOptimisticRemove:f})]}):a.jsx("div",{className:"h-full",children:a.jsx(De,{})})}const At=Object.assign(bt,{List:De,Reading:vt,Intelligence:yt,Phone:St});export{At as B};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as t,e as r}from"./index-
|
|
1
|
+
import{j as t,e as r}from"./index-BKi_1Qmh.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 U,r,cq as X,l as H,bb as Y,aF as Z,aG as ee,j as n,m as te}from"./index-BKi_1Qmh.js";import{u as se,p as ae,R as ne}from"./useSearchTokenContext-SHA9xnEZ.js";import{E as re,a7 as oe,F as de,at as ie,a8 as le,b as ce,M as ue,af as ge,au as he,ah as me,q as fe,I as Ie,N as V,L as pe,J as xe,d as Te,X as be,Y as ve,Z as K,_ as W,$ as ye,a0 as Re,a1 as Ce}from"./MailListHeader-DznCndIp.js";import{u as Se,b as je,a as we}from"./MailViewChrome-BEuukQ7E.js";import{f as Fe}from"./ErrorState-Bn1oQw8C.js";import{u as Me}from"./useMediaQuery-BS2MwPdz.js";import{o as Pe,f as Oe,h as ke,p as Le,r as Ne}from"./useMessageBodyContent-_8vqUkeq.js";const Ae=()=>X({query:{starred:!0,order:"desc"}});function _(){const{data:e,isLoading:a,isError:t,error:d,refetch:m,fetchNextPage:s,hasNextPage:l,isFetchingNextPage:c}=Se({queryKey:Ae(),queryFn:async({pageParam:I})=>{const{data:g}=await U({query:{starred:!0,order:"desc",continuationToken:I},throwOnError:!0});return g},initialPageParam:void 0,getNextPageParam:I=>I.continuationToken,staleTime:6e4});return{threads:r.useMemo(()=>(e?.pages??[]).flatMap(I=>I.items??[]),[e]),isLoading:a,isError:t,error:d,refetch:m,fetchNextPage:s,hasNextPage:l,isFetchingNextPage:c}}const De=e=>{const a=new Set;return e.filter(t=>a.has(t.threadId)?!1:(a.add(t.threadId),!0))},Ee={unread:e=>!e.isRead,attachment:e=>e.hasAttachment===!0};function qe({rows:e,verb:a}){const{selectedIds:t,exitSelection:d}=me(),m=r.useMemo(()=>e.filter(s=>t.has(s.id)).map(s=>({id:s.id,sender:s.fromName,email:s.fromEmail,subject:s.subject,date:s.timeLabel})),[e,t]);return n.jsx(fe,{verb:a,selection:m,selectionRestriction:"spansAccounts",onFinished:d})}function Be({selectedMessageId:e,onOpenThread:a,commandsRef:t,onTriageContextChange:d,onDeleteMessages:m}){const{searchQuery:s,resultFolderIndex:l}=H(),c=se(),M=Me(),I=Y(),[g,f]=r.useState("all"),[R,P]=r.useState(new Set),v=r.useCallback(o=>{P(h=>{const p=new Set(h);return p.has(o)?p.delete(o):p.add(o),p})},[]),C=r.useCallback(()=>{f("all"),P(new Set)},[]),{threads:O,isLoading:T,isError:k,error:q,refetch:L,fetchNextPage:Q,hasNextPage:x,isFetchingNextPage:S}=_(),{freeText:y,tokens:N}=ae(s.trim().toLowerCase(),c),u=r.useMemo(()=>{const o=Array.from(R).map(h=>Ee[h]).filter(h=>h!=null);return De(O).map(re).filter(h=>(g==="all"||h.category===g)&&o.every(p=>p(h))&&(!y||oe(h,y))&&de(h,N))},[O,g,R,y,N]),j=r.useCallback((o,h)=>{const p=u.find(J=>J.id===o)?.threadId;p&&a?.({threadId:p,messageId:o},h)},[u,a]),w=r.useCallback(o=>{const h=o.threadId??u.find(p=>p.id===o.id)?.threadId;h&&a?.({threadId:h,messageId:o.id})},[u,a]),B=r.useMemo(()=>ie(),[]),z=r.useMemo(()=>u.map(o=>le(o,l)),[u,l]),A=r.useMemo(()=>u.filter(o=>!o.isRead).length,[u]),D=T?"loading":k?"error":u.length===0?"empty":"ready",i=r.useCallback(()=>{const o=Z(ee());window.open(o,"_blank","noopener,noreferrer")},[]),b=ce(),F=n.jsx("div",{className:"flex h-full min-h-0 flex-col",children:n.jsxs("div",{className:"flex-1 overflow-y-auto",children:[n.jsx("div",{className:"divide-y divide-line",children:u.map(o=>n.jsx(ue,{thread:o,active:o.id===e,onClick:()=>j(o.id)},o.id))}),x?n.jsx("button",{type:"button",className:"w-full py-3 text-sm text-muted hover:text-fg disabled:opacity-50",onClick:()=>Q(),disabled:S,children:S?"Loading…":"Load more"}):null]})});return n.jsx(je,{title:"Starred",unreadCount:A,preset:B,selectedCategory:g,activeFilters:R,onSelectCategory:f,onToggleFilter:v,onClearFilters:C,searchResults:z,searchLoading:T,onSelectSearchResult:w,searchResultsInBody:!0,children:n.jsxs(ge,{selectedMessageId:e,rows:u,onOpen:j,onDeleteMessages:m,onSelectionVerb:I.start,wizardOpen:I.isOpen,commandsRef:t,onTriageContextChange:d,children:[n.jsx(we,{listTitle:"Starred",sections:[{id:"flagged",threads:u}],flatList:!0,hideHeader:!0,listState:b.searchResults?"ready":D,searchQuery:y?s:void 0,errorMessage:k?Fe(q):void 0,onRetry:()=>L(),onReportError:i,selectedThreadId:e,onSelectThread:j,isDesktop:M,selectionBar:n.jsx(he,{title:"Starred"}),listBody:b.searchResults??(D==="ready"?F:void 0)}),n.jsx(qe,{rows:u,verb:I.verb})]})})}const $=r.createContext(null);function E(){const e=r.useContext($);if(!e)throw new Error("FlaggedPane.* must be used inside <FlaggedPane>");return e}function ze({thread:e,children:a}){const t=te(),d=Pe(),{searchInput:m}=H(),s=e?.threadId,l=e?.messageId,{threads:c}=_(),M=r.useMemo(()=>{if(s)return c.find(i=>i.messageId===l)??c.find(i=>i.threadId===s)},[c,s,l]),I=Ie(s,l),g=M??I,f=l??g?.messageId,R=r.useMemo(()=>{if(s)return{threadId:s,mailboxId:g?.mailboxId??"",subject:g?.subject,messageId:f,authenticity:g?.authenticity}},[s,g,f]),P=r.useCallback((i,b)=>{t({to:"/mail/flagged/$threadId/$messageId",params:i,replace:b?.replace,search:F=>({...F,q:m||void 0}),hash:d})},[t,d,m]),v=r.useCallback(()=>{t({to:"/mail/flagged",search:i=>i,hash:d})},[t,d]),C=r.useCallback(i=>{f&&i.includes(f)&&v()},[f,v]),O=V({thread:g,onAfterOptimisticRemove:C}),T=pe(),{deleteMessages:k}=xe({mailboxId:g?.mailboxId??"",messages:c,onAfterOptimisticRemove:C}),{toggleReadFor:q}=Te({mailboxId:g?.mailboxId??"",messages:c}),L=T.focusedMessageId,x=r.useMemo(()=>c.find(i=>i.messageId===L),[c,L])??g,S=V({thread:x}),y=Oe(),N=ke(),u=Le(),j=r.useMemo(()=>Ne(u,s,f),[u,s,f]),w=r.useMemo(()=>{if(x)return i=>u({threadId:x.threadId,messageId:x.messageId,mode:i})},[u,x]),{nextMessageId:B,previousMessageId:z}=be({context:T,orderedIds:T.orderedIds,selectedMessageId:f,enabled:!y&&!N,onClose:v,handlers:{reply:()=>w?.("reply"),replyAll:()=>w?.("reply-all"),forward:()=>w?.("forward"),delete:()=>{T.listCommandsRef.current?.requestVerb("delete")||S.deleteThread()},toggleStar:S.toggleStar,toggleRead:()=>{T.listCommandsRef.current?.requestVerb("markRead")||x&&q([x.messageId],!x.isRead)},goBrief:()=>t({to:"/mail/brief"}),goSettings:()=>t({to:"/settings"})}}),A=r.useCallback(i=>{if(!i)return;const b=c.find(F=>F.messageId===i);return b?{threadId:b.threadId,messageId:i}:void 0},[c]),D={selectedMessageId:f,selectedThread:g,conversation:R,onOpenThread:P,onCloseThread:v,nextThread:A(B),previousThread:A(z),actions:O,onReply:j,triage:T,onDeleteMessages:k,handleDeselectIfRemoved:C};return n.jsx($.Provider,{value:D,children:a})}function G(){const{selectedMessageId:e,onOpenThread:a,triage:t,onDeleteMessages:d}=E();return n.jsx(Be,{selectedMessageId:e,onOpenThread:a,commandsRef:t.listCommandsRef,onTriageContextChange:t.onTriageContextChange,onDeleteMessages:d})}function He(){const{conversation:e,selectedThread:a,actions:t,onReply:d,handleDeselectIfRemoved:m}=E(),s=!!e,l=Re(e?.threadId);return n.jsxs(n.Fragment,{children:[n.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[n.jsx(Ce,{hasThread:s,intelligenceOpen:l.isShowing,canToggleIntelligence:l.canToggle,onToggleIntelligence:l.toggle,onReply:d?()=>d("reply"):void 0,onReplyAll:d?()=>d("reply-all"):void 0,onForward:d?()=>d("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}),n.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?n.jsx(K,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,selectedMessageId:e.messageId,authenticity:e.authenticity,onOpenIntelligence:l.open}):n.jsx(ne,{})})]}),n.jsx(W,{isOpen:l.drawerOpen,onClose:l.closeDrawer,thread:a,mailboxId:a?.mailboxId,accountId:a?.accountId,onAfterOptimisticRemove:m})]})}function Qe(){const{selectedThread:e,handleDeselectIfRemoved:a}=E(),{onToggleIntelligence:t}=H();return n.jsx(ye,{onClose:t,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId,onAfterOptimisticRemove:a})}function Ve(){const{selectedThread:e,conversation:a,onCloseThread:t,onOpenThread:d,nextThread:m,previousThread:s,handleDeselectIfRemoved:l}=E(),c=ve(a?.threadId??null);return a?n.jsxs(n.Fragment,{children:[n.jsx(K,{threadId:a.threadId,mailboxId:a.mailboxId,subject:a.subject,selectedMessageId:a.messageId,authenticity:a.authenticity,onBack:t,onOpenIntelligence:c.toggle,onSwipeNext:m?()=>d(m):void 0,onSwipePrevious:s?()=>d(s):void 0,mobileIntelligenceOpen:c.isOpen}),n.jsx(W,{isOpen:c.isOpen,onClose:c.close,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId,onAfterOptimisticRemove:l})]}):n.jsx("div",{className:"h-full",children:n.jsx(G,{})})}const Xe=Object.assign(ze,{List:G,Reading:He,Intelligence:Qe,Phone:Ve});export{Xe as F};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as n,s as f,Q as m,j as e,X as N}from"./index-
|
|
1
|
+
import{r as n,s as f,Q as m,j as e,X as N}from"./index-BKi_1Qmh.js";import{E as u}from"./ErrorState-Bn1oQw8C.js";import{D as r,C as x,u as k}from"./index-DGOEldLQ.js";import{u as w}from"./useMediaQuery-BS2MwPdz.js";import{k as p,s as h,t as C}from"./useMessageBodyContent-_8vqUkeq.js";import{C as E}from"./confirm-dialog-BZchyNni.js";const b=t=>t?"Draft":"New Message",I=()=>{const t=n.useRef(!1);return n.useCallback(()=>{const s=document.querySelector("[data-subject-field]")?.value??"",o=(document.querySelector('[data-testid="compose-body"]')?.textContent??"").replace(/--\s*/g,"").trim();return t.current=s.trim().length>0||o.length>0,t.current},[])},S=()=>{const t=p(),i=h(),s=C(),a=I(),[l,o]=n.useState(!1),{isError:d,error:c,refetch:g}=f({...m(),staleTime:1/0}),j=n.useCallback(D=>{D||(a()?o(!0):s())},[s,a]),y=n.useCallback(()=>{o(!1),s()},[s]),v=n.useCallback(()=>{o(!1)},[]);return e.jsxs(r.Root,{open:!0,onOpenChange:j,children:[e.jsxs(r.Portal,{children:[e.jsx(r.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),e.jsxs(r.Content,{className:"fixed inset-x-0 bottom-0 z-50 flex flex-col rounded-t-lg bg-canvas pb-[env(safe-area-inset-bottom,0px)]",style:{height:"95dvh"},children:[e.jsx(r.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-muted/30"}),e.jsx(r.Title,{className:"px-4 py-2 text-base font-semibold border-b border-line",children:b(t)}),d?e.jsx("div",{className:"flex-1 flex items-center justify-center p-4",children:e.jsx(u,{title:"Couldn't load compose",error:c,onRetry:()=>{g()}})}):e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsx(x,{mode:"new",outboxMessageId:t,onDraftCreated:i,onClose:s})})]})]}),e.jsx(E,{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})]})},q=()=>{const t=p(),i=h(),s=C(),a=w(),{isError:l,error:o,refetch:d}=f({...m(),staleTime:1/0});if(k({bindings:[{key:"Escape",handler:s,preventDefault:!0}]}),!a)return e.jsx(S,{});const c=e.jsxs("header",{className:"flex items-center justify-between gap-2 px-4 py-3 border-b border-line shrink-0",children:[e.jsx("div",{className:"flex items-center gap-2 min-w-0",children:e.jsx("h2",{className:"text-lg font-semibold truncate",children:b(t)})}),e.jsx("button",{type:"button",onClick:s,className:"p-2 rounded-md hover:bg-surface-raised transition-colors min-h-11 min-w-11 inline-flex items-center justify-center","aria-label":"Close",children:e.jsx(N,{className:"size-5"})})]});return l?e.jsxs("div",{className:"h-full flex flex-col bg-canvas",children:[c,e.jsx("div",{className:"flex-1 flex items-center justify-center p-4",children:e.jsx(u,{title:"Couldn't load compose",error:o,onRetry:()=>{d()}})})]}):e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-canvas",children:[c,e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e.jsx(x,{mode:"new",outboxMessageId:t,onDraftCreated:i,onClose:s})})]})};export{q as F};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import{a4 as ys,ca as xr,r as l,c as ce,j as a,C as ut,d as On,B as V,X as Dt,at as Ne,cb as zn,b as z,a as Ve,S as Ge,aT as vr,cc as yr,ag as Ft,T as Ot,cd as _n,a_ as ks,ce as kr,cf as Un,an as jr,af as Kn,e as wr,cg as Cr,as as Bn,ch as Sr,ci as Nr,cj as Tr,ck as Er,cl as Ir,cm as Mr,cn as Rr,co as Ar,G as $r,s as Z,Q as gt,q as bt,cp as zt,z as Qn,bf as qn,cq as Hn,n as oe,a5 as be,a7 as pe,K as We,bn as Ee,cr as _t,c1 as Lr,cs as Ie,ct as Pr,cu as Dr,cv as Fr,cw as Or,cx as zr,bN as _r,cy as Ur,p as Kr,aU as Br,m as Gn,aF as Qr,aG as qr,bU as Hr,k as Vn,bT as Gr,cz as Vr,cA as Wr,cB as Wn,b6 as js,bs as Yr,bj as Gs,cC as Xr,cD as Jr,b5 as Zr,N as eo,W as to,D as so,bg as Vs,aY as no,cE as ao,cF as ro,a8 as Ws,be as oo,cG as io,cH as lo,l as Ut,cI as co,cJ as uo,cK as Ys,cL as fo,cM as mo,cN as po,i as Yn,cO as ws,cP as ho,bV as go,cQ as bo,cR as Xs,g as xo,bW as vo}from"./index-BKi_1Qmh.js";import{B as yo,l as ko,m as jo,S as Xn,c as Cs,f as wo,D as Co,b as Et,a as So,t as it,g as No,n as To,o as Eo,e as Io,u as Mo,i as Ro}from"./search-token-index-CBTVc3D8.js";import{K as Ao}from"./kbd-CaLtMuEp.js";import{P as Jn,f as $o,U as Lo,E as Po,s as Do}from"./attachment-file-BLDkIwOJ.js";import{M as Fo}from"./mail-BhxrrdBx.js";import{A as ft}from"./avatar-DN2GOVwx.js";import{M as Oo,c as zo,d as Zn,e as _o,f as ea,g as ta,a as Uo,b as Ko,S as Js,s as sa,u as na,p as Bo,r as Qo}from"./useSearchTokenContext-SHA9xnEZ.js";import{v as qo,w as Ho,o as Go,x as Vo,y as Wo,p as Yo,N as aa,b as Xo}from"./useMessageBodyContent-_8vqUkeq.js";import{C as Jo,D as Be,u as Zo}from"./index-DGOEldLQ.js";import{E as Oe}from"./ErrorState-Bn1oQw8C.js";import{u as Ss}from"./useMediaQuery-BS2MwPdz.js";import{d as ra,b as Ye,a as ei,e as ti,c as ze,g as si}from"./format-D7umvejg.js";import{P as Zs,C as ni,D as es,M as ve}from"./enums-B_igRgfI.js";import{D as ai}from"./download-DmAkhhMn.js";import{S as ri}from"./shield-check-bHOnFfMN.js";import{u as oa}from"./useDebouncedValue-DVdVjbNi.js";import{a as ia,u as la,b as ca,f as da}from"./move-options-yXxXVQoL.js";import{h as en,u as oi,a as ii,i as li,n as ci,o as di,j as ui,k as fi,S as mi}from"./useFilters-CX8meUa-.js";import{C as It}from"./confirm-dialog-BZchyNni.js";import{C as pi}from"./clock-aSLlxPRI.js";import{r as hi,b as gi}from"./search-scope-Ci5AdKCU.js";import{M as bi}from"./menu-3dLcSCcM.js";function mt(e){if(xi())e.focus({preventScroll:!0});else{let t=vi(e);e.focus(),yi(t)}}let Mt=null;function xi(){if(Mt==null){Mt=!1;try{document.createElement("div").focus({get preventScroll(){return Mt=!0,!0}})}catch{}}return Mt}function vi(e){let t=e.parentNode,s=[],n=document.scrollingElement||document.documentElement;for(;t instanceof HTMLElement&&t!==n;)(t.offsetHeight<t.scrollHeight||t.offsetWidth<t.scrollWidth)&&s.push({element:t,scrollTop:t.scrollTop,scrollLeft:t.scrollLeft}),t=t.parentNode;return n instanceof HTMLElement&&s.push({element:n,scrollTop:n.scrollTop,scrollLeft:n.scrollLeft}),s}function yi(e){for(let{element:t,scrollTop:s,scrollLeft:n}of e)t.scrollTop=s,t.scrollLeft=n}const Se=e=>e?.ownerDocument??document,Te=e=>e&&"window"in e&&e.window===e?e:Se(e).defaultView||window;function ki(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&typeof e.nodeType=="number"}function ji(e){return ki(e)&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e}let wi=!1;function ua(){return wi}function ge(e,t){if(!ua())return t&&e?e.contains(t):!1;if(!e||!t)return!1;let s=t;for(;s!==null;){if(s===e)return!0;s.tagName==="SLOT"&&s.assignedSlot?s=s.assignedSlot.parentNode:ji(s)?s=s.host:s=s.parentNode}return!1}function J(e){if(ua()&&e.target instanceof Element&&e.target.shadowRoot){if("composedPath"in e)return e.composedPath()[0]??null;if("composedPath"in e.nativeEvent)return e.nativeEvent.composedPath()[0]??null}return e.target}const Ci=typeof Element<"u"&&"checkVisibility"in Element.prototype;function Si(e){const t=Te(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}=Te(e);let{display:i,visibility:c}=o(e);r=i!=="none"&&c!=="hidden"&&c!=="collapse"}return r}function Ni(e,t){return!e.hasAttribute("hidden")&&!e.hasAttribute("data-react-aria-prevent-focus")&&(e.nodeName==="DETAILS"&&t&&t.nodeName!=="SUMMARY"?e.hasAttribute("open"):!0)}function fa(e,t){return Ci?e.checkVisibility({visibilityProperty:!0})&&!e.closest("[data-react-aria-prevent-focus]"):e.nodeName!=="#comment"&&Si(e)&&Ni(e,t)&&(!e.parentElement||fa(e.parentElement,e))}const ma=["input:not([disabled]):not([type=hidden])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","a[href]","area[href]","summary","iframe","object","embed","audio[controls]","video[controls]",'[contenteditable]:not([contenteditable^="false"])',"permission"],Ti=ma.join(":not([hidden]),")+",[tabindex]:not([disabled]):not([hidden])";ma.push('[tabindex]:not([tabindex="-1"]):not([disabled])');function Ei(e,t){return e.matches(Ti)&&!Ii(e)&&(t?.skipVisibilityCheck||fa(e))}function Ii(e){let t=e;for(;t!=null;){if(t instanceof Te(t).HTMLElement&&t.inert)return!0;t=t.parentElement}return!1}const Ns=typeof document<"u"?ys.useLayoutEffect:()=>{};function Mi(e){let t=e;return t.nativeEvent=e,t.isDefaultPrevented=()=>t.defaultPrevented,t.isPropagationStopped=()=>t.cancelBubble,t.persist=()=>{},t}function Ri(e,t){Object.defineProperty(e,"target",{value:t}),Object.defineProperty(e,"currentTarget",{value:t})}function Ai(e){for(;e&&!Ei(e,{skipVisibilityCheck:!0});)e=e.parentElement;let t=Te(e),s=t.document.activeElement;if(!s||s===e)return;let n=!1,r=m=>{(J(m)===s||n)&&m.stopImmediatePropagation()},o=m=>{(J(m)===s||n)&&(m.stopImmediatePropagation(),!e&&!n&&(n=!0,mt(s),d()))},i=m=>{(J(m)===e||n)&&m.stopImmediatePropagation()},c=m=>{(J(m)===e||n)&&(m.stopImmediatePropagation(),n||(n=!0,mt(s),d()))};t.addEventListener("blur",r,!0),t.addEventListener("focusout",o,!0),t.addEventListener("focusin",c,!0),t.addEventListener("focus",i,!0);let d=()=>{cancelAnimationFrame(v),t.removeEventListener("blur",r,!0),t.removeEventListener("focusout",o,!0),t.removeEventListener("focusin",c,!0),t.removeEventListener("focus",i,!0),n=!1},v=requestAnimationFrame(d);return d}function Kt(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 Ts(e){return typeof window<"u"&&window.navigator!=null?e.test(window.navigator.userAgentData?.platform||window.navigator.platform):!1}function Me(e){let t=null;return()=>(t==null&&(t=e()),t)}const $t=Me(function(){return Ts(/^Mac/i)}),$i=Me(function(){return Ts(/^iPhone/i)}),pa=Me(function(){return Ts(/^iPad/i)||$t()&&navigator.maxTouchPoints>1}),ha=Me(function(){return $i()||pa()}),Li=Me(function(){return Kt(/AppleWebKit/i)&&!Pi()}),Pi=Me(function(){return Kt(/Chrome/i)}),ga=Me(function(){return Kt(/Android/i)}),Di=Me(function(){return Kt(/Firefox/i)});function Fi(e){return e.pointerType===""&&e.isTrusted?!0:ga()&&e.pointerType?e.type==="click"&&e.buttons===1:e.detail===0&&!e.pointerType}function Oi(e){return!ga()&&e.width===0&&e.height===0||e.width===1&&e.height===1&&e.pressure===0&&e.detail===0&&e.pointerType==="mouse"}function pt(e,t,s=!0){let{metaKey:n,ctrlKey:r,altKey:o,shiftKey:i}=t;Di()&&window.event?.type?.startsWith("key")&&e.target==="_blank"&&($t()?n=!0:r=!0);let c=Li()&&$t()&&!pa()?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});pt.isOpening=s,mt(e),e.dispatchEvent(c),pt.isOpening=!1}pt.isOpening=!1;let Ce=new Map,ds=new Set;function tn(){if(typeof window>"u")return;function e(n){return"propertyName"in n}let t=n=>{let r=J(n);if(!e(n)||!r)return;let o=Ce.get(r);o||(o=new Set,Ce.set(r,o),r.addEventListener("transitioncancel",s,{once:!0})),o.add(n.propertyName)},s=n=>{let r=J(n);if(!e(n)||!r)return;let o=Ce.get(r);if(o&&(o.delete(n.propertyName),o.size===0&&(r.removeEventListener("transitioncancel",s),Ce.delete(r)),Ce.size===0)){for(let i of ds)i();ds.clear()}};document.body.addEventListener("transitionrun",t),document.body.addEventListener("transitionend",s)}typeof document<"u"&&(document.readyState!=="loading"?tn():document.addEventListener("DOMContentLoaded",tn));function zi(){for(const[e]of Ce)"isConnected"in e&&!e.isConnected&&Ce.delete(e)}function _i(e){requestAnimationFrame(()=>{zi(),Ce.size===0?e():ds.add(e)})}function ba(...e){return(...t)=>{for(let s of e)typeof s=="function"&&s(...t)}}let us=new Map;typeof FinalizationRegistry<"u"&&new FinalizationRegistry(e=>{us.delete(e)});function Ui(e,t){if(e===t)return e;let s=us.get(e);if(s)return s.forEach(r=>r.current=t),t;let n=us.get(t);return n?(n.forEach(r=>r.current=e),e):t}function Ki(...e){return e.length===1&&e[0]?e[0]:t=>{let s=!1;const n=e.map(r=>{const o=sn(r,t);return s||=typeof o=="function",o});if(s)return()=>{n.forEach((r,o)=>{typeof r=="function"?r():sn(e[o],null)})}}}function sn(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function xt(...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]=ba(o,i):(r==="className"||r==="UNSAFE_className")&&typeof o=="string"&&typeof i=="string"?t[r]=xr(o,i):r==="id"&&o&&i?t.id=Ui(o,i):r==="ref"&&o&&i?t.ref=Ki(o,i):t[r]=i!==void 0?i:o}}return t}function Bi(e,t){Ns(()=>{if(e&&e.ref&&t)return e.ref.current=t.current,()=>{e.ref&&(e.ref.current=null)}})}const Qi=ys.useInsertionEffect??Ns;function ts(e){const t=l.useRef(null);return Qi(()=>{t.current=e},[e]),l.useCallback((...s)=>{const n=t.current;return n?.(...s)},[])}let qe="default",fs="",At=new WeakMap;function qi(e){if(ha()){if(qe==="default"){const t=Se(e);fs=t.documentElement.style.webkitUserSelect,t.documentElement.style.webkitUserSelect="none"}qe="disabled"}else if(e instanceof HTMLElement||e instanceof SVGElement){let t="userSelect"in e.style?"userSelect":"webkitUserSelect";At.set(e,e.style[t]),e.style[t]="none"}}function nn(e){if(ha()){if(qe!=="disabled")return;qe="restoring",setTimeout(()=>{_i(()=>{if(qe==="restoring"){const t=Se(e);t.documentElement.style.webkitUserSelect==="none"&&(t.documentElement.style.webkitUserSelect=fs||""),fs="",qe="default"}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&e&&At.has(e)){let t=At.get(e),s="userSelect"in e.style?"userSelect":"webkitUserSelect";e.style[s]==="none"&&(e.style[s]=t),e.getAttribute("style")===""&&e.removeAttribute("style"),At.delete(e)}}function an(e){return e?.defaultView?.__webpack_nonce__||globalThis.__webpack_nonce__||void 0}let ss=new WeakMap;function Hi(e){let t=e??(typeof document<"u"?document:void 0);if(!t)return an(t);if(ss.has(t))return ss.get(t);let s=t.querySelector('meta[property="csp-nonce"]'),n=s&&s instanceof Te(s).HTMLMetaElement&&(s.nonce||s.content)||an(t)||void 0;return n!==void 0&&ss.set(t,n),n}const xa=ys.createContext({register:()=>{}});xa.displayName="PressResponderContext";function va(){let e=l.useRef(new Map),t=l.useCallback((r,o,i,c)=>{let d=c?.once?(...v)=>{e.current.delete(i),i(...v)}:i;e.current.set(i,{type:o,eventTarget:r,fn:d,options:c}),r.addEventListener(o,d,c)},[]),s=l.useCallback((r,o,i,c)=>{let d=e.current.get(i)?.fn||i;r.removeEventListener(o,d,c),e.current.delete(i)},[]),n=l.useCallback(()=>{e.current.forEach((r,o)=>{s(r.eventTarget,r.type,o,r.options)})},[s]);return l.useEffect(()=>n,[n]),{addGlobalListener:t,removeGlobalListener:s,removeAllGlobalListeners:n}}function Gi(e){let t=l.useContext(xa);if(t){let{register:s,ref:n,...r}=t;e=xt(r,e),s()}return Bi(t,e.ref),e}class Rt{#e;constructor(t,s,n,r){this.#e=!0;const i=(r?.target??n.currentTarget)?.getBoundingClientRect();let c,d=0,v,m=null;n.clientX!=null&&n.clientY!=null&&(v=n.clientX,m=n.clientY),i&&(v!=null&&m!=null?(c=v-i.left,d=m-i.top):(c=i.width/2,d=i.height/2)),this.type=t,this.pointerType=s,this.target=n.currentTarget,this.shiftKey=n.shiftKey,this.metaKey=n.metaKey,this.ctrlKey=n.ctrlKey,this.altKey=n.altKey,this.x=c,this.y=d,this.key=n.key}continuePropagation(){this.#e=!1}get shouldStopPropagation(){return this.#e}}const rn=Symbol("linkClicked"),on="react-aria-pressable-style",ln="data-react-aria-pressable";function Vi(e){let{onPress:t,onPressChange:s,onPressStart:n,onPressEnd:r,onPressUp:o,onClick:i,isDisabled:c,isPressed:d,preventFocusOnPress:v,shouldCancelOnPointerExit:m,allowTextSelectionOnPress:b,ref:p,...g}=Gi(e),[h,u]=l.useState(!1),f=l.useRef({isPressed:!1,ignoreEmulatedMouseEvents:!1,didFirePressStart:!1,isTriggeringEvent:!1,activePointerId:null,target:null,isOverTarget:!1,pointerType:null,disposables:[]}),{addGlobalListener:x,removeAllGlobalListeners:C}=va(),y=l.useCallback((k,R)=>{let A=f.current;if(c||A.didFirePressStart)return!1;let S=!0;if(A.isTriggeringEvent=!0,n){let E=new Rt("pressstart",R,k);n(E),S=E.shouldStopPropagation}return s&&s(!0),A.isTriggeringEvent=!1,A.didFirePressStart=!0,u(!0),S},[c,n,s]),j=l.useCallback((k,R,A=!0)=>{let S=f.current;if(!S.didFirePressStart)return!1;S.didFirePressStart=!1,S.isTriggeringEvent=!0;let E=!0;if(r){let w=new Rt("pressend",R,k);r(w),E=w.shouldStopPropagation}if(s&&s(!1),u(!1),t&&A&&!c){let w=new Rt("press",R,k);t(w),E&&=w.shouldStopPropagation}return S.isTriggeringEvent=!1,E},[c,r,s,t]),N=ts(j),M=l.useCallback((k,R)=>{let A=f.current;if(c)return!1;if(o){A.isTriggeringEvent=!0;let S=new Rt("pressup",R,k);return o(S),A.isTriggeringEvent=!1,S.shouldStopPropagation}return!0},[c,o]),P=ts(M),I=l.useCallback(k=>{let R=f.current;if(R.isPressed&&R.target){R.didFirePressStart&&R.pointerType!=null&&j(De(R.target,k),R.pointerType,!1),R.isPressed=!1,R.isOverTarget=!1,R.activePointerId=null,R.pointerType=null,C(),b||nn(R.target);for(let A of R.disposables)A();R.disposables=[]}},[b,C,j]),F=ts(I);l.useEffect(()=>{c&&f.current.isPressed&&F({currentTarget:f.current.target,shiftKey:!1,ctrlKey:!1,metaKey:!1,altKey:!1})},[c]);let O=l.useCallback(k=>{m&&I(k)},[m,I]),_=l.useCallback(k=>{c||i?.(k)},[c,i]),D=l.useCallback((k,R)=>{if(!c&&i){let A=new MouseEvent("click",k);Ri(A,R),i(Mi(A))}},[c,i]),K=l.useMemo(()=>{let k=f.current,R={onKeyDown(S){if(ns(S.nativeEvent,S.currentTarget)&&ge(S.currentTarget,J(S))){cn(J(S),S.key)&&S.preventDefault();let E=!0;!k.isPressed&&!S.repeat&&(k.target=S.currentTarget,k.isPressed=!0,k.pointerType="keyboard",E=y(S,"keyboard"));let w=S.currentTarget,L=U=>{ns(U,w)&&!U.repeat&&ge(w,J(U))&&k.target&&P(De(k.target,U),"keyboard")};x(Se(S.currentTarget),"keyup",ba(L,A),!0),E&&S.stopPropagation(),S.metaKey&&$t()&&k.metaKeyEvents?.set(S.key,S.nativeEvent)}else S.key==="Meta"&&(k.metaKeyEvents=new Map)},onClick(S){if(!(S&&!ge(S.currentTarget,J(S)))&&S&&S.button===0&&!k.isTriggeringEvent&&!pt.isOpening){let E=!0;if(c&&S.preventDefault(),!k.ignoreEmulatedMouseEvents&&!k.isPressed&&(k.pointerType==="virtual"||Fi(S.nativeEvent))){let w=y(S,"virtual"),L=P(S,"virtual"),U=N(S,"virtual");_(S),E=w&&L&&U}else if(k.isPressed&&k.pointerType!=="keyboard"){let w=k.pointerType||S.nativeEvent.pointerType||"virtual",L=P(De(S.currentTarget,S),w),U=N(De(S.currentTarget,S),w,!0);E=L&&U,k.isOverTarget=!1,_(S),F(S)}k.ignoreEmulatedMouseEvents=!1,E&&S.stopPropagation()}}},A=S=>{if(k.isPressed&&k.target&&ns(S,k.target)){cn(J(S),S.key)&&S.preventDefault();let E=J(S),w=ge(k.target,E);N(De(k.target,S),"keyboard",w),w&&D(S,k.target),C(),S.key!=="Enter"&&Es(k.target)&&ge(k.target,E)&&!S[rn]&&(S[rn]=!0,pt(k.target,S,!1)),k.isPressed=!1,k.metaKeyEvents?.delete(S.key)}else if(S.key==="Meta"&&k.metaKeyEvents?.size){let E=k.metaKeyEvents;k.metaKeyEvents=void 0;for(let w of E.values())k.target?.dispatchEvent(new KeyboardEvent("keyup",w))}};if(typeof PointerEvent<"u"){R.onPointerDown=w=>{if(w.button!==0||!ge(w.currentTarget,J(w)))return;if(Oi(w.nativeEvent)){k.pointerType="virtual";return}k.pointerType=w.pointerType;let L=!0;if(!k.isPressed){k.isPressed=!0,k.isOverTarget=!0,k.activePointerId=w.pointerId,k.target=w.currentTarget,b||qi(k.target),L=y(w,k.pointerType);let U=J(w);"releasePointerCapture"in U&&("hasPointerCapture"in U?U.hasPointerCapture(w.pointerId)&&U.releasePointerCapture(w.pointerId):U.releasePointerCapture(w.pointerId)),x(Se(w.currentTarget),"pointerup",S,!1),x(Se(w.currentTarget),"pointercancel",E,!1)}L&&w.stopPropagation()},R.onMouseDown=w=>{if(ge(w.currentTarget,J(w))&&w.button===0){if(v){let L=Ai(w.target);L&&k.disposables.push(L)}w.stopPropagation()}},R.onPointerUp=w=>{!ge(w.currentTarget,J(w))||k.pointerType==="virtual"||w.button===0&&!k.isPressed&&P(w,k.pointerType||w.pointerType)},R.onPointerEnter=w=>{w.pointerId===k.activePointerId&&k.target&&!k.isOverTarget&&k.pointerType!=null&&(k.isOverTarget=!0,y(De(k.target,w),k.pointerType))},R.onPointerLeave=w=>{w.pointerId===k.activePointerId&&k.target&&k.isOverTarget&&k.pointerType!=null&&(k.isOverTarget=!1,N(De(k.target,w),k.pointerType,!1),O(w))};let S=w=>{if(w.pointerId===k.activePointerId&&k.isPressed&&w.button===0&&k.target){if(ge(k.target,J(w))&&k.pointerType!=null){let L=!1,U=setTimeout(()=>{k.isPressed&&k.target instanceof HTMLElement&&(L?F(w):(mt(k.target),k.target.click()))},80);x(w.currentTarget,"click",()=>L=!0,!0),k.disposables.push(()=>clearTimeout(U))}else F(w);k.isOverTarget=!1}},E=w=>{F(w)};R.onDragStart=w=>{ge(w.currentTarget,J(w))&&F(w)}}return R},[x,c,v,C,b,O,y,_,D]);return l.useEffect(()=>{if(!p)return;const k=Se(p.current);if(!k||!k.head||k.getElementById(on))return;const R=k.createElement("style");R.id=on;let A=Hi(k);A&&(R.nonce=A),R.textContent=`
|
|
2
|
+
@layer {
|
|
3
|
+
[${ln}] {
|
|
4
|
+
touch-action: pan-x pan-y pinch-zoom;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
`.trim(),k.head.prepend(R)},[p]),l.useEffect(()=>{let k=f.current;return()=>{b||nn(k.target??void 0);for(let R of k.disposables)R();k.disposables=[]}},[b]),{isPressed:d||h,pressProps:xt(g,K,{[ln]:!0})}}function Es(e){return e.tagName==="A"&&e.hasAttribute("href")}function ns(e,t){const{key:s,code:n}=e,r=t,o=r.getAttribute("role");return(s==="Enter"||s===" "||s==="Spacebar"||n==="Space")&&!(r instanceof Te(r).HTMLInputElement&&!ya(r,s)||r instanceof Te(r).HTMLTextAreaElement||r.isContentEditable)&&!((o==="link"||!o&&Es(r))&&s!=="Enter")}function De(e,t){let s=t.clientX,n=t.clientY;return{currentTarget:e,shiftKey:t.shiftKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,altKey:t.altKey,clientX:s,clientY:n,key:t.key}}function Wi(e){return e instanceof HTMLInputElement?!1:e instanceof HTMLButtonElement?e.type!=="submit"&&e.type!=="reset":!Es(e)}function cn(e,t){return e instanceof HTMLInputElement?!ya(e,t):Wi(e)}const Yi=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);function ya(e,t){return e.type==="checkbox"||e.type==="radio"?t===" ":Yi.has(e.type)}let Xi=0;const as=new Map;function Ji(e){let[t,s]=l.useState();return Ns(()=>{if(!e)return;let n=as.get(e);if(n)s(n.element.id);else{let r=`react-aria-description-${Xi++}`;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},as.set(e,n)}return n.refCount++,()=>{n&&--n.refCount===0&&(n.element.remove(),as.delete(e))}},[e]),{"aria-describedby":e?t:void 0}}const Zi=500;function el(e){let{isDisabled:t,onLongPressStart:s,onLongPressEnd:n,onLongPress:r,threshold:o=Zi,accessibilityDescription:i}=e;const c=l.useRef(void 0);let{addGlobalListener:d,removeGlobalListener:v}=va(),{pressProps:m}=Vi({isDisabled:t,onPressStart(p){if(p.continuePropagation(),(p.pointerType==="mouse"||p.pointerType==="touch")&&(s&&s({...p,type:"longpressstart"}),c.current=setTimeout(()=>{p.target.dispatchEvent(new PointerEvent("pointercancel",{bubbles:!0})),Se(p.target).activeElement!==p.target&&mt(p.target),r&&r({...p,type:"longpress"}),c.current=void 0},o),p.pointerType==="touch")){let g=u=>{u.preventDefault()},h=Te(p.target);d(p.target,"contextmenu",g,{once:!0}),d(h,"pointerup",()=>{setTimeout(()=>{v(p.target,"contextmenu",g)},30)},{once:!0})}},onPressEnd(p){c.current&&clearTimeout(c.current),n&&(p.pointerType==="mouse"||p.pointerType==="touch")&&n({...p,type:"longpressend"})}}),b=Ji(r&&!t?i:void 0);return{longPressProps:xt(m,b)}}const Bt=ce("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 ka=ce("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]);const ja=ce("Forward",[["polyline",{points:"15 17 20 12 15 7",key:"1w3sku"}],["path",{d:"M4 18v-2a4 4 0 0 1 4-4h12",key:"jmiej9"}]]);const tl=ce("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 Is=ce("MailOpen",[["path",{d:"M21.2 8.4c.5.38.8.97.8 1.6v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V10a2 2 0 0 1 .8-1.6l8-6a2 2 0 0 1 2.4 0l8 6Z",key:"1jhwl8"}],["path",{d:"m22 10-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 10",key:"1qfld7"}]]);const sl=ce("MailX",[["path",{d:"M22 13V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v12c0 1.1.9 2 2 2h9",key:"1j9vog"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}],["path",{d:"m17 17 4 4",key:"1b3523"}],["path",{d:"m21 17-4 4",key:"uinynz"}]]);const nl=ce("Minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);const Qt=ce("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 wa=ce("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 Ca=ce("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 Xe=ce("ShieldAlert",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M12 16h.01",key:"1drbdi"}]]);const al=ce("ShieldQuestion",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M9.1 9a3 3 0 0 1 5.82 1c0 2-3 3-3 3",key:"mhlwft"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);const rl=ce("ShieldX",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m14.5 9.5-5 5",key:"17q4r4"}],["path",{d:"m9.5 9.5 5 5",key:"18nt4w"}]]),ol=({address:e,showTrustedBadge:t=!1})=>{const s=t?a.jsx(Bt,{className:"inline-block size-4 ml-1 -mt-0.5 text-positive","aria-label":"Trusted sender","data-testid":"trusted-sender-badge"}):null;return e.displayName?a.jsxs("span",{children:[a.jsx("span",{className:"text-fg",children:e.displayName}),a.jsxs("span",{className:"text-fg-muted",children:[" ","<",e.normalizedEmail,">"]}),s]}):a.jsxs("span",{className:"text-fg",children:[e.normalizedEmail,s]})},il=({label:e,addresses:t,showTrustedBadge:s=!1})=>{const[n,r]=l.useState(!1);if(t.length===0)return null;const o=t.length>3,i=c=>{const d=s&&c.flags?.trusted?.value===!0;return a.jsx(ol,{address:c,showTrustedBadge:d})};return a.jsxs("div",{className:"flex gap-2 text-sm",children:[a.jsxs("span",{className:"text-fg-muted shrink-0 w-12",children:[e,":"]}),a.jsx("div",{className:"flex-1 min-w-0",children:n?a.jsx("div",{className:"flex flex-wrap gap-1",children:t.map((c,d)=>a.jsxs("span",{children:[i(c),d<t.length-1&&", "]},d))}):a.jsx("div",{className:"truncate",children:t.map((c,d)=>a.jsxs("span",{children:[i(c),d<t.length-1&&", "]},d))})}),o&&a.jsx("button",{type:"button",onClick:c=>{c.stopPropagation(),r(!n)},className:"shrink-0 text-fg-muted hover:text-fg transition-colors","aria-label":n?"Collapse":"Expand",children:n?a.jsx(ut,{className:"h-4 w-4"}):a.jsx(On,{className:"h-4 w-4"})})]})},ll={unknown:{label:"Unknown sender",tone:"neutral"},wellknown:{label:"Known sender",tone:"positive"},vip:{label:"VIP",tone:"accent"}};function Qe({label:e,children:t,className:s}){return a.jsxs("section",{className:z("border-b border-line px-row-inset py-3",s),children:[a.jsx("h3",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e}),a.jsx("div",{className:"mt-2",children:t})]})}function cl({sender:e}){const t=ll[e.trust],s=e.inboundCount==null?null:(e.replyCount??0)>0?`${e.inboundCount} received · you replied ${e.replyCount}×`:`${e.inboundCount} received · you've never replied`;return a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx(ft,{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(Ne,{tone:"danger",dot:!0,children:"Address couldn't be verified"}):a.jsx(Ne,{tone:t.tone,dot:!0,children:t.label})}),a.jsxs("p",{className:"mt-2 text-xs text-fg-muted",children:["First seen ",e.firstSeenLabel,s?` · ${s}`:""]})]})}function dl({auth:e,onShowSimilar:t}){if(e.verdict==="aligned")return a.jsxs("div",{className:"flex items-start gap-2 text-xs text-fg-muted",children:[a.jsx(ri,{className:"mt-0.5 size-3.5 shrink-0 text-positive"}),a.jsx("span",{children:e.summary})]});if(e.verdict==="caution")return a.jsxs("div",{className:"flex items-start gap-2 rounded-md bg-warning/10 p-3 text-warning",children:[a.jsx(al,{className:"mt-0.5 size-4 shrink-0"}),a.jsx("p",{className:"text-xs leading-relaxed",children:e.summary})]});const s=e.addressUnreadable?"This sender can't be verified":"This message may be impersonating someone";return a.jsxs("div",{className:"rounded-md bg-danger-soft p-3",children:[a.jsxs("div",{className:"flex items-start gap-2",children:[a.jsx(Xe,{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(V,{variant:"secondary",size:"sm",className:"mt-2 w-full border-danger/30 text-danger hover:bg-danger-soft",onClick:t,children:[e.similarCount," similar messages"]})]})}function lt({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:z("flex items-center gap-2 rounded-md border px-2 py-1 text-xs transition-colors",s?"border-accent-2 bg-accent-2-soft text-accent-2":"border-line text-fg-muted hover:border-line-strong hover:text-fg",n&&!s&&"text-danger hover:bg-danger-soft",i&&"cursor-not-allowed opacity-50 hover:border-line"),children:[e,t]})}const ul={sender:"matched: sender",recipient:"matched: recipient",subject:"matched: subject",attachment:"matched: attachment",body:"matched: body",entities:"matched: entities"};function Sa({data:e,onClose:t,onShowSimilar:s,actions:n,similarState:r="ready",similarLinkComponent:o,className:i,hideCloseButton:c=!1,reportSpamPending:d=!1,notSpamPending:v=!1}){const{sender:m,authenticity:b,category:p,flags:g={},similar:h}=e;return a.jsxs("aside",{className:z("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(V,{variant:"ghost",size:"sm",icon:a.jsx(Dt,{className:"size-3.5"}),onClick:t,"aria-label":"Collapse intelligence sidebar"})]}),a.jsx(Qe,{label:"Sender",children:a.jsx(cl,{sender:m})}),a.jsx(Qe,{label:"Authenticity",children:a.jsx(dl,{auth:b,onShowSimilar:s})}),a.jsx(Qe,{label:"Category",children:a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Ne,{tone:zn[p.value],children:p.value}),p.overridden&&a.jsx("span",{className:"text-2xs text-fg-subtle",children:"your override"}),a.jsx("button",{type:"button",className:z("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(Qe,{label:"Quick actions",children:[a.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[a.jsx(lt,{icon:a.jsx(Ve,{className:"size-3.5"}),label:"VIP",active:g.vip,onClick:n?.onToggleVip}),a.jsx(lt,{icon:a.jsx(yo,{className:"size-3.5"}),label:"Mute",active:g.muted,onClick:n?.onToggleMute}),n?.onNotSpam&&a.jsx(lt,{icon:a.jsx(tl,{className:"size-3.5"}),label:v?"Undoing…":"Not spam",active:!0,onClick:n.onNotSpam,pending:v}),n?.onReportSpam&&a.jsx(lt,{icon:a.jsx(rl,{className:"size-3.5"}),label:d?"Reporting…":"Report spam",danger:!0,onClick:n.onReportSpam,pending:d}),a.jsx(lt,{icon:a.jsx(sl,{className:"size-3.5"}),label:"Unsubscribe",active:g.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"||h.length>0)&&a.jsx(Qe,{label:"Similar messages",children:r==="loading"?a.jsx("div",{className:"animate-pulse space-y-2",children:Array.from({length:3}).map((u,f)=>a.jsxs("div",{className:"space-y-1",children:[a.jsx("div",{className:"h-3 w-3/4 rounded bg-surface-sunken"}),a.jsx("div",{className:"h-2.5 w-1/2 rounded bg-surface-sunken"})]},f))}):r==="error"?a.jsx("p",{className:"text-xs text-fg-subtle",children:"Similarity search unavailable"}):a.jsx("ul",{className:"-mx-1 space-y-1",children:h.map(u=>{const f="block w-full rounded-md px-1 py-1 text-left hover:bg-surface-sunken",x=`Open message from ${u.fromName||"unknown sender"}: ${u.subject}`,C=a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[a.jsx("span",{className:"truncate text-xs font-medium text-fg",children:u.fromName}),a.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:u.timeLabel})]}),a.jsx("div",{className:"truncate text-xs text-fg-muted",children:u.subject}),a.jsx("span",{className:"mt-1 inline-block rounded-full bg-surface-sunken px-1.5 py-px text-2xs text-fg-subtle",children:ul[u.matched]})]});return a.jsx("li",{children:o?o({mailboxId:u.mailboxId,threadId:u.threadId,messageId:u.id,className:f,ariaLabel:x,children:C}):a.jsx("div",{className:f,children:C})},u.id)})})}),a.jsx(Qe,{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(Ge,{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(Ge,{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 ms=e=>({shiftKey:e.shiftKey,metaKey:e.metaKey,ctrlKey:e.ctrlKey}),dn=e=>e.shiftKey||e.metaKey||e.ctrlKey,fl=e=>e.shiftKey?"range":e.metaKey||e.ctrlKey?"toggle":"open",ml=(e,t)=>!t&&e>0,pl=(e,t,s)=>{const n=e.indexOf(s);if(n===-1)return[];const r=t===void 0?-1:e.indexOf(t);if(r===-1)return[s];const o=Math.min(r,n),i=Math.max(r,n);return e.slice(o,i+1)},hl=(e,t,s,n)=>t!==void 0&&e.includes(t)?t:s!==void 0&&e.includes(s)?s:n,gl=(e,t)=>{const s=new Set(t),n=new Set;for(const r of e)s.has(r)&&n.add(r);return n},bl=(e,t,s)=>{if(e.length===0)return;const n=t===void 0?-1:e.indexOf(t);if(n===-1)return s>0?e[0]:e[e.length-1];const r=Math.min(Math.max(n+s,0),e.length-1);return e[r]},xl=e=>{const[t,s]=l.useState(()=>new Set(e?.initialSelectedIds)),[n,r]=l.useState(void 0),o=l.useCallback(u=>t.has(u),[t]),i=l.useCallback(u=>{r(u),s(f=>{const x=new Set(f);return x.has(u)?x.delete(u):x.add(u),x})},[]),c=l.useCallback(u=>{r(u),s(f=>{if(f.has(u))return f;const x=new Set(f);return x.add(u),x})},[]),d=l.useCallback(u=>{s(f=>{if(!f.has(u))return f;const x=new Set(f);return x.delete(u),x})},[]),v=l.useCallback(u=>{s(new Set(u))},[]),m=l.useCallback(()=>{r(void 0),s(new Set)},[]),b=l.useCallback(u=>{s(f=>u.every(C=>f.has(C))?new Set:new Set(u))},[]),p=l.useCallback(u=>{r(u)},[]),g=l.useCallback(u=>{s(f=>{if(f.size===0)return f;const x=gl(f,u);return x.size===f.size?f:x})},[]),h=l.useCallback((u,f,x)=>{const C=hl(u,n,x,f);s(y=>{const j=pl(u,C,f);if(j.length===0)return y;const N=new Set(y);for(const M of j)N.add(M);return N}),r(C)},[n]);return{selectedIds:t,selectedCount:t.size,hasSelection:t.size>0,isSelected:o,toggle:i,select:c,deselect:d,selectAll:v,clearSelection:m,toggleAll:b,selectRange:h,setAnchor:p,anchorId:n,intersectWith:g}};function _f({hints:e=ko,className:t}){return e.length===0?null:a.jsx("footer",{className:z("flex items-center gap-2 border-t border-line px-row-inset py-1 text-2xs text-fg-subtle",t),children:e.map(s=>a.jsx(vl,{hint:s},s.label))})}function vl({hint:e}){return a.jsxs("span",{className:"flex items-center gap-1",children:[e.keys.map(t=>a.jsx(Ao,{children:t},t)),a.jsx("span",{children:e.label})]})}const Na="outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",Ta=({active:e,focused:t})=>z("relative flex h-8 w-full items-center gap-2 px-row-inset text-left",Na,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})=>z("relative flex w-full items-start gap-3 py-2 pl-5 pr-row-inset text-left transition-colors",Na,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 Ea({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(Xe,{className:"size-3.5 text-danger"}):e.starred?a.jsx(Ve,{className:"size-3 fill-warning text-warning"}):t?a.jsx("span",{className:"size-1.5 rounded-full bg-accent"}):null}),a.jsx("span",{className:z("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:z(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(Qt,{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),d=0;for(;c!==-1;)c>i&&o.push(e.slice(i,c)),o.push(a.jsx("mark",{className:"bg-transparent font-semibold text-fg",children:e.slice(c,c+r.length)},d++)),i=c+r.length,c=n.indexOf(r,i);return i<e.length&&o.push(e.slice(i)),o}function yl({thread:e,badge:t,highlightQuery:s}){const n=!e.isRead;return a.jsxs("span",{className:"min-w-0 flex-1",children:[a.jsxs("span",{className:"flex items-baseline justify-between gap-2",children:[a.jsxs("span",{className:z("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:z("truncate text-sm",n?"text-fg":"text-fg-muted"),children:un(e.subject,s)}),e.suspicious&&a.jsx(Xe,{className:"size-3.5 shrink-0 text-danger"}),e.starred&&a.jsx(Ve,{className:"size-3 shrink-0 fill-warning text-warning"}),e.hasAttachment&&a.jsx(Qt,{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(Ne,{tone:zn[e.category],className:"shrink-0",children:e.category}),e.labels?.map(r=>a.jsx(vr,{label:r,className:"max-w-20"},r.labelId)),t]})]})}function kl({thread:e,selection:t}){if(!t)return a.jsx(ft,{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(ft,{name:e.fromName,email:e.fromEmail,size:"sm",className:z("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:z("absolute inset-0 size-7 items-center justify-center rounded-full border transition-opacity",n?"flex":"hidden sm:flex",s?"bg-accent border-accent text-accent-fg opacity-100":n?"border-fg-subtle/40 bg-canvas opacity-100":"border-fg-subtle/40 bg-canvas opacity-0 group-hover:opacity-100"),"aria-label":s?"Deselect message":"Select message",children:s&&a.jsx(Ft,{className:"size-3"})})]})}function Rs({thread:e,selection:t,badge:s,highlightQuery:n}){const r=!e.isRead;return a.jsxs(a.Fragment,{children:[r&&a.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),a.jsx(kl,{thread:e,selection:t}),a.jsx(yl,{thread:e,badge:s,highlightQuery:n})]})}const Ia=e=>({...yr,[jo]:"","data-message-id":e.id});function Uf({thread:e,active:t,focused:s,tabIndex:n,onClick:r}){return a.jsx("button",{type:"button",...Ia(e),tabIndex:n,onClick:r,className:Ta({active:t,focused:s}),children:a.jsx(Ea,{thread:e})})}function Kf({thread:e,active:t,focused:s,tabIndex:n,selection:r,onClick:o}){return a.jsx("button",{type:"button",...Ia(e),tabIndex:n,onClick:o,className:z("group",Ms({active:t,focused:s})),children:a.jsx(Rs,{thread:e,selection:r})})}let He;const jl=5e3;function Ma(e){e.preventDefault(),Lt()}function Lt(){He!==void 0&&(clearTimeout(He),He=void 0,document.removeEventListener("contextmenu",Ma,!0),document.removeEventListener("pointerup",Lt,!0))}function wl(){He===void 0?(document.addEventListener("contextmenu",Ma,!0),document.addEventListener("pointerup",Lt,!0)):clearTimeout(He),He=setTimeout(Lt,jl)}function Cl({onLongPress:e,isDisabled:t,delayMs:s=500,accessibilityDescription:n}){const{longPressProps:r}=el({isDisabled:t,threshold:s,accessibilityDescription:n,onLongPress:e}),o=l.useCallback(i=>{i.pointerType!=="touch"&&i.pointerType!=="pen"||wl()},[]);return{longPressProps:xt(r,{onPointerDown:o})}}const ct="min-h-11 min-w-11 px-0";function Ra({hasThread:e,onReply:t,onReplyAll:s,onForward:n,isStarred:r,onToggleStar:o,onDelete:i,isRead:c,onToggleRead:d,moveSlot:v,overflowItems:m=[],onUnavailable:b,unavailableHint:p,className:g}){const h=(f,x)=>()=>{if(!e){b?.(f);return}x?.()},u=d?[{key:"toggle-read",label:c?"Mark as unread":"Mark as read",icon:c?a.jsx(Fo,{className:"size-4"}):a.jsx(Is,{className:"size-4"}),onSelect:h("toggleRead",d)}]:[];return a.jsxs("div",{className:z("relative",g),children:[a.jsxs("div",{className:"flex h-12 shrink-0 items-center gap-0.5 bg-canvas px-1",children:[t&&a.jsx(V,{variant:"ghost",size:"sm",icon:a.jsx(Ca,{className:"size-5"}),onClick:h("reply",t),"aria-label":"Reply",title:"Reply",className:ct}),s&&a.jsx(V,{variant:"ghost",size:"sm",icon:a.jsx(wa,{className:"size-5"}),onClick:h("replyAll",s),"aria-label":"Reply all",title:"Reply all",className:ct}),n&&a.jsx(V,{variant:"ghost",size:"sm",icon:a.jsx(ja,{className:"size-5"}),onClick:h("forward",n),"aria-label":"Forward",title:"Forward",className:ct}),a.jsx("div",{className:"flex-1"}),o&&a.jsx(V,{variant:"ghost",size:"sm",icon:a.jsx(Ve,{className:z("size-5",r&&"fill-warning text-warning")}),onClick:h("star",o),"aria-label":r?"Unstar":"Star","aria-pressed":r,title:r?"Unstar":"Star",className:ct}),v,i&&a.jsx(V,{variant:"ghost",size:"sm",icon:a.jsx(Ot,{className:"size-5"}),onClick:h("delete",i),"aria-label":"Move to Trash",title:"Move to Trash",className:ct}),a.jsx(Jn,{triggerLabel:"More actions",items:[...u,...m]})]}),!e&&p&&a.jsx("p",{role:"status",className:"bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:p})]})}function Sl({open:e=!1,enabled:t=!0,onToggle:s,className:n}){return a.jsx(V,{variant:"ghost",size:"sm",icon:a.jsx(_n,{className:"size-4"}),title:"Intelligence","aria-label":e?"Hide intelligence sidebar":"Show intelligence sidebar","aria-pressed":e,disabled:!t,onClick:s,className:z(e&&"bg-accent-2-soft text-accent-2",n)})}function Nl({hasThread:e,onUnavailable:t,unavailableHint:s,isStarred:n,showTriage:r=!0,onReply:o,onReplyAll:i,onForward:c,onDelete:d,onToggleStar:v,moveSlot:m,onMove:b,replyTitle:p="Reply (r)",replyAllTitle:g="Reply all (a)",forwardTitle:h="Forward (f)",deleteTitle:u="Move to Trash (#)",flagTitle:f="Star (s)",children:x,className:C}){const y=(j,N)=>()=>{if(!e||!N){t?.(j);return}N()};return a.jsxs("div",{className:"relative",children:[a.jsxs("header",{className:z("flex h-pane-header shrink-0 items-center gap-1 border-b border-line bg-surface px-3",C),children:[a.jsx(V,{variant:"ghost",size:"sm",icon:a.jsx(Ca,{className:"size-4"}),title:p,"aria-label":"Reply",onClick:y("reply",o)}),a.jsx(V,{variant:"ghost",size:"sm",icon:a.jsx(wa,{className:"size-4"}),title:g,"aria-label":"Reply all",onClick:y("replyAll",i)}),a.jsx(V,{variant:"ghost",size:"sm",icon:a.jsx(ja,{className:"size-4"}),title:h,"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(V,{variant:"ghost",size:"sm",icon:a.jsx(Ot,{className:"size-4"}),title:u,"aria-label":"Move to Trash",onClick:y("delete",d)}),m??a.jsx(V,{variant:"ghost",size:"sm",icon:a.jsx(ks,{className:"size-4"}),title:"Move to mailbox","aria-label":"Move to mailbox",onClick:y("move",b)}),a.jsx(V,{variant:"ghost",size:"sm",icon:a.jsx(Ve,{className:z("size-4",n&&"fill-warning text-warning")}),title:f,"aria-label":"Star",onClick:y("flag",v)})]}),a.jsx("div",{className:"flex-1"}),x]}),s&&a.jsx("p",{role:"status",className:"border-b border-line bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:s})]})}function Aa({message:e,onClick:t,isFocused:s,isUnread:n,trailing:r}){const o=a.jsxs(a.Fragment,{children:[a.jsx(On,{className:"size-3.5 shrink-0 text-fg-subtle"}),a.jsxs("div",{className:"relative shrink-0",children:[a.jsx(ft,{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:z("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=z("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=>{kr(c)&&(c.preventDefault(),t())},className:z(i,"cursor-pointer"),children:o}):a.jsx("div",{className:i,children:o})}function $a({message:e,warning:t,onHeaderClick:s,isFocused:n,senderBadge:r,trailing:o,to:i,indicators:c,actionMenu:d,actionBar:v,body:m}){const b=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:z("-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(ut,{className:"size-3.5"})}):a.jsx(ut,{className:"mt-1 size-3.5 shrink-0 text-fg-subtle"}),a.jsx(ft,{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:b}):b,c]}),d&&a.jsx("div",{className:"shrink-0",children:d})]}),t&&a.jsxs("div",{className:"mt-3 flex items-start gap-3 rounded-md bg-danger-soft p-3",children:[a.jsx(Xe,{className:"mt-0.5 size-4 shrink-0 text-danger"}),a.jsxs("div",{className:"text-sm text-fg",children:[a.jsx("span",{className:"font-semibold text-danger",children:"Caution: "}),t," ",a.jsx("button",{type:"button",className:"text-accent underline",children:"Why?"})]})]}),v&&a.jsx("div",{className:"mt-3 -mx-2 lg:-mx-4",children:v}),a.jsx(Oo,{children:m??a.jsx(zo,{className:"mt-3",html:e.bodyHtml,category:e.framed?"newsletter":"personal",allowImages:!0})})]})}function Tl({thread:e,onBack:t,intelligence:s,intelligenceOpen:n,onToggleIntelligence:r,actions:o,children:i,touchHandlers:c}){const[d,v]=l.useState(!1),m=r!==void 0,b=m?n??!1:d,p=!!s||m,g=()=>{if(m){r?.();return}v(u=>!u)},h=()=>{if(m){b&&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(V,{variant:"ghost",size:"sm",icon:a.jsx(Un,{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}),p&&a.jsx(V,{variant:"ghost",size:"sm",icon:a.jsx(_n,{className:"size-4"}),onClick:g,"aria-label":b?"Hide intelligence panel":"Show intelligence panel","aria-pressed":b,title:"Intelligence",className:z("shrink-0",b&&"bg-accent-2-soft text-accent-2")})]}),a.jsx("div",{className:"flex-1 overflow-y-auto",style:c?{touchAction:"pan-y"}:void 0,...c,children:i??[...e.messages].reverse().map(u=>{const f=x=>x?()=>x(u.id):void 0;return u.expanded?a.jsx($a,{message:u,warning:e.warning,onHeaderClick:f(o?.onToggleExpand),actionBar:a.jsx(Ra,{hasThread:!0,onReply:f(o?.onReply),onReplyAll:f(o?.onReplyAll),onForward:f(o?.onForward),onToggleStar:f(o?.onToggleStar),onDelete:f(o?.onDelete),onToggleRead:f(o?.onToggleRead),moveSlot:o?.moveSlot?.(u.id)})},u.id):a.jsx(Aa,{message:u,onClick:f(o?.onToggleExpand)},u.id)})}),s&&!m&&a.jsx(jr,{open:b,onClose:h,title:"Intelligence",anchor:"right",className:"p-0",children:a.jsx(Sa,{data:s,onClose:h,className:"h-full w-full border-l-0"})})]})}function El({state:e,onRetry:t}){return a.jsxs("div",{role:"alert","data-testid":"attachment-error",className:"flex items-start gap-2 border-t border-danger/30 bg-danger-soft px-2 py-2 text-xs",children:[a.jsx(wr,{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 Il({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:z("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(Qt,{className:"size-3","aria-hidden":!0}),e.length===0?"Attachment":e.length===1?"1 attachment":`${e.length} attachments`]}),e.length>0&&a.jsx("ul",{className:"overflow-hidden rounded-sm border border-line bg-surface",children:e.map(r=>{const o=r.download.status==="downloading";return a.jsxs("li",{className:"border-t border-line first:border-t-0",children:[a.jsxs("button",{type:"button",onClick:()=>t(r.attachmentId),disabled:o,"data-testid":"attachment-download","aria-label":`Download ${r.filename}`,className:"flex w-full items-center gap-2 px-2 py-2 text-left transition-colors hover:bg-surface-sunken disabled:cursor-progress disabled:opacity-60",children:[a.jsxs("span",{className:"min-w-0 flex-1",children:[a.jsx("bdi",{className:"block truncate text-sm text-fg",title:r.filename,children:r.filename}),a.jsxs("span",{className:"block truncate text-2xs text-fg-subtle",children:[r.typeLabel," ·"," ",$o(r.sizeOctets)]})]}),o?a.jsx(Kn,{className:"size-4 shrink-0 animate-spin text-fg-subtle","aria-hidden":!0}):a.jsx(ai,{className:"size-4 shrink-0 text-fg-subtle","aria-hidden":!0})]}),r.download.status==="failed"&&a.jsx(El,{state:r.download,onRetry:()=>t(r.attachmentId)})]},r.attachmentId)})}),s&&a.jsx("p",{role:"alert","data-testid":"attachment-unlisted",className:"rounded-sm border border-line bg-surface px-2 py-2 text-xs text-fg-muted",children:"The mail server says this message carries an attachment, but none of its parts describe one. Re-sync the account from Settings; if the attachment still does not appear, the message is worth reporting."})]})}function Ml({label:e,onUndo:t,undoLabel:s="Undo",filtersHref:n,className:r}){return a.jsxs(Ne,{tone:"accent",className:z("py-1 text-xs",r),children:[a.jsx(Lo,{className:"size-3.5 shrink-0","aria-hidden":!0}),a.jsx("span",{children:e}),t&&a.jsx("button",{type:"button",onClick:o=>{o.stopPropagation(),t()},className:"font-semibold underline decoration-dotted underline-offset-2 hover:decoration-solid",children:s}),n&&a.jsx("a",{href:n,onClick:o=>{o.stopPropagation()},className:"font-semibold underline decoration-dotted underline-offset-2 hover:decoration-solid",children:"Manage filter"})]})}const Rl="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",fn="pointer-events-none absolute inset-0 m-auto size-3.5 text-accent-fg";function Al({label:e,description:t,indeterminate:s=!1,checked:n,onChange:r,className:o,...i}){const c=l.useRef(null);l.useEffect(()=>{c.current&&(c.current.indeterminate=s)},[s]);const d=a.jsxs("span",{className:"relative inline-flex",children:[a.jsx("input",{ref:c,type:"checkbox",checked:n,onChange:r,className:Rl,...i}),a.jsx(Ft,{className:z(fn,"hidden peer-checked:block"),"aria-hidden":!0}),a.jsx(nl,{className:z(fn,"hidden peer-indeterminate:block"),"aria-hidden":!0})]});return e===void 0&&t===void 0?a.jsx("span",{className:o,children:d}):a.jsxs("label",{className:z("flex min-h-11 cursor-pointer items-center gap-3 text-left",o),children:[d,a.jsxs("span",{className:"flex min-w-0 flex-col",children:[e!==void 0&&a.jsx("span",{className:"text-sm text-fg",children:e}),t!==void 0&&a.jsx("span",{className:"text-xs text-fg-subtle",children:t})]})]})}function $l(e){return{id:e.id,fromName:e.sender,fromEmail:e.senderEmail??e.sender,subject:e.subject,snippet:e.snippet,timeLabel:e.date,isRead:!e.unread,starred:e.flagged,...e.mailboxId?{mailboxId:e.mailboxId}:{}}}function Ll({result:e,onClick:t,query:s,showFolder:n=!0}){const r=n&&e.folder?Cr(e.folder):void 0;return a.jsx("button",{type:"button",onClick:t,className:z("group",Ms({}),"border-b border-line"),children:a.jsx(Rs,{thread:$l(e),highlightQuery:s,badge:a.jsxs(a.Fragment,{children:[r&&a.jsx(Ne,{tone:"neutral",className:"shrink-0",children:r}),e.category&&a.jsx(Ne,{tone:e.category.tone??"neutral",className:"shrink-0",children:e.category.label}),e.matchedChunkLabel&&a.jsx(Ne,{tone:"neutral",className:"shrink-0",children:`matched: ${e.matchedChunkLabel}`}),e.score!=null&&a.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.score.toFixed(2)})]})})})}const Pl=e=>e===1?"result":"results";function Dl({count:e,onScopeToSpam:t}){return a.jsx(Bn,{tone:"info",variant:"soft",className:"items-center justify-between gap-3 rounded-none border-b border-line",children:a.jsxs("div",{className:"flex items-center justify-between gap-3",children:[a.jsxs("p",{className:"min-w-0 text-xs text-fg-muted",children:[a.jsx("span",{className:"font-semibold text-fg tabular-nums",children:e})," ",`${Pl(e)} from Spam`]}),a.jsx(V,{variant:"ghost",size:"sm",onClick:t,className:"shrink-0 text-accent",children:"Go to Spam"})]})})}const mn=6,Fl={kind:"global"},Ol=e=>e.kind==="folder"&&e.role==="junk",zl=e=>e.folder?.role==="junk";function La(e){const t=[],s=[];for(const n of e)zl(n)?s.push(n):t.push(n);return{kept:t,spam:s}}function Pa({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:z("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(Sr,{className:"size-3.5 shrink-0","aria-hidden":"true"}),a.jsx("span",{children:"Make this a filter"})]}),t&&a.jsx(Nr,{id:s,reason:t,nudged:n,className:"px-2 pt-1 text-2xs text-warning"})]})}function _l({section:e,query:t,onSelectResult:s,showFolder:n}){const[r,o]=l.useState(e.initialCollapsed??!1),[i,c]=l.useState(!1),d=e.results.length>mn,m=!i&&d?e.results.slice(0,mn):e.results,b=e.results.length-m.length;return a.jsxs("div",{children:[a.jsxs("button",{type:"button","aria-expanded":!r,onClick:()=>o(p=>!p),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(ut,{className:z("size-3 shrink-0 text-fg-subtle transition-transform duration-200",r?"rotate-0":"rotate-180")})]}),!r&&a.jsxs(a.Fragment,{children:[m.map(p=>a.jsx(Ll,{result:p,query:t,showFolder:n,onClick:s?()=>s(p):void 0},p.id)),d&&a.jsxs("button",{type:"button",onClick:()=>c(p=>!p),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 ${b} more`,!i&&a.jsx(ut,{className:"ml-1 size-3"})]})]})]})}function Da({value:e,recentSearches:t,onPickRecent:s,sections:n,loading:r,onSelectResult:o,tokens:i,scope:c=Fl,makeFilter:d}){if(!(e.trim().length>0))return t&&t.length>0?a.jsxs("div",{className:"flex flex-col",children:[a.jsx("h3",{className:"px-row-inset pb-1 pt-3 text-2xs font-semibold uppercase tracking-wide text-fg-subtle",children:"Recent searches"}),t.map(j=>a.jsxs("button",{type:"button",onClick:()=>s?.(j),className:"flex w-full items-center gap-2.5 border-b border-line px-row-inset py-2.5 text-left transition-colors hover:bg-surface-sunken",children:[a.jsx(pi,{className:"size-4 shrink-0 text-fg-subtle"}),a.jsx("span",{className:"min-w-0 flex-1 truncate text-sm text-fg-muted",children:j})]},j))]}):a.jsx("p",{className:"px-row-inset py-6 text-center text-sm text-fg-subtle",children:"Search across your mail by sender, subject or words in the message."});const m=i&&i.length>0&&a.jsx(Tr,{tokens:i}),b=d&&a.jsx(Pa,{...d});if(r)return a.jsxs("div",{className:"flex flex-col",children:[b,m,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 p=c.kind==="global",g=Ol(c)||c.kind==="collection",h=p||c.kind==="collection",u=(n??[]).map(j=>{if(g)return{section:j,spam:[]};const{kept:N,spam:M}=La(j.results);return{section:{...j,results:N},spam:M}}),f=u.map(j=>j.section),x=u.reduce((j,N)=>j+N.spam.length,0),C=c.kind==="global"&&x>0&&c.onScopeToSpam!==void 0?a.jsx(Dl,{count:x,onScopeToSpam:c.onScopeToSpam}):void 0;return f.some(j=>j.results.length>0)?a.jsxs("div",{className:"flex flex-col",children:[b,m,C,f.filter(j=>j.results.length>0).map(j=>a.jsx(_l,{section:j,query:e,showFolder:h,onSelectResult:o},j.id))]}):a.jsxs("div",{className:"flex flex-col",children:[b,m,C,a.jsxs("div",{className:"px-row-inset py-10 text-center",children:[a.jsxs("p",{className:"text-sm font-medium text-fg",children:["No matches for “",e,"”"]}),a.jsx("p",{className:"mt-1 text-xs text-fg-subtle",children:"Try a different word, or adjust the filters above."})]})]})}function Ul({value:e,onChange:t,onClear:s,onCancel:n,filter:r,recentSearches:o,onPickRecent:i,sections:c,loading:d,onSelectResult:v,tokens:m,chips:b,onRemoveChip:p,scope:g,makeFilter:h,suggest:u,suggestList:f}){const x=a.jsx(Da,{value:e,recentSearches:o,onPickRecent:i,sections:c,loading:d,onSelectResult:v,tokens:m,scope:g,makeFilter:h});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(Xn,{value:e,onChange:t,onClear:s,chips:b,onRemoveChip:p,globalFocusKey:!1,showClearButton:!1,suggest:u})}),a.jsx(V,{variant:"ghost",size:"sm",icon:a.jsx(Dt,{className:"size-4"}),onClick:n,"aria-label":"Clear and close search",className:"-mr-1 shrink-0"})]}),f,r&&e.trim().length===0?a.jsx(Er,{children:a.jsx(Ir,{...r,children:x})}):a.jsx("div",{className:"flex-1 overflow-y-auto",children:x})]})}const pn=e=>e.toLocaleString();function hn({selectAll:e,selecting:t,className:s}){return a.jsx(Al,{className:s,checked:e.checked,indeterminate:e.indeterminate,onChange:e.onChange,label:a.jsx("span",{className:"font-medium text-accent",children:e.checked&&t?"Deselect all":"Select all"})})}function Kl({title:e,count:t,onCancel:s,onDelete:n,onMove:r,onOrganize:o,onJunk:i,onMarkRead:c,navSlot:d,titleMeta:v,searchSlot:m,searchField:b,idleSlot:p,overflowSlot:g,isBusy:h=!1,isCounting:u=!1,selectAll:f,statusLabel:x,progress:C,notice:y}){const j=t>0||u,N=f?.checked?`All ${pn(t)} loaded selected`:`${pn(t)} ${t===1?"message":"messages"} selected`,M=[];return i&&!h&&!u&&M.push({key:"junk",label:"Junk",icon:a.jsx(Xe,{className:"size-4"}),onSelect:i}),c&&!h&&!u&&M.push({key:"mark-read",label:"Mark read",icon:a.jsx(Is,{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(V,{variant:"ghost",size:"touch",icon:a.jsx(Un,{className:"size-5"}),onClick:s,"aria-label":"Cancel selection",className:"-ml-2 shrink-0"}):d,f&&a.jsx(hn,{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??N}):b?a.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-1",children:b}):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,m]}),j&&!u&&a.jsxs(a.Fragment,{children:[a.jsx(V,{variant:"ghost",size:"touch",icon:h?a.jsx(Kn,{className:"size-5 animate-spin"}):a.jsx(Ot,{className:"size-5 text-danger"}),onClick:h?void 0:n,"aria-label":"Move selected messages to Trash","aria-busy":h||void 0,className:"shrink-0"}),!h&&r&&a.jsx(V,{variant:"ghost",size:"touch",icon:a.jsx(ks,{className:"size-5"}),onClick:r,"aria-label":"Move selected messages",className:"shrink-0"}),!h&&o&&a.jsx(V,{variant:"ghost",size:"touch",icon:a.jsx(Ge,{className:"size-5"}),onClick:o,"aria-label":"Organize selected messages",className:"shrink-0"})]}),j&&a.jsx(Jn,{triggerLabel:"More actions",items:M,className:"shrink-0",children:!h&&!u&&g})]}),!j&&p,j&&f&&a.jsx("div",{"data-selection-bar-row":"select-all",className:"px-row-inset pb-2 md:hidden",children:a.jsx(hn,{selectAll:f,selecting:j,className:"w-full"})}),C&&a.jsx("div",{className:"px-row-inset pb-2",children:a.jsx(Mr,{value:C.value,max:C.max,tone:C.tone})}),y&&a.jsx(Bn,{"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(V,{variant:"ghost",size:"md",onClick:y.action.onClick,className:"-my-1 min-h-11 shrink-0",children:y.action.label})]})})]})}const As=[{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"}],Fa={id:"unread",label:"Unread"},Bl={id:"flagged",label:"Starred"},Oa={id:"attachment",label:"Has attachment"};function Ql(e){if(!(e.length<=1))return e.map(t=>({id:t.id,label:t.label,count:t.count,active:t.active}))}function Bf(e=[]){return{categories:[...As],filters:Rr,sources:Ql(e)}}function Qf(){return{categories:[...As],filters:[Fa,Bl,Oa]}}function qf(){return{categories:[...As],filters:[Fa,Oa]}}function ql(e,t){return e.endsWith(t)?e.length===t.length||e[e.length-t.length-1]===".":!1}function Hl(e,t){const s=e.length-t.length-2,n=e.lastIndexOf(".",s);return n===-1?e:e.slice(n+1)}function Gl(e,t,s){if(s.validHosts!==null){const r=s.validHosts;for(const o of r)if(ql(t,o))return o}let n=0;if(t.startsWith("."))for(;n<t.length&&t[n]===".";)n+=1;return e.length===t.length-n?null:Hl(t,e)}const rs=/[\t\n\r]/g;let ps=!1;function gn(e){return e>=97&&e<=122||e>=48&&e<=57||e>127||e>=65&&e<=90||e===45||e===95}function bn(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 dt(e,t,s=!1){let n=0,r=e.length,o=!1,i=!1;if(ps=!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=bn(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 C=0;for(;(e.charCodeAt(n)===47||e.charCodeAt(n)===92)&&C<2;)n+=1,C+=1;if(C<2)return null}else{for(let C=n;C<f;C+=1){const y=e.charCodeAt(C)|32;if(!(y>=97&&y<=122||y>=48&&y<=57||y===46||y===45||y===43)){const j=e.charCodeAt(C);return j===9||j===10||j===13?dt(e.replace(rs,""),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 C=n;C<r;C+=1){const y=e.charCodeAt(C);if(y===9||y===10||y===13)return dt(e.replace(rs,""),t,s);if(y===58){x=C;break}if(y===47||y===92||y===63||y===35)break}if(x!==-1){let C=!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){C=!0;break}}if(!C){let y=!0,j=x+1;for(;j<r;j+=1){const N=e.charCodeAt(j);if(N===47||N===92||N===63||N===35)break;if(N<48||N>57){y=!1;break}}if(j===x+1&&(y=!1),!y){const N=bn(e,n,x);if(N===0){let M=!1;for(let P=x+1;P<r;P+=1){const I=e.charCodeAt(P);if(I===47||I===92||I===63||I===35)break;if(I===58){M=!0;break}}if(!M)return null}else if(i=!0,n=x+1,N===2){let M=0;for(;(e.charCodeAt(n)===47||e.charCodeAt(n)===92)&&M<2;)n+=1,M+=1;if(M<2)return null}else for(;e.charCodeAt(n)===47||e.charCodeAt(n)===92;)n+=1}}}}}let d=-1,v=-1,m=-1,b=-1,p=!1,g=s,h=n-1,u=-1;if(s&&n<r){const f=e.charCodeAt(n);(!(gn(f)||f===46||f===95)||f===45)&&(g=!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?(b===-1&&(b=f),m=f):x===9||x===10||x===13?p=!0:s&&(x===46?((f-h>64||u===46||u===45)&&(g=!1),h=f):(x<48||x>57)&&(x!==45||u===46)&&(g=!1));else if(i&&x===92){r=f;break}else x===64?(d=f,b=-1):x===93?v=f:x>=65&&x<=90?o=!0:s&&!gn(x)&&(g=!1);s&&(u=x)}if(p)return dt(e.replace(rs,""),t,s);if(d!==-1&&d>=n&&d<r&&(n=d+1),e.charCodeAt(n)===91)return v!==-1?e.slice(n+1,v).toLowerCase():null;if(m!==-1&&m>n&&m<r&&b===m&&(r=m),n>=r)return null;s&&g&&d===-1&&m===-1&&v===-1&&e.charCodeAt(r-1)!==46&&r-n<=255&&r-h-1<=63&&u!==45&&(ps=!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 Vl(e){if(e.length<7||e.length>15)return!1;let t=0;for(let s=0;s<e.length;s+=1){const n=e.charCodeAt(s);if(n===46)t+=1;else if(n<48||n>57)return!1}return t===3&&e.charCodeAt(0)!==46&&e.charCodeAt(e.length-1)!==46}function Wl(e){if(e.length<3)return!1;let t=e.startsWith("[")?1:0,s=e.length;if(e[s-1]==="]"&&(s-=1),s-t>39)return!1;let n=!1;for(;t<s;t+=1){const r=e.charCodeAt(t);if(r===58)n=!0;else if(!(r>=48&&r<=57||r>=97&&r<=102||r>=65&&r<=70))return!1}return n}function Yl(e){return Wl(e)||Vl(e)}function xn(e){return e>=97&&e<=122||e>=48&&e<=57||e>127}function vn(e){if(e.length>255||e.length===0||!xn(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(!(xn(o)||o===45||o===95)||o===45&&s===46)return!1;s=o}return n-t-1<=63&&s!==45}function Xl({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 Jl=Xl({});function Zl(e){return Jl}function ec(){return{domain:null,domainWithoutSuffix:null,hostname:null,isIcann:null,isIp:null,isPrivate:null,isSpecialUse:null,publicSuffix:null,subdomain:null}}function tc(e){e.domain=null,e.domainWithoutSuffix=null,e.hostname=null,e.isIcann=null,e.isIp=null,e.isPrivate=null,e.isSpecialUse=null,e.publicSuffix=null,e.subdomain=null}function sc(e,t,s,n,r){const o=Zl();if(typeof e!="string")return r;let i=!1;return o.extractHostname?o.mixedInputs?(i=vn(e),r.hostname=dt(e,i,o.validateHostname)):r.hostname=dt(e,!1,o.validateHostname):r.hostname=e,o.detectIp&&r.hostname!==null&&(r.isIp=Yl(r.hostname),r.isIp)?r:o.validateHostname&&o.extractHostname&&r.hostname!==null&&!(i&&r.hostname===e)&&!ps&&!vn(r.hostname)?(r.hostname=null,r):(r.hostname===null||(s(r.hostname,o,r),r.publicSuffix===null)||(r.domain=Gl(r.publicSuffix,r.hostname,o)),r)}const yn=ec();function nc(e,t){return tc(yn),sc(e,3,Ar,t,yn).domain}const qt=e=>{const t=new Set,s=[];for(const n of e){const r=n.trim();if(r==="")continue;const o=r.toLowerCase();t.has(o)||(t.add(o),s.push(r))}return s},ac=e=>{const t=e.lastIndexOf("@");return t>=0?e.slice(t+1):e},za=e=>nc(ac(e.trim())),rc=e=>{const t=qt(e);if(t.length<2)return null;let s=null;for(const n of t){const r=za(n);if(r===null)return null;if(s===null)s=r;else if(s!==r)return null}return s},Ht=e=>{const t=rc(e);return t!==null?[{field:"FromDomain",value:t}]:qt(e).map(s=>({field:"From",value:s}))},oc=e=>{const t=new Map;for(const r of e){const o=r.normalizedEmail.trim().toLowerCase();if(o==="")continue;const i=t.get(o);i?i.count+=1:t.set(o,{sender:r,count:1})}let s,n=0;for(const{sender:r,count:o}of t.values())o<=n||(s=r,n=o);return s},_a=e=>e.displayName?.trim()||e.normalizedEmail,ic=/^\s*(?:(?:re|aw|fwd?|vs|sv|antw|res|enc|tr)\s*(?:\[\d+\])?\s*:|\[[^\]]{1,32}\])\s*/i,lc=e=>{let t=e.replace(/\s+/g," ").trim();for(;;){const s=t.replace(ic,"");if(s===t)return t.trim();t=s}},cc=new Set(["a","an","and","are","as","at","be","by","for","from","has","have","in","is","it","me","my","new","of","on","or","our","the","this","to","was","we","with","you","your"]),dc=3,os=e=>e.split(" ").filter(t=>t!==""),kn=e=>e.length===0||e.join(" ").length<dc?!1:e.some(t=>!cc.has(t.toLowerCase())),uc=(e,t)=>e.findIndex((s,n)=>t.every((r,o)=>e[n+o]?.toLowerCase()===r.toLowerCase())),fc=e=>{const t=e.map(lc).filter(o=>o!=="");if(t.length===0)return;const[s,...n]=t;if(n.length===0)return kn(os(s))?s:void 0;const r=os(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(kn(c)&&n.every(d=>uc(os(d),c)>=0))return c.join(" ")}},mc=(e,t)=>{const s=Ht(e);if(qt(e).length===1||s.length===1&&s[0].field==="FromDomain")return s;const n=fc(t);return n!==void 0?[{field:"Subject",value:n}]:s},pc=({match:e,sender:t,folder:s})=>{const n=e??t;return n?s?`${n} → ${s}`:e?`Mail matching ${e}`:`Mail from ${n}`:s?`Mail to ${s}`:""},hc=e=>e.clauses.length>0,gc=e=>({scopedOutFolder:e.scopedOut?.label,droppedFacets:e.droppedFacets.map(t=>t.label),droppedSemantic:e.droppedSemantic}),bc=({orderedIds:e,isDesktop:t,initialFocusedId:s,initialSelectedIds:n,onExitSelection:r})=>{const[o,i]=l.useState(s),[c,d]=l.useState(),v=l.useCallback(S=>{d(E=>E===S?E:void 0),i(S)},[]),m=xl({initialSelectedIds:n}),{selectedCount:b,toggle:p,clearSelection:g,selectRange:h,setAnchor:u,selectAll:f}=m,x=ml(b,t),C=l.useRef(null),y=l.useRef(!1),j=l.useCallback(()=>{r?.(),g()},[g,r]),N=l.useMemo(()=>o?e.indexOf(o):-1,[e,o]),M=l.useCallback(S=>{if(S<0||S>=e.length)return;const E=e[S];if(x){p(E);return}C.current=E,y.current=!1,d(E),i(E)},[e,x,p]),P=l.useCallback(()=>{e.length!==0&&M(N<0?0:Math.min(N+1,e.length-1))},[e.length,N,M]),I=l.useCallback(()=>{e.length!==0&&M(N<=0?0:N-1)},[e.length,N,M]),F=l.useCallback(()=>M(0),[M]),O=l.useCallback(()=>M(e.length-1),[M,e.length]),_=l.useCallback(()=>{o&&p(o)},[o,p]),D=l.useCallback((S,E)=>{const w=fl(E);return w==="range"?(h(e,S,o),!0):w==="toggle"?(p(S),!0):(j(),u(S),!1)},[e,o,h,p,j,u]),K=l.useCallback(S=>{const E=bl(e,o,S);E!==void 0&&(h(e,E),C.current=E,y.current=!1,d(void 0),i(E))},[e,o,h]),k=l.useCallback(()=>K(-1),[K]),R=l.useCallback(()=>K(1),[K]),A=l.useCallback(()=>{e.length>0&&f(e)},[e,f]);return{focusedMessageId:o,setFocusedMessageId:v,keyboardFocusedMessageId:c,focusIndex:N,pendingDomFocusRef:C,cursorMovedByPointerRef:y,selection:m,isMultiSelectMode:x,exitSelection:j,moveFocusToIndex:M,focusNext:P,focusPrevious:I,focusFirst:F,focusLast:O,toggleFocusedSelection:_,extendRangeUp:k,extendRangeDown:R,selectAllLoaded:A,handleRowSelect:D}};function xc(e,t){if(e===void 0)return{shouldBlockFn:()=>!0,withResolver:!1};if("shouldBlockFn"in e)return e;if(typeof e=="function")return{shouldBlockFn:async()=>await e(),enableBeforeUnload:!0,withResolver:!1};const s=!!(e.condition??!0),n=e.blockerFn;return{shouldBlockFn:async()=>s&&n!==void 0?await n():s,enableBeforeUnload:s,withResolver:n===void 0}}function vc(e,t){const{shouldBlockFn:s,enableBeforeUnload:n=!0,disabled:r=!1,withResolver:o=!1}=xc(e),i=$r(),{history:c}=i,[d,v]=l.useState({status:"idle",current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0});return l.useEffect(()=>{const m=async b=>{function p(x){const C=i.parseLocation(x),y=i.getMatchedRoutes(C.pathname);return y.foundRoute===void 0?{routeId:"__notFound__",fullPath:C.pathname,pathname:C.pathname,params:y.routeParams,search:i.options.parseSearch(x.search)}:{routeId:y.foundRoute.id,fullPath:y.foundRoute.fullPath,pathname:C.pathname,params:y.routeParams,search:i.options.parseSearch(x.search)}}const g=p(b.currentLocation),h=p(b.nextLocation);if(g.routeId==="__notFound__"&&h.routeId!=="__notFound__")return!1;const u=await s({action:b.action,current:g,next:h});if(!o)return u;if(!u)return!1;const f=await new Promise(x=>{v({status:"blocked",current:g,next:h,action:b.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:m,enableBeforeUnload:n})},[s,n,r,o,c,i]),d}const $s=e=>{const{data:t,isLoading:s}=Z({...gt(),staleTime:1/0}),n=l.useMemo(()=>(t?.accounts??[]).map(c=>c.accountId),[t?.accounts]),r=Cs({queries:n.map(c=>({...bt({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(m=>m.mailboxId===e))return n[c]}},[e,n,r]),isLoading:o}},yc=({surface:e})=>{const t=qo(),s=Ho(),{data:n}=Z({...zt({path:{messageId:e.sourceMessageId}})}),{data:r}=Z({...gt(),staleTime:1/0}),{accountId:o}=$s(n?.message.mailboxId),i=r?.accounts?.find(c=>c.accountId===o);return a.jsx("div",{className:"border-b border-line bg-canvas",children:a.jsx(Jo,{layout:"flow",mode:e.mode,account:i,sourceMessage:n,outboxMessageId:e.outboxMessageId,onDraftCreated:t,onClose:s})})},Ua=({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})]}),kc=100,hs=async e=>e.then(t=>({ok:!0,value:t}),t=>({ok:!1,error:t})),jc=(e,t=kc)=>{if(e.length===0)return[];const s=[];for(let n=0;n<e.length;n+=t)s.push(e.slice(n,n+t));return s},Ka=async(e,t,s,n)=>{const r=jc(e),o=e.length;let i=0;const c=[];for(let d=0;d<r.length;d++){if(n())return c.push(...r.slice(d).flat()),{done:i,failedIds:c,cancelled:!0};const v=r[d],m=await hs(t(v));if(!m.ok)return c.push(...r.slice(d).flat()),s({done:i,total:o}),{done:i,failedIds:c,cancelled:!1,error:m.error};i+=v.length,s({done:i,total:o})}return{done:i,failedIds:c,cancelled:!1}},ht=async(e,t)=>{await Ka(e,async s=>(await t(s),{successCount:s.length,failureCount:0}),()=>{},()=>!1)},wc=async(e,t,s,n,r)=>{let o=0;const i=[];let c;do{if(r())return{done:o,failedIds:i,cancelled:!0};const d=await hs(e(c));if(!d.ok)return{done:o,failedIds:i,cancelled:!1,error:d.error};const v=d.value;if(v.ids.length>0){const m=await hs(s(v.ids));if(!m.ok)return{done:o,failedIds:i,cancelled:!1,error:m.error};o+=v.ids.length,n({done:o,total:t})}c=v.continuationToken}while(c);return{done:o,failedIds:i,cancelled:!1}},Cc=e=>({done:e.done,total:Math.max(e.total,e.done)}),Ba=e=>typeof e=="object"&&e!==null&&Array.isArray(e.pages),Qa=e=>typeof e=="object"&&e!==null&&Array.isArray(e.items),qa=(e,t)=>e===void 0?e:Ba(e)?{...e,pages:e.pages.map(s=>({...s,items:t(s.items)}))}:Qa(e)?{...e,items:t(e.items)}:e,ye=e=>{const t=[];for(const s of new Set(e))t.push(Qn({path:{mailboxId:s}})),t.push(qn({path:{mailboxId:s}}));return t.push(Hn()),t},vt=(e,t)=>Promise.all(t.map(s=>e.cancelQueries({queryKey:s}))),yt=(e,t)=>t.flatMap(s=>e.getQueriesData({queryKey:s})).filter(s=>s[1]!==void 0).map(([s,n])=>({queryKey:s,data:n})),kt=(e,t,s)=>{const n=r=>qa(r,s);for(const r of t)e.setQueriesData({queryKey:r},n)},jt=(e,t)=>{for(const s of t)e.setQueryData(s.queryKey,s.data)},ke=(e,t)=>{for(const s of t)e.invalidateQueries({queryKey:s})},Sc=3e3,Nc=(e,t,s)=>{if(e.length===0)return()=>{};const n=setTimeout(()=>s(e),t);return()=>clearTimeout(n)},Ls=(e,t,s)=>{const n=new Map(t.map(o=>[o.messageId,o.mailboxId])),r=new Set;for(const o of e)r.add(n.get(o)??s);return[...r]},Pt=(e,t,s)=>e.map(n=>t.has(n.messageId)?{...n,isRead:s}:n),Tc=(e,t,s,n)=>e.filter(r=>!r.isRead&&t.has(r.threadMessageId)&&!s.has(r.messageId)&&!n.has(r.messageId)).map(r=>r.messageId),Ec=({messages:e,expandedIds:t,threadId:s,mailboxId:n,accountId:r})=>{const o=oe(),{pushError:i}=be(),c=l.useRef(new Set),d=l.useRef(new Set),{mutate:v}=pe({..._t(),meta:Lr,onMutate:async p=>{const g=new Set(p.body.messageIds??[]),h=p.body.isRead??!0,u=Ie({path:{threadId:s}}),f=ye(Ls(g,e,n));await Promise.all([o.cancelQueries({queryKey:u}),vt(o,f)]);const x=o.getQueriesData({queryKey:u}).filter(y=>y[1]!==void 0).map(([y,j])=>({queryKey:y,data:j})),C=yt(o,f);return o.setQueriesData({queryKey:u},y=>y&&{...y,items:Pt(y.items,g,h)}),kt(o,f,y=>Pt(y,g,h)),{threadMessagesPrefix:u,listPrefixes:f,previousThreadMessages:x,previousThreadsList:C}},onSuccess:(p,g)=>{const h=g.body.messageIds??[];for(const u of h)c.current.add(u),d.current.delete(u)},onError:(p,g,h)=>{const u=g.body.messageIds??[];for(const x of u)d.current.delete(x);if(h){for(const x of h.previousThreadMessages)o.setQueryData(x.queryKey,x.data);jt(o,h.previousThreadsList)}const f=g.body.isRead??!0;i({title:f?"Couldn't mark as read":"Couldn't mark as unread",detail:Ee(p),error:p})},onSettled:(p,g,h,u)=>{u&&(o.invalidateQueries({queryKey:u.threadMessagesPrefix}),ke(o,u.listPrefixes),r&&o.invalidateQueries({queryKey:We({path:{accountId:r}})}))}}),m=l.useCallback(p=>{const g=p.filter(h=>!c.current.has(h)&&!d.current.has(h));if(g.length!==0){for(const h of g)d.current.add(h);v({body:{messageIds:g,isRead:!0}})}},[v]),b=l.useMemo(()=>Tc(e,t,c.current,d.current),[e,t]);l.useEffect(()=>Nc(b,Sc,m),[b,m]),l.useEffect(()=>{c.current.clear(),d.current.clear()},[s])},Hf=e=>{const{mailboxId:t,accountId:s,messages:n}=e,r=oe(),{pushError:o}=be(),{mutateAsync:i,isPending:c}=pe({..._t(),onError:(v,m)=>{const b=m.body.isRead??!0;o({title:b?"Couldn't mark as read":"Couldn't mark as unread",detail:Ee(v),error:v})},onSettled:(v,m,b)=>{ke(r,ye(Ls(b.body.messageIds??[],n??[],t))),s&&r.invalidateQueries({queryKey:We({path:{accountId:s}})})}});return{toggleReadFor:l.useCallback((v,m)=>{v.length!==0&&ht(v,b=>i({body:{messageIds:b,isRead:m}}))},[i]),isPending:c}},Ic=60,Mc=1.5,Rc=(e,t,s)=>{const n=Math.abs(e),r=Math.abs(t);return n<s?{direction:null}:n<r*Mc?{direction:null}:{direction:e<0?"left":"right"}},Ac=({onSwipeLeft:e,onSwipeRight:t,thresholdPx:s=Ic})=>{const n=l.useRef(null),r=l.useCallback(d=>{if(d.pointerType==="mouse"){n.current=null;return}n.current={x:d.clientX,y:d.clientY}},[]),o=l.useCallback(()=>{},[]),i=l.useCallback(d=>{const v=n.current;if(n.current=null,!v)return;const{direction:m}=Rc(d.clientX-v.x,d.clientY-v.y,s);m==="left"&&e?.(),m==="right"&&t?.()},[e,t,s]),c=l.useCallback(()=>{n.current=null},[]);return{handlers:{onPointerDown:r,onPointerMove:o,onPointerUp:i,onPointerCancel:c}}},$c=(e,t,s)=>t?.find(n=>n.messageId===e)?.mailboxId??s,jn=(e,t,s)=>e.map(n=>n.messageId===t?{...n,hasStars:s}:n),Ha=({threadId:e,mailboxId:t,messages:s})=>{const n=oe(),{pushError:r}=be(),{mutate:o,isPending:i,variables:c}=pe({...Pr(),onMutate:async v=>{const m=v.path.messageId,b=v.body.isStarred??!1,p=Ie({path:{threadId:e}}),g=ye([$c(m,s,t)]);await Promise.all([n.cancelQueries({queryKey:p}),vt(n,g)]);const h=n.getQueriesData({queryKey:p}).filter(f=>f[1]!==void 0).map(([f,x])=>({queryKey:f,data:x})),u=yt(n,g);return n.setQueriesData({queryKey:p},f=>qa(f,x=>jn(x,m,b))),kt(n,g,f=>jn(f,m,b)),{threadMessagesPrefix:p,listPrefixes:g,previousThreadMessages:h,previousThreadsList:u}},onError:(v,m,b)=>{if(b){for(const g of b.previousThreadMessages)n.setQueryData(g.queryKey,g.data);jt(n,b.previousThreadsList)}const p=m.body.isStarred??!1;r({title:p?"Couldn't star message":"Couldn't unstar message",detail:Ee(v),error:v})},onSettled:(v,m,b,p)=>{p&&(n.invalidateQueries({queryKey:p.threadMessagesPrefix}),ke(n,p.listPrefixes))}});return{toggleStar:(v,m)=>{o({path:{messageId:v},body:{isStarred:!m}})},isPending:i,pendingMessageId:i?c?.path.messageId:void 0}};function wn({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(Xe,{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 Ga(e){return e===void 0?"uncategorized":e}const Lc={inbox:"Inbox",junk:"Junk"},Ps=e=>e.destinationMailboxId!==void 0,Pc=(e,t)=>{if(Ps(e))return`Moved from ${t??"another folder"} by Remit`;const s=e.fromPlacement??"";return`Moved from ${Lc[s]??"another folder"} by Remit`},Dc=(e,t)=>{if(e===Zs.MoveToInbox)return t.inboxMailboxId;if(e===Zs.MoveToJunk)return t.junkMailboxId},Fc=(e,t,s)=>{if(!e||!t)return!1;const n=Ps(e)?e.destinationMailboxId:Dc(e.action,s);return n!==void 0&&n===t},Oc="Reported as spam",zc=(e,t)=>{if(e){if(Ps(e))return e.fromMailboxId;if(e.fromPlacement==="inbox")return t.inboxMailboxId;if(e.fromPlacement==="junk")return t.junkMailboxId}},Gt=(e,t)=>{const{data:s,isLoading:n}=Z({...gt(),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}},Gf=e=>{const{mailboxId:t,isLoading:s}=Gt(e,"Archive");return{archiveMailboxId:t,isLoading:s}},Vf=e=>{const{mailboxId:t,isLoading:s}=Gt(e,"Drafts");return{draftsMailboxId:t,isLoading:s}},_c=e=>{const{mailboxId:t,isLoading:s}=Gt(e,"Inbox");return{inboxMailboxId:t,isLoading:s}},Va=e=>{const{mailboxId:t,isLoading:s}=Gt(e,"Junk");return{junkMailboxId:t,isLoading:s}},Uc=()=>{const{data:e,isError:t}=Z({...gt(),staleTime:1/0});return{trashByAccount:l.useMemo(()=>{const n=new Map;for(const r of e?.accounts??[])n.set(r.accountId,r.folderAppointments.find(o=>o.role==="Trash")?.mailboxId);return n},[e]),hasAppointments:e!==void 0,isError:t}},Wa=e=>{const{data:t}=Z({...gt(),staleTime:1/0,enabled:!!e});return l.useMemo(()=>t?.accounts.find(s=>s.accountId===e)?.folderAppointments??[],[t,e])},Cn=(e,t)=>e.filter(s=>!t.has(s.messageId)),Vt=({mailboxId:e,threadId:t,accountId:s,onAfterOptimisticRemove:n})=>{const r=oe(),{pushError:o}=be(),{mutateAsync:i,isPending:c,isError:d}=pe({...Dr(),onMutate:async m=>{const b=new Set(m.body.messageIds??[]),p=t?Ie({path:{threadId:t}}):[],g=ye([e,m.body.destinationMailboxId]);await Promise.all([...t?[r.cancelQueries({queryKey:p})]:[],vt(r,g)]);const h=t?r.getQueriesData({queryKey:p}).filter(f=>f[1]!==void 0).map(([f,x])=>({queryKey:f,data:x})):[],u=yt(r,g);return t&&r.setQueriesData({queryKey:p},f=>f&&{...f,items:Cn(f.items,b)}),kt(r,g,f=>Cn(f,b)),n?.(Array.from(b)),{threadMessagesPrefix:p,listPrefixes:g,previousThreadMessages:h,previousThreadsList:u}},onError:(m,b,p)=>{if(p){for(const h of p.previousThreadMessages)r.setQueryData(h.queryKey,h.data);jt(r,p.previousThreadsList)}const g=b.body.messageIds?.length??0;o({title:g>1?`Couldn't move ${g} messages`:"Couldn't move this message",detail:Ee(m),error:m})},onSettled:(m,b,p,g)=>{g&&(t&&r.invalidateQueries({queryKey:g.threadMessagesPrefix}),ke(r,g.listPrefixes),s&&r.invalidateQueries({queryKey:We({path:{accountId:s}})}))}});return{moveMessages:l.useCallback((m,b)=>{m.length!==0&&ht(m,p=>i({body:{messageIds:p,destinationMailboxId:b}}))},[i]),isPending:c,isError:d}},Kc="This message could not be processed. Please try again. If it keeps failing, report it.",Bc=(e,t)=>e.replace(`Message ${t}'s`,"This message's"),Sn=e=>{if(e.failureCount===0)return;const t=e.failures?.[0],s=t?.reason??Kc,n=t?Bc(s,t.messageId):s;throw new zr(n,422)};function Ya({mailboxId:e,threadId:t,accountId:s,onAfterOptimisticRemove:n}){const r=oe(),{pushError:o}=be(),i=ye([e]),c=t?Ie({path:{threadId:t}}):[],d=()=>{t&&r.invalidateQueries({queryKey:c}),ke(r,i),s&&r.invalidateQueries({queryKey:We({path:{accountId:s}})})},v=()=>(u,f)=>{d(),n?.(f.body.messageIds)},m=u=>(f,x)=>{o({title:u(x.body.messageIds.length),detail:Ee(f),error:f})},b=pe({mutationFn:async u=>{const{data:f}=await Fr({...u,throwOnError:!0});return Sn(f),f},meta:{softError:!0},onSuccess:v(),onError:m(u=>u>1?`Couldn't report ${u} messages as spam`:"Couldn't report this message as spam")}),p=pe({mutationFn:async u=>{const{data:f}=await Or({...u,throwOnError:!0});return Sn(f),f},meta:{softError:!0},onSuccess:v(),onError:m(u=>u>1?`Couldn't undo the spam report for ${u} messages`:"Couldn't undo the spam report")}),g=l.useCallback(u=>{u.length!==0&&ht(u,f=>b.mutateAsync({body:{messageIds:f}}))},[b.mutateAsync]),h=l.useCallback(u=>{u.length!==0&&ht(u,f=>p.mutateAsync({body:{messageIds:f}}))},[p.mutateAsync]);return{reportSpam:g,notSpam:h,isReporting:b.isPending,isRestoring:p.isPending}}const Qc=({accountId:e,messageId:t,threadId:s,mailboxId:n,autoMoved:r,spamReport:o})=>{const{inboxMailboxId:i}=_c(e),{junkMailboxId:c}=Va(e),{moveMessages:d,isPending:v}=Vt({mailboxId:n,threadId:s,accountId:e}),{notSpam:m,isRestoring:b}=Ya({mailboxId:n,threadId:s,accountId:e}),{data:p}=Z({...bt({path:{accountId:e??""}}),staleTime:1/0,enabled:!!e&&r?.fromMailboxId!==void 0}),g={inboxMailboxId:i,junkMailboxId:c},h=zc(r,g),u=l.useCallback(()=>{h&&d([t],h)},[d,t,h]),f=l.useCallback(()=>{m([t])},[m,t]);if(o)return{show:!0,label:Oc,onUndo:f,isUndoing:b};if(!Fc(r,n,g)||!r)return{show:!1,label:"",isUndoing:!1};const C=r.fromMailboxId?p?.items.filter(y=>y.mailboxId===r.fromMailboxId).map(y=>_r(y.fullPath))[0]:void 0;return{show:!0,label:Pc(r,C),onUndo:h?u:void 0,isUndoing:v,...r.filterId?{filtersHref:"/settings/filters"}:{}}};function qc({accountId:e,messageId:t,threadId:s,mailboxId:n,autoMoved:r,spamReport:o}){const i=Qc({accountId:e,messageId:t,threadId:s,mailboxId:n,autoMoved:r,spamReport:o});return i.show?a.jsx(Ml,{label:i.label,onUndo:i.onUndo,undoLabel:i.isUndoing?"Undoing…":"Undo",filtersHref:i.filtersHref}):null}const Nn=(e,t)=>e.filter(s=>!t.has(s.messageId)),Wf=e=>e.filter(t=>t.isDeleted!==!0),Ds=({mailboxId:e,threadId:t,accountId:s,messages:n,onAfterOptimisticRemove:r})=>{const o=oe(),{pushError:i}=be(),{mutateAsync:c,isPending:d}=pe({...Ur(),onMutate:async m=>{const b=new Set(m.body.messageIds??[]),p=t?Ie({path:{threadId:t}}):[],g=ye(Ls(b,n??[],e));await Promise.all([o.cancelQueries({queryKey:p}),vt(o,g)]);const h=t?o.getQueriesData({queryKey:p}).filter(f=>f[1]!==void 0).map(([f,x])=>({queryKey:f,data:x})):[],u=yt(o,g);return t&&o.setQueriesData({queryKey:p},f=>f&&{...f,items:Nn(f.items,b)}),kt(o,g,f=>Nn(f,b)),r?.(Array.from(b)),{threadMessagesPrefix:p,listPrefixes:g,previousThreadMessages:h,previousThreadsList:u}},onError:(m,b,p)=>{if(p){for(const h of p.previousThreadMessages)o.setQueryData(h.queryKey,h.data);jt(o,p.previousThreadsList)}const g=b.body.messageIds?.length??0;i({title:g>1?`Couldn't delete ${g} messages`:"Couldn't delete this message",detail:Ee(m),error:m})},onSettled:(m,b,p,g)=>{g&&(t&&o.invalidateQueries({queryKey:g.threadMessagesPrefix}),ke(o,g.listPrefixes),s&&o.invalidateQueries({queryKey:We({path:{accountId:s}})}))}});return{deleteMessages:l.useCallback(m=>{m.length!==0&&ht(m,b=>c({body:{messageIds:b}}))},[c]),isPending:d}},Xa="inline-flex items-center justify-center transition-colors",Hc=z(Xa,"min-h-11 min-w-11 rounded hover:bg-surface-raised"),Gc=z(Xa,"min-h-11 gap-1.5 px-3 rounded text-sm font-medium hover:bg-surface-raised"),Fs=({accountId:e,currentMailboxId:t,onMove:s,disabled:n=!1,disabledHint:r,variant:o="icon-only",label:i,defaultOpen:c=!1})=>{const[d,v]=l.useState(c),[m,b]=l.useState(),p=Ss(),g=l.useRef(null),h=i??"Move to folder",u=l.useId(),{t:f}=Kr("mail",{useSuspense:!1}),x=ia(),{data:C,isLoading:y,isError:j,error:N,refetch:M}=Z({...bt({path:{accountId:e}}),staleTime:1/0,enabled:d}),P=Wa(e),{createFolderIn:I}=la(e),F=l.useMemo(()=>ca({mailboxes:C?.items??[],folderAppointments:P,currentMailboxId:t,translator:x}),[C?.items,P,t,x]),O=da(C?.items??[]),_=F.find(E=>E.id===m),D=l.useCallback(()=>{v(!1),b(void 0)},[]),K=l.useCallback(()=>{_&&(D(),s(_.id))},[_,D,s]);l.useEffect(()=>{if(!d||!p)return;const E=L=>{g.current&&!g.current.contains(L.target)&&D()},w=L=>{L.key==="Escape"&&D()};return document.addEventListener("mousedown",E),document.addEventListener("keydown",w),()=>{document.removeEventListener("mousedown",E),document.removeEventListener("keydown",w)}},[d,p,D]);const k=n||!!r,R=a.jsxs("button",{type:"button",onClick:E=>{E.stopPropagation(),!k&&v(w=>!w)},"aria-label":h,"aria-haspopup":p?"tree":"dialog","aria-expanded":d,"aria-controls":d?u:void 0,title:r,className:o==="icon-only"?Hc:Gc,children:[a.jsx(ks,{className:o==="icon-only"?"size-5":"size-4"}),o==="compact"&&a.jsx("span",{className:"hidden sm:inline",children:"Move"})]}),A=y?a.jsx("div",{className:"px-3 py-5 text-sm text-fg-muted",children:"Loading folders…"}):j?a.jsx("div",{className:"p-3",children:a.jsx(Oe,{variant:"inline",title:"Couldn't load folders",error:N,onRetry:()=>M()})}):a.jsx(Br,{folders:F,selectedId:m,delimiter:O,onSelect:b,onCreateFolder:I,onCancel:D,labels:{filterPlaceholder:f("move_picker_filter_placeholder",{defaultValue:"Filter folders…"}),filterAriaLabel:f("move_picker_filter_label",{defaultValue:"Filter folders"})}}),S=_&&a.jsx("div",{className:"shrink-0 border-t border-line p-2",children:a.jsx(V,{variant:"primary",onClick:K,className:"h-11 w-full font-semibold",children:`Move to ${_.label}`})});return p?a.jsxs("div",{ref:g,className:"relative inline-block",children:[R,d&&a.jsxs("div",{id:u,className:z("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:[A,S]})]}):a.jsxs(a.Fragment,{children:[R,a.jsx(Be.Root,{open:d,onOpenChange:E=>E?v(!0):D(),children:a.jsxs(Be.Portal,{children:[a.jsx(Be.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),a.jsxs(Be.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:u,children:[a.jsx(Be.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-subtle/30"}),a.jsx(Be.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:A}),S]})]})})]})},Vc=({messageId:e,threadId:t,mailboxId:s,isRead:n,accountId:r,fromAddressId:o,isTrusted:i=!1,showRaw:c=!1,onToggleRaw:d})=>{const v=oe(),m=Gn(),b=Go(),{pushError:p}=be(),g=wo()?.messageId,{mutate:h,isPending:u}=pe({..._t(),onMutate:async A=>{const S=A.body.isRead??!0,E=new Set(A.body.messageIds??[]),w=Ie({path:{threadId:t}}),L=ye([s]);await Promise.all([v.cancelQueries({queryKey:w}),vt(v,L)]);const U=v.getQueriesData({queryKey:w}).filter(Q=>Q[1]!==void 0).map(([Q,ie])=>({queryKey:Q,data:ie})),X=yt(v,L);return v.setQueriesData({queryKey:w},Q=>Q&&{...Q,items:Pt(Q.items,E,S)}),kt(v,L,Q=>Pt(Q,E,S)),{threadMessagesPrefix:w,listPrefixes:L,previousThreadMessages:U,previousThreadsList:X}},onError:(A,S,E)=>{if(E){for(const L of E.previousThreadMessages)v.setQueryData(L.queryKey,L.data);jt(v,E.previousThreadsList)}const w=S.body.isRead??!0;p({title:w?"Couldn't mark as read":"Couldn't mark as unread",detail:Ee(A),error:A})},onSettled:(A,S,E,w)=>{w&&(v.invalidateQueries({queryKey:w.threadMessagesPrefix}),ke(v,w.listPrefixes))}}),f=l.useCallback(A=>{g&&A.includes(g)&&m({to:"/mail/$mailboxId",params:{mailboxId:s},search:S=>S,hash:b})},[g,s,m,b]),{deleteMessages:x,isPending:C}=Ds({mailboxId:s,threadId:t,onAfterOptimisticRemove:f}),{moveMessages:y,isPending:j}=Vt({mailboxId:s,threadId:t,accountId:r,onAfterOptimisticRemove:f}),{toggleTrusted:N,isPending:M,error:P,reset:I}=Zn({messageId:e}),F=()=>{h({body:{messageIds:[e],isRead:!1}})},O=()=>{x([e])},_=()=>{o&&N(o,i)},D=u||C||j||M,K=D||!o,k=l.useCallback(A=>{y([e],A)},[y,e]),R=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(Fs,{accountId:r,currentMailboxId:s,onMove:k,disabled:D,label:"Move this message"}),a.jsxs(Co,{trigger:a.jsx(Po,{className:"size-4"}),children:[a.jsxs(Et,{onClick:_,disabled:K,children:[i?a.jsx(Bt,{className:"size-4 text-positive"}):a.jsx(Ft,{className:"size-4 opacity-0"}),a.jsx("span",{title:R,children:"Trusted sender"})]}),n&&a.jsxs(Et,{onClick:F,disabled:D,children:[a.jsx(Is,{className:"size-4"}),"Mark as unread"]}),d&&a.jsxs(Et,{onClick:d,children:[a.jsx(ka,{className:"size-4"}),c?"Show formatted":"Show raw email"]}),a.jsx(So,{}),a.jsxs(Et,{onClick:O,disabled:D,destructive:!0,children:[a.jsx(Ot,{className:"size-4"}),"Delete"]})]})]}),P&&a.jsx("div",{className:"w-64",children:a.jsx(Oe,{variant:"inline",title:"Couldn't update trust",error:P,onRetry:()=>{I(),_()}})})]})},Wc=e=>e==="link-expired"||e==="not-ready";class gs extends Error{reason;status;constructor(t,s,n){super(s),this.name="AttachmentFetchError",this.reason=t,this.status=n}}const Yc="x-remit-403-reason",Xc="expired",Jc=(e,t)=>{if(t?.trim()===Xc)return"link-expired";const s=Vo(e,t);return s==="auth"?"auth":s==="body-missing"?"missing":"generic"},Zc=300*1e3,Tn=async(e,t)=>{const s={},n=await t();n&&(s.Authorization=`Bearer ${n}`);const r=await Hr(e,{headers:s,signal:AbortSignal.timeout(Zc)});if(r.status===202)throw new gs("not-ready","Attachment is still being fetched from the mail server",202);if(!r.ok)throw new gs(Jc(r.status,r.headers.get(Yc)),`Failed to download attachment (${r.status} ${r.statusText})`,r.status);return r.blob()},ed=(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}}},En=e=>e instanceof gs?e.reason:"generic",td=e=>e instanceof Error?e.message:typeof e=="string"?e:"An unexpected error occurred while downloading this attachment.",sd=(e,t,s)=>{if(e!=="auth")return Qr(qr({title:`Bug: attachment download failed (${e})`,errorMessage:`Downloading "${t}" failed: ${s}`}))},nd=(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)},ad=e=>{const t=e.toUpperCase();return t==="OCTET-STREAM"?"FILE":t},rd=e=>{const t=e.toLowerCase().replace(/[^a-z0-9]/g,"");return t.length>0?`attachment.${t}`:"attachment"},In=e=>e.filter(t=>!t.isMultipart&&t.disposition===ni.Attachment&&t.contentUrl.length>0).map(t=>({bodyPartId:t.bodyPartId,filename:Do(t.dispositionFilename??"",rd(t.mediaSubtype)),typeLabel:ad(t.mediaSubtype),sizeOctets:t.sizeOctets,contentUrl:t.contentUrl})),Mn={status:"idle"},od=({messageId:e,bodyParts:t,hasAttachment:s=!1,className:n})=>{const{getToken:r}=Vn(),o=oe(),[i,c]=l.useState({}),d=l.useMemo(()=>In(t??[]),[t]),v=Gr({path:{messageId:e}}),m=h=>Tn(h.contentUrl,r).catch(u=>{if(!Wc(En(u)))throw u;return o.refetchQueries({queryKey:v}).then(()=>{const f=o.getQueryData(v),x=f?In(f.bodyParts).find(C=>C.bodyPartId===h.bodyPartId):void 0;return Tn(x?.contentUrl??h.contentUrl,r)})}),b=(h,u)=>c(f=>({...f,[h]:u})),p=h=>{const u=d.find(f=>f.bodyPartId===h);if(!u)throw new Error(`No attachment part ${h} on message ${e}`);b(h,{status:"downloading"}),m(u).then(f=>{nd(f,u.filename),b(h,Mn)}).catch(f=>{const x=En(f),C=td(f),{title:y,detail:j}=ed(x,u.filename,C);b(h,{status:"failed",title:y,detail:j,reportUrl:sd(x,u.filename,C)})})},g=s&&t!==void 0&&d.length===0;return a.jsx(Il,{className:n,attachments:d.map(h=>({attachmentId:h.bodyPartId,filename:h.filename,typeLabel:h.typeLabel,sizeOctets:h.sizeOctets,download:i[h.bodyPartId]??Mn})),onDownload:p,hasUnlistedAttachment:g})},id=({messageId:e,threadId:t,mailboxId:s,accountId:n,isRead:r,isStarred:o,onToggleStar:i,fromAddressId:c,isTrusted:d,showRaw:v,onToggleRaw:m,onReply:b,onReplyAll:p,onForward:g})=>{const h=oe(),{deleteMessages:u}=Ds({mailboxId:s,threadId:t}),{moveMessages:f}=Vt({mailboxId:s,threadId:t,accountId:n}),{toggleTrusted:x}=Zn({messageId:e}),{mutate:C}=pe({..._t(),onSettled:()=>{h.invalidateQueries({queryKey:Ie({path:{threadId:t}})}),ke(h,ye([s]))}}),y=l.useCallback(P=>{f([e],P)},[f,e]),j=l.useCallback(()=>{u([e])},[u,e]),N=l.useCallback(()=>{C({body:{messageIds:[e],isRead:!r}})},[C,e,r]),M=[];return c&&M.push({key:"trusted",label:d?"Trusted sender":"Mark sender trusted",icon:d?a.jsx(Bt,{className:"size-4 text-positive"}):a.jsx(Ft,{className:"size-4"}),onSelect:()=>x(c,d)}),m&&M.push({key:"raw",label:v?"Show formatted":"Show raw email",icon:a.jsx(ka,{className:"size-4"}),onSelect:m}),a.jsx(Ra,{hasThread:!0,onReply:b,onReplyAll:p,onForward:g,isStarred:o,onToggleStar:i,onDelete:j,isRead:r,onToggleRead:N,overflowItems:M,moveSlot:n?a.jsx(Fs,{accountId:n,currentMailboxId:s,onMove:y,label:"Move this message"}):void 0})},ld=()=>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"})]}),cd=({messageId:e,enabled:t=!0})=>{const{data:s,isLoading:n,isError:r,error:o,refetch:i}=Z({...Vr({path:{messageId:e}}),enabled:t});if(n)return a.jsx("div",{className:"message-body",children:a.jsx(ld,{})});if(r)return a.jsx("div",{className:"message-body",children:a.jsx(Oe,{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})})},dd=()=>a.jsx(Bt,{className:"inline-block size-4 ml-1 -mt-0.5 text-positive align-middle","aria-label":"Trusted sender","data-testid":"trusted-sender-badge"}),Ja=(e,t)=>({id:e.messageId,fromName:e.fromName??e.fromEmail??"?",fromEmail:e.fromEmail??"",toLabel:"",dateLabel:t,snippet:e.snippet||"",bodyHtml:""}),Za=({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:z("shrink-0 p-0.5 rounded transition-colors",e?"text-warning":z("text-fg-subtle hover:text-warning",n&&"opacity-0 group-hover:opacity-100 focus:opacity-100"),s&&"opacity-50"),children:a.jsx(Ve,{className:z("size-3.5",e&&"fill-current")})}),ud=({threadMessage:e,isFocused:t,onToggle:s,onToggleStar:n,isStarPending:r})=>{const o=ra(e.sentDate,"datetime"),i=Ja(e,o);return a.jsx(Aa,{message:i,onClick:s,isFocused:t,isUnread:!e.isRead,trailing:a.jsxs(a.Fragment,{children:[e.hasAttachment&&a.jsx(Qt,{className:"size-3 shrink-0 text-fg-subtle",role:"img","aria-label":"Has an attachment"}),a.jsx(Za,{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})]})})},fd=({threadMessage:e,messageData:t,isLoading:s,isError:n,error:r,onRetry:o,isFocused:i,onToggle:c,onToggleStar:d,isStarPending:v,accountId:m,showRaw:b,onToggleRaw:p,mobile:g,onReply:h,onReplyAll:u,onForward:f})=>{const x=ra(e.sentDate,"long"),C=!e.isRead,y=t?.envelope.from[0]?.flags?.trusted?.value===!0,j=t?.envelope.from[0]?.addressId,N=Ja(e,x),M=e.autoMoved||e.spamReport?a.jsx(qc,{accountId:m,messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,autoMoved:e.autoMoved,spamReport:e.spamReport}):null;return a.jsx($a,{message:N,isFocused:g?!1:i,onHeaderClick:c,senderBadge:y?a.jsx(dd,{}):void 0,trailing:a.jsx("span",{"data-testid":"message-date",className:"text-2xs text-fg-subtle",children:x}),to:t?a.jsx(il,{label:"To",addresses:t.envelope.to}):null,indicators:M||!g?a.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mt-0.5",children:[M,!g&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"flex items-center justify-end gap-1",children:a.jsx(Za,{isStarred:e.hasStars,onToggleStar:d,isStarPending:v})}),C&&a.jsx("span",{className:"size-1.5 rounded-full bg-accent","aria-label":"Unread"})]})]}):void 0,actionMenu:g?void 0:a.jsx(Vc,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,isRead:e.isRead,accountId:m,fromAddressId:j,isTrusted:y,showRaw:b,onToggleRaw:p}),actionBar:g?a.jsx(id,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,accountId:m,isRead:e.isRead,isStarred:e.hasStars,onToggleStar:d,fromAddressId:j,isTrusted:y,showRaw:b,onToggleRaw:p,onReply:h,onReplyAll:u,onForward:f}):void 0,body:s?a.jsxs("div",{className:"mt-3 animate-pulse space-y-2",children:[a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-full"}),a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-3/4"}),a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-1/2"})]}):n&&Wr(r)?a.jsx("div",{className:"mt-3",children:a.jsx(Ua,{message:"This message has been deleted"})}):n?a.jsx("div",{className:"mt-3",children:a.jsx(Oe,{variant:"inline",title:"Couldn't load this message",error:r,onRetry:o})}):b?a.jsx("div",{className:"mt-3",children:a.jsx(cd,{messageId:e.messageId})}):a.jsxs("div",{className:"mt-3",children:[a.jsx(_o,{bodyParts:t?.bodyParts,messageId:e.messageId,fromAddressId:t?.envelope.from[0]?.addressId,isTrusted:y,category:Ga(e.category)}),a.jsx(od,{messageId:e.messageId,bodyParts:t?.bodyParts,hasAttachment:e.hasAttachment,className:"mt-4"})]})})},md=({threadMessage:e,isExpanded:t,isFocused:s,onToggle:n,onToggleStar:r,isStarPending:o,accountId:i,mobile:c,onReply:d,onReplyAll:v,onForward:m})=>{const[b,p]=l.useState(!1),{data:g,isLoading:h,isError:u,error:f,refetch:x}=Z({...zt({path:{messageId:e.messageId}}),enabled:t,meta:{softError:!0}});return t?a.jsx(fd,{threadMessage:e,messageData:g,isLoading:h,isError:u,error:f,onRetry:()=>x(),isFocused:s,onToggle:n,onToggleStar:r,isStarPending:o,accountId:i,showRaw:b,onToggleRaw:()=>p(C=>!C),mobile:c,onReply:d,onReplyAll:v,onForward:m}):a.jsx(ud,{threadMessage:e,isFocused:s,onToggle:n,onToggleStar:r,isStarPending:o})},pd=()=>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))})]}),Yf=({threadId:e,mailboxId:t,subject:s,selectedMessageId:n,authenticity:r,onOpenIntelligence:o,onBack:i,onSwipeNext:c,onSwipePrevious:d,mobileIntelligenceOpen:v})=>{const m=Ss(),{handlers:b}=Ac({onSwipeLeft:c,onSwipeRight:d}),{accountId:p}=$s(t),{data:g,isLoading:h,isError:u,error:f,refetch:x}=Z({...Wn({path:{threadId:e}})}),C=l.useMemo(()=>g?.items??[],[g?.items]),y=C[C.length-1],j=l.useMemo(()=>[...C].reverse(),[C]),N=l.useRef(new Map),[M,P]=l.useState(new Set),[I,F]=l.useState(null),[O,_]=l.useState(0);l.useEffect(()=>{if(C.length>0&&e!==I){F(e);const B=new Set([C[C.length-1].threadMessageId]);if(n){const q=C.find(te=>te.messageId===n);q&&B.add(q.threadMessageId)}P(B),_(0)}},[e,C,I,n]);const D=l.useCallback(B=>{P(q=>{const te=new Set(q);return te.has(B)?te.delete(B):te.add(B),te})},[]),K=l.useCallback(B=>{const q=j[B];if(!q)return;N.current.get(q.threadMessageId)?.scrollIntoView({behavior:"smooth",block:"nearest"})},[j]),k=l.useCallback(()=>{if(j.length===0)return;const B=Math.min(O+1,j.length-1);_(B),K(B)},[j.length,O,K]),R=l.useCallback(()=>{if(j.length===0)return;const B=Math.max(O-1,0);_(B),K(B)},[j.length,O,K]),A=l.useCallback(()=>{const B=j[O];B&&D(B.threadMessageId)},[j,O,D]);Ec({messages:C,expandedIds:M,threadId:e,mailboxId:t,accountId:p});const{toggleStar:S,isPending:E,pendingMessageId:w}=Ha({threadId:e,mailboxId:t,messages:C}),L=Wo(),U=Yo(),X=n??y?.messageId,Q=l.useCallback((B,q)=>{q&&U({threadId:e,messageId:q,mode:B})},[U,e]),ie=l.useCallback(()=>Q("reply",X),[Q,X]),ee=l.useCallback(()=>Q("reply-all",X),[Q,X]),he=l.useCallback(()=>Q("forward",X),[Q,X]),se=l.useRef(null),de=L?.kind==="reply"?`${L.mode}:${L.sourceMessageId}`:void 0;if(l.useEffect(()=>{de&&se.current?.scrollIntoView({behavior:"smooth",block:"start"})},[de]),Zo({enabled:!h&&C.length>0&&L===void 0,bindings:[{key:"j",handler:k,preventDefault:!0},{key:"ArrowDown",handler:k,preventDefault:!0},{key:"k",handler:R,preventDefault:!0},{key:"ArrowUp",handler:R,preventDefault:!0},{key:"Enter",handler:A,preventDefault:!0},{key:"o",handler:A,preventDefault:!0},{key:"r",handler:ie,preventDefault:!0},{key:"R",handler:ee,noModifiers:!1,preventDefault:!0},{key:"f",handler:he,preventDefault:!0}]}),h)return a.jsx(pd,{});if(u)return a.jsx("div",{className:"flex h-full items-center justify-center",children:a.jsx(Oe,{title:L?"Couldn't load this conversation, so there is nothing to answer":"Couldn't load this conversation",error:f,onRetry:()=>x()})});if(C.length===0)return a.jsx("div",{className:"flex h-full items-center justify-center p-4",children:L?a.jsx(Oe,{variant:"inline",title:"There is nothing here to answer",error:"This conversation has no messages left. Another mail client may have moved or deleted them."}):a.jsx(Ua,{message:"No messages in this thread"})});const ue=s||C[0]?.subject||"(No subject)",le=C.length,fe=B=>a.jsx("div",{"data-testid":"conversation-messages",children:j.map((q,te)=>a.jsx("div",{ref:je=>{je&&N.current.set(q.threadMessageId,je)},children:a.jsx(md,{threadMessage:q,isExpanded:M.has(q.threadMessageId),isFocused:te===O,onToggle:()=>D(q.threadMessageId),onToggleStar:()=>S(q.messageId,q.hasStars),isStarPending:E&&w===q.messageId,accountId:p,mobile:B,onReply:B?()=>Q("reply",q.messageId):void 0,onReplyAll:B?()=>Q("reply-all",q.messageId):void 0,onForward:B?()=>Q("forward",q.messageId):void 0})},q.threadMessageId))}),G=L&&a.jsx("div",{ref:se,children:L.kind==="reply"?a.jsx(yc,{surface:L}):a.jsx("div",{className:"border-b border-line bg-canvas p-4",children:a.jsx(Oe,{variant:"inline",title:"That is not a way to answer a message",error:`"${L.segment}" is not reply, reply-all or forward.`})})}),ae=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:ue}),a.jsxs("p",{className:"mt-1 text-2xs text-fg-subtle",children:[le," ",le===1?"message":"messages"]})]});return m?a.jsxs("article",{className:"h-full flex flex-col",children:[ae,r?.dkimMismatch&&a.jsx(wn,{authenticity:r,onOpenIntelligence:o}),a.jsxs("div",{className:"min-h-0 flex-1 overflow-auto",children:[G,fe(!1)]})]}):a.jsxs(Tl,{thread:{subject:ue,messages:[]},onBack:i??(()=>{}),intelligenceOpen:v,onToggleIntelligence:o,touchHandlers:b,children:[r?.dkimMismatch&&a.jsx(wn,{authenticity:r,onOpenIntelligence:o}),G,fe(!0)]})},hd=({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=p=>{p.key==="Escape"&&(p.preventDefault(),t())};document.addEventListener("keydown",v),i.current?.querySelector("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])")?.focus();const b=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",v),document.body.style.overflow=b,c.current?.focus()}},[e,t]),!e)return null;const d=r==="left"?"left-0 border-r animate-in slide-in-from-left duration-150":"right-0 border-l animate-in slide-in-from-right duration-150";return a.jsxs("div",{className:"fixed inset-0 z-50",role:"dialog","aria-modal":"true","aria-label":n,children:[a.jsx("button",{type:"button","aria-label":"Close menu",onClick:t,className:"absolute inset-0 bg-black/40 animate-in fade-in duration-150 cursor-default"}),a.jsxs("div",{ref:i,className:z("safe-area-frame absolute top-0 bottom-0 bg-canvas border-line shadow-xl flex flex-col",o,d),children:[a.jsx("div",{className:"flex items-center justify-end h-12 px-2 border-b border-line shrink-0",children:a.jsx("button",{type:"button",onClick:t,className:"p-2 rounded-md hover:bg-surface-raised transition-colors min-h-11 min-w-11 inline-flex items-center justify-center","aria-label":"Close menu",children:a.jsx(Dt,{className:"size-5"})})}),a.jsx("div",{className:"flex-1 overflow-y-auto",children:s})]})]})},gd=10,er=e=>({q:e?.toLowerCase()??"",limit:gd}),bd=(e,t)=>{if(!t)return;const s=t.toLowerCase();return e?.find(n=>n.normalizedEmail===s)};function xd(e){const t=new Date(e),s=new Date;return t.toDateString()===s.toDateString()?"today":ei(t,{month:"short",year:"numeric"})}function tr(e){if(!e)return!0;const[,t]=e.split("@");return t?!t.includes("."):!0}const vd="We can't verify the sender of this email, which could mean it's from an insecure source.",yd="We couldn't read this sender's address, so we can't confirm who really sent this message.";function kd(e,t){const s=e.category??"personal";return{value:Xr(s)?s:"uncategorized",overridden:t?.flags?.category?.value!=null&&t.flags.category.value!==e.category}}function jd(e,t){return{name:e.fromName??e.fromEmail??"Unknown",email:e.fromEmail??"",trust:e.senderTrust,firstSeenLabel:t?xd(t.createdAt):"unknown",inboundCount:t?.inboundCount,replyCount:t?.replyCount,addressUnverified:tr(e.fromEmail)}}function wd(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 Rn(e){if(e.fromName&&e.fromName!==e.fromEmail)return e.fromName}function Cd(e){return e.length===1?e[0]:`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function Sd(e,t){const s=[],n=e.displayNameCorrespondence;t&&(n===es.Unrelated?s.push(`The name it shows, "${t}", has nothing to do with ${e.fromDomain}.`):n===es.Lookalike?s.push(`The name it shows, "${t}", only looks like ${e.fromDomain}.`):n===es.ForeignAddress&&s.push(`The name it shows, "${t}", is an address ${e.fromDomain} cannot send from.`));const r=Nd(e.offDomainLinkDomains);return r.length>0&&s.push(`Its links go to ${Cd(r.slice(0,3))}.`),s}function Nd(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&t.length>0):[]}function Td(e,t){const s=t>0?t:void 0;if(tr(e.fromEmail))return{verdict:"mismatch",fromDomain:"",addressUnreadable:!0,summary:yd,similarCount:s};const n=e.authenticity;if(!n)return{verdict:"caution",fromDomain:e.fromEmail?.split("@")[1]??"",summary:vd};if(!n.dkimMismatch){const v=Rn(e),m=Sd(n,v);return m.length>0?{verdict:"caution",fromDomain:n.fromDomain,dkimDomain:n.dkimDomain,claimedBrand:v,summary:m.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=Rn(e),c=o?`it was actually sent from ${o}`:"its signature failed to verify",d=i?`The display name claims "${i}", but ${c}${o?` — not ${r}`:""}. Real senders use their own address.`:`This message claims to be from ${r}, but ${c}.`;return{verdict:"mismatch",fromDomain:r,dkimDomain:o,claimedBrand:i,summary:d,similarCount:s}}function Ed(e,t){const s=e?.fromEmail??null,n=e?.subject??"",{data:r,error:o}=Z({...js({query:er(s??void 0)}),enabled:!!s,staleTime:3e4}),i=bd(r?.items,s??void 0),c=[n,s].filter(Boolean).join(" "),{data:d,isLoading:v,error:m}=Z({...Yr({query:{query:c,limit:5}}),enabled:!!(e&&c.length>3),staleTime:6e4,retry:1});return{data:l.useMemo(()=>{if(!e)return null;const p=(d?.items??[]).filter(x=>x.messageId!==e.messageId).map(x=>({id:x.messageId,threadId:x.threadId,mailboxId:t!=null&&x.mailboxIds.includes(t)?t:x.mailboxIds[0]??"",fromName:x.fromName??"",subject:x.subject??"(No subject)",timeLabel:x.sentDate!=null?Ye(x.sentDate*1e3):"",matched:x.matchedChunkType})),g=jd(e,i),h=Td(e,p.length),u=kd(e,i),f=wd(i);return{sender:g,authenticity:h,category:u,flags:f,similar:p}},[e,i,d,t]),isSimilarLoading:v,similarError:m,similarErrorIsFatal:Gs(m),addressErrorIsFatal:Gs(o),addressId:i?.addressId,address:i}}function Id(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 Md({addressId:e,senderEmail:t}){const s=oe(),{pushError:n}=be(),r=Jr({query:er(t)}),{mutate:o,isPending:i}=pe({...Zr(),onMutate:async d=>{const v=d.body.flags??{};await s.cancelQueries({queryKey:r});const m=s.getQueryData(r);return s.setQueryData(r,b=>b&&{...b,items:b.items.map(p=>p.addressId===d.path.addressId?{...p,flags:Id(p.flags,v)}:p)}),{previous:m}},onError:(d,v,m)=>{m?.previous!==void 0&&s.setQueryData(r,m.previous),n({title:"Couldn't update sender preference",detail:Ee(d),error:d})},onSettled:()=>{s.invalidateQueries({queryKey:r})}});return{updateFlags:l.useCallback(d=>{if(!e){eo(new Error(`Quick action fired but the sender's address record did not resolve (sender: ${t??"unknown"}). This should never happen — the address row exists.`));return}o({path:{addressId:e},body:{flags:d}})},[e,o,t]),isPending:i}}const Xf=e=>e==="vip"?"A sender you know":e==="wellknown"?"You've emailed them before":"Passed authentication",Rd=e=>e.senderTrust!=="vip"&&e.senderTrust!=="wellknown"?!1:e.authenticity?.dkimMismatch!==!0;function Jf(e,t){e.recordEvent("rescue.candidates_surfaced",{count:String(t)})}function Zf(e,t){e.recordEvent("rescue.flow_opened",{count:String(t)})}function em(e,t){e.recordEvent("rescue.committed",{selected:String(t.selected),total:String(t.total),destination:t.toInbox?"inbox":"other"})}function Ad(e,t){e.recordEvent("rescue.sent_to_junk",{count:String(t.count),senderTrust:t.senderTrust,wasRescuable:String(t.wasRescuable)})}const $d=["personal","newsletter","marketing","automated","transactional","social"],Ld=e=>e.spamReport?"notSpam":"reportSpam",Pd=e=>{const{similarError:t,similarErrorIsFatal:s,isSimilarLoading:n}=e;return t&&!s?"error":n?"loading":"ready"};function Dd(){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(Ge,{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 Fd({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(so,{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:$d.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 Od({thread:e,onClose:t,mailboxId:s,accountId:n,hideCloseButton:r,onAfterOptimisticRemove:o}){const{data:i,addressId:c,isSimilarLoading:d,similarError:v,similarErrorIsFatal:m}=Ed(e,s),[b,p]=l.useState(!1),g=e.fromEmail??void 0,{updateFlags:h}=Md({addressId:c,senderEmail:g}),{reportSpam:u,notSpam:f,isReporting:x,isRestoring:C}=Ya({mailboxId:e.mailboxId,threadId:e.threadId,accountId:n,onAfterOptimisticRemove:o}),y=to(),j=Ld(e),N=l.useCallback(()=>{f([e.messageId])},[f,e.messageId]),M=l.useCallback(()=>{Ad(y,{count:1,senderTrust:e.senderTrust,wasRescuable:Rd(e)}),u([e.messageId])},[u,e,y]),P=l.useCallback(()=>{},[]),I=l.useCallback(()=>{const A=i?.flags?.vip!==!0;h({vip:{value:A}})},[i?.flags?.vip,h]),F=l.useCallback(()=>{const A=i?.flags?.muted!==!0;h({muted:{value:A}})},[i?.flags?.muted,h]),O=l.useCallback(()=>{const A=i?.flags?.unsubscribed!==!0;h({unsubscribed:{value:A}})},[i?.flags?.unsubscribed,h]),_=l.useCallback(A=>{p(!1),h({category:{value:A}})},[h]),D=c!==void 0,K={onToggleVip:D?I:void 0,onToggleMute:D?F:void 0,onToggleUnsubscribe:D?O:void 0,onReclassify:D?()=>p(!0):void 0,onNotSpam:j==="notSpam"?N:void 0,onReportSpam:j==="reportSpam"?M:void 0},k=({mailboxId:A,threadId:S,messageId:E,className:w,ariaLabel:L,children:U})=>a.jsx(aa,{to:"/mail/$mailboxId/$threadId/$messageId",params:{mailboxId:A,threadId:S,messageId:E},search:X=>X,variant:"row",className:w,"aria-label":L,children:U});if(!i)return a.jsx(Dd,{});const R=Pd({similarError:v,similarErrorIsFatal:m,isSimilarLoading:d});return a.jsxs(a.Fragment,{children:[a.jsx(Sa,{data:i,onClose:t,hideCloseButton:r,onShowSimilar:P,actions:K,similarState:R,similarLinkComponent:k,reportSpamPending:x,notSpamPending:C,className:"border-l-0 h-full w-full"}),a.jsx(Fd,{isOpen:b,current:i.category.value,onSelect:_,onCancel:()=>p(!1)})]})}const zd=({onClose:e,thread:t,mailboxId:s,accountId:n,hideCloseButton:r,onAfterOptimisticRemove:o})=>t?a.jsx(Od,{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(Ge,{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(Ge,{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."})]})]});function tm({isOpen:e,onClose:t,thread:s,mailboxId:n,accountId:r,onAfterOptimisticRemove:o}){return a.jsx(hd,{isOpen:e,onClose:t,ariaLabel:"Message details",side:"right",children:a.jsx(zd,{onClose:t,thread:s,mailboxId:n,accountId:r,hideCloseButton:!0,onAfterOptimisticRemove:o})})}const _d=e=>{const{trashByAccount:t,hasAppointments:s,isError:n}=Uc();return l.useMemo(()=>ti({targets:e,trashByAccount:t,hasAppointments:s,isError:n}),[e,t,s,n])},Ud={delete:(e,t)=>`Deleting ${e} of ${t}…`,move:(e,t)=>`Moving ${e} of ${t}…`,markRead:(e,t)=>`Marking ${e} of ${t} as read…`},Kd={delete:"moved to Trash",move:"moved",markRead:"marked as read"},sr=(e,t)=>e==="delete"&&t==="permanent"?"permanently deleted":Kd[e],Bd={delete:"couldn't be deleted",move:"couldn't be moved",markRead:"couldn't be marked as read"},Qd={delete:"Couldn't delete these messages",move:"Couldn't move these messages",markRead:"Couldn't mark these messages as read"},qd={delete:"The delete didn't finish.",move:"The move didn't finish.",markRead:"The update didn't finish."},sm=(e,t,s)=>Ud[e](ze(t),ze(s)),Hd=(e,t,s="trash")=>`${ze(t)} ${sr(e,s)}. Your mail server is still catching up.`,Gd=e=>`Stopped after ${ze(e)}`,Vd=(e,t,s,n="trash")=>`${ze(t)} of ${ze(s)} ${sr(e,n)}. Nothing was sent for the rest, so they are untouched.`,Wd=(e,t)=>t>0?`Stopped after ${ze(t)} — some messages ${Bd[e]}`:Qd[e],Yd=e=>qd[e],nm=e=>e==="delete"?"danger":"info",am=(e,t,s,n)=>s.error!==void 0?null:s.cancelled?{severity:"warning",title:Gd(s.done),detail:Vd(e,s.done,t,n)}:{severity:"info",title:Hd(e,s.done,n)},Xd=100,Jd=(e,t)=>e.kind==="move"?[t,e.destinationMailboxId]:[t],Zd=({mailboxId:e,accountId:t,enabled:s,predicateKey:n,searchQuery:r})=>{const[o,i]=l.useState({kind:"idle"}),[c,d]=l.useState(void 0),[v,m]=l.useState(void 0),b=l.useRef(!1),p=l.useRef(!1),g=oe(),{pushError:h}=be();l.useEffect(()=>{p.current||(b.current=!0),i({kind:"idle"})},[s,n]);const u=l.useRef(r);u.current=r;const f=l.useCallback(I=>async F=>{const{data:O}=await Vs({path:{mailboxId:e},query:{...I,continuationToken:F,limit:Xd},throwOnError:!0});return{ids:(O.items??[]).map(_=>_.messageId),continuationToken:O.continuationToken}},[e]),x=l.useCallback(async()=>{const{data:I}=await Vs({path:{mailboxId:e},query:{...u.current,count:!0,results:!1},throwOnError:!0});if(I.count===void 0)throw new Error("the search returned no count for the selection");return I.count},[e]),C=l.useCallback(I=>async F=>{if(I.kind==="move"){const{data:_}=await no({body:{messageIds:F,destinationMailboxId:I.destinationMailboxId},throwOnError:!0});return _}if(I.kind==="markRead"){const{data:_}=await ao({body:{messageIds:F,isRead:!0},throwOnError:!0});return _}const{data:O}=await ro({body:{messageIds:F},throwOnError:!0});return O},[]),y=l.useCallback(I=>{ke(g,ye(Jd(I,e))),t&&g.invalidateQueries({queryKey:We({path:{accountId:t}})})},[g,e,t]),j=l.useCallback(()=>{b.current=!1,i({kind:"counting"}),x().then(I=>{if(b.current){i({kind:"idle"});return}i({kind:"escalated",total:I})},I=>{h(Ws("Couldn't count matching messages","The count didn't finish.",I)),i({kind:"idle"})})},[x,h]),N=l.useCallback(()=>{b.current=!0},[]),M=l.useCallback(()=>{p.current||(b.current=!0,i({kind:"idle"}))},[]),P=l.useCallback(async(I,F)=>{b.current=!1,p.current=!0,d(I);const O=k=>m(Cc(k)),_=C(I),D=f(u.current);let K;try{K=F!==void 0?await Ka(F,_,O,()=>b.current):await wc(D,o.kind==="escalated"?o.total:0,_,O,()=>b.current)}finally{p.current=!1}return d(void 0),m(void 0),i({kind:"idle"}),K.error&&h(Ws(Wd(I.kind,K.done),Yd(I.kind),K.error)),K.done>0&&y(I),K},[C,f,o,h,y]);return{phase:o,escalate:j,stop:N,clear:M,isRunning:c!==void 0,runningAction:c,progress:v,runAction:P}},eu=120,tu=({keyboardFocusedMessageId:e,openMessageId:t,enabled:s,open:n,delayMs:r=eu})=>{const o=l.useRef(n);o.current=n;const i=l.useRef(void 0);l.useEffect(()=>{const c=e;if(!s){i.current=c;return}if(c===void 0||c===t)return;if(c===i.current){i.current=void 0;return}const d=setTimeout(()=>o.current(c),r);return()=>clearTimeout(d)},[s,e,t,r])},nr="This account has no Junk folder appointed, so there is nowhere to file these. Appoint one under Settings › Folder roles.",su="These are already in Junk, so there is nowhere to file them.",nu=(e,t)=>e!==void 0&&e!==t?e:void 0,rm=(e,t)=>{if(nu(e,t)===void 0)return e===void 0?nr:su};function au(e,t){if(e.length!==0)return t!==void 0&&e.includes(t)?t:e[0]}const ru={title:"",navSlot:null,titleMeta:null,searchSlot:null,searchField:null,searchResults:null,makeFilterSlot:null},bs=l.createContext(ru),ar=()=>l.useContext(bs),ou="/settings/folders",iu=({isOpen:e,count:t,outcome:s,isDeleting:n=!1,onConfirm:r,onCancel:o})=>{const{Account:i}=Vn(),c=si(t,s);return s==="noTrash"?a.jsx(It,{isOpen:e,...c,onConfirm:()=>{window.location.assign(ou)},onCancel:o}):s==="unavailable"?a.jsx(i,{fallback:a.jsx(It,{isOpen:e,...c,confirmLabel:"Reload reader",onConfirm:()=>window.location.reload(),onCancel:o}),children:({signOut:d})=>a.jsx(It,{isOpen:e,...c,onConfirm:()=>d(),onCancel:o})}):a.jsx(It,{isOpen:e,...c,destructive:!0,isBusy:n||s==="unknown",onConfirm:r,onCancel:o})},rr=8,or=e=>e==="From"||e==="FromDomain",lu=e=>({value:e.email,label:e.displayName??e.email,...e.displayName?{hint:e.email}:{},...e.fromSelection?{source:"selected"}:{}}),cu=e=>{const t=za(e.email);if(t!==null)return{value:t,...e.fromSelection?{source:"selected"}:{}}},du=(e,t)=>e.value.toLowerCase().includes(t)||(e.label??"").toLowerCase().includes(t),uu=(e,t,s)=>{if(!or(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"?lu(i):cu(i);if(!c)continue;const d=c.value.toLowerCase();if(!(d===""||r.has(d))&&(r.add(d),d!==n&&!(n!==""&&!du(c,n))&&(o.push(c),o.length===rr)))break}return o},fu=250,mu=2,pu=(e,t,s)=>{const n=t.trim(),r=oa(n,fu),o=e!==void 0&&or(e),{data:i}=Z({...js({query:{q:r,limit:rr}}),enabled:o&&r.length>=mu});if(!o||e===void 0)return[];const c=[...s.map(d=>({email:d,fromSelection:!0})),...(i?.items??[]).map(d=>({email:d.normalizedEmail,...d.displayName?{displayName:d.displayName}:{}}))];return uu(e,n,c)},ir=12,hu=e=>{const{envelope:t}=e,s=t.from[0];return{id:t.messageId,sender:s?_a({normalizedEmail:s.normalizedEmail,displayName:s.displayName}):"Unknown",subject:t.subject??"(No subject)",date:Ye(t.date)}},gu=(e,t)=>{const s=e!==void 0&&t!==void 0,{data:n,isLoading:r}=Z({...oo({path:{mailboxId:e??""},query:{...t,limit:ir}}),enabled:s,staleTime:3e4});return{messages:(n?.items??[]).map(bu),isPending:s&&r}},bu=e=>({id:e.messageId,sender:e.fromName||e.fromEmail||"Unknown",subject:e.subject??"(No subject)",date:Ye(e.sentDate)}),xu=e=>Cs({queries:e.slice(0,ir).map(t=>({...zt({path:{messageId:t}}),staleTime:Number.POSITIVE_INFINITY})),combine:t=>({messages:t.map(s=>s.data).filter(s=>s!==void 0).map(hu),isPending:t.some(s=>s.isPending)})}),vu=e=>({matchOperator:"Or",literalClauses:Ht(e)}),yu=(e,t,s)=>{const n=pe(io()),{mutate:r,reset:o}=n,[i,c]=l.useState(!1),d=l.useMemo(()=>qt(s),[s]),v=l.useCallback(()=>{!e||!t||(c(!1),r({path:{accountId:e},body:en({anchorMessageId:t,matchOperator:"And",literalClauses:[]})}))},[e,t,r]),m=l.useCallback(()=>{c(!1),o()},[o]),b=n.data,p=b?.semanticUnavailable===!0&&!i&&d.length>0;l.useEffect(()=>{!p||!e||(c(!0),r({path:{accountId:e},body:en(vu(d))}))},[p,e,d,r]);const g=i||(b?.semanticUnavailable??!1),h=n.isPending||p,u=i?{matchOperator:"Or",literalClauses:Ht(d)}:{...t?{anchorMessageId:t}:{},matchOperator:"And",literalClauses:[]};return{preview:v,reset:m,matchedCount:h?void 0:b?.matchedCount,messageIds:h?void 0:b?.messageIds,semanticUnavailable:g,senderFallback:i,senders:d,matchPredicate:u,isPending:h,isError:n.isError,error:n.error}},ku=()=>[Qn({path:{mailboxId:""}}),qn({path:{mailboxId:""}}),Hn()].map(e=>[{_id:e[0]._id}]),ju=e=>Ba(e)?e.pages:Qa(e)?[e]:[],wu=e=>typeof e=="object"&&e!==null&&typeof e.messageId=="string",Cu=(e,t)=>{const s=new Set(t),n=new Map;for(const r of e)for(const o of ju(r))for(const i of o.items){if(!wu(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)},Su=e=>{const t=oe(),s=e.join("\0");return l.useMemo(()=>{const n=ku().flatMap(r=>t.getQueriesData({queryKey:r}).map(([,o])=>o));return Cu(n,e)},[t,s])},Nu=new Set(["hasAttachment","isUnread","isRead","isStarred","category","before","after"]),Tu=e=>Nu.has(e),Eu=(e,{searchHadSemanticReach:t})=>{const s=[],n=[];let r,o;for(const d of e.tokens){if(d.type==="from"){s.push({field:"From",value:d.value});continue}if(d.type==="subject"){s.push({field:"Subject",value:d.value});continue}if(d.type==="in"){r={mailboxId:d.mailboxId,label:d.value};continue}if(d.type==="account"){o=d.accountId;continue}Tu(d.type)&&n.push({type:d.type,label:ea(d)})}const i=e.freeText.trim(),c=i.length>0;return c&&s.push({field:"HasWords",value:i}),{clauses:s,matchOperator:"all",scopedOut:r,droppedFacets:n,targetAccountId:o,keptTerms:c,droppedSemantic:c&&t}},Iu=(e,t,s)=>e.targetAccountId??t??s[0]?.accountId,Mu=({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",Ru={clauses:[],matchOperator:"any"},Au={clauses:[],matchOperator:"all",droppedFacets:[],keptTerms:!1,droppedSemantic:!1},$u=[],Fe={state:"saving",matched:0,applied:0,failed:0,failures:[]},is=(e,t)=>e.map((s,n)=>({...s,id:`${t}-${n}`})),An=(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},ls=e=>e==="move"||e==="junk"||e==="organize",$n=e=>e==="junk"?nr:"No destination was chosen, so there is nowhere to file these. Go back and pick a folder.";function Lu({verb:e,accountId:t,mailboxId:s,selection:n,selectionRestriction:r,escalated:o,escalatedProgress:i,searchConversion:c,onFinished:d,onRunEnded:v,step:m,goToStep:b,goBack:p,closeWizard:g}){const[h]=l.useState(()=>c),[u]=l.useState(()=>o),f=h!==void 0,[x,C]=l.useState(f?"properties":"selected"),y=u?"escalated":x,[j,N]=l.useState(()=>h?{clauses:is(h.clauses,"search"),matchOperator:h.matchOperator}:Ru),[M,P]=l.useState(void 0),[I,F]=l.useState(void 0),[O,_]=l.useState(!1),[D,K]=l.useState(void 0),[k,R]=l.useState(void 0),[A,S]=l.useState(),E=l.useRef(!1),w=l.useRef(!1),L=l.useMemo(()=>n.map(T=>T.id),[n]),U=l.useMemo(()=>n.map(T=>T.email).filter(Boolean),[n]),X=L[0],Q=Su(L),{junkMailboxId:ie}=Va(t),ee=yu(u?void 0:t,X,U),{preview:he}=ee;l.useEffect(()=>{he()},[he]);const se=y==="similar"||y==="properties",de=l.useMemo(()=>({matchOperator:j.matchOperator==="all"?"And":"Or",literalClauses:j.clauses.map(T=>({field:T.field,value:T.value}))}),[j.clauses,j.matchOperator]),ue=y==="similar"?ee.matchPredicate:de,{count:le,matchedIds:fe}=oi(se?t:void 0,ue),G=xu(se?fe:[]),ae=gu(u?s:void 0,u?.searchQuery),B=u?{status:"ready",count:u.total}:se?le:{status:"ready",count:n.length},{data:q}=Z({...bt({path:{accountId:t??""}}),enabled:!!t,staleTime:Number.POSITIVE_INFINITY}),te=Wa(t),je=ia(),Wt=l.useMemo(()=>ca({mailboxes:q?.items??[],folderAppointments:te,currentMailboxId:s,translator:je}),[q?.items,te,s,je]),{createFolderIn:wt}=la(t),Ct=Wt.find(T=>T.id===j.moveMailboxId)?.label,Je=oc(n.map(T=>({normalizedEmail:T.email,displayName:T.sender}))),Ze=pc({match:y==="properties"&&j.clauses[0]?.value.trim()||void 0,sender:Je?_a(Je):void 0,folder:Ct}),H=l.useMemo(()=>({...j,name:j.name??Ze}),[j,Ze]),St=pu(M?.draft.field,M?.draft.value??"",U),me=ii(t),we=li(t),Re=Zd({mailboxId:s??"",accountId:t,enabled:!1,predicateKey:"selection-wizard",searchQuery:{}}),{runAction:et}=Re,re=uo({verb:e,mode:y,scope:j.scope,fromSearch:f}),Y=re[Ys(re,m)],Ae=fo(t,r),$e=(T=>{if(T==="folder")return Ae.destination;if(T==="rule")return H.scope==="standing"||H.scope==="until"?Ae.rule:void 0})(Y)??mo(Y,H,B),tt=l.useCallback(()=>is(mc(U,Q),"seed"),[U,Q]),_e=l.useCallback(T=>{C(T),N($=>({...$,widen:T==="similar"&&X?{anchorCount:Math.max(n.length,1)}:void 0,...T==="properties"&&$.clauses.length===0?{clauses:tt()}:{}}))},[X,n.length,tt]),st=l.useCallback(()=>{_(!0),C("properties"),N(T=>({...T,widen:void 0,clauses:is(Ht(U),"sender"),matchOperator:"any"})),b("properties")},[U,b]),Le=ee.semanticUnavailable||ee.isError;l.useEffect(()=>{Y==="match"&&(y!=="similar"||!Le||O||st())},[Y,y,Le,O,st]);const nt=l.useCallback(()=>{P({mode:"add",draft:{field:"From",value:""}})},[]),at=l.useCallback(T=>{const $=j.clauses.find(W=>W.id===T);$&&P({mode:"edit",clauseId:T,draft:{field:$.field,value:$.value}})},[j.clauses]),rt=l.useCallback(T=>{N($=>({...$,clauses:$.clauses.filter(W=>W.id!==T)}))},[]),ne=l.useCallback(T=>{P($=>$&&{...$,draft:T})},[]),xe=l.useCallback(()=>{P(T=>{if(!T)return;const $=ci(T.draft.field,T.draft.value),W={...T.draft,value:$};N(Ue=>({...Ue,clauses:T.clauseId?Ue.clauses.map(ot=>ot.id===T.clauseId?{...ot,...W}:ot):[...Ue.clauses,{id:crypto.randomUUID(),...W}]}))})},[]),ur=l.useCallback(()=>{if($e){F(Y);return}F(void 0);const T=re[Ys(re,Y)+1];T&&b(T)},[$e,Y,re,b]),Yt=l.useCallback(async T=>{const $=An(e,H.moveMailboxId,ie);if(!$){R({matched:T.length,failureReason:$n(e)});return}R({matched:T.length});const W=await et($,[...T]);R({matched:T.length,outcome:W}),w.current&&v?.($.kind,T.length,W)},[e,H.moveMailboxId,ie,et,v]),Xt=l.useCallback(async()=>{if(!u)return;const T=An(e,H.moveMailboxId,ie);if(!T){R({matched:u.total,failureReason:$n(e)});return}R({matched:u.total});const $=await u.run(T);R({matched:u.total,outcome:$}),w.current&&v?.(T.kind,u.total,$)},[u,e,H.moveMailboxId,ie,v]),{start:Nt}=me,{createFilterAsync:Us}=we,Tt=l.useCallback(()=>{if(u){Xt();return}const T=di({mode:x,ruleScope:H.scope}),$=ui({mode:x,ruleScope:H.scope,anchorMessageId:X,clauses:H.clauses,matchOperator:H.matchOperator,moveMailboxId:H.moveMailboxId,until:H.until});if(K(T),T==="standing"||T==="temporary"){const W=fi($)?$:void 0;S(W),Us($,T,(H.name??"").trim()).then(Ue=>{Ue&&W&&Nt(W)});return}if(T==="all-like-these"&&ls(e)){Nt($);return}Yt(T==="just-these"?L:fe)},[u,Xt,x,H,X,e,L,fe,Us,Nt,Yt]),fr=l.useCallback(()=>{if($e){F(Y);return}E.current||(E.current=!0,b("run"),Tt())},[$e,Y,b,Tt]),Ks=l.useCallback(T=>{const $=me.progress,W=Mu({failure:me.failure,isStarting:me.isStarting,isRunning:me.isRunning,isDone:me.isDone,failedCount:$.failedCount,ruleSaved:T});return W==="saving"||W==="commitFailed"||W==="backApplyStartFailed"?{...Fe,state:W}:{state:W,matched:$.matchedCount,applied:$.appliedCount,failed:W==="backApplyFailed"||W==="backApplyRestartFailed"?$.failedCount:0,failures:[]}},[me]),Bs=l.useMemo(()=>{const T=new Map;for(const $ of[...n,...G.messages,...ae.messages])T.set($.id,$);return T},[n,G.messages,ae.messages]),Qs=u?i:Re.progress,qs=l.useCallback(()=>{if(!k)return Fe;const{matched:T,outcome:$,failureReason:W}=k;if(W!==void 0)return{...Fe,state:"commitFailed",failureReason:W};if(!$){const Ke=Qs?.done??0;return{state:"backApplyRunning",matched:Math.max(T,Ke),applied:Ke,failed:0,failures:[]}}if(!($.cancelled||$.error!==void 0))return{state:"backApplyComplete",matched:Math.max(T,$.done),applied:$.done,failed:0,failures:[]};if($.done===0)return{...Fe,state:"commitFailed"};const ot=$.failedIds.map(Ke=>Bs.get(Ke)).filter(Ke=>Ke!==void 0),br=$.failedIds.length>0?$.failedIds.length:Math.max(T-$.done,1);return{state:"runStopped",matched:Math.max(T,$.done),applied:$.done,failed:br,failures:ot}},[k,Qs,Bs]),Pe=u?qs():D==="standing"||D==="temporary"?we.isError?{...Fe,state:"commitFailed"}:we.isSuccess?A?Ks(!0):{...Fe,state:"filterSaved"}:Fe:D==="all-like-these"&&ls(e)?Ks(!1):qs(),mr=()=>{if(Pe.state==="statusUnknown"){me.refreshStatus();return}if(u){Xt();return}if(D==="standing"||D==="temporary"){if(we.isError){we.reset(),Tt();return}A&&Nt(A);return}if(D==="all-like-these"&&ls(e)){Tt();return}const T=k?.outcome?.failedIds??[];Yt(T.length>0?T:L)},pr=l.useCallback(()=>{g(re,Y)},[g,re,Y]),Jt=l.useCallback(()=>{w.current=!0,g(re,Y),d()},[g,re,Y,d]),{stop:Hs}=Re,hr=k!==void 0&&k.outcome===void 0&&k.failureReason===void 0,gr=l.useCallback(()=>{if(u){u.stop();return}Hs()},[u,Hs]);vc({shouldBlockFn:({action:T})=>T!=="BACK"?!1:(Jt(),!0),enableBeforeUnload:!1,disabled:Y!=="run"});const Zt={messages:u?ae.messages:se?G.messages:n,count:B,label:y==="selected"?"Your selection":"A sample of what matches",emptyReason:y==="similar"&&Le?"notIndexed":"noMatch",loading:u?ae.isPending:se&&(B.status==="loading"||G.isPending)};return a.jsx(po,{verb:e,steps:re,step:Y,blockedReason:$e,nudged:I===Y,onBack:p,onExit:Y==="run"?Jt:pr,onContinue:ur,onCommit:fr,match:{selectedCount:n.length,mode:y,accountId:Ae.accountId,onModeChange:_e,semanticUnavailable:Le,semanticErrorDetail:ee.error instanceof Error?ee.error.message:void 0,semanticFallbackTaken:O,onSemanticFallback:st,escalatedScope:u?.scope,sample:Zt},properties:{clauses:H.clauses,matchOperator:H.matchOperator,onMatchOperatorChange:T=>N($=>({...$,matchOperator:T})),clauseEdit:M,onStartAddClause:nt,onStartEditClause:at,onRemoveClause:rt,onChangeDraft:ne,onSubmitClause:xe,onCancelClause:()=>P(void 0),clauseFields:mi,clauseSuggestions:St,conversionNotice:h?gc(h):void 0,semanticFallbackTaken:O,sample:{...Zt,label:"What this matches"}},folder:{folders:Wt,mailboxId:H.moveMailboxId,delimiter:da(q?.items??[]),onSelect:T=>N($=>({...$,moveMailboxId:T})),onCreateFolder:t?wt:void 0,restriction:Ae.destination},rule:{draft:H,onScopeChange:T=>N($=>({...$,scope:T})),onUntilChange:T=>N($=>({...$,until:T})),restriction:Ae.rule},name:{name:H.name??"",onNameChange:T=>N($=>({...$,name:T})),nudged:I===Y},review:{verb:e,mode:y,selectedCount:n.length,clauses:H.clauses,matchOperator:H.matchOperator,folder:Ct,scope:H.scope,until:H.until,ruleName:re.includes("name")?H.name:void 0,escalatedScope:u?.scope,sample:Zt},run:{state:Pe.state,verb:e,scope:H.scope,matched:Pe.matched,applied:Pe.applied,failedCount:Pe.failed,failures:Pe.failures,failureReason:Pe.failureReason,onRetry:mr,onDismiss:Jt,onCancelRun:hr?gr:void 0}})}function om(e){const t=lo()==="search",{searchConversion:s}=ar(),{accounts:n}=Ut(),{step:r,goToStep:o,goBack:i,closeWizard:c}=co(t?"properties":"match");if(!r)return null;const d=t?s??Au:void 0;return a.jsx(Lu,{...e,...d?{verb:"organize",accountId:Iu(d,e.accountId,n),selection:$u,selectionRestriction:void 0,escalated:void 0,searchConversion:d}:{},step:r,goToStep:o,goBack:i,closeWizard:c})}const Pu=[],Os=l.createContext(null),Du=e=>{const t=l.useContext(Os);return t?t.rowInteraction(e):null},Fu=()=>{const e=l.useContext(Os);if(!e)throw new Error("useThreadListSelection must be used inside <ThreadListInteraction>");return e},Ou="[data-message-id]",zu=e=>Array.from(e.querySelectorAll(Ou)).map(t=>t.dataset.messageId).filter(t=>t!==void 0),_u=(e,t)=>e.length===t.length&&e.every((s,n)=>s===t[n]),Uu=e=>{const[t,s]=l.useState([]);return l.useEffect(()=>{const n=e.current;if(!n)return;const r=()=>{const i=zu(n);s(c=>_u(c,i)?c:i)};r();const o=new MutationObserver(r);return o.observe(n,{childList:!0,subtree:!0}),()=>o.disconnect()},[e]),t};function im({selectedMessageId:e,rows:t,onOpen:s,onDeleteMessages:n,onSelectionVerb:r,wizardOpen:o=!1,isDeleting:i=!1,commandsRef:c,onTriageContextChange:d,children:v}){const m=Ss(),{pushError:b}=be(),p=l.useRef(null),g=Uu(p),h=bc({orderedIds:g,isDesktop:m,initialFocusedId:e}),{focusedMessageId:u,setFocusedMessageId:f,pendingDomFocusRef:x,cursorMovedByPointerRef:C,selection:y,isMultiSelectMode:j,exitSelection:N,handleRowSelect:M}=h,{selectedIds:P,selectedCount:I,isSelected:F,toggle:O,select:_,toggleAll:D}=y,K=g.length>0&&g.every(G=>P.has(G)),k=l.useCallback(()=>{g.length>0&&D(g)},[g,D]),{intersectWith:R}=y;l.useEffect(()=>{R(g)},[R,g]),l.useEffect(()=>{const G=x.current;G!==null&&(x.current=null,p.current?.querySelector(`[data-message-id="${G}"]`)?.focus())});const A=l.useCallback(G=>{C.current=!0,f(G)},[C,f]),S=l.useCallback(G=>{m||_(G)},[m,_]),E=l.useCallback(()=>{u&&s(u)},[u,s]),w=l.useCallback(G=>s(G,{replace:!0}),[s]);tu({keyboardFocusedMessageId:h.keyboardFocusedMessageId,openMessageId:e,enabled:m&&I===0,open:w});const[L,U]=l.useState(null),X=_d(L?.targets??Pu),Q=l.useCallback(G=>{if(L!==null)return!0;if(I>0)return r(G),!0;if(G!=="delete"||!u)return!1;const ae=t.find(B=>B.id===u);return!ae?.mailboxId||!ae.accountId?(b({title:"Couldn't delete this message",detail:"This list has lost track of which account and folder it is in, so reader can't tell whether deleting it would move it to Trash or erase it. Nothing was deleted.",action:{label:"Reload the list",href:window.location.href}}),!0):(U({ids:[u],targets:[{accountId:ae.accountId,mailboxId:ae.mailboxId}]}),!0)},[L,I,r,u,t,b]),ie=l.useCallback(()=>{L!==null&&(n(L.ids),U(null),N())},[L,n,N]),ee=l.useCallback(()=>U(null),[]),he=l.useCallback(()=>I===0?!1:(N(),!0),[I,N]),se=g.length>0;l.useEffect(()=>{if(c){if(!se){c.current=null;return}return c.current={focusNext:h.focusNext,focusPrevious:h.focusPrevious,focusFirst:h.focusFirst,focusLast:h.focusLast,openFocused:E,toggleSelect:h.toggleFocusedSelection,extendSelectDown:h.extendRangeDown,extendSelectUp:h.extendRangeUp,selectAll:h.selectAllLoaded,clearSelection:he,requestVerb:Q,toggleDensity:()=>{}},()=>{c.current=null}}},[c,se,h.focusNext,h.focusPrevious,h.focusFirst,h.focusLast,h.toggleFocusedSelection,h.extendRangeDown,h.extendRangeUp,h.selectAllLoaded,E,he,Q]);const de=l.useMemo(()=>Array.from(P),[P]),ue=L!==null;l.useEffect(()=>{d?.({focusedMessageId:u,selectedIds:de,orderedIds:g,hasList:se,blocksKeyboard:ue||o})},[d,u,de,g,se,ue,o]);const le=au(g,u),fe=l.useMemo(()=>({selectedIds:P,selectedCount:I,exitSelection:N,startSelectionVerb:r,orderedIds:g,allSelected:K,toggleAllLoaded:k,rowInteraction:G=>({focused:G===u,isTabStop:G===le,isDesktop:m,onFocusRow:A,selection:{isChecked:F(G),onToggleCheck:O,onRowSelect:M,isMultiSelectMode:j,onLongPress:S}})}),[P,I,N,r,g,K,k,u,le,m,A,F,O,M,j,S]);return a.jsxs(Os.Provider,{value:fe,children:[a.jsx("div",{ref:p,className:"contents",children:v}),a.jsx(iu,{isOpen:ue,count:L?.ids.length??0,outcome:X,isDeleting:i,onConfirm:ie,onCancel:ee})]})}function lm({title:e,isDeleting:t}){const s=ar(),{selectedCount:n,exitSelection:r,startSelectionVerb:o,orderedIds:i,allSelected:c,toggleAllLoaded:d}=Fu();return a.jsx(Kl,{title:s.title||e,navSlot:s.navSlot,titleMeta:s.titleMeta,searchSlot:s.searchSlot,searchField:s.searchField,idleSlot:s.makeFilterSlot,count:n,onCancel:r,onDelete:()=>o("delete"),onMarkRead:()=>o("markRead"),isBusy:t,selectAll:i.length>0?{checked:c,indeterminate:n>0&&!c,onChange:d}:void 0})}const cs=e=>{e.preventDefault(),e.stopPropagation()},Ku=(e,t)=>{const s=l.useRef(!1),n=l.useCallback(i=>{if(s.current=!1,i.button!==0)return;const c=ms(i);dn(c)&&t?.(e,c)&&(cs(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,cs(i),!0;const c=ms(i);return!dn(c)||!t?.(e,c)?!1:(cs(i),c.shiftKey&&window.getSelection()?.removeAllRanges(),!0)},[t,e]);return{onMouseDown:n,onContextMenu:r,claimClick:o}},Bu=({thread:e,active:t=!1,focused:s,isTabStop:n,density:r="comfortable",isDesktop:o,badge:i,selection:c,inListbox:d=!1,link:v,onClick:m,onFocusRow:b})=>{const p=oe(),g=e.id,h=Du(g),u=s??h?.focused??!1,f=n??h?.isTabStop??!1,x=c??h?.selection,C=b??h?.onFocusRow,y=o??h?.isDesktop??!0,j=x?.isChecked??!1,N=x?.isMultiSelectMode??!1,M=x?.onToggleCheck,P=x?.onRowSelect,I=x?.onLongPress,F=l.useCallback(w=>{w.preventDefault(),w.stopPropagation(),M?.(g)},[M,g]),O=Ku(g,P),_=l.useCallback(w=>{if(!O.claimClick(w)){if(!y){if(N){w.preventDefault(),w.stopPropagation(),M?.(g);return}m?.();return}P?.(g,ms(w)),m?.()}},[O,y,N,M,P,m,g]),D=l.useCallback(()=>{I?.(g)},[I,g]),{longPressProps:K}=Cl({onLongPress:D,accessibilityDescription:j?"Deselect message":"Select message"}),k=l.useCallback(()=>{p.prefetchQuery(zt({path:{messageId:g}}))},[p,g]),R=l.useCallback(()=>{k(),C?.(g)},[k,C,g]),A=xt({"data-list-row":"","data-message-row":!0,"data-message-id":g,...d?{role:"option","aria-selected":j}:{},tabIndex:f?0:-1,onClick:_,onMouseDown:O.onMouseDown,onContextMenu:O.onContextMenu,onMouseEnter:k,onFocus:R},y||!x?{}:K),S=z(r==="compact"?Ta({active:t,focused:u}):z("group",Ms({active:t,focused:u})),"outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-inset",j&&"bg-accent-soft",!y&&"min-h-11 select-none [-webkit-touch-callout:none]"),E=r==="compact"?a.jsx(Ea,{thread:e}):a.jsx(Rs,{thread:e,badge:i,selection:x?{checked:j,alwaysVisible:N,onToggle:F}:void 0});return v===void 0?a.jsx("button",{type:"button",...A,className:S,children:E}):a.jsx(aa,{to:"/mail/$mailboxId/$threadId/$messageId",params:{...v,messageId:g},search:w=>w,variant:"row",...A,className:S,children:E})},cm=l.memo(Bu),Qu="Open a message first",qu="This conversation hasn't loaded yet",Hu="The mailbox list hasn't loaded yet",Gu="Couldn't find this mailbox's account — reload to try again",Vu={reply:"Reply",replyAll:"Reply all",forward:"Forward",delete:"Move to Trash",move:"Move to mailbox",flag:"Star"},dm=({hasThread:e,messageId:t,intelligenceOpen:s,canToggleIntelligence:n,onToggleIntelligence:r,onReply:o,onReplyAll:i,onForward:c,onDelete:d,onToggleStar:v,isStarred:m,moveContext:b,moveContextLoading:p})=>{const[g,h]=l.useState(null),u=t??null,f=I=>e?I==="move"?b?null:p?Hu:Gu:{reply:o,replyAll:i,forward:c,delete:d,flag:v}[I]?null:qu:Qu,x=g&&g.messageId===u?g:null,C=x?f(x.action):null,y=x?.action==="move"&&x.overThread&&!!b,j=C??(x&&!y?`${Vu[x.action]} is ready — press it again`:null),N=I=>h({action:I,messageId:u,overThread:e}),M=I=>()=>N(I),P=(I,F)=>F?()=>{h(null),F()}:M(I);return a.jsx(Nl,{hasThread:e,isStarred:m,onUnavailable:N,unavailableHint:j,replyTitle:`Reply ${it("reply")}`,replyAllTitle:`Reply all ${it("replyAll")}`,forwardTitle:`Forward ${it("forward")}`,deleteTitle:`Move to Trash ${it("delete")}`,flagTitle:`Star ${it("toggleStar")}`,onReply:P("reply",o),onReplyAll:P("replyAll",i),onForward:P("forward",c),onDelete:P("delete",d),onToggleStar:P("flag",v),onMove:M("move"),moveSlot:b?a.jsx(Fs,{accountId:b.accountId,currentMailboxId:b.currentMailboxId,onMove:b.onMove,label:"Move to mailbox",defaultOpen:y}):void 0,children:a.jsx(Sl,{open:s,enabled:n,onToggle:r})})};function Wu(e){const[t,s]=l.useState(null);t!==null&&t!==e&&s(null);const n=e!==null&&t===e,r=l.useCallback(()=>s(null),[]),o=l.useCallback(()=>s(e),[e]),i=l.useCallback(()=>s(n?null:e),[n,e]);return{isOpen:n,open:o,close:r,toggle:i}}const um=e=>{const{intelligenceOpen:t,onToggleIntelligence:s}=Ut(),n=Yn()?.showIntelligencePane??!1,r=e??null,o=Wu(r),i=!n&&o.isOpen,{open:c,toggle:d}=o,v=l.useCallback(()=>{if(n){s();return}d()},[n,s,d]),m=l.useCallback(()=>{!n||t||s()},[n,t,s]);return{canToggle:r!==null,isShowing:r!==null&&(n?t:i),toggle:v,open:n?s:c,drawerOpen:i,closeDrawer:o.close,railFits:n,openRail:m}},Yu=()=>{const e=oe();return l.useCallback(t=>{const s=Ie({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])},fm=({thread:e,mailboxId:t,accountId:s,onAfterOptimisticRemove:n})=>{const r=t??e?.mailboxId,o=s??e?.accountId,{accountId:i}=$s(o?void 0:r),c=o??i,d=Yu(),{deleteMessages:v}=Ds({mailboxId:r??"",threadId:e?.threadId,accountId:c,onAfterOptimisticRemove:n}),{moveMessages:m}=Vt({mailboxId:r??"",threadId:e?.threadId,accountId:c,onAfterOptimisticRemove:n}),{toggleStar:b}=Ha({threadId:e?.threadId??"",mailboxId:r??""}),p=l.useCallback(()=>{e&&v(d(e))},[e,d,v]),g=l.useCallback(u=>{e&&m(d(e),u)},[e,d,m]),h=l.useCallback(()=>{e&&b(e.messageId,e.hasStars)},[e,b]);return{mailboxId:r,accountId:c,isStarred:e?.hasStars,deleteThread:p,moveThread:g,toggleStar:h}},mm=(e,t)=>{const{data:s}=Z({...Wn({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},Ln=(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]},pm=()=>{const[e,t]=l.useState(void 0),[s,n]=l.useState([]),[r,o]=l.useState([]),i=l.useRef(null),[c,d]=l.useState(!1),[v,m]=l.useState(!1),b=l.useCallback(p=>{t(p.focusedMessageId),n(p.selectedIds),p.orderedIds&&o(p.orderedIds),d(p.hasList),m(p.blocksKeyboard)},[]);return{listCommandsRef:i,onTriageContextChange:b,focusedMessageId:e,selectedIds:s,orderedIds:r,hasList:c,blocksKeyboard:v}},hm=({context:e,orderedIds:t,selectedMessageId:s,enabled:n=!0,onClose:r,handlers:o})=>{const{listCommandsRef:i,hasList:c,blocksKeyboard:d}=e,v=l.useCallback(()=>{i.current?.clearSelection()||s&&r()},[i,s,r]);return No({enabled:n&&!d,handlers:{...c?{focusNext:()=>i.current?.focusNext(),focusPrevious:()=>i.current?.focusPrevious(),focusFirst:()=>i.current?.focusFirst(),focusLast:()=>i.current?.focusLast(),openFocused:()=>i.current?.openFocused(),toggleSelect:()=>i.current?.toggleSelect(),extendSelectDown:()=>i.current?.extendSelectDown(),extendSelectUp:()=>i.current?.extendSelectUp(),selectAll:()=>i.current?.selectAll(),toggleDensity:()=>i.current?.toggleDensity()}:{},back:v,...o}}),{goBack:v,nextMessageId:Ln(t,s,"next")??void 0,previousMessageId:Ln(t,s,"previous")??void 0}},Xu={sender:"sender",recipient:"recipient",subject:"subject",attachment:"attachment",body:"body",entities:"entities"};function Ju(e){return Xu[e]??e}function gm(e,t){const{folder:s}=ws(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:Ye(e.sentDate),unread:!e.isRead,flagged:e.hasStars===!0,threadId:e.threadId,mailboxId:e.mailboxId,...s?{folder:s}:{}}}function bm(e,t){const{folder:s}=ws(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 Zu(e,t){const{mailboxId:s,folder:n}=ws(t,e.mailboxIds);return{id:e.messageId,sender:e.fromName??"Unknown",subject:e.subject??"(No subject)",snippet:"",date:e.sentDate!=null?Ye(e.sentDate*1e3):"",threadId:e.threadId,matchedChunkLabel:Ju(e.matchedChunkType),score:e.score,...s?{mailboxId:s}:{},...n?{folder:n}:{}}}function xm(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(Zu(o,s)));return r}function vm(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:Ye(e.sentDate),sentDate:e.sentDate,isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Ga(e.category),suspicious:t}}function ym(e){return e.filter(t=>t.muted!==!0)}function km(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 Pn=[{id:"personal",label:"Personal",category:ve.personal},{id:"transactional",label:"Transactional",category:ve.transactional},{id:"newsletter",label:"Newsletter",category:ve.newsletter},{id:"marketing",label:"Marketing",category:ve.marketing},{id:"social",label:"Social",category:ve.social},{id:"automated",label:"Automated",category:ve.automated},{id:"uncategorized",label:"Unclassified",category:ve.uncategorized}];function jm(e){const t=new Map(Pn.map(n=>[n.category,[]]));for(const n of e){const r=n.category??ve.uncategorized;(t.get(r)??t.get(ve.uncategorized))?.push(n)}const s=[];for(const n of Pn){const r=t.get(n.category);r&&r.length>0&&s.push({id:n.id,label:n.label,threads:r})}return s}function wm(e,t){return e.fromName.toLowerCase().includes(t)||e.fromEmail.toLowerCase().includes(t)||e.subject.toLowerCase().includes(t)||e.snippet.toLowerCase().includes(t)}function Cm(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 lr=8;function zs(e,t){const s=Math.max(0,Math.min(t,e.length)),n=Uo(e).find(o=>s>=o.start&&s<=o.end);if(!n)return{start:s,end:s,raw:""};const r=Ko(n.raw);return r?{start:n.start,end:n.end,raw:n.raw,name:r.name,value:r.value}:{start:n.start,end:n.end,raw:n.raw}}function ef(e,t){const s=zs(e,t);if(s.name===void 0)return{kind:"token",query:s.raw};const n=ta(s.name);if(n)return{kind:"value",token:n.name,source:n.values,query:s.value??""}}const tf={mailbox:"mailboxes",account:"accounts",contact:"contacts"},sf=(e,t)=>{if(e.values==="fixed")return e.options??[];const s=tf[e.values];return s?t[s]??[]:[]},nf=(e,t)=>{if(t==="")return 1;const s=e.toLowerCase();return s.startsWith(t)?0:s.includes(t)?1:-1},xs=(e,...t)=>{let s=-1;for(const n of t){if(n===void 0)continue;const r=nf(n,e);r<0||(s<0||r<s)&&(s=r)}return s},cr=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,lr).map(s=>s.suggestion)},Dn=e=>({value:`${e.name}:`,label:`${e.name}:`,hint:e.label});function af(e){const t=e.trim().toLowerCase();if(t==="")return Js.map(Dn);const s=[];for(const n of Js)if(s.push({rank:xs(t,`${n.name}:`,n.label),suggestion:Dn(n)}),n.values==="fixed")for(const r of n.options??[]){const o=sa(n.name,r.value);s.push({rank:xs(t,o,r.label),suggestion:{value:o,label:r.label??o,hint:o}})}return cr(s)}function rf(e,t,s){const n=t.trim().toLowerCase(),r=sf(e,s).map(o=>({rank:xs(n,o.value,o.label),suggestion:{value:sa(e.name,o.value),label:o.label??o.value,...o.hint?{hint:o.hint}:{}}}));return cr(r)}function of(e,t,s={}){const n=zs(e,t);if(n.name===void 0)return af(n.raw);const r=ta(n.name);return r?rf(r,n.value??"",s):[]}function lf(e,t,s){const n=zs(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 cf=e=>({value:e.normalizedEmail,...e.displayName?{label:e.displayName,hint:e.normalizedEmail}:{}}),df=250,uf=2;function ff({query:e,cursor:t,enabled:s}){const{accounts:n}=Ut(),{mailboxesByName:r}=na(),o=r!==void 0,i=s?ef(e,t):void 0,c=i?.source==="contact"?i.query.trim():"",d=oa(c,df),{data:v}=Z({...js({query:{q:d,limit:lr}}),enabled:d.length>=uf}),m=Cs({queries:n.map(h=>({...bt({path:{accountId:h.accountId}}),staleTime:1/0}))}),b=l.useMemo(()=>o?To(m.map(h=>h.data?.items??[]),n):[],[o,m,n]),p=l.useMemo(()=>Eo(n),[n]),g=l.useMemo(()=>(v?.items??[]).map(cf),[v]);return l.useMemo(()=>{if(!s)return[];const h=of(e,t,{mailboxes:b,accounts:p,contacts:g});return o?h:h.filter(u=>u.value!=="in:")},[s,e,t,b,p,g,o])}const dr="remit.recentSearches",mf=5;function vs(){try{const e=localStorage.getItem(dr);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}catch{return[]}}function Fn(e){const t=e.trim();if(!t)return vs();const s=[t,...vs().filter(n=>n!==t)].slice(0,mf);try{localStorage.setItem(dr,JSON.stringify(s))}catch{return s}return s}const pf=e=>e.tier!=="phone"&&e.hasLiveInput&&!(e.bodyRendersCommittedResults&&e.hasCommittedQuery);function hf(e){const{spam:t}=La([...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 Sm({title:e,unreadCount:t,children:s,selectionBar:n,paneOverlay:r,footer:o,searchFilter:i,searchResults:c,searchLoading:d,relatedResults:v,relatedLoading:m,onSelectSearchResult:b,searchResultsLabel:p="Top matches",relatedResultsLabel:g="Related",searchResultsInBody:h=!1,refreshControl:u}){const{accounts:f,resultFolderIndex:x,searchQuery:C,searchInput:y,onSearchChange:j,onSearchClear:N,searchViewKey:M}=Ut(),P=na(),I=Gn(),F=Yn(),O=Io(),[_,D]=l.useState(!1),[K,k]=l.useState(vs),R=ho(),A=l.useRef(M);l.useEffect(()=>{A.current!==M&&(A.current=M,D(!1))},[M]);const[S,E]=l.useState(0),[w,L]=l.useState(!1),[U,X]=l.useState(void 0),Q=ff({query:y,cursor:S,enabled:w&&y.trim().length>0}),ie=l.useCallback(ne=>{const xe=lf(y,S,ne);j(xe.query),X({cursor:xe.cursor})},[y,S,j]),ee=go({count:Q.length,onAccept:ne=>{const xe=Q[ne];xe&&ie(xe)}}),{comboboxProps:he,handleKeyDown:se}=ee,de=l.useMemo(()=>({comboboxProps:he,onKeyDown:se,onCaretChange:E,onFocusChange:L,...U?{caret:U}:{}}),[he,se,U]),ue=ee.open?a.jsx(vo,{id:ee.listId,suggestions:Q,activeIndex:ee.activeIndex,optionId:ee.optionId,onPick:ie,onHighlight:ee.setActiveIndex,label:"Search suggestions",className:"mx-row-inset mt-1 shrink-0"}):null,le=y.trim().length>0,{mailboxesByName:fe,accountsByName:G}=P,ae=l.useMemo(()=>Bo(y,{mailboxesByName:fe,accountsByName:G}),[y,fe,G]),B=ae.tokens.map(ne=>({label:ea(ne),onRemove:()=>j(Qo(y,ne))})),q=c??[],te=v??[],je=le?[{id:"top",label:p,results:q},{id:"related",label:g,results:te}]:[],wt=!(q.length+te.length>0)&&(d===!0||m===!0),{scope:Ct}=Mo(f),Je=Xo({select:ne=>ne.matches}),Ze=hi(Je),H=gi(Je,Ct,Ze?x.get(Ze)?.role:void 0),St=H.kind==="global"?hf([...q,...te]):void 0,me=St?{kind:"global",onScopeToSpam:()=>I({to:"/mail/$mailboxId",params:{mailboxId:St.mailboxId},search:{q:C||void 0}})}:H,we=te.length>0,Re=l.useMemo(()=>Eu(ae,{searchHadSemanticReach:we}),[ae,we]),et=le?Re:void 0,re=le?{onClick:()=>{D(!1),R("properties","search")},blockedReason:hc(Re)?void 0:bo(Re.droppedFacets.map(ne=>ne.label))}:void 0,Y=re?a.jsx(Pa,{...re}):null,Ae=pf({tier:O,hasLiveInput:le,hasCommittedQuery:C.trim().length>0,bodyRendersCommittedResults:h}),_s=ne=>{k(Fn(y)),b?.(ne)},$e=a.jsx(Da,{value:y,sections:je,loading:wt,onSelectResult:_s,tokens:B,scope:me}),tt=n===void 0,_e=Ae?a.jsx("div",{className:"h-full overflow-y-auto",children:$e}):null,st=_e&&!tt?_e:s,Le=_e&&tt?_e:null,nt=Ro(O),at=nt&&(_||le),rt=l.useMemo(()=>({title:e,searchResults:Le,makeFilterSlot:Y,searchConversion:et,navSlot:F&&!F.showNavPane&&a.jsx(V,{variant:"ghost",size:"touch",icon:a.jsx(bi,{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(Xs,{}),u]}),searchSlot:nt&&!at&&a.jsx(V,{variant:"ghost",size:"touch",icon:a.jsx(xo,{className:"size-5"}),onClick:()=>D(!0),"aria-label":"Search",className:"shrink-0"}),searchField:at&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"min-w-0 flex-1",children:a.jsx(Xn,{value:y,onChange:j,onClear:N,globalFocusKey:!1,showClearButton:!1,suggest:de})}),a.jsx(V,{variant:"ghost",size:"touch",icon:a.jsx(Dt,{className:"size-5"}),onClick:()=>{N(),D(!1)},"aria-label":"Close search",className:"shrink-0"}),a.jsx(Xs,{})]})}),[e,t,F,nt,at,y,j,N,de,Le,Y,et,u]);if(O==="phone"&&_){const ne=xe=>{k(Fn(y)),D(!1),b?.(xe)};return a.jsxs(bs.Provider,{value:rt,children:[a.jsx(Ul,{value:y,onChange:j,onClear:N,onCancel:()=>{D(!1),N()},filter:i,recentSearches:K,onPickRecent:j,makeFilter:re,sections:je,loading:wt,onSelectResult:ne,tokens:B,scope:me,suggest:de,suggestList:ue}),r]})}return a.jsx(bs.Provider,{value:rt,children:a.jsxs("section",{className:"relative flex h-full w-full flex-col bg-surface",children:[n?.(rt),ue,a.jsx("div",{className:"min-h-0 flex-1",children:st}),o,r]})})}export{zd as $,em as A,Xf as B,Al as C,iu as D,vm as E,Cm as F,$s as G,Wf as H,mm as I,Ds as J,Vt as K,pm as L,cm as M,fm as N,Vf as O,Gf as P,Yu as Q,Ha as R,Kl as S,Ed as T,Md as U,Ad as V,Rd as W,hm as X,Wu as Y,Yf as Z,tm as _,yl as a,um as a0,dm as a1,Qf as a2,gm as a3,xm as a4,ym as a5,km as a6,wm as a7,bm as a8,La as a9,hf as aa,jm as ab,Bf as ac,pf as ad,Dl as ae,im as af,_f as ag,Fu as ah,Sm as ai,ke as aj,ye as ak,Ls as al,ht as am,Cl as an,xt as ao,Is as ap,ms as aq,Uf as ar,Kf as as,qf as at,lm as au,ar as b,Ms as c,Hf as d,Va as e,_d as f,xl as g,Zd as h,tu as i,rm as j,Hd as k,vc as l,sm as m,bl as n,nm as o,au as p,om as q,am as r,ml as s,Ga as t,Ku as u,nu as v,_c as w,Wa as x,Jf as y,Zf as z};
|