import React from 'react'; import { View, Text, StyleSheet, TouchableOpacity } from 'react-native'; import { Ionicons } from '@expo/vector-icons'; import { theme } from '../theme'; import { Event } from '../types'; import { safeParseDate } from '../utils/recurrence'; interface EventCardProps { event: Event; onEdit: (event: Event) => void; onToggleComplete: (event: Event) => void; onDelete: (event: Event) => void; } const WEEKDAY_NAMES = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']; // 生成循环规则中文描述 const getRecurrenceLabel = (recurrence: string | null): string | null => { if (!recurrence) return null; const parts = recurrence.split(';'); const type = parts[0]; let interval = 1; let by: number[] = []; for (let i = 1; i < parts.length; i++) { const [key, val] = parts[i].split('='); if (key === 'interval') interval = parseInt(val) || 1; if (key === 'by') by = val.split(',').map(Number); } if (type === 'DAILY') { return interval === 1 ? '每天' : `每${interval}天`; } if (type === 'WEEKLY') { const prefix = interval === 1 ? '每周' : `每${interval}周`; if (by.length > 0) { return `${prefix} ${by.map(d => WEEKDAY_NAMES[d] || '').join('、')}`; } return prefix; } return null; }; export default function EventCard({ event, onEdit, onToggleComplete, onDelete, }: EventCardProps) { const formatTime = (dateString: string) => { const date = safeParseDate(dateString); return date.toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit', }); }; const recurrenceLabel = getRecurrenceLabel(event.recurrence); return ( onEdit(event)} activeOpacity={0.7} > onToggleComplete(event)} > {event.completed ? ( ) : ( )} {event.title} {event.content ? ( {event.content} ) : null} {formatTime(event.start)} {recurrenceLabel && ( <> {recurrenceLabel} )} onDelete(event)} > ); } const styles = StyleSheet.create({ container: { flexDirection: 'row', backgroundColor: theme.colors.surface, borderRadius: theme.borderRadius.lg, padding: theme.spacing.md, marginBottom: theme.spacing.sm, alignItems: 'center', borderWidth: 1, borderColor: theme.colors.surfaceVariant, }, completedContainer: { opacity: 0.6, }, checkbox: { marginRight: theme.spacing.sm, }, checkboxEmpty: { width: 28, height: 28, borderRadius: 14, borderWidth: 2, borderColor: theme.colors.textSecondary, }, content: { flex: 1, }, title: { ...theme.typography.h3, color: theme.colors.text, marginBottom: theme.spacing.xs, }, contentText: { ...theme.typography.bodySmall, color: theme.colors.textSecondary, marginBottom: theme.spacing.xs, }, completedText: { textDecorationLine: 'line-through', }, timeContainer: { flexDirection: 'row', alignItems: 'center', gap: theme.spacing.xs, }, timeText: { ...theme.typography.caption, color: theme.colors.textSecondary, }, recurrenceText: { ...theme.typography.caption, color: theme.colors.primary, }, deleteButton: { padding: theme.spacing.sm, }, });