import { Colors } from '@/constants/Colors'; import { useColorScheme } from '@/hooks/useColorScheme'; import { TaskListItem } from '@/types/goals'; import React from 'react'; import { StyleSheet, Text, TouchableOpacity, View } from 'react-native'; interface TaskCardProps { task: TaskListItem; onPress?: (task: TaskListItem) => void; onComplete?: (task: TaskListItem) => void; onSkip?: (task: TaskListItem) => void; } export const TaskCard: React.FC = ({ task, onPress, onComplete, onSkip, }) => { const theme = useColorScheme() ?? 'light'; const colorTokens = Colors[theme]; const getStatusColor = (status: string) => { switch (status) { case 'completed': return '#10B981'; case 'in_progress': return '#F59E0B'; case 'overdue': return '#EF4444'; case 'skipped': return '#6B7280'; default: return '#3B82F6'; } }; const getStatusText = (status: string) => { switch (status) { case 'completed': return '已完成'; case 'in_progress': return '进行中'; case 'overdue': return '已过期'; case 'skipped': return '已跳过'; default: return '待开始'; } }; const getCategoryColor = (category?: string) => { if (!category) return '#6B7280'; if (category.includes('运动') || category.includes('健身')) return '#EF4444'; if (category.includes('工作')) return '#3B82F6'; if (category.includes('健康')) return '#10B981'; if (category.includes('财务')) return '#F59E0B'; return '#6B7280'; }; const formatDate = (dateString: string) => { const date = new Date(dateString); const today = new Date(); const tomorrow = new Date(today); tomorrow.setDate(tomorrow.getDate() + 1); if (date.toDateString() === today.toDateString()) { return '今天'; } else if (date.toDateString() === tomorrow.toDateString()) { return '明天'; } else { return date.toLocaleDateString('zh-CN', { month: 'short', day: 'numeric' }); } }; return ( onPress?.(task)} activeOpacity={0.7} > {task.title} {task.goal?.category && ( {task.goal?.category} )} {getStatusText(task.status)} {task.description && ( {task.description} )} 进度: {task.currentCount}/{task.targetCount} {task.progressPercentage}% {formatDate(task.startDate)} {task.status === 'pending' || task.status === 'in_progress' ? ( onSkip?.(task)} > 跳过 onComplete?.(task)} > 完成 ) : null} ); }; const styles = StyleSheet.create({ container: { padding: 16, borderRadius: 12, marginBottom: 12, shadowColor: '#000', shadowOffset: { width: 0, height: 2 }, shadowOpacity: 0.1, shadowRadius: 4, elevation: 3, }, header: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'flex-start', marginBottom: 8, }, titleContainer: { flex: 1, marginRight: 8, }, title: { fontSize: 16, fontWeight: '600', marginBottom: 4, }, categoryTag: { paddingHorizontal: 8, paddingVertical: 2, borderRadius: 12, alignSelf: 'flex-start', }, categoryText: { color: '#FFFFFF', fontSize: 12, fontWeight: '500', }, statusTag: { paddingHorizontal: 8, paddingVertical: 4, borderRadius: 12, }, statusText: { color: '#FFFFFF', fontSize: 12, fontWeight: '500', }, description: { fontSize: 14, marginBottom: 12, lineHeight: 20, }, progressContainer: { marginBottom: 12, }, progressInfo: { flexDirection: 'row', justifyContent: 'space-between', marginBottom: 6, }, progressText: { fontSize: 12, fontWeight: '500', }, progressBar: { height: 6, borderRadius: 3, overflow: 'hidden', }, progressFill: { height: '100%', borderRadius: 3, }, footer: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', }, dateText: { fontSize: 12, fontWeight: '500', }, actionButtons: { flexDirection: 'row', gap: 8, }, actionButton: { paddingHorizontal: 12, paddingVertical: 6, borderRadius: 16, }, skipButton: { backgroundColor: '#F3F4F6', }, skipButtonText: { color: '#6B7280', fontSize: 12, fontWeight: '500', }, completeButton: { backgroundColor: '#10B981', }, completeButtonText: { color: '#FFFFFF', fontSize: 12, fontWeight: '500', }, });