PageSourceSearch

https://harbor-os.com/assets/MessageCenter-3zEOLuJv.js

js harbor-os.com collected 2026-09-24 14:45:44 UTC 34,414 bytes, 1 lines download raw bytes

1import{u as fs,r as o,g as B,i as R,j as e,d2 as le,e0 as js,b_ as z,e as bs,X as Xe,cj as ws,by as Qe,bF as Ns,gJ as ys,aR as se,bR as Z,bQ as we,L as Ze,G as _,fB as Ye,b8 as vs,go as Ss,bG as Ie,bv as ks,aD as Cs,eW as Is,_ as Fs,dw as Ms,N as Ds,db as $s,bY as es,$ as Ps,cg as Ts,M as Os,bK as He,gK as Ge,bu as We,fx as Rs,aT as As,aF as Es,aK as zs}from"./vendor-BeA4siBz.js";import{n as Ks,u as ss,H as Us,B as u,g as Ls,I as ae,D as Fe,h as Me,j as De,k as $e,m as Je,l as as,f as F,q as i}from"./index-C2NQ_9nj.js";import{i as Pe,c as te,u as ne,a as Ne,r as re,b as he,d as Ve,f as qs}from"./notification-cache-DxRe_1-Z.js";import{T as Bs}from"./textarea-BzoSp81z.js";import{A as _s,a as Qs,b as Ys}from"./avatar-DeezITWg.js";import{D as ye,a as ve,b as Se,e as v,c as ie,d as Hs,f as Gs,g as Ws,h as Js}from"./dropdown-menu-BymWdUjc.js";import{I as Vs}from"./ImageLightbox-BQ7wLHui.js";const ts=[{key:"all",label:"All",icon:le},{key:"message",label:"Messages",icon:Ms},{key:"order",label:"Orders",icon:Ds},{key:"auction",label:"Auctions",icon:$s},{key:"notice",label:"Notices",icon:es},{key:"special",label:"Specials",icon:Ps},{key:"marketing",label:"Marketing",icon:Ts},{key:"email",label:"Emails",icon:Os}],ke={message:"bg-violet-500",order:"bg-blue-500",auction:"bg-amber-500",notice:"bg-slate-500",special:"bg-pink-500",marketing:"bg-fuchsia-500",email:"bg-emerald-600"};function Ce({category:m,className:k}){const g=ts.find(x=>x.key===m),b=(g==null?void 0:g.icon)||es;return e.jsx(b,{className:k||"h-4 w-4 text-white"})}function ns(m){const k=new Date(m),b=new Date().getTime()-k.getTime(),x=Math.floor(b/6e4);if(x<1)return"just now";if(x<60)return`${x}m ago`;const w=Math.floor(x/60);if(w<24)return`${w}h ago`;const S=Math.floor(w/24);return S<7?`${S}d ago`:k.toLocaleDateString()}function Xs(m){return m<1024?`${m} B`:m<1024*1024?`${(m/1024).toFixed(0)} KB`:`${(m/(1024*1024)).toFixed(1)} MB`}function Zs(m){const k=new Date(m),g=new Date,b=w=>new Date(w.getFullYear(),w.getMonth(),w.getDate()).getTime(),x=Math.round((b(g)-b(k))/864e5);return x===0?"Today":x===1?"Yesterday":x<7?"This Week":x<31?"This Month":"Older"}function ea({conversationId:m,myUserId:k}){const{toast:g}=ss(),[b,x]=o.useState(""),[w,S]=o.useState([]),[Q,K]=o.useState(!1),[xe,U]=o.useState([]),[pe,N]=o.useState(null),[C,P]=o.useState(null),h=o.useRef(null),A=o.useRef(null),{data:Y=[],isLoading:L}=B({queryKey:["/api/dm/conversations",m,"messages"],queryFn:()=>fetch(`/api/dm/conversations/${m}/messages?limit=30`).then(n=>{if(!n.ok)throw new Error("Failed to load messages");return n.json()})}),{data:M}=B({queryKey:["/api/message-center/attachments/policy"],staleTime:5*60*1e3}),{data:oe=[]}=B({queryKey:["/api/dm/conversations"],enabled:!!C});o.useEffect(()=>{var n;(n=A.current)==null||n.scrollIntoView({block:"nearest"})},[Y.length]);const q=R({mutationFn:async()=>{await F("POST",`/api/dm/conversations/${m}/messages`,{messageType:"text",body:b.trim()||void 0,attachmentIds:w.map(n=>n.id)})},onSuccess:()=>{x(""),S([]),i.invalidateQueries({queryKey:["/api/dm/conversations",m,"messages"]}),Pe(i)},onError:n=>g({title:"Send failed",description:(n==null?void 0:n.message)||"Please try again",variant:"destructive"})}),l=R({mutationFn:async n=>{C&&await F("POST",`/api/message-center/attachments/${C.id}/forward`,{conversationId:n})},onSuccess:()=>{P(null),g({title:"Forwarded",description:"The attachment was sent."}),Pe(i)},onError:n=>g({title:"Forward failed",description:(n==null?void 0:n.message)||"Please try again",variant:"destructive"})});async function T(n){if(!(!n||n.length===0)){K(!0);try{for(const f of Array.from(n)){if(M&&f.size>M.maxFileSizeMb*1024*1024){g({title:"File too large",description:`${f.name} is over ${M.maxFileSizeMb} MB`,variant:"destructive"});continue}const r=new FormData;r.append("file",f);const j=await fetch("/api/message-center/attachments",{method:"POST",body:r,credentials:"include"});if(!j.ok){const O=await j.json().catch(()=>({}));g({title:"Upload failed",description:(O==null?void 0:O.message)||f.name,variant:"destructive"});continue}const de=await j.json();S(O=>[...O,de])}}finally{K(!1),h.current&&(h.current.value="")}}}function y(n,f){const r=n.filter(j=>j.isImage);U(r.map(j=>j.url)),N(Math.max(0,r.findIndex(j=>j.id===f.id)))}return e.jsxs("div",{className:"border border-slate-200 rounded-lg bg-slate-50/50 mt-1",onClick:n=>n.stopPropagation(),children:[e.jsxs("div",{className:"max-h-72 overflow-y-auto p-3 space-y-2",children:[L&&e.jsx("div",{className:"py-4 text-center",children:e.jsx(_,{className:"h-4 w-4 animate-spin mx-auto text-slate-300"})}),!L&&Y.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground text-center py-3",children:"No messages yet."}),Y.map(n=>{const f=n.senderId===k;return e.jsx("div",{className:`flex ${f?"justify-end":"justify-start"}`,children:e.jsxs("div",{className:`max-w-[80%] rounded-xl px-3 py-1.5 text-[13px] ${f?"bg-primary text-white":"bg-white border border-slate-200 text-slate-700"}`,children:[n.body&&e.jsx("p",{className:"whitespace-pre-wrap break-words",children:n.body}),(n.attachments||[]).length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-1.5",children:(n.attachments||[]).map(r=>r.isImage?e.jsxs("div",{className:"relative group",children:[e.jsx("img",{src:r.url,alt:r.fileName,className:"w-24 h-24 object-cover rounded-lg border border-black/10 cursor-zoom-in bg-slate-100",onClick:()=>y(n.attachments||[],r),"data-testid":`attachment-img-${r.id}`}),e.jsxs("div",{className:"absolute bottom-1 right-1 flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.jsx("a",{href:`${r.url}?download=1`,className:"rounded-full bg-black/60 p-1 text-white hover:bg-black/80","aria-label":`Download ${r.fileName}`,onClick:j=>j.stopPropagation(),children:e.jsx(He,{className:"h-3 w-3"})}),e.jsx("button",{className:"rounded-full bg-black/60 p-1 text-white hover:bg-black/80","aria-label":`Forward ${r.fileName}`,onClick:()=>P(r),children:e.jsx(Ge,{className:"h-3 w-3"})})]})]},r.id):e.jsxs("div",{className:`flex items-center gap-1.5 rounded-lg px-2 py-1 text-xs ${f?"bg-white/15":"bg-slate-100"}`,children:[e.jsx(We,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"truncate max-w-[120px]",children:r.fileName}),e.jsx("span",{className:"opacity-70",children:Xs(r.sizeBytes)}),e.jsx("a",{href:`${r.url}?download=1`,"aria-label":`Download ${r.fileName}`,className:"hover:opacity-70",children:e.jsx(He,{className:"h-3 w-3"})}),e.jsx("button",{"aria-label":`Forward ${r.fileName}`,className:"hover:opacity-70",onClick:()=>P(r),children:e.jsx(Ge,{className:"h-3 w-3"})})]},r.id))}),e.jsx("p",{className:`text-[9px] mt-0.5 ${f?"text-white/60":"text-slate-400"}`,children:ns(n.createdAt)})]})},n.id)}),e.jsx("div",{ref:A})]}),(M==null?void 0:M.tier)==="free"&&e.jsxs("div",{className:"px-3 py-1.5 border-t border-amber-100 bg-amber-50 text-[11px] text-amber-700 flex items-center gap-1.5",children:[e.jsx(Ie,{className:"h-3 w-3 shrink-0"}),e.jsxs("span",{children:["Photos and files you share expire after ",M.freeVisibleDays," days on the free plan."," ",e.jsx(Ze,{href:"/subscriptions",className:"underline font-medium",children:"Upgrade"})," to keep them for ",M.planDays," days."]})]}),w.length>0&&e.jsx("div",{className:"px-3 py-1.5 border-t border-slate-100 flex flex-wrap gap-1.5",children:w.map(n=>e.jsxs("span",{className:"flex items-center gap-1 bg-slate-100 rounded-full px-2 py-0.5 text-[11px] text-slate-600",children:[n.isImage?e.jsx("img",{src:n.url,alt:"",className:"w-4 h-4 rounded object-cover"}):e.jsx(We,{className:"h-3 w-3"}),e.jsx("span",{className:"truncate max-w-[100px]",children:n.fileName}),e.jsx("button",{"aria-label":`Remove ${n.fileName}`,onClick:()=>S(f=>f.filter(r=>
1r.id!==n.id)),children:e.jsx(Xe,{className:"h-3 w-3 hover:text-red-500"})})]},n.id))}),e.jsxs("div",{className:"flex items-end gap-1.5 p-2 border-t border-slate-200 bg-white rounded-b-lg",children:[e.jsx("input",{ref:h,type:"file",multiple:!0,className:"hidden",onChange:n=>T(n.target.files)}),e.jsx(u,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 shrink-0",onClick:()=>{var n;return(n=h.current)==null?void 0:n.click()},disabled:Q,"aria-label":"Attach files","data-testid":"button-attach-file",children:Q?e.jsx(_,{className:"h-4 w-4 animate-spin"}):e.jsx(Rs,{className:"h-4 w-4"})}),e.jsx(Bs,{value:b,onChange:n=>x(n.target.value),placeholder:"Write a reply…",className:"min-h-[36px] max-h-28 text-[13px] resize-none flex-1",rows:1,onKeyDown:n=>{n.key==="Enter"&&!n.shiftKey&&(n.preventDefault(),(b.trim()||w.length>0)&&!q.isPending&&q.mutate())},"data-testid":"input-dm-reply"}),e.jsx(u,{size:"sm",className:"h-8 shrink-0",disabled:!b.trim()&&w.length===0||q.isPending||Q,onClick:()=>q.mutate(),"data-testid":"button-dm-send",children:q.isPending?e.jsx(_,{className:"h-4 w-4 animate-spin"}):e.jsx(As,{className:"h-4 w-4"})})]}),e.jsx(Vs,{urls:xe,index:pe,onIndexChange:N,onClose:()=>N(null)}),e.jsx(Fe,{open:!!C,onOpenChange:n=>!n&&P(null),children:e.jsxs(Me,{className:"max-w-sm",children:[e.jsxs(De,{children:[e.jsx($e,{children:"Forward attachment"}),e.jsx(as,{className:"truncate",children:C==null?void 0:C.fileName})]}),e.jsxs("div",{className:"max-h-64 overflow-y-auto space-y-1",children:[oe.filter(n=>n.id!==m).length===0&&e.jsx("p",{className:"text-sm text-muted-foreground py-3 text-center",children:"No other conversations to forward to."}),oe.filter(n=>n.id!==m).map(n=>e.jsx("button",{className:"w-full text-left px-3 py-2 rounded-lg hover:bg-slate-50 border border-slate-100 text-sm",onClick:()=>l.mutate(n.id),disabled:l.isPending,"data-testid":`forward-target-${n.id}`,children:n.other.captainName||n.other.fullName||n.other.username},n.id))]})]})})]})}function oa(){var Be,_e;const{user:m}=Ks(),[,k]=fs(),{toast:g}=ss(),{data:b}=Us(),[x,w]=o.useState("all"),[S,Q]=o.useState(null),[K,xe]=o.useState(!1),[U,pe]=o.useState(!1),[N,C]=o.useState(null),[P,h]=o.useState(1),[A,Y]=o.useState(null),[L,M]=o.useState(null),[oe,q]=o.useState(()=>{try{return new Set(JSON.parse(localStorage.getItem("mc-minimized")||"[]"))}catch{return new Set}}),[l,T]=o.useState(null),[y,n]=o.useState(null),[f,r]=o.useState(null),[j,de]=o.useState(""),[O,rs]=o.useState(""),[H,Te]=o.useState(""),[G,Oe]=o.useState(""),[ge,is]=o.useState(!1),[ls,os]=o.useState(!1);o.useEffect(()=>{const s=setTimeout(()=>{rs(j.trim()),h(1)},350);return()=>clearTimeout(s)},[j]);function ds(s){q(a=>{const t=new Set(a);t.has(s)?t.delete(s):t.add(s);try{localStorage.setItem("mc-minimized",JSON.stringify([...t]))}catch{}return t})}const fe=[{slug:"harbor-shoppers",name:"Harbor Shoppers"},...((b==null?void 0:b.divisions)||[]).filter(s=>s.slug&&s.slug!=="hirevi"&&s.slug!=="harbor-shoppers").map(s=>({slug:s.slug,name:s.name||s.slug}))],D=new URLSearchParams;D.set("category",x),D.set("page",String(P)),S&&D.set("brand",S),K&&D.set("unread","1"),U&&D.set("important","1"),N&&D.set("folder",String(N)),O&&D.set("q",O),H&&D.set("from",H),G&&D.set("to",`${G}T23:59:59`),ge&&D.set("sort","oldest");const{data:E,isLoading:je,error:Re,refetch:cs,isFetching:Ae}=B({queryKey:["/api/message-center/feed",x,S,K,U,N,P,O,H,G,ge],queryFn:()=>fetch(`/api/message-center/feed?${D.toString()}`).then(s=>{if(!s.ok)throw new Error("Failed to load inbox");return s.json()}),enabled:!!m}),{data:$}=B({queryKey:["/api/message-center/unread-count"],enabled:!!m,refetchInterval:3e4}),{data:W=[]}=B({queryKey:["/api/message-center/folders"],enabled:!!m}),{data:ce,isLoading:ms}=B({queryKey:["/api/message-center/emails",A],queryFn:()=>fetch(`/api/message-center/emails/${A}`).then(s=>{if(!s.ok)throw new Error("Failed to load email");return s.json()}),enabled:!!A}),I=()=>{Pe(i)},us=R({mutationFn:async s=>{await F("POST",`/api/notifications/${s}/read`)},onMutate:async s=>{r(null),await te(i);let a;const t=ne(i,d=>d.source==="notification"&&String(d.id)===String(s)&&!d.isRead?(a=d,{...d,isRead:!0,unreadCount:0}):d),c=a?Ne(i,a,-1):[];return{feedSnapshots:t,unreadSnapshots:c}},onSuccess:()=>{r(null),I()},onError:(s,a,t)=>{t!=null&&t.feedSnapshots&&re(i,t.feedSnapshots),t!=null&&t.unreadSnapshots&&he(i,t.unreadSnapshots),r((s==null?void 0:s.message)||"Couldn't mark the notification read."),I()}}),Ee=R({mutationFn:async()=>{await F("POST","/api/message-center/read-all")},onMutate:async()=>{r(null),await te(i);const s=ne(i,t=>({...t,...t.source==="email"?{}:{isRead:!0,unreadCount:(t.source==="dm",0)}})),a=i.getQueryData(["/api/message-center/unread-count"]);return i.setQueryData(["/api/message-center/unread-count"],t=>t&&{...t,total:0,byCategory:Object.fromEntries(Object.entries(t.byCategory||{}).map(([c,d])=>[c,c==="email"?d:0])),bySource:t.bySource?{...t.bySource,dm:0,notification:0}:t.bySource,bySourceCategory:t.bySourceCategory?Object.fromEntries(Object.entries(t.bySourceCategory).map(([c,d])=>[c,Object.fromEntries(Object.keys(d||{}).map(X=>[X,0]))])):t.bySourceCategory}),{feedSnapshots:s,unreadSnapshot:a}},onSuccess:()=>{r(null),I()},onError:(s,a,t)=>{t!=null&&t.feedSnapshots&&re(i,t.feedSnapshots),t!=null&&t.unreadSnapshot&&i.setQueryData(["/api/message-center/unread-count"],t.unreadSnapshot),r((s==null?void 0:s.message)||"Couldn't mark everything read."),I()}}),hs=R({mutationFn:async s=>{await F("PUT",`/api/dm/conversations/${s}/read`)},onMutate:async s=>{r(null),await te(i);let a;const t=ne(i,d=>d.source==="dm"&&String(d.id)===String(s)&&!d.isRead?(a=d,{...d,isRead:!0,unreadCount:0}):d),c=a?Ne(i,a,-1):[];return{feedSnapshots:t,unreadSnapshots:c}},onSuccess:()=>{r(null),I()},onError:(s,a,t)=>{t!=null&&t.feedSnapshots&&re(i,t.feedSnapshots),t!=null&&t.unreadSnapshots&&he(i,t.unreadSnapshots),r((s==null?void 0:s.message)||"Couldn't mark the conversation read."),I()}}),J=R({mutationFn:async s=>{await F("POST","/api/message-center/clear",{scope:s})},onMutate:async s=>{r(null),await te(i);const a=ne(i,c=>(s==="messages"?c.source==="dm":c.source==="notification"&&(s==="all-notices"||c.isRead===!0))?null:c),t=s==="messages"?Ve(i,"dm"):s==="all-notices"?Ve(i,"notification"):[];return{snapshots:a,unreadSnapshots:t}},onError:(s,a,t)=>{t!=null&&t.snapshots&&re(i,t.snapshots),t!=null&&t.unreadSnapshots&&he(i,t.unreadSnapshots),r((s==null?void 0:s.message)||"Couldn't clear those items.")},onSettled:I}),xs=R({mutationFn:async s=>{await F("POST","/api/message-center/items/meta",{source:s.source,itemId:String(s.id),isArchived:!0})},onMutate:async s=>{r(null),await te(i);let a;const t=ne(i,(d,X)=>qs(d,s.source,s.id)?(d.isRead||(a=d),X.some(p=>p==="archive")?{...d,isArchived:!0}:null):d),c=a?Ne(i,a,-1):[];return{snapshots:t,unreadSnapshots:c}},onError:(s,a,t)=>{t!=null&&t.snapshots&&re(i,t.snapshots),t!=null&&t.unreadSnapshots&&he(i,t.unreadSnapshots),r((s==null?void 0:s.message)||"Couldn't clear the item.")},onSettled:I}),V=R({mutationFn:async s=>{await F("POST","/api/message-center/items/meta",s)},onSuccess:()=>{I(),i.invalidateQueries({queryKey:["/api/message-center/folders"]})},onError:s=>{r((s==null?void 0:s.message)||"Couldn't update the item."),I()}}),me=R({mutationFn:async s=>{s.mode==="create"?await F("POST","/api/message-center/folders",{name:s.name,parentId:s.parentId??null}):s.mode==="rename"?await F("PATCH",`/api/message-center/folders/${s.id}`,{name:s.name}):await F("DELETE",`/api/message-center/folders/${s.id}`)},onSuccess:()=>{i.invalidateQueries({queryKey:["/api/message-center/folders"]}),i.invalidateQueries({queryKey:["/api/message-center/feed"]}),T(null)},onError:s=>g({title:"Folder error",description:(s==null?void 0:s.message)||"Failed",variant:"destructive"})}),be=R({mutationFn:async s=>{await F("POST","/api/message-center/reminders",{source:s.item.source,itemId:String(s.item.id),title:s.item.title,link:s.item.link||"/message-center",remindAt:new Date(s.when).toISOString()})},onSuccess:()=>{n(null),g({title:"Reminder set",description:"You'll get a notification at that time."})},onError:s=>g({title:"Reminder failed",description:(s==null?void 0:s.message)||"Please try again",variant:"destructive"})});if(!m)return e.jsxs("div",{className:"container mx-auto px-4 py-16 text-center",children:[e.jsx(le,{className:"h-10 w-10 mx-auto text-slate-300 mb-3"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:"Sign in to see your messages."}),e.jsx(u,{onClick:()=>k("/auth?redirect=%2Fmessage-center"),children:"Sign In"})]});function ps(s){if(s.source==="email"){Y(A===s.id?null:s.id),A!==s.id&&setTimeout(I,600);return}if(s.source==="dm"){s.isRead||hs.mutate(s.id),M(L===s.id?null:s.id),L!==s.id&&setTimeout(I,800);return}if(s.source==="notification"){s.isRead||us.mutate(s.id),s.link&&k(s.link);return}s.link&&k(s.link)}const ze=(E==null?void 0:E.items)||[],ue=[];for(const s of ze){const a=s.isPinned?"📌 Pinned":Zs(s.createdAt),t=ue[ue.length-1];t&&t.label===a?t.items.push(s):ue.push({label:a,items:[s]})}const Ke=W.filter(s=>!s.parentId),Ue=s=>W.filter(a=>a.parentId===s),Le=N==="archive"?null:W.find(s=>
1s.id===N),gs=S?((Be=fe.find(s=>s.slug===S))==null?void 0:Be.name)||S:null,qe=(s,a)=>e.jsxs(v,{className:"flex items-center justify-between gap-2",style:{paddingLeft:8+a*16},onClick:()=>{C(s.id),h(1)},children:[e.jsxs("span",{className:"flex items-center min-w-0",children:[e.jsx(Z,{className:"h-3.5 w-3.5 mr-2 shrink-0"}),e.jsx("span",{className:"truncate",children:s.name})]}),e.jsxs("span",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("span",{className:"text-[10px] text-muted-foreground",children:s.itemCount}),a===0&&e.jsx("button",{className:"p-0.5 hover:text-primary",onClick:t=>{t.stopPropagation(),T({mode:"create",parentId:s.id,name:""})},"aria-label":`New subfolder in ${s.name}`,title:"New subfolder",children:e.jsx(we,{className:"h-3 w-3"})}),e.jsx("button",{className:"p-0.5 hover:text-primary",onClick:t=>{t.stopPropagation(),T({mode:"rename",id:s.id,name:s.name})},"aria-label":`Rename folder ${s.name}`,children:e.jsx(Es,{className:"h-3 w-3"})}),e.jsx("button",{className:"p-0.5 hover:text-red-500",onClick:t=>{t.stopPropagation(),confirm(`Delete folder "${s.name}"? Items go back to the main inbox.`)&&(N===s.id&&C(null),me.mutate({mode:"delete",id:s.id}))},"aria-label":`Delete folder ${s.name}`,children:e.jsx(zs,{className:"h-3 w-3"})})]})]},s.id);return e.jsxs("div",{className:"container mx-auto px-2 sm:px-4 py-4 sm:py-6 max-w-4xl",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 mb-4 px-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(le,{className:"h-6 w-6 text-primary"}),e.jsx("h1",{className:"text-xl sm:text-2xl font-bold",children:"Message Center"}),(($==null?void 0:$.total)||0)>0&&e.jsxs(Ls,{className:"bg-red-500 text-white",children:[$.total>99?"99+":$.total," unread"]})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-1",children:[e.jsxs(u,{variant:"ghost",size:"sm",className:"text-xs",onClick:()=>Ee.mutate(),disabled:Ee.isPending,children:[e.jsx(js,{className:"h-3.5 w-3.5 mr-1"})," Mark all read"]}),e.jsxs(u,{variant:"ghost",size:"sm",className:"text-xs",onClick:()=>J.mutate("read-notices"),disabled:J.isPending,children:[e.jsx(z,{className:"h-3.5 w-3.5 mr-1"})," Clear read notices"]}),e.jsxs(u,{variant:"ghost",size:"sm",className:"text-xs",onClick:()=>{window.confirm("Clear all notices? You can recover them from Archive.")&&J.mutate("all-notices")},disabled:J.isPending,children:[e.jsx(z,{className:"h-3.5 w-3.5 mr-1"})," Clear all notices"]}),e.jsxs(u,{variant:"ghost",size:"sm",className:"text-xs",onClick:()=>{window.confirm("Clear all messages? You can recover them from Archive.")&&J.mutate("messages")},disabled:J.isPending,children:[e.jsx(z,{className:"h-3.5 w-3.5 mr-1"})," Clear messages"]})]})]}),f&&e.jsx("div",{role:"alert",className:"mx-2 mb-3 rounded-md border border-red-100 bg-red-50 px-3 py-2 text-xs text-red-700",children:f}),e.jsx("div",{className:"px-2 pb-2",children:e.jsxs("div",{className:"relative",children:[e.jsx(bs,{className:"h-4 w-4 absolute left-3 top-1/2 -translate-y-1/2 text-slate-400"}),e.jsx(ae,{value:j,onChange:s=>de(s.target.value),placeholder:"Search messages, notifications, emails…",className:"pl-9 h-9 text-sm","data-testid":"input-mc-search"}),j&&e.jsx("button",{className:"absolute right-3 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600",onClick:()=>de(""),"aria-label":"Clear search",children:e.jsx(Xe,{className:"h-4 w-4"})})]})}),e.jsx("div",{className:"flex gap-1.5 overflow-x-auto scrollbar-none px-2 pb-2",children:ts.map(s=>{var c;const a=s.key==="all"?($==null?void 0:$.total)||0:((c=$==null?void 0:$.byCategory)==null?void 0:c[s.key])||0,t=x===s.key;return e.jsxs("button",{onClick:()=>{w(s.key),h(1),Y(null),M(null)},className:`flex items-center gap-1.5 px-3 py-1.5 rounded-full text-xs font-medium whitespace-nowrap border transition-colors ${t?"bg-primary text-white border-primary":"bg-white text-slate-600 border-slate-200 hover:border-slate-300"}`,"data-testid":`chip-${s.key}`,children:[e.jsx(s.icon,{className:"h-3.5 w-3.5"}),s.label,a>0&&e.jsx("span",{className:`text-[10px] font-bold rounded-full px-1.5 min-w-[16px] text-center ${t?"bg-white/25 text-white":"bg-red-500 text-white"}`,children:a>99?"99+":a})]},s.key)})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 px-2 pb-3",children:[e.jsxs(u,{variant:K?"default":"outline",size:"sm",className:"h-7 text-xs",onClick:()=>{xe(!K),h(1)},children:[e.jsx(ws,{className:"h-3 w-3 mr-1"})," Unread"]}),e.jsxs(u,{variant:U?"default":"outline",size:"sm",className:"h-7 text-xs",onClick:()=>{pe(!U),h(1)},children:[e.jsx(Qe,{className:`h-3 w-3 mr-1 ${U?"":"text-amber-500"}`})," Important"]}),e.jsxs(u,{variant:H||G?"default":"outline",size:"sm",className:"h-7 text-xs",onClick:()=>os(s=>!s),"data-testid":"button-date-filter",children:[e.jsx(Ns,{className:"h-3 w-3 mr-1"})," Dates"]}),e.jsxs(u,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>{is(s=>!s),h(1)},"data-testid":"button-sort-toggle",children:[e.jsx(ys,{className:"h-3 w-3 mr-1"})," ",ge?"Oldest first":"Newest first"]}),e.jsxs(ye,{children:[e.jsx(ve,{asChild:!0,children:e.jsxs(u,{variant:"outline",size:"sm",className:"h-7 text-xs",children:[gs||"All Brands"," ",e.jsx(se,{className:"h-3 w-3 ml-1"})]})}),e.jsxs(Se,{align:"start",children:[e.jsx(v,{onClick:()=>{Q(null),h(1)},children:"All Brands"}),e.jsx(ie,{}),fe.map(s=>e.jsx(v,{onClick:()=>{Q(s.slug),h(1)},children:s.name},s.slug))]})]}),e.jsxs(ye,{children:[e.jsx(ve,{asChild:!0,children:e.jsxs(u,{variant:N?"default":"outline",size:"sm",className:"h-7 text-xs",children:[N==="archive"?e.jsx(z,{className:"h-3 w-3 mr-1"}):e.jsx(Z,{className:"h-3 w-3 mr-1"}),N==="archive"?"Archive":Le?Le.name:"Folders"," ",e.jsx(se,{className:"h-3 w-3 ml-1"})]})}),e.jsxs(Se,{align:"start",className:"w-60",children:[e.jsx(Hs,{className:"text-xs",children:"My Folders"}),e.jsxs(v,{onClick:()=>{C(null),h(1)},children:[e.jsx(le,{className:"h-3.5 w-3.5 mr-2"})," All items"]}),e.jsxs(v,{onClick:()=>{C("archive"),h(1)},"data-testid":"folder-archive",children:[e.jsx(z,{className:"h-3.5 w-3.5 mr-2"})," Archive"]}),e.jsx(ie,{}),Ke.map(s=>e.jsxs("div",{children:[qe(s,0),Ue(s.id).map(a=>qe(a,1))]},s.id)),e.jsx(ie,{}),e.jsxs(v,{onSelect:s=>{s.preventDefault(),T({mode:"create",name:""})},children:[e.jsx(we,{className:"h-3.5 w-3.5 mr-2"})," New folder"]})]})]}),e.jsx("div",{className:"ml-auto flex items-center gap-2",children:e.jsx(Ze,{href:"/messages",className:"text-xs text-primary hover:underline",children:"Open Chat"})})]}),ls&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 px-2 pb-3",children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:"From"}),e.jsx(ae,{type:"date",value:H,onChange:s=>{Te(s.target.value),h(1)},className:"h-8 w-36 text-xs","data-testid":"input-date-from"}),e.jsx("label",{className:"text-xs text-muted-foreground",children:"To"}),e.jsx(ae,{type:"date",value:G,onChange:s=>{Oe(s.target.value),h(1)},className:"h-8 w-36 text-xs","data-testid":"input-date-to"}),(H||G)&&e.jsx(u,{variant:"ghost",size:"sm",className:"h-7 text-xs",onClick:()=>{Te(""),Oe(""),h(1)},children:"Clear"})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-slate-200 overflow-hidden",children:[je&&e.jsx("div",{className:"py-16 text-center",children:e.jsx(_,{className:"h-6 w-6 animate-spin mx-auto text-slate-300"})}),!je&&Re&&e.jsxs("div",{className:"py-16 text-center",children:[e.jsx("p",{className:"text-sm text-red-500 mb-3",children:"Couldn't load your inbox."}),e.jsxs(u,{variant:"outline",size:"sm",onClick:()=>cs(),disabled:Ae,children:[Ae?e.jsx(_,{className:"h-3.5 w-3.5 mr-1 animate-spin"}):null," Retry"]})]}),!je&&!Re&&ze.length===0&&e.jsxs("div",{className:"py-16 text-center",children:[e.jsx(le,{className:"h-10 w-10 mx-auto text-slate-200 mb-2"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:N==="archive"?"Your archive is empty.":O?"No results for your search.":"Nothing here yet."})]}),ue.map(s=>e.jsxs("div",{children:[e.jsx("div",{className:"px-4 py-1.5 bg-slate-50 border-y border-slate-100 text-[11px] font-semibold text-slate-400 uppercase tracking-wide",children:s.label}),s.items.map(a=>{var c,d,X;const t=oe.has(a.key);return e.jsxs("div",{className:`border-b border-slate-50 last:border-0 ${a.isRead?"":"bg-blue-50/40"}`,children:[e.jsxs("div",{className:`flex items-start gap-3 px-3 sm:px-4 ${t?"py-1.5":"py-3"} hover:bg-slate-50 cursor-pointer transition-colors`,onClick:()=>ps(a),"data-testid":`item-${a.key}`,children:[!t&&(a.source==="dm"&&a.other?e.jsxs(_s,{className:"h-10 w-10 shrink-0",children:[e.jsx(Qs,{src:a.other.avatarUrl||void 0}),e.jsx(Ys,{className:"bg-violet-100 text-violet-700 text-sm font-bold",children:(((c=a.title)==null?void 0:c[0])||"?").toUpperCase()})]}):a.imageUrl?e.jsxs("div",{className:"relative shrink-0",children:[e.jsx("img",{src:a.imageUrl,alt:"",className:"w-10 h-10 rounded-lg object-cover bg-slate-100 border border-slate-200"}),e.jsx("span",{className:`absolute -bottom-1 -right-1 ${ke[a.category]||"bg-slate-500"} rounded-full p-0.5 ring-2 ring-white`,children:e.jsx(Ce,{category:a.category,className:"h-2.5 w-2.5 text-white"})})]}):e.jsx("div",{className:`shrink-0 w-10 h-10 rounded-full ${ke[a.category]||"bg-slate-500"} flex items-center justify-center`,children:e.jsx(Ce,{category:a.category})})),t&&e.jsx("span",{className:`shrink-0 w-5 h-5 mt-0.5 rounded-full ${ke[a.category]||"bg-slate-500"} flex items-center justify-center`,children:e.jsx(Ce,{category:a.category,className:"h-3 w-3 text-white"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("span",{className:`text-[13px] leading-tight flex items-center gap-1 min-w-0 ${a.isRead?"font-medium text-slate-600":"font-semibold text-slate-900"}`,children:[a.isPinned&&e.jsx(Ye,{className:"h-3 w-3 text-primary shrink-0 rotate-45"}),e.jsx("span",{className:"truncate",children:a.title})]}),e.jsx("span",{className:"text-[10px] text-slate-400 shrink-0 mt-0.5",children:ns(a.createdAt)})]}),!t&&a.preview&&e.jsx("p",{className:"text-[12px] text-muted-foreground line-clamp-2 mt-0.5",children:a.preview}),!t&&e.jsxs("div",{className:"flex items-center gap-1.5 mt-1",children:[a.brandKey!=="harbor-shoppers"&&e.jsx("span",{className:"text-[9px] font-semibold uppercase px-1.5 py-0.5 rounded bg-slate-100 text-slate-500",children:((d=fe.find(p=>p.slug===a.brandKey))==null?void 0:d.name)||a.brandKey}),!a.isRead&&e.jsx("span",{className:"w-2 h-2 bg-blue-500 rounded-full"}),a.folderId&&e.jsxs("span",{className:"text-[9px] text-slate-400 flex items-center gap-0.5",children:[e.jsx(Z,{className:"h-2.5 w-2.5"}),(X=W.find(p=>p.id===a.folderId))==null?void 0:X.name]}),a.isArchived&&e.jsxs("span",{className:"text-[9px] text-slate-400 flex items-center gap-0.5",children:[e.jsx(z,{className:"h-2.5 w-2.5"}),"Archived"]})]})]}),e.jsxs("div",{className:"flex items-center gap-0.5 shrink-0",onClick:p=>p.stopPropagation(),children:[e.jsx("button",{className:"p-1.5 rounded hover:bg-slate-100",onClick:()=>ds(a.key),"aria-label":t?"Expand":"Minimize",title:t?"Expand":"Minimize","data-testid":`minimize-${a.key}`,children:t?e.jsx(se,{className:"h-4 w-4 text-slate-300"}):e.jsx(vs,{className:"h-4 w-4 text-slate-300"})}),e.jsx("button",{className:"p-1.5 rounded hover:bg-slate-100",onClick:()=>V.mutate({source:a.source,itemId:String(a.id),isImportant:!a.isImportant}),"aria-label":a.isImportant?"Unstar":"Mark important","data-testid":`star-${a.key}`,children:e.jsx(Qe,{className:`h-4 w-4 ${a.isImportant?"fill-amber-400 text-amber-400":"text-slate-300"}`})}),e.jsx("button",{className:"p-1.5 rounded hover:bg-slate-100",onClick:()=>xs.mutate(a),"aria-label":a.source==="dm"?"Clear conversation":"Clear notification",title:"Clear","data-testid":`clear-${a.key}`,children:e.jsx(z,{className:"h-4 w-4 text-slate-300"})}),e.jsxs(ye,{children:[e.jsx(ve,{asChild:!0,children:e.jsx("button",{className:"p-1.5 rounded hover:bg-slate-100","aria-label":"More actions","data-testid":`more-${a.key}`,children:e.jsx(se,{className:"h-4 w-4 text-slate-300"})})}),e.jsxs(Se,{align:"end",className:"w-52",children:[e.jsxs(v,{onClick:()=>V.mutate({source:a.source,itemId:String(a.id),isPinned:!a.isPinned}),children:[e.jsx(Ye,{className:"h-3.5 w-3.5 mr-2"})," ",a.isPinned?"Unpin":"Pin to top"]}
1),e.jsxs(v,{onClick:()=>V.mutate({source:a.source,itemId:String(a.id),isArchived:!a.isArchived}),children:[a.isArchived?e.jsx(Ss,{className:"h-3.5 w-3.5 mr-2"}):e.jsx(z,{className:"h-3.5 w-3.5 mr-2"}),a.isArchived?"Restore from archive":"Archive"]}),e.jsxs(v,{onClick:()=>{const p=new Date(Date.now()+36e5);p.setMinutes(0,0,0);const ee=new Date(p.getTime()-p.getTimezoneOffset()*6e4).toISOString().slice(0,16);n({item:a,when:ee})},children:[e.jsx(Ie,{className:"h-3.5 w-3.5 mr-2"})," Remind me…"]}),e.jsx(ie,{}),e.jsxs(Gs,{children:[e.jsxs(Ws,{children:[e.jsx(Z,{className:"h-3.5 w-3.5 mr-2"})," Move to folder"]}),e.jsxs(Js,{className:"w-52",children:[a.folderId&&e.jsx(v,{onClick:()=>V.mutate({source:a.source,itemId:String(a.id),folderId:null}),children:"Remove from folder"}),W.length===0&&e.jsx(v,{disabled:!0,children:"No folders yet"}),Ke.map(p=>e.jsxs("div",{children:[e.jsxs(v,{onClick:()=>V.mutate({source:a.source,itemId:String(a.id),folderId:p.id}),children:[e.jsx(Z,{className:"h-3.5 w-3.5 mr-2"}),p.name]}),Ue(p.id).map(ee=>e.jsxs(v,{className:"pl-8",onClick:()=>V.mutate({source:a.source,itemId:String(a.id),folderId:ee.id}),children:[e.jsx(Z,{className:"h-3 w-3 mr-2"}),ee.name]},ee.id))]},p.id)),e.jsx(ie,{}),e.jsxs(v,{onSelect:p=>{p.preventDefault(),T({mode:"create",name:""})},children:[e.jsx(we,{className:"h-3.5 w-3.5 mr-2"})," New folder"]})]})]})]})]}),a.source==="notification"&&e.jsx(ks,{className:"h-4 w-4 text-slate-200 mt-1.5 hidden sm:block"}),a.source==="dm"&&(L===a.id?e.jsx(Cs,{className:"h-4 w-4 text-slate-300 mt-1.5 hidden sm:block"}):e.jsx(se,{className:"h-4 w-4 text-slate-200 mt-1.5 hidden sm:block"}))]})]}),a.source==="dm"&&L===a.id&&e.jsx("div",{className:"px-3 sm:px-4 pb-3",children:e.jsx(ea,{conversationId:a.id,myUserId:m.id})}),a.source==="email"&&A===a.id&&e.jsx("div",{className:"px-4 pb-4",children:e.jsx("div",{className:"border border-slate-200 rounded-lg bg-slate-50/50 p-3 sm:p-4",children:ms?e.jsx("div",{className:"py-6 text-center",children:e.jsx(_,{className:"h-4 w-4 animate-spin mx-auto text-slate-300"})}):ce!=null&&ce.htmlBody?e.jsx("div",{className:"prose prose-sm max-w-none overflow-x-auto [&_img]:max-w-full",dangerouslySetInnerHTML:{__html:Is.sanitize(ce.htmlBody)}}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"The full content of this email isn't available (older emails only kept the subject line)."})})})]},a.key)})]},s.label))]}),(P>1||(E==null?void 0:E.hasMore))&&e.jsxs("div",{className:"flex items-center justify-center gap-3 py-4",children:[e.jsx(u,{variant:"outline",size:"sm",disabled:P<=1,onClick:()=>h(s=>s-1),children:"Previous"}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Page ",P]}),e.jsx(u,{variant:"outline",size:"sm",disabled:!(E!=null&&E.hasMore),onClick:()=>h(s=>s+1),children:"Next"})]}),e.jsx(Fe,{open:!!l,onOpenChange:s=>!s&&T(null),children:e.jsxs(Me,{className:"max-w-sm",children:[e.jsx(De,{children:e.jsx($e,{children:(l==null?void 0:l.mode)==="create"?l!=null&&l.parentId?`New Subfolder in "${((_e=W.find(s=>s.id===l.parentId))==null?void 0:_e.name)||""}"`:"New Folder":"Rename Folder"})}),e.jsx(ae,{value:(l==null?void 0:l.name)||"",onChange:s=>T(a=>a&&{...a,name:s.target.value}),placeholder:"Folder name",maxLength:60,autoFocus:!0,onKeyDown:s=>{s.key==="Enter"&&(l!=null&&l.name.trim())&&me.mutate({mode:l.mode,id:l.id,name:l.name.trim(),parentId:l.parentId??null})}}),e.jsxs(Je,{children:[e.jsx(u,{variant:"outline",onClick:()=>T(null),children:"Cancel"}),e.jsx(u,{disabled:!(l!=null&&l.name.trim())||me.isPending,onClick:()=>l&&me.mutate({mode:l.mode,id:l.id,name:l.name.trim(),parentId:l.parentId??null}),children:(l==null?void 0:l.mode)==="create"?e.jsxs(e.Fragment,{children:[e.jsx(Fs,{className:"h-3.5 w-3.5 mr-1"}),"Create"]}):"Save"})]})]})}),e.jsx(Fe,{open:!!y,onOpenChange:s=>!s&&n(null),children:e.jsxs(Me,{className:"max-w-sm",children:[e.jsxs(De,{children:[e.jsx($e,{children:"Remind me about this"}),e.jsx(as,{className:"truncate",children:y==null?void 0:y.item.title})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:"When should we remind you?"}),e.jsx(ae,{type:"datetime-local",value:(y==null?void 0:y.when)||"",onChange:s=>n(a=>a&&{...a,when:s.target.value}),"data-testid":"input-reminder-when"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:[{label:"In 1 hour",ms:36e5},{label:"Tomorrow 9am",ms:-1},{label:"In 3 days",ms:3*864e5}].map(s=>e.jsx(u,{variant:"outline",size:"sm",className:"h-6 text-[11px]",onClick:()=>{let a;s.ms===-1?(a=new Date,a.setDate(a.getDate()+1),a.setHours(9,0,0,0)):a=new Date(Date.now()+s.ms);const t=new Date(a.getTime()-a.getTimezoneOffset()*6e4).toISOString().slice(0,16);n(c=>c&&{...c,when:t})},children:s.label},s.label))})]}),e.jsxs(Je,{children:[e.jsx(u,{variant:"outline",onClick:()=>n(null),children:"Cancel"}),e.jsxs(u,{disabled:!(y!=null&&y.when)||be.isPending,onClick:()=>y&&be.mutate(y),"data-testid":"button-set-reminder",children:[be.isPending?e.jsx(_,{className:"h-3.5 w-3.5 mr-1 animate-spin"}):e.jsx(Ie,{className:"h-3.5 w-3.5 mr-1"}),"Set reminder"]})]})]})})]})}export{oa as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.