'use client'; import { useState, useEffect } from 'react'; import { useRouter } from 'next/navigation'; import { useAuth } from '@/components/AuthProvider'; import BottomNav from '@/components/BottomNav'; import { getSettings, saveSettings, logout } from '@/lib/pocketbase'; import { AppSettings, DEFAULT_SETTINGS } from '@/lib/types'; import { cn } from '@/lib/utils'; import { Settings, Clock, Crosshair, Moon, Type, WifiOff, LogOut, ChevronRight, Save, RotateCcw, Info, } from 'lucide-react'; const INTERVAL_OPTIONS = [ { value: 30, label: '30 seconds' }, { value: 60, label: '1 minute' }, { value: 120, label: '2 minutes' }, { value: 300, label: '5 minutes' }, { value: 600, label: '10 minutes' }, ]; const ACCURACY_OPTIONS = [ { value: 10, label: '10m (High)' }, { value: 50, label: '50m (Balanced)' }, { value: 100, label: '100m (Battery)' }, { value: 500, label: '500m (Low)' }, ]; export default function SettingsPage() { const router = useRouter(); const { isLoggedIn, user, isLoading: authLoading } = useAuth(); const [settings, setSettings] = useState(DEFAULT_SETTINGS); const [saved, setSaved] = useState(false); useEffect(() => { if (!authLoading && !isLoggedIn) { router.push('/login/'); } }, [isLoggedIn, authLoading, router]); useEffect(() => { setSettings(getSettings()); }, []); const updateSetting = (key: K, value: AppSettings[K]) => { const updated = { ...settings, [key]: value }; setSettings(updated); saveSettings({ [key]: value }); setSaved(true); setTimeout(() => setSaved(false), 2000); }; const resetSettings = () => { if (confirm('Reset all settings to defaults?')) { setSettings(DEFAULT_SETTINGS); saveSettings(DEFAULT_SETTINGS); setSaved(true); setTimeout(() => setSaved(false), 2000); } }; if (authLoading) { return (
); } if (!isLoggedIn) { return null; } return (
{/* Header */}

Settings

{user?.name || user?.email}

{/* Location Settings */}

Location Tracking

{/* Update Interval */}
Update Interval
{settings.locationInterval}s
{INTERVAL_OPTIONS.map((option) => ( ))}

How often your location is sent to the server

{/* Minimum Accuracy */}
Minimum Accuracy
{settings.minimumAccuracy}m
{ACCURACY_OPTIONS.map((option) => ( ))}

Skip location updates with worse accuracy

{/* High Accuracy Toggle */}
High Accuracy Mode Uses GPS for better precision
{/* Display Settings */}

Display

{/* Font Size */}
Font Size
{(['small', 'normal', 'large'] as const).map((size) => ( ))}
{/* Offline Mode */}
Offline Queue Queue actions when offline
{/* About */}

About

1Driver

Version 1.0.0

Collections Management App

{/* Actions */}
{/* Saved Toast */} {saved && (
Settings saved
)}
); }