import { useFetchEvent } from '@/hooks' import { getZapInfoFromEvent } from '@/lib/event-metadata' import { shouldHideInteractions } from '@/lib/event-filtering' import { formatAmount } from '@/lib/lightning' import { openNoteFromFetchOrCache } from '@/lib/navigation-related-events' import { relayHintsFromEventTags } from '@/lib/relay-list-builder' import { getSuperchatPaytoType } from '@/lib/superchat' import { toProfile } from '@/lib/link' import { cn } from '@/lib/utils' import { Event } from 'nostr-tools' import { useMemo, type MouseEvent } from 'react' import { useTranslation } from 'react-i18next' import { useSmartNoteNavigationOptional, useSecondaryPageOptional } from '@/PageManager' import Username from '../Username' import SuperchatPaymentMethodLabel from './SuperchatPaymentMethodLabel' import SuperchatCommentMarkdown from './SuperchatCommentMarkdown' import TurnIntoSuperchatButton from '../TurnIntoSuperchatButton' export default function Zap({ event, className }: { event: Event className?: string }) { const { t } = useTranslation() const zapInfo = useMemo(() => getZapInfoFromEvent(event), [event]) const zapRelayHints = useMemo(() => relayHintsFromEventTags(event), [event]) const zapFetchOpts = useMemo( () => (zapRelayHints.length ? { relayHints: zapRelayHints } : undefined), [zapRelayHints] ) const { event: targetEvent } = useFetchEvent(zapInfo?.eventId, undefined, zapFetchOpts) const isEventZap = Boolean(targetEvent || zapInfo?.eventId) const isProfileZap = Boolean(!isEventZap && zapInfo?.recipientPubkey) const actualRecipientPubkey = useMemo(() => { if (isEventZap && targetEvent) { return targetEvent.pubkey } if (isProfileZap) { return zapInfo?.recipientPubkey } return undefined }, [isEventZap, isProfileZap, targetEvent, zapInfo?.recipientPubkey]) const paytoType = useMemo(() => getSuperchatPaytoType(event), [event]) const { navigateToNote } = useSmartNoteNavigationOptional() const secondaryPage = useSecondaryPageOptional() const push = secondaryPage?.push ?? ((url: string) => { window.location.href = url }) const inQuietMode = targetEvent ? shouldHideInteractions(targetEvent) : false if (inQuietMode) { return null } if (!zapInfo || !zapInfo.senderPubkey) { return (