'use client'; import React, { useState, useEffect } from 'react'; import dynamic from 'next/dynamic'; import { Header } from '@/components/Header'; import { ParkingList } from '@/components/parking/ParkingList'; import { HCMCGPSSimulator } from '@/components/HCMCGPSSimulator'; // import { ErrorMessage } from '@/components/ui/ErrorMessage'; import { LoadingSpinner } from '@/components/ui/LoadingSpinner'; import { useParkingSearch } from '@/hooks/useParkingSearch'; import { ParkingLot, UserLocation, TransportationMode } from '@/types'; import toast from 'react-hot-toast'; export default function ParkingFinderPage() { // State management const [selectedParkingLot, setSelectedParkingLot] = useState(null); const [userLocation, setUserLocation] = useState(null); const [searchRadius, setSearchRadius] = useState(4000); // meters - bán kính 4km const [sortType, setSortType] = useState<'availability' | 'price' | 'distance'>('availability'); // Fixed to car mode only const transportationMode: TransportationMode = 'auto'; // Custom hooks const { parkingLots, error: parkingError, searchLocation } = useParkingSearch(); // Handle GPS location change from simulator const handleLocationChange = (location: UserLocation) => { setUserLocation(location); // Search for parking near the new location if (location) { searchLocation({ latitude: location.lat, longitude: location.lng }); toast.success('Đã cập nhật vị trí GPS và tìm kiếm bãi đỗ xe gần đó'); } }; const handleRefresh = () => { if (userLocation) { searchLocation({ latitude: userLocation.lat, longitude: userLocation.lng }); toast.success('Đã làm mới danh sách bãi đỗ xe'); } else { toast.error('Vui lòng chọn vị trí GPS trước'); } }; const handleParkingLotSelect = (lot: ParkingLot) => { // If the same parking lot is selected again, deselect it if (selectedParkingLot && selectedParkingLot.id === lot.id) { setSelectedParkingLot(null); toast.success('Đã bỏ chọn bãi đỗ xe'); return; } setSelectedParkingLot(lot); toast.success(`Đã chọn ${lot.name}`); }; // Show error messages useEffect(() => { if (parkingError) { toast.error(parkingError); } }, [parkingError]); return (
{/* Left Column - Map and Parking List */}
{/* Summary Section */}

Parking Finder - HCMC

Find and book parking spots in Ho Chi Minh City

{parkingLots.length > 0 && (
Found {parkingLots.length} parking locations nearby
)}
{/* Parking List Section */}

Bãi đỗ xe trong bán kính 4km

� Chỉ hiển thị bãi xe đang mở cửa và còn chỗ trống

{!userLocation ? (

Vui lòng chọn vị trí GPS để tìm bãi đỗ xe

) : parkingLots.length === 0 ? (

Không tìm thấy bãi đỗ xe nào gần vị trí này

) : ( )}
{/* Right Column - GPS Simulator */}
{/* Show errors */} {parkingError && (
{parkingError}
)}
); }