import { Colors } from '@/constants/Colors'; import { useColorScheme } from '@/hooks/useColorScheme'; import { Ionicons } from '@expo/vector-icons'; import dayjs from 'dayjs'; import React from 'react'; import { Dimensions, StyleSheet, Text, TouchableOpacity, View } from 'react-native'; export interface TodoItem { id: string; title: string; description?: string; time: string; category: 'workout' | 'finance' | 'personal' | 'work' | 'health'; isCompleted?: boolean; priority?: 'high' | 'medium' | 'low'; } interface TodoCardProps { item: TodoItem; onPress?: (item: TodoItem) => void; onToggleComplete?: (item: TodoItem) => void; } const { width: screenWidth } = Dimensions.get('window'); const CARD_WIDTH = (screenWidth - 60) * 0.65; // 显示1.5张卡片 const getCategoryIcon = (category: TodoItem['category']) => { switch (category) { case 'workout': return 'fitness-outline'; case 'finance': return 'card-outline'; case 'personal': return 'person-outline'; case 'work': return 'briefcase-outline'; case 'health': return 'heart-outline'; default: return 'checkmark-circle-outline'; } }; const getCategoryColor = (category: TodoItem['category']) => { switch (category) { case 'workout': return '#FF6B6B'; case 'finance': return '#4ECDC4'; case 'personal': return '#45B7D1'; case 'work': return '#96CEB4'; case 'health': return '#FFEAA7'; default: return '#DDA0DD'; } }; const getPriorityColor = (priority: TodoItem['priority']) => { switch (priority) { case 'high': return '#FF4757'; case 'medium': return '#FFA502'; case 'low': return '#2ED573'; default: return '#747D8C'; } }; export function TodoCard({ item, onPress, onToggleComplete }: TodoCardProps) { const theme = useColorScheme() ?? 'light'; const colorTokens = Colors[theme]; const categoryColor = getCategoryColor(item.category); const categoryIcon = getCategoryIcon(item.category); const priorityColor = getPriorityColor(item.priority); const timeFormatted = dayjs(item.time).format('HH:mm'); const isToday = dayjs(item.time).isSame(dayjs(), 'day'); return ( onPress?.(item)} activeOpacity={0.8} > {/* 顶部标签和优先级 */} {item.category} {item.priority && ( )} {/* 主要内容 */} {item.title} {item.description && ( {item.description} )} {/* 底部时间和完成状态 */} {timeFormatted} onToggleComplete?.(item)} > {item.isCompleted && ( )} {/* 完成状态遮罩 */} {item.isCompleted && ( )} ); } const styles = StyleSheet.create({ container: { width: CARD_WIDTH, height: 140, marginHorizontal: 8, borderRadius: 20, padding: 16, shadowColor: '#000', shadowOffset: { width: 0, height: 4, }, shadowOpacity: 0.1, shadowRadius: 8, elevation: 6, position: 'relative', }, header: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', marginBottom: 12, }, categoryBadge: { flexDirection: 'row', alignItems: 'center', paddingHorizontal: 8, paddingVertical: 4, borderRadius: 12, backgroundColor: '#4ECDC4', }, categoryText: { fontSize: 10, fontWeight: '600', color: '#fff', marginLeft: 4, textTransform: 'capitalize', }, priorityDot: { width: 8, height: 8, borderRadius: 4, backgroundColor: '#FF4757', }, content: { flex: 1, justifyContent: 'center', }, title: { fontSize: 16, fontWeight: '700', lineHeight: 20, marginBottom: 4, }, description: { fontSize: 12, lineHeight: 16, opacity: 0.7, }, footer: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', marginTop: 12, }, timeContainer: { flexDirection: 'row', alignItems: 'center', }, timeText: { fontSize: 12, fontWeight: '500', marginLeft: 4, }, completeButton: { width: 24, height: 24, borderRadius: 12, borderWidth: 1.5, justifyContent: 'center', alignItems: 'center', }, completedOverlay: { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, backgroundColor: 'rgba(255, 255, 255, 0.9)', borderRadius: 20, justifyContent: 'center', alignItems: 'center', }, });