1import{cr as V,cs as P,ct as q,cu as ee,x as te,cv as ae,r as o,w as se,j as e,b4 as z,O as le,B as M,cw as re,aj as oe,I as ne,X as ie,s as h,a4 as B,a5 as O,a6 as I,a7 as A,a8 as m,aU as E,u as de,cx as ce,b1 as xe,b5 as me,f as he,an as pe,ax as ue,b2 as R}from"./index-BLjq2FqK.js";import{F as G}from"./filter-POyWeszE.js";import{R as be}from"./reply-DP_5Bwit.js";import{S as ge}from"./send-ItU64Gbp.js";function fe(t,r,n){const d=V(t,n),p=V(r,n);return+d==+p}function je(t,r){return fe(t,P(t),r)}function ye(t){return q(t,P(t))}function Ne(t){return q(t,ee(P(t),1))}const H={task_assigned:{label:"Assigned",color:"bg-blue-500/15 text-blue-400",dot:"bg-blue-400",icon:"ð¯"},task_reassigned:{label:"Reassigned",color:"bg-blue-500/15 text-blue-400",dot:"bg-blue-400",icon:"ð"},comment_added:{label:"Comment",color:"bg-purple-500/15 text-purple-400",dot:"bg-purple-400",icon:"ð¬"},comment_mention:{label:"Mention",color:"bg-pink-500/15 text-pink-400",dot:"bg-pink-400",icon:"@"},status_change:{label:"Status",color:"bg-yellow-500/15 text-yellow-400",dot:"bg-yellow-400",icon:"ð"},phase_change:{label:"Phase",color:"bg-indigo-500/15 text-indigo-400",dot:"bg-indigo-400",icon:"ð"},task_due_soon:{label:"Due Soon",color:"bg-orange-500/15 text-orange-400",dot:"bg-orange-400",icon:"â°"},task_overdue:{label:"Overdue",color:"bg-red-500/15 text-red-400",dot:"bg-red-500",icon:"ð¨"},project_update:{label:"Project",color:"bg-teal-500/15 text-teal-400",dot:"bg-teal-400",icon:"ð"},milestone_update:{label:"Milestone",color:"bg-green-500/15 text-green-400",dot:"bg-green-400",icon:"ð"},timesheet_reminder:{label:"Timesheet",color:"bg-gray-500/15 text-gray-400",dot:"bg-gray-400",icon:"â±"}},K={task_overdue:"high",comment_mention:"high",task_due_soon:"medium",status_change:"medium",phase_change:"medium",task_assigned:"low",task_reassigned:"low",comment_added:"low",project_update:"low",milestone_update:"low",timesheet_reminder:"low"},U={high:{label:"High",color:"bg-red-500/15 text-red-400"},medium:{label:"Medium",color:"bg-orange-500/15 text-orange-400"},low:{label:"Low",color:"bg-gray-500/15 text-gray-400"}},we={label:"Update",color:"bg-gray-500/15 text-gray-400",dot:"bg-gray-400",icon:"ð"};function ke(t){const r=new Date(t);return ye(r)?"today":Ne(r)?"yesterday":je(r,{weekStartsOn:1})?"this_week":"older"}const ve={today:"Today",yesterday:"Yesterday",this_week:"Earlier this week",older:"Older"};function _e({taskId:t,onSubmit:r,onCancel:n}){const[d,p]=o.useState(""),[j,y]=o.useState(!1),u=o.useRef(null);o.useEffect(()=>{var l;(l=u.current)==null||l.focus()},[]);const N=async()=>{const l=d.trim();if(!l)return;y(!0),await r(t,l)?(R.success("Reply sent"),n()):R.error("Failed to send reply"),y(!1)};return e.jsxs("div",{className:"mt-3 space-y-2 border-t border-[#2a3048] pt-3",children:[e.jsx(ue,{ref:u,value:d,onChange:l=>p(l.target.value),placeholder:"Write a replyâ¦",className:"min-h-[72px] bg-[#0e1120] border-[#2a3048] text-white placeholder:text-[#2d3a4a] text-sm resize-none",onKeyDown:l=>{l.key==="Enter"&&(l.metaKey||l.ctrlKey)&&N(),l.key==="Escape"&&n()}}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(M,{size:"sm",className:"bg-[#FF6B35] hover:bg-[#e55a24] text-white gap-1.5 h-7 text-xs",onClick:N,disabled:j||!d.trim(),children:[j?e.jsx(E,{className:"w-3 h-3 animate-spin"}):e.jsx(ge,{className:"w-3 h-3"}),"Reply"]}),e.jsx(M,{variant:"ghost",size:"sm",className:"h-7 text-xs text-[#4a5d70] hover:text-white",onClick:n,children:"Cancel"}),e.jsx("span",{className:"text-[10px] text-[#2d3a4a] ml-auto",children:"ââµ to send"})]})]})}function Ce({n:t,projectName:r,onRead:n,onDelete:d,onReply:p,onMarkComplete:j,activeReplyId:y,setActiveReplyId:u}){const N=de(),l=H[t.type]??we,c=K[t.type]??"low",w=ce(new Date(t.created_at),{addSuffix:!0}),v=t.type==="comment_added"||t.type==="comment_mention",b=["task_assigned","task_reassigned","task_due_soon","task_overdue"].includes(t.type),g=y===t.id,[x,k]=o.useState(!1),f=()=>{if(n(t.id),t.link){const S=t.link.replace(/^https?:\/\/[^/]+/,"");N(S)}},_=async()=>{if(!t.related_task_id)return;k(!0),await j(t.related_task_id)?(R.success("Task marked complete"),n(t.id)):R.error("Failed to update task"),k(!1)};return e.jsx("div",{className:h("group rounded-xl border transition-all",t.is_read?"border-[#2a3048] bg-[#141722]":"border-[#FF6B35]/20 bg-[#1a1f35]"),children:e.jsxs("div",{className:"flex items-start gap-4 p-4",children:[e.jsxs("div",{className:"relative shrink-0 mt-0.5",children:[e.jsx("div",{className:h("w-10 h-10 rounded-lg flex items-center justify-center text-lg",t.is_read?"bg-[#1d2233]":"bg-[#252c45]"),children:l.icon}),!t.is_read&&e.jsx("span",{className:h("absolute -top-1 -right-1 w-2.5 h-2.5 rounded-full border-2 border-[#141722]",l.dot)})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mb-1",children:[e.jsx("span",{className:h("text-[10px] font-semibold px-1.5 py-0.5 rounded",l.color),children:l.label}),e.jsx("span",{className:h("text-[10px] px-1.5 py-0.5 rounded",U[c].color),children:U[c].label}),r&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-[#2a3048] text-[#8a9db5]",children:r}),e.jsx("span",{className:"text-[11px] text-[#4a5d70] ml-auto shrink-0",children:w})]}),e.jsx("p",{className:h("text-sm font-medium leading-snug",t.is_read?"text-[#8a9db5]":"text-white"),children:t.title}),t.body&&e.jsx("p",{className:"text-xs text-[#4a5d70] mt-1 leading-relaxed",children:t.body}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mt-3",children:[t.link&&e.jsxs("button",{onClick:f,className:"inline-flex items-center gap-1 text-[11px] text-[#8a9db5] hover:text-white border border-[#2a3048] hover:border-[#3a4060] rounded-md px-2.5 py-1 transition-colors",children:[e.jsx(xe,{className:"w-3 h-3"}),"Open"]}),v&&t.related_task_id&&e.jsxs("button",{onClick:()=>u(g?null:t.id),className:h("inline-flex items-center gap-1 text-[11px] border rounded-md px-2.5 py-1 transition-colors",g?"text-[#FF6B35] border-[#FF6B35]/40 bg-[#FF6B35]/10":"text-[#8a9db5] hover:text-white border-[#2a3048] hover:border-[#3a4060]"),children:[e.jsx(be,{className:"w-3 h-3"}),"Reply"]}),b&&t.related_task_id&&e.jsxs("button",{onClick:_,disabled:x,className:"inline-flex items-center gap-1 text-[11px] text-[#8a9db5] hover:text-green-400 border border-[#2a3048] hover:border-green-500/40 rounded-md px-2.5 py-1 transition-colors disabled:opacity-50",children:[x?e.jsx(E,{className:"w-3 h-3 animate-spin"}):e.jsx(me,{className:"w-3 h-3"}),"Mark complete"]}),!t.is_read&&e.jsxs("button",{onClick:()=>n(t.id),className:"inline-flex items-center gap-1 text-[11px] text-[#4a5d70] hover:text-white border border-transparent hover:border-[#2a3048] rounded-md px-2.5 py-1 transition-colors",children:[e.jsx(he,{className:"w-3 h-3"}),"Mark read"]})]}),g&&t.related_task_id&&e.jsx(_e,{taskId:t.related_task_id,onSubmit:p,onCancel:()=>u(null)})]}),e.jsx("button",{onClick:()=>d(t.id),className:"shrink-0 p-1.5 rounded-lg text-[#2d3a4a] hover:text-red-400 hover:bg-red-500/10 transition-colors opacity-0 group-hover:opacity-100",children:e.jsx(pe,{className:"w-3.5 h-3.5"})})]})})}function Be(){var Y;const{user:t}=te(),{notifications:r,unreadCount:n,loading:d,markRead:p,markAllRead:j,deleteNotification:y,replyToComment:u,markTaskComplete:N}=ae(),[l,c]=o.useState(""),[w,v]=o.useState("all"),[b,g]=o.useState("all"),[x,k]=o.useState("all"),[f,_]=o.useState("all"),[S,J]=o.useState(null),[T,X]=o.useState({});o.useEffect(()=>{var s;const a=(s=t==null?void 0:t.user_metadata)==null?void 0:s.tenantId;a&&se.from("projects").select("id, name").eq("tenantId",a).then(({data:i})=>{const D={};for(const W of i??[])D[W.id]=W.name;X(D)})}
1,[(Y=t==null?void 0:t.user_metadata)==null?void 0:Y.tenantId]);const L=o.useMemo(()=>{const a=new Set(r.map(s=>s.related_project_id).filter(Boolean));return Array.from(a).map(s=>({id:s,name:T[s]??s}))},[r,T]),Q=o.useMemo(()=>{const a=new Set(r.map(s=>s.type));return Array.from(a)},[r]),F=o.useMemo(()=>r.filter(a=>{if(w==="unread"&&a.is_read||b!=="all"&&a.type!==b||x!=="all"&&a.related_project_id!==x||f!=="all"&&(K[a.type]??"low")!==f)return!1;if(l){const s=l.toLowerCase();if(!a.title.toLowerCase().includes(s)&&!(a.body??"").toLowerCase().includes(s))return!1}return!0}),[r,w,b,x,f,l]),Z=o.useMemo(()=>{const a={};for(const s of F){const i=ke(s.created_at);a[i]||(a[i]=[]),a[i].push(s)}return a},[F]),$=["today","yesterday","this_week","older"],C=w!=="all"||b!=="all"||x!=="all"||f!=="all"||l;return e.jsxs("div",{className:"min-h-screen bg-[#1a1d29] px-6 py-8 max-w-4xl mx-auto",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold text-white flex items-center gap-3",children:[e.jsx(z,{className:"w-6 h-6 text-[#FF6B35]"}),"Notifications",n>0&&e.jsxs(le,{className:"bg-[#FF6B35] text-white text-xs px-2",children:[n," unread"]})]}),e.jsx("p",{className:"text-sm text-[#4a5d70] mt-1",children:"Your activity feed â task assignments, comments, status changes and more."})]}),n>0&&e.jsxs(M,{variant:"outline",size:"sm",className:"border-[#2a3048] text-[#8a9db5] hover:text-white gap-2",onClick:j,children:[e.jsx(re,{className:"w-4 h-4"}),"Mark all read"]})]}),e.jsxs("div",{className:"bg-[#141722] border border-[#2a3048] rounded-xl p-4 mb-6 space-y-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(oe,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-[#4a5d70]"}),e.jsx(ne,{value:l,onChange:a=>c(a.target.value),placeholder:"Search notificationsâ¦",className:"pl-9 bg-[#0e1120] border-[#2a3048] text-white placeholder:text-[#2d3a4a]"}),l&&e.jsx("button",{onClick:()=>c(""),className:"absolute right-3 top-1/2 -translate-y-1/2 text-[#4a5d70] hover:text-white",children:e.jsx(ie,{className:"w-3.5 h-3.5"})})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(G,{className:"w-3.5 h-3.5 text-[#4a5d70] shrink-0"}),e.jsx("div",{className:"flex rounded-lg border border-[#2a3048] overflow-hidden",children:["all","unread"].map(a=>e.jsx("button",{onClick:()=>v(a),className:h("text-xs px-3 py-1.5 transition-colors",w===a?"bg-[#FF6B35] text-white":"text-[#4a5d70] hover:text-white hover:bg-[#1d2233]"),children:a==="all"?"All":"Unread"},a))}),e.jsxs(B,{value:b,onValueChange:g,children:[e.jsx(O,{className:"h-8 text-xs bg-[#0e1120] border-[#2a3048] text-[#8a9db5] w-36",children:e.jsx(I,{placeholder:"All types"})}),e.jsxs(A,{className:"bg-[#1d2233] border-[#2a3048]",children:[e.jsx(m,{value:"all",className:"text-xs text-[#8a9db5]",children:"All types"}),Q.map(a=>{var s;return e.jsx(m,{value:a,className:"text-xs text-[#8a9db5]",children:((s=H[a])==null?void 0:s.label)??a},a)})]})]}),e.jsxs(B,{value:f,onValueChange:_,children:[e.jsx(O,{className:"h-8 text-xs bg-[#0e1120] border-[#2a3048] text-[#8a9db5] w-32",children:e.jsx(I,{placeholder:"Any priority"})}),e.jsxs(A,{className:"bg-[#1d2233] border-[#2a3048]",children:[e.jsx(m,{value:"all",className:"text-xs text-[#8a9db5]",children:"Any priority"}),e.jsx(m,{value:"high",className:"text-xs text-red-400",children:"High"}),e.jsx(m,{value:"medium",className:"text-xs text-orange-400",children:"Medium"}),e.jsx(m,{value:"low",className:"text-xs text-gray-400",children:"Low"})]})]}),L.length>0&&e.jsxs(B,{value:x,onValueChange:k,children:[e.jsx(O,{className:"h-8 text-xs bg-[#0e1120] border-[#2a3048] text-[#8a9db5] w-40",children:e.jsx(I,{placeholder:"All projects"})}),e.jsxs(A,{className:"bg-[#1d2233] border-[#2a3048]",children:[e.jsx(m,{value:"all",className:"text-xs text-[#8a9db5]",children:"All projects"}),L.map(a=>e.jsx(m,{value:a.id,className:"text-xs text-[#8a9db5]",children:a.name},a.id))]})]}),C&&e.jsx("button",{onClick:()=>{c(""),v("all"),g("all"),k("all"),_("all")},className:"text-[11px] text-[#FF6B35] hover:underline ml-auto",children:"Clear filters"})]})]}),d?e.jsxs("div",{className:"flex items-center justify-center py-20 gap-3 text-[#4a5d70]",children:[e.jsx(E,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{className:"text-sm",children:"Loading notificationsâ¦"})]}):F.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-24 gap-4 text-center",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-[#1d2233] border border-[#2a3048] flex items-center justify-center",children:C?e.jsx(G,{className:"w-7 h-7 text-[#2d3a4a]"}):e.jsx(z,{className:"w-7 h-7 text-[#2d3a4a]"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-white font-medium",children:C?"N
1o notifications match your filters":"You're all caught up!"}),e.jsx("p",{className:"text-sm text-[#4a5d70] mt-1",children:C?"Try adjusting the filters above.":"New activity will appear here as it happens."})]}),C&&e.jsx("button",{onClick:()=>{c(""),v("all"),g("all"),k("all"),_("all")},className:"text-sm text-[#FF6B35] hover:underline",children:"Clear all filters"})]}):e.jsxs("div",{className:"space-y-8",children:[$.map(a=>{const s=Z[a];return s!=null&&s.length?e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx("h2",{className:"text-xs font-semibold text-[#4a5d70] uppercase tracking-wider",children:ve[a]}),e.jsx("div",{className:"flex-1 border-t border-[#2a3048]"}),e.jsx("span",{className:"text-[10px] text-[#2d3a4a]",children:s.length})]}),e.jsx("div",{className:"space-y-2",children:s.map(i=>e.jsx(Ce,{n:i,projectName:i.related_project_id?T[i.related_project_id]:void 0,onRead:p,onDelete:y,onReply:u,onMarkComplete:N,activeReplyId:S,setActiveReplyId:J},i.id))})]},a):null}),e.jsx("div",{className:"text-center pb-8",children:e.jsxs("span",{className:"text-xs text-[#2d3a4a]",children:["Showing ",F.length," of ",r.length," notification",r.length!==1?"s":""]})})]})]})}export{Be as NotificationsHub};
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.