'use client' import { useState, useEffect } from 'react' import { useRouter } from 'next/navigation' import Link from 'next/link' import { multiTripIdentity, TripIdentity } from '@/lib/multiTripIdentity' import DarkModeToggle from '@/components/DarkModeToggle' export default function DashboardPage() { const router = useRouter() const [trips, setTrips] = useState([]) const [loading, setLoading] = useState(true) useEffect(() => { loadUserTrips() }, []) const loadUserTrips = () => { const userTrips = multiTripIdentity.getAllTrips() setTrips(userTrips) setLoading(false) } const handleSelectTrip = (trip: TripIdentity) => { multiTripIdentity.updateLastAccessed(trip.tripId) router.push(`/trip/${trip.tripId}`) } const handleLeaveTrip = (trip: TripIdentity) => { if (confirm(`Are you sure you want to leave "${trip.tripName}"?`)) { multiTripIdentity.removeTripIdentity(trip.tripId) loadUserTrips() } } const formatLastAccessed = (timestamp: number) => { const date = new Date(timestamp) const now = new Date() const diffInHours = (now.getTime() - date.getTime()) / (1000 * 60 * 60) if (diffInHours < 1) { return 'Just now' } else if (diffInHours < 24) { return `${Math.floor(diffInHours)} hour${Math.floor(diffInHours) > 1 ? 's' : ''} ago` } else if (diffInHours < 24 * 7) { const days = Math.floor(diffInHours / 24) return `${days} day${days > 1 ? 's' : ''} ago` } else { return date.toLocaleDateString() } } if (loading) { return (

Loading your trips...

) } return (
{/* Header */}

My Trips

{trips.length === 0 ? (

No trips yet

Create your first trip or join an existing one to start tracking expenses.

Get Started
) : ( <> {/* Stats Card */}

Active Trips

{trips.length}

Total Created

{trips.filter(t => t.isCreator).length}

{/* Trips List */}
{trips.map((trip) => (
handleSelectTrip(trip)} >

{trip.tripName}

{trip.isCreator && ( Creator )}
Code: {trip.shareCode} You: {trip.participantName}

Last accessed: {formatLastAccessed(trip.lastAccessed)}

))}
{/* Action Buttons */}

Create Trip

Join Trip

)}
{/* Bottom Navigation */}
My Trips Create Join
) }