import { Colors } from '@/constants/Colors'; import { useColorScheme } from '@/hooks/useColorScheme'; import { useWaterDataByDate } from '@/hooks/useWaterData'; import { getQuickWaterAmount } from '@/utils/userPreferences'; import { Ionicons } from '@expo/vector-icons'; import { Image } from 'expo-image'; import { LinearGradient } from 'expo-linear-gradient'; import { router, useLocalSearchParams } from 'expo-router'; import React, { useEffect, useState } from 'react'; import { Alert, KeyboardAvoidingView, Platform, ScrollView, StyleSheet, Text, TouchableOpacity, View } from 'react-native'; import { Swipeable } from 'react-native-gesture-handler'; import { HeaderBar } from '@/components/ui/HeaderBar'; import { useSafeAreaTop } from '@/hooks/useSafeAreaWithPadding'; import dayjs from 'dayjs'; interface WaterDetailProps { selectedDate?: string; } const WaterDetail: React.FC = () => { const safeAreaTop = useSafeAreaTop() const { selectedDate } = useLocalSearchParams<{ selectedDate?: string }>(); const theme = (useColorScheme() ?? 'light') as 'light' | 'dark'; const colorTokens = Colors[theme]; const [dailyGoal, setDailyGoal] = useState('2000'); const [quickAddAmount, setQuickAddAmount] = useState('250'); // Remove modal states as they are now in separate settings page // 使用新的 hook 来处理指定日期的饮水数据 const { waterRecords, dailyWaterGoal, updateWaterGoal, removeWaterRecord } = useWaterDataByDate(selectedDate); // 处理设置按钮点击 - 跳转到设置页面 const handleSettingsPress = () => { router.push('/water/settings'); }; // Remove all modal-related functions as they are now in separate settings page // 删除饮水记录 const handleDeleteRecord = async (recordId: string) => { await removeWaterRecord(recordId); }; // 加载用户偏好设置和当前饮水目标 useEffect(() => { const loadUserPreferences = async () => { try { const amount = await getQuickWaterAmount(); setQuickAddAmount(amount.toString()); // 设置当前的饮水目标 if (dailyWaterGoal) { setDailyGoal(dailyWaterGoal.toString()); } } catch (error) { console.error('加载用户偏好设置失败:', error); } }; loadUserPreferences(); }, [dailyWaterGoal]); // 新增:饮水记录卡片组件 const WaterRecordCard = ({ record, onDelete }: { record: any; onDelete: () => void }) => { const swipeableRef = React.useRef(null); // 处理删除操作 const handleDelete = () => { Alert.alert( '确认删除', '确定要删除这条饮水记录吗?此操作无法撤销。', [ { text: '取消', style: 'cancel', }, { text: '删除', style: 'destructive', onPress: () => { onDelete(); swipeableRef.current?.close(); }, }, ] ); }; // 渲染右侧删除按钮 const renderRightActions = () => { return ( 删除 ); }; return ( {dayjs(record.recordedAt || record.createdAt).format('HH:mm')} {record.amount}ml {record.note && ( {record.note} )} ); }; return ( {/* 背景渐变 */} {/* 装饰性圆圈 */} { // 这里会通过路由自动处理返回 router.back(); }} right={ } /> {/* 第二部分:饮水记录 */} {selectedDate ? dayjs(selectedDate).format('MM月DD日') : '今日'}饮水记录 {waterRecords && waterRecords.length > 0 ? ( {waterRecords.map((record) => ( handleDeleteRecord(record.id)} /> ))} {/* 总计显示 */} 总计:{waterRecords.reduce((sum, record) => sum + record.amount, 0)}ml 目标:{dailyWaterGoal}ml ) : ( 暂无饮水记录 点击"添加记录"开始记录饮水量 )} {/* All modals have been moved to the separate water-settings page */} ); }; const styles = StyleSheet.create({ container: { flex: 1, }, gradientBackground: { position: 'absolute', left: 0, right: 0, top: 0, bottom: 0, }, decorativeCircle1: { position: 'absolute', top: 40, right: 20, width: 60, height: 60, borderRadius: 30, backgroundColor: '#0EA5E9', opacity: 0.1, }, decorativeCircle2: { position: 'absolute', bottom: -15, left: -15, width: 40, height: 40, borderRadius: 20, backgroundColor: '#0EA5E9', opacity: 0.05, }, keyboardAvoidingView: { flex: 1, }, scrollView: { flex: 1, }, scrollContent: { padding: 20, }, section: { marginBottom: 32, }, sectionTitle: { fontSize: 16, fontWeight: '500', marginBottom: 20, letterSpacing: -0.5, }, subsectionTitle: { fontSize: 14, fontWeight: '500', marginBottom: 12, letterSpacing: -0.3, }, sectionSubtitle: { fontSize: 12, fontWeight: '400', lineHeight: 18, }, // 饮水记录相关样式 recordsList: { gap: 12, }, recordCardContainer: { // iOS 阴影效果 shadowColor: '#000000', shadowOffset: { width: 0, height: 1 }, shadowOpacity: 0.08, shadowRadius: 4, // Android 阴影效果 elevation: 2, }, recordCard: { borderRadius: 12, padding: 10, }, recordMainContent: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', }, recordIconContainer: { width: 40, height: 40, borderRadius: 10, alignItems: 'center', justifyContent: 'center', }, recordIcon: { width: 20, height: 20, }, recordInfo: { flex: 1, marginLeft: 12, }, recordLabel: { fontSize: 16, fontWeight: '600', marginBottom: 8, }, recordTimeContainer: { flexDirection: 'row', alignItems: 'center', gap: 4, }, recordAmountContainer: { alignItems: 'flex-end', }, recordAmount: { fontSize: 14, fontWeight: '500', }, deleteSwipeButton: { backgroundColor: '#EF4444', justifyContent: 'center', alignItems: 'center', width: 80, borderRadius: 12, marginLeft: 8, }, deleteSwipeButtonText: { color: '#FFFFFF', fontSize: 12, fontWeight: '600', marginTop: 4, }, recordTimeText: { fontSize: 12, fontWeight: '400', }, recordNote: { marginTop: 8, fontSize: 14, fontStyle: 'italic', lineHeight: 20, }, recordsSummary: { marginTop: 20, padding: 16, borderRadius: 12, flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', }, summaryText: { fontSize: 12, fontWeight: '500', }, summaryGoal: { fontSize: 12, fontWeight: '500', }, noRecordsContainer: { alignItems: 'center', justifyContent: 'center', paddingVertical: 40, gap: 16, }, noRecordsText: { fontSize: 15, fontWeight: '500', lineHeight: 20, }, noRecordsSubText: { fontSize: 13, textAlign: 'center', lineHeight: 18, opacity: 0.7, }, modalBackdrop: { ...StyleSheet.absoluteFillObject, backgroundColor: 'rgba(0,0,0,0.4)', }, modalSheet: { position: 'absolute', left: 0, right: 0, bottom: 0, padding: 16, backgroundColor: '#FFFFFF', borderTopLeftRadius: 16, borderTopRightRadius: 16, // iOS 阴影效果 shadowColor: '#000000', shadowOffset: { width: 0, height: -2 }, shadowOpacity: 0.1, shadowRadius: 8, // Android 阴影效果 elevation: 16, }, modalHandle: { width: 36, height: 4, backgroundColor: '#E0E0E0', borderRadius: 2, alignSelf: 'center', marginBottom: 20, }, modalTitle: { fontSize: 20, fontWeight: '600', textAlign: 'center', marginBottom: 20, }, pickerContainer: { height: 200, marginBottom: 20, }, picker: { height: 200, }, modalActions: { flexDirection: 'row', justifyContent: 'flex-end', gap: 12, }, modalBtn: { paddingHorizontal: 14, paddingVertical: 10, borderRadius: 10, minWidth: 80, alignItems: 'center', }, modalBtnPrimary: { // backgroundColor will be set dynamically }, modalBtnText: { fontSize: 16, fontWeight: '600', }, modalBtnTextPrimary: { // color will be set dynamically }, settingsButton: { width: 32, height: 32, alignItems: 'center', justifyContent: 'center', }, settingsModalSheet: { position: 'absolute', left: 0, right: 0, bottom: 0, padding: 16, backgroundColor: '#FFFFFF', borderTopLeftRadius: 16, borderTopRightRadius: 16, shadowColor: '#000000', shadowOffset: { width: 0, height: -2 }, shadowOpacity: 0.1, shadowRadius: 8, elevation: 16, }, settingsModalTitle: { fontSize: 18, fontWeight: '600', textAlign: 'center', marginBottom: 20, }, settingsMenuContainer: { backgroundColor: '#FFFFFF', borderRadius: 12, shadowColor: '#000', shadowOffset: { width: 0, height: 1 }, shadowOpacity: 0.05, shadowRadius: 4, elevation: 2, overflow: 'hidden', }, settingsMenuItem: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', paddingVertical: 14, paddingHorizontal: 16, borderBottomWidth: 1, borderBottomColor: '#F1F3F4', }, settingsMenuItemLeft: { flexDirection: 'row', alignItems: 'center', flex: 1, }, settingsIconContainer: { width: 32, height: 32, borderRadius: 6, alignItems: 'center', justifyContent: 'center', marginRight: 12, }, settingsMenuItemContent: { flex: 1, }, settingsMenuItemTitle: { fontSize: 15, fontWeight: '500', marginBottom: 2, }, settingsMenuItemSubtitle: { fontSize: 12, marginBottom: 4, }, settingsMenuItemValue: { fontSize: 14, }, // 喝水提醒配置弹窗样式 waterReminderModalSheet: { position: 'absolute', left: 0, right: 0, bottom: 0, padding: 16, backgroundColor: '#FFFFFF', borderTopLeftRadius: 16, borderTopRightRadius: 16, maxHeight: '80%', shadowColor: '#000000', shadowOffset: { width: 0, height: -2 }, shadowOpacity: 0.1, shadowRadius: 8, elevation: 16, }, waterReminderContent: { flex: 1, marginBottom: 20, }, waterReminderSection: { marginBottom: 24, }, waterReminderSectionHeader: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', marginBottom: 8, }, waterReminderSectionTitleContainer: { flexDirection: 'row', alignItems: 'center', gap: 8, }, waterReminderSectionTitle: { fontSize: 16, fontWeight: '600', }, waterReminderSectionDesc: { fontSize: 14, lineHeight: 20, marginTop: 4, }, timeRangeContainer: { flexDirection: 'row', gap: 16, marginTop: 16, }, timePickerContainer: { flex: 1, }, timeLabel: { fontSize: 14, fontWeight: '500', marginBottom: 8, }, timePicker: { paddingVertical: 12, paddingHorizontal: 16, borderRadius: 8, flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 8, }, timePickerText: { fontSize: 16, fontWeight: '500', }, timePickerIcon: { opacity: 0.6, }, intervalContainer: { marginTop: 16, }, intervalPickerContainer: { backgroundColor: '#F8F9FA', borderRadius: 8, overflow: 'hidden', }, intervalPicker: { height: 120, }, // 时间选择器弹窗样式 timePickerModalSheet: { position: 'absolute', left: 0, right: 0, bottom: 0, padding: 16, backgroundColor: '#FFFFFF', borderTopLeftRadius: 16, borderTopRightRadius: 16, maxHeight: '60%', shadowColor: '#000000', shadowOffset: { width: 0, height: -2 }, shadowOpacity: 0.1, shadowRadius: 8, elevation: 16, }, timePickerContent: { flex: 1, marginBottom: 20, }, timePickerSection: { marginBottom: 20, }, timePickerLabel: { fontSize: 16, fontWeight: '600', marginBottom: 12, textAlign: 'center', }, hourPickerContainer: { backgroundColor: '#F8F9FA', borderRadius: 8, overflow: 'hidden', }, hourPicker: { height: 160, }, timeRangePreview: { backgroundColor: '#F0F8FF', borderRadius: 8, padding: 16, marginTop: 16, alignItems: 'center', }, timeRangePreviewLabel: { fontSize: 12, fontWeight: '500', marginBottom: 4, }, timeRangePreviewText: { fontSize: 18, fontWeight: '600', marginBottom: 8, }, timeRangeWarning: { fontSize: 12, color: '#FF6B6B', textAlign: 'center', lineHeight: 18, }, }); export default WaterDetail;