// components/workout/WorkoutOfflineState.tsx
import React from 'react';
import { View, TouchableOpacity } from 'react-native';
import { Text } from '@/components/ui/text';
import { WifiOffIcon, RefreshCwIcon, ArrowLeftIcon } from 'lucide-react-native';
import { useConnectivity } from '@/lib/db/services/ConnectivityService';
import { useRouter } from 'expo-router';
interface WorkoutOfflineStateProps {
workoutId?: string;
}
export default function WorkoutOfflineState({ workoutId }: WorkoutOfflineStateProps) {
const { lastOnlineTime, checkConnection } = useConnectivity();
const router = useRouter();
// Format last online time
const lastOnlineText = lastOnlineTime
? `Last online: ${new Date(lastOnlineTime).toLocaleDateString()} at ${new Date(lastOnlineTime).toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'})}`
: 'Not connected recently';
// Handle manual refresh attempt
const handleRefresh = () => {
checkConnection();
};
// Handle go back
const handleGoBack = () => {
router.back();
};
return (
( Component: React.ComponentType
): React.FC
{
return (props: P & { workoutId?: string; workout?: any }) => {
const { isOnline } = useConnectivity();
// If we're online or we already have the workout data locally, show the component
if (isOnline || props.workout) {
return