import React from 'react'; import { Chore } from '../api/chores'; import { useAuth } from '../contexts/AuthContext'; interface ChoreCardProps { chore: Chore; onComplete: (id: number) => void; onDelete: (id: number) => void; onEdit?: (id: number) => void; } const ChoreCard: React.FC = ({ chore, onComplete, onDelete, onEdit }) => { const { user } = useAuth(); const statusColors = { pending: 'bg-yellow-100 text-yellow-800', in_progress: 'bg-blue-100 text-blue-800', completed: 'bg-green-100 text-green-800', skipped: 'bg-gray-100 text-gray-800', }; const frequencyIcons = { daily: '📅', weekly: '📆', fortnightly: '🗓️', monthly: '📊', on_trigger: '⏱️', }; // Check if current user is assigned to this chore const isAssignedToMe = chore.assigned_users?.some(u => u.id === user?.id); const myAssignment = chore.assigned_users?.find(u => u.id === user?.id); const myCompletionStatus = myAssignment?.completed_at ? 'completed' : chore.status; // Check if today is anyone's birthday const today = new Date(); const hasBirthdayUser = chore.assigned_users?.some(u => { if (!u.birthday) return false; const bday = new Date(u.birthday); return bday.getMonth() === today.getMonth() && bday.getDate() === today.getDate(); }); return (

{chore.title}

{chore.points > 0 && (
⭐ {chore.points} pts
)}
{chore.status.replace('_', ' ')}
{chore.description && (

{chore.description}

)}
{chore.room}
{frequencyIcons[chore.frequency] || '📋'} {chore.frequency.replace('_', ' ')}
{/* Assigned Users */} {chore.assigned_users && chore.assigned_users.length > 0 && (
Assigned to:
{chore.assigned_users.map(assignedUser => { const isBirthday = assignedUser.birthday && (() => { const bday = new Date(assignedUser.birthday); return bday.getMonth() === today.getMonth() && bday.getDate() === today.getDate(); })(); return (
{assignedUser.full_name} {isBirthday && ' 🎂'} {assignedUser.completed_at && ( ✓ Done )}
); })}
)} {chore.due_date && (
{new Date(chore.due_date).toLocaleDateString()}
)}
{isAssignedToMe && myCompletionStatus !== 'completed' && ( )} {user?.is_admin && onEdit && ( )} {user?.is_admin && ( )}
{hasBirthdayUser && (

🎂 Birthday chore! Give them a break today.

)}
); }; export default ChoreCard;