import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from '@/components/ui/alert-dialog' import { Button } from '@/components/ui/button' import { useFollowList } from '@/providers/FollowListProvider' import { useNostr } from '@/providers/NostrProvider' import { Loader } from 'lucide-react' import { useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' import { toast } from 'sonner' export default function FollowButton({ pubkey }: { pubkey: string }) { const { t } = useTranslation() const { pubkey: accountPubkey, checkLogin } = useNostr() const { followingSet, follow, unfollow } = useFollowList() const [updating, setUpdating] = useState(false) const [hover, setHover] = useState(false) const isFollowing = useMemo(() => followingSet.has(pubkey), [followingSet, pubkey]) if (!accountPubkey || (pubkey && pubkey === accountPubkey)) return null const handleFollow = async (e: React.MouseEvent) => { e.stopPropagation() checkLogin(async () => { if (isFollowing) return setUpdating(true) try { await follow(pubkey) } catch (error) { toast.error(t('Follow failed') + ': ' + (error as Error).message) } finally { setUpdating(false) } }) } const handleUnfollow = async (e: React.MouseEvent) => { e.stopPropagation() checkLogin(async () => { if (!isFollowing) return setUpdating(true) try { await unfollow(pubkey) } catch (error) { toast.error(t('Unfollow failed') + ': ' + (error as Error).message) } finally { setUpdating(false) } }) } return isFollowing ? (