// components/templates/TemplateCard.tsx import React from 'react'; import { View, TouchableOpacity, Platform } from 'react-native'; import { Text } from '@/components/ui/text'; import { Card, CardContent } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { Trash2, Star, Play } from 'lucide-react-native'; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from '@/components/ui/alert-dialog'; import { Template, TemplateExerciseDisplay } from '@/types/templates'; import { useIconColor } from '@/lib/theme/iconUtils'; import { FIXED_COLORS } from '@/lib/theme/colors'; interface TemplateCardProps { template: Template; onPress: () => void; onDelete: (id: string) => void; onFavorite: () => void; onStartWorkout: () => void; } export function TemplateCard({ template, onPress, onDelete, onFavorite, onStartWorkout }: TemplateCardProps) { const [showDeleteAlert, setShowDeleteAlert] = React.useState(false); const lastUsed = template.metadata?.lastUsed ? new Date(template.metadata.lastUsed) : undefined; const { getIconProps, getIconColor } = useIconColor(); const { id, title, type, category, exercises, description, tags = [], source, isFavorite } = template; const handleConfirmDelete = () => { onDelete(id); setShowDeleteAlert(false); }; // Prevent event propagation when clicking on action buttons const handleStartWorkout = (e: any) => { if (e && e.stopPropagation) { e.stopPropagation(); } onStartWorkout(); }; const handleFavorite = (e: any) => { if (e && e.stopPropagation) { e.stopPropagation(); } onFavorite(); }; return ( {title} {source} {type} {category} {exercises.length > 0 && ( Exercises: {exercises.slice(0, 3).map((exercise, index) => ( • {exercise.title} ({exercise.targetSets}×{exercise.targetReps}) ))} {exercises.length > 3 && ( +{exercises.length - 3} more )} )} {description && ( {description} )} {tags.length > 0 && ( {tags.map(tag => ( {tag} ))} )} {lastUsed && ( Last used: {lastUsed.toLocaleDateString()} )} Delete Template Are you sure you want to delete {title}? This action cannot be undone. ); }