import { useThemeColor } from '@/hooks/useThemeColor'; import { ChatSession, useAppStore } from '@/store/useAppStore'; import { useRouter } from 'expo-router'; import { ArrowLeft, MessageSquare, Trash2 } from 'lucide-react-native'; import React from 'react'; import { FlatList, StyleSheet, Text, TouchableOpacity, View } from 'react-native'; export default function HistoryScreen() { const colors = useThemeColor(); const router = useRouter(); const chatSessions = useAppStore(state => state.chatSessions); const loadChat = useAppStore(state => state.loadChat); const deleteChatSession = useAppStore(state => state.deleteChatSession); const handleLoadChat = (id: string) => { loadChat(id); router.back(); }; return ( router.back()} style={styles.backButton}> Chat History {chatSessions.length === 0 ? ( No saved chats yet. ) : ( item.id} contentContainerStyle={styles.listContent} renderItem={({ item }: { item: ChatSession }) => ( handleLoadChat(item.id)} > {item.title} {new Date(item.updatedAt).toLocaleString()} ยท {item.messages.length} msgs deleteChatSession(item.id)} > )} /> )} ); } const styles = StyleSheet.create({ container: { flex: 1, }, header: { flexDirection: 'row', alignItems: 'center', paddingHorizontal: 16, paddingVertical: 14, borderBottomWidth: 1, }, backButton: { marginRight: 16, }, title: { fontSize: 20, fontWeight: 'bold', }, emptyState: { flex: 1, alignItems: 'center', justifyContent: 'center', padding: 32, }, emptyText: { marginTop: 16, fontSize: 16, }, listContent: { padding: 16, gap: 12, }, chatItem: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', padding: 16, borderRadius: 12, borderWidth: 1, }, chatInfo: { flex: 1, marginRight: 16, }, chatTitle: { fontSize: 16, fontWeight: '600', marginBottom: 4, }, chatDate: { fontSize: 12, }, deleteButton: { padding: 8, }, });