"use client" import { useState, useTransition } from "react" import { useRouter } from "next/navigation" import { Star } from "lucide-react" import { toggleFollowAction } from "@/app/actions" import { cn } from "@/lib/utils" export function FollowButton({ lotteryId, country, targetDrawDate, initialFollowing, isAuthenticated, }: { lotteryId: string country: string targetDrawDate: string initialFollowing: boolean isAuthenticated: boolean }) { const [following, setFollowing] = useState(initialFollowing) const [pending, startTransition] = useTransition() const router = useRouter() function handleClick() { if (!isAuthenticated) { router.push(`/connexion?next=${encodeURIComponent(window.location.pathname + window.location.search)}`) return } const next = !following setFollowing(next) startTransition(async () => { const res = await toggleFollowAction(lotteryId, country, targetDrawDate, following) if (!res.ok) setFollowing(!next) }) } return ( ) }