import React, { useState, useEffect, useCallback } from 'react'; import { View, Text, StyleSheet, ScrollView, TouchableOpacity, RefreshControl, } from 'react-native'; import { useLocalSearchParams, router } from 'expo-router'; import { Ionicons } from '@expo/vector-icons'; import { SafeAreaView } from 'react-native-safe-area-context'; import { api } from '@/services/api'; import { LoadingSpinner } from '@/components/ui/LoadingSpinner'; import { FullScreenError } from '@/components/ui/ErrorMessage'; import { Button } from '@/components/ui/Button'; import { AppColors, BorderRadius, FontSizes, Spacing } from '@/constants/theme'; import type { Patient } from '@/types'; export default function PatientDashboardScreen() { const { id } = useLocalSearchParams<{ id: string }>(); const [patient, setPatient] = useState(null); const [isLoading, setIsLoading] = useState(true); const [isRefreshing, setIsRefreshing] = useState(false); const [error, setError] = useState(null); const loadPatient = useCallback(async (showLoading = true) => { if (!id) return; if (showLoading) setIsLoading(true); setError(null); try { const response = await api.getPatient(parseInt(id, 10)); if (response.ok && response.data) { setPatient(response.data); } else { setError(response.error?.message || 'Failed to load patient'); } } catch (err) { setError(err instanceof Error ? err.message : 'An error occurred'); } finally { setIsLoading(false); setIsRefreshing(false); } }, [id]); useEffect(() => { loadPatient(); }, [loadPatient]); const handleRefresh = useCallback(() => { setIsRefreshing(true); loadPatient(false); }, [loadPatient]); const handleChatPress = () => { router.push('/(tabs)/chat'); }; if (isLoading) { return ; } if (error || !patient) { return ( loadPatient()} /> ); } return ( {/* Header */} router.back()} > {patient.name} } > {/* Patient Info Card */} {patient.name.charAt(0).toUpperCase()} {patient.status === 'online' ? 'Online' : 'Offline'} {patient.name} {patient.relationship} Last activity: {patient.last_activity} {/* Health Stats */} Health Overview {patient.health_data?.heart_rate || '--'} Heart Rate BPM {patient.health_data?.steps?.toLocaleString() || '--'} Steps Today steps {patient.health_data?.sleep_hours || '--'} Sleep hours {/* Quick Actions */} Quick Actions Chat with Julia Set Reminder Video Call Medications {/* Chat with Julia Button */}