import type { NostrEvent } from '@nostrify/nostrify'; import { MessageCircle, MoreHorizontal, Share2, Zap } from 'lucide-react'; import { nip19 } from 'nostr-tools'; import { useCallback } from 'react'; import { RepostIcon } from '@/components/icons/RepostIcon'; import { ReactionButton } from '@/components/ReactionButton'; import { RepostMenu } from '@/components/RepostMenu'; import { ZapDialog } from '@/components/ZapDialog'; import { useAuthor } from '@/hooks/useAuthor'; import { useCurrentUser } from '@/hooks/useCurrentUser'; import { useEventStats } from '@/hooks/useTrending'; import { useToast } from '@/hooks/useToast'; import { canZap } from '@/lib/canZap'; import { formatNumber } from '@/lib/formatNumber'; import { hasGoalZapSplits } from '@/lib/goalUtils'; import { shareOrCopy } from '@/lib/share'; import { cn } from '@/lib/utils'; interface PostActionBarProps { event: NostrEvent; /** Label and action for the first (reply/comments) button. */ replyLabel?: string; onReply: () => void; onMore: () => void; /** Hide the zap button entirely. Useful for events with their own donation * flow (e.g. fundraising campaigns) where a generic Lightning zap is the * wrong primary CTA. Defaults to false. */ hideZap?: boolean; /** Extra classes on the outer wrapper div. */ className?: string; } export function PostActionBar({ event, replyLabel = 'Reply', onReply, onMore, hideZap = false, className, }: PostActionBarProps) { const { toast } = useToast(); const { user } = useCurrentUser(); const author = useAuthor(event.pubkey); const metadata = author.data?.metadata; // TODO: Enable zapping split-recipient NIP-75 goals once zap split payments are supported. const canZapAuthor = !hideZap && user && canZap(metadata) && !hasGoalZapSplits(event); const { data: stats } = useEventStats(event.id, event); const repostTotal = (stats?.reposts ?? 0) + (stats?.quotes ?? 0); const handleShare = useCallback(async () => { let encoded: string; if (event.kind >= 30000 && event.kind < 40000) { const dTag = event.tags.find(([n]) => n === 'd')?.[1] ?? ''; encoded = nip19.naddrEncode({ kind: event.kind, pubkey: event.pubkey, identifier: dTag }); } else if (event.kind >= 10000 && event.kind < 20000) { encoded = nip19.naddrEncode({ kind: event.kind, pubkey: event.pubkey, identifier: '' }); } else { encoded = nip19.neventEncode({ id: event.id, author: event.pubkey }); } const url = `${window.location.origin}/${encoded}`; const result = await shareOrCopy(url); if (result === 'copied') toast({ title: 'Link copied to clipboard' }); }, [event, toast]); return (