1import{u as K,D as Y,m as x,R as Z,j as e,A as q,V as S}from"./index-CiCw9Duq.js";import{r as n}from"./vendor-i18n-BBu7i065.js";import{r as J,L as C}from"./vendor-react-BL5zx_iT.js";import{g as Q}from"./notification-grouping-DdPywy3u.js";import{bB as F,_ as T,c as X,w as A,G as M,aa as I,Z as ee,ai as te}from"./vendor-ui-Ct1FBp4w.js";import"./vendor-solana-BIelvPCZ.js";import"./vendor-supabase-DbyvBBOg.js";function me({userId:c}){const{theme:D}=K(),B=D==="light",[i,d]=n.useState(!1),[f,p]=n.useState([]),[u,w]=n.useState(0),[se,re]=n.useState(!1),[P,g]=n.useState(!1),[j,_]=n.useState(!1),y=n.useRef(null),N=n.useRef(null),b=n.useRef(null);Y(b,i);const[v,V]=n.useState(null),l=n.useRef(void 0),k=n.useCallback(async()=>{if(c){if(i){const t=setTimeout(()=>g(!0),400);l.current=t}try{const[t,s]=await Promise.all([x.getNotifications(c,20),x.getUnreadCount(c)]);p(t),w(s)}catch(t){t?.message?.includes("Failed to fetch")||console.error("Failed to fetch notifications:",t)}finally{l.current&&clearTimeout(l.current),g(!1)}}},[c,i]);n.useEffect(()=>{c&&k()},[c,k]),Z(k,c),n.useEffect(()=>{const t=s=>{y.current&&!y.current.contains(s.target)&&(d(!1),l.current&&clearTimeout(l.current),g(!1))};return document.addEventListener("mousedown",t),()=>{document.removeEventListener("mousedown",t),l.current&&clearTimeout(l.current)}},[]);const $=async t=>{try{await x.markAsRead(t),p(s=>s.map(r=>r.id===t?{...r,read:!0}:r)),w(s=>Math.max(0,s-1))}catch(s){console.error("Failed to mark as read:",s)}},z=async()=>{if(!j){_(!0);try{await x.markAllAsRead(c),p(t=>t.map(s=>({...s,read:!0}))),w(0)}catch(t){console.error("Failed to mark all as read:",t)}finally{_(!1)}}},U=t=>{switch(t){case"like":return e.jsx(te,{className:"w-4 h-4 text-sky-500"});case"reply":return e.jsx(A,{className:"w-4 h-4 text-sky-500"});case"repost":return e.jsx(ee,{className:"w-4 h-4 text-green-500"});case"follow":return e.jsx(I,{className:"w-4 h-4 text-sky-500"});case"purchase":return e.jsx(M,{className:"w-4 h-4 text-emerald-500"});case"tip":return e.jsx(M,{className:"w-4 h-4 text-green-400"});case"message":return e.jsx(A,{className:"w-4 h-4 text-sky-400"});default:return e.jsx(F,{className:"w-4 h-4 text-white/50"})}},m=(t,s)=>t?.verified||t?.is_lifetime_member||t?.is_diamond_member||t?.account_type==="business"?e.jsxs(e.Fragment,{children:[" ",e.jsx("span",{className:"inline-flex align-[-3px]",children:e.jsx(S,{size:"xs",username:s,accountType:t?.account_type,isPrime:t?.is_diamond_member})})]}):null,G=t=>{const s=t.actors;if(s.length===0)return e.jsx("strong",{className:"text-white",children:"Someone"});if(s.length===1){const r=s[0];return e.jsxs(e.Fragment,{children:[e.jsxs("strong",{className:"text-white",children:["@",r.username]}),m(r,r.username)]})}return s.length===2?e.jsxs(e.Fragment,{children:[e.jsxs("strong",{className:"text-white",children:["@",s[0].username]}),m(s[0],s[0].username),e.jsx("span",{className:"text-white/60",children:" and "}),e.jsxs("strong",{className:"text-white",children:["@",s[1].username]}),m(s[1],s[1].username)]}):e.jsxs(e.Fragment,{children:[e.jsxs("strong",{className:"text-white",children:["@",s[0].username]}),m(s[0],s[0].username),e.jsx("span",{className:"text-white/60",children:", "}),e.jsxs("strong",{className:"text-white",children:["@",s[1].username]}),m(s[1],s[1].username),e.jsxs("span",{className:"text-white/60",children:[" and ",s.length-2," other",s.length-2===1?"":"s"]})]})},o=t=>{const s=t.actor?.username||"Someone",r=t.actor,h=r?.verified||r?.is_lifetime_member||r?.is_diamond_member||r?.account_type==="business";return e.jsxs(e.Fragment,{children:[e.jsxs("strong",{className:"text-white",children:["@",s]}),h&&e.jsxs(e.Fragment,{children:[" ",e.jsx("span",{className:"inline-flex align-[-3px]",children:e.jsx(S,{size:"xs",username:s,accountType:r?.account_type,isPrime:r?.is_diamond_member})})]})]})},O=t=>{const s=t.primary;if(s.type==="tip"&&t.tipSummary&&t.tipSummary.count>1){const{count:r,display:a}=t.tipSummary;return e.jsxs(e.Fragment,{children:[o(s),e.jsx("span",{className:"text-white/60",children:" sent you "}),e.jsxs("span",{className:"text-white font-semibold",children:["Ã",r]}),e.jsx("span",{className:"text-white/60",children:" tips"}),a&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-white/40",children:" · "}),e.jsx("span",{className:"text-green-400 font-semibold",children:a})]})]})}if(t.actors.length>1){const r=s.type==="like"?" liked your post":s.type==="repost"?" reposted your post":s.type==="follow"?" started following you":"";if(r)return e.jsxs(e.Fragment,{children:[G(t),e.jsx("span",{className:"text-white/60",children:r})]})}return L(s)},L=t=>
1{switch(t.actor?.username,t.type){case"like":return e.jsxs(e.Fragment,{children:[o(t),e.jsx("span",{className:"text-white/60",children:" liked your post"})]});case"reply":return e.jsxs(e.Fragment,{children:[o(t),e.jsx("span",{className:"text-white/60",children:" replied to your post"})]});case"repost":return e.jsxs(e.Fragment,{children:[o(t),e.jsx("span",{className:"text-white/60",children:" reposted your post"})]});case"follow":return e.jsxs(e.Fragment,{children:[o(t),e.jsx("span",{className:"text-white/60",children:" started following you"})]});case"purchase":return e.jsxs(e.Fragment,{children:[o(t),e.jsx("span",{className:"text-white/60",children:" purchased your content"})]});case"mention":return e.jsxs(e.Fragment,{children:[o(t),e.jsx("span",{className:"text-white/60",children:" mentioned you"})]});case"tip":return e.jsxs(e.Fragment,{children:[o(t),e.jsx("span",{className:"text-white/60",children:" sent you a tip"}),t.content&&e.jsxs("span",{className:"text-green-400 font-semibold",children:[" ",t.content]})]});case"message":return e.jsxs(e.Fragment,{children:[o(t),e.jsx("span",{className:"text-white/60",children:" sent you a message"})]});case"moderation_block":return e.jsxs("span",{className:"text-white/60",children:[e.jsx("strong",{className:"text-amber-400 font-semibold",children:"Content blocked by moderation."}),t.content&&e.jsxs(e.Fragment,{children:[" ",t.content]})]});default:return e.jsx("span",{className:"text-white/60",children:"You have a new notification"})}},H=t=>{const s=new Date(t),a=new Date().getTime()-s.getTime(),h=Math.floor(a/6e4),E=Math.floor(a/36e5),R=Math.floor(a/864e5);return h<1?"now":h<60?`${h}m`:E<24?`${E}h`:R<7?`${R}d`:s.toLocaleDateString("en-US",{month:"short",day:"numeric"})},W=t=>t.type==="message"?"/messages":t.post_id?`/post/${t.post_id}`:t.type==="follow"&&t.actor?.username?`/profile/${t.actor.username}`:"#";return n.useLayoutEffect(()=>{if(!i)return;const t=()=>{const s=N.current;if(!s)return;const r=s.getBoundingClientRect();V({top:r.bottom+8,right:Math.max(8,window.innerWidth-r.right)})};return t(),window.addEventListener("resize",t),window.addEventListener("scroll",t,!0),()=>{window.removeEventListener("resize",t),window.removeEventListener("scroll",t,!0)}},[i]),n.useEffect(()=>{if(!i)return;const t=r=>{const a=r.target;b.current?.contains(a)||N.current?.contains(a)||d(!1)},s=r=>{r.key==="Escape"&&d(!1)};return document.addEventListener("mousedown",t),document.addEventListener("keydown",s),()=>{document.removeEventListener("mousedown",t),document.removeEventListener("keydown",s)}},[i]),e.jsxs("div",{className:"relative",ref:y,children:[e.jsxs("button",{ref:N,onClick:()=>d(!i),className:`relative p-2 rounded-full transition-all ${B?"text-gray-600 hover:text-gray-900 hover:bg-gray-100":"text-white/60 hover:text-white hover:bg-white/[0.06]"}`,"aria-label":"Notifications",children:[e.jsx(F,{className:"w-5 h-5"}),u>0&&e.jsx("span",{className:"absolute -top-0.5 -right-0.5 min-w-[18px] h-[18px] flex items-center justify-center bg-sky-500 text-white text-[10px] font-bold rounded-full px-1",children:u>99?"99+":u})]}),i&&v&&typeof document<"u"&&document.body&&J.createPortal(e.jsxs("div",{ref:b,role:"dialog","aria-label":"Notifications",style:{position:"fixed",top:v.top,right:v.right},className:"w-80 sm:w-96 bg-[#0a0a0a] border border-white/10 rounded-2xl shadow-2xl z-[210] overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-white/[0.08]",children:[e.jsx("h3",{className:"text-lg font-bold text-white",children:"Notifications"}),u>0&&e.jsxs("button",{onClick:z,disabled:j,className:"text-xs text-sky-400 hover:text-sky-300 font-medium disabled:opacity-50 flex items-center gap-1",children:[j?e.jsx(T,{className:"w-3 h-3 animate-spin"}):e.jsx(X,{className:"w-3 h-3"}),"Mark all read"]})]}),e.jsx("div",{className:"max-h-[400px] overflow-y-auto",children:P?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(T,{className:"w-6 h-6 text-sky-500 animate-spin"})}):f.length===0?e.jsxs("div",{className:"text-center py-8 px-4",children:[e.jsx(F,{className:"w-10 h-10 text-white/20 mx-auto mb-3"}),e.jsx("p",{className:"text-white/40 text-sm",children:"No notifications yet"}),e.jsx("p",{className:"text-white/25 text-xs mt-1",children:"When someone interacts with your content, you'll see it here"})]}):e.jsx("div",{className:"divide-y divide-white/[0.04]",children:Q(f).map(t=>{const s=t.primary,r=t.actors.length>1;return e.jsxs(C,{to:W(s),onClick:()=>{t.items.filter(a=>
1!a.read).forEach(a=>$(a.id)),d(!1)},className:`flex items-start gap-3 px-4 py-3 hover:bg-white/[0.03] transition-colors ${t.hasUnread?"bg-sky-500/[0.03]":""}`,children:[e.jsxs("div",{className:"relative flex-shrink-0",children:[e.jsx(q,{src:t.actors[0]?.avatar??s.actor?.avatar,username:t.actors[0]?.username||s.actor?.username||"?",size:"md"}),e.jsx("div",{className:"absolute -bottom-1 -right-1 w-5 h-5 rounded-full bg-black border-2 border-[#0a0a0a] flex items-center justify-center",children:U(s.type)})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm leading-snug",children:r?O(t):L(s)}),e.jsx("p",{className:"text-xs text-white/30 mt-1",children:H(s.created_at)})]}),t.hasUnread&&e.jsx("div",{className:"w-2 h-2 rounded-full bg-sky-500 flex-shrink-0 mt-2"})]},t.key)})})}),f.length>0&&e.jsx("div",{className:"border-t border-white/[0.08] p-2",children:e.jsx(C,{to:"/notifications",onClick:()=>d(!1),className:"block w-full text-center py-2 text-sm text-sky-400 hover:text-sky-300 hover:bg-white/[0.03] rounded-lg transition-colors",children:"View all notifications"})})]}),document.body)]})}
1export{me 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.