import { Habit } from '@/lib/types' import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card' import { Button } from '@/components/ui/button' import { Coins, Edit, Trash2, Check, Undo2 } from 'lucide-react' import { useEffect, useState } from 'react' interface HabitItemProps { habit: Habit onEdit: () => void onDelete: () => void onComplete: () => void onUndo: () => void } export default function HabitItem({ habit, onEdit, onDelete, onComplete, onUndo }: HabitItemProps) { const today = new Date().toISOString().split('T')[0] const isCompletedToday = habit.completions?.includes(today) const [isHighlighted, setIsHighlighted] = useState(false) useEffect(() => { const params = new URLSearchParams(window.location.search) const highlightId = params.get('highlight') if (highlightId === habit.id) { setIsHighlighted(true) // Scroll the element into view after a short delay to ensure rendering setTimeout(() => { const element = document.getElementById(`habit-${habit.id}`) if (element) { element.scrollIntoView({ behavior: 'smooth', block: 'center' }) } }, 100) // Remove highlight after animation const timer = setTimeout(() => setIsHighlighted(false), 2000) return () => clearTimeout(timer) } }, [habit.id]) return ( {habit.name} {habit.description}

Frequency: {habit.frequency}

{habit.coinReward} coins per completion
{isCompletedToday && ( )}
) }