import React, { useState, useEffect, useRef } from 'react'; import { useSearchParams, Link } from 'react-router-dom'; import { getRooms } from '../../services/api/roomService'; import type { Room } from '../../services/api/roomService'; import RoomFilter from '../../components/rooms/RoomFilter'; import RoomCard from '../../components/rooms/RoomCard'; import RoomCardSkeleton from '../../components/rooms/RoomCardSkeleton'; import Pagination from '../../components/rooms/Pagination'; import { ArrowLeft, Hotel, Filter, ChevronDown, ChevronUp } from 'lucide-react'; const RoomListPage: React.FC = () => { const [searchParams] = useSearchParams(); const [rooms, setRooms] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [isFilterOpen, setIsFilterOpen] = useState(false); const filterRef = useRef(null); const [pagination, setPagination] = useState({ total: 0, page: 1, limit: 10, totalPages: 1, }); // Scroll to filter when opened on mobile useEffect(() => { if (isFilterOpen && filterRef.current && window.innerWidth < 1280) { setTimeout(() => { filterRef.current?.scrollIntoView({ behavior: 'smooth', block: 'start' }); }, 100); } }, [isFilterOpen]); // Fetch rooms based on URL params useEffect(() => { const fetchRooms = async () => { setLoading(true); setError(null); try { const params = { type: searchParams.get('type') || undefined, minPrice: searchParams.get('minPrice') ? Number(searchParams.get('minPrice')) : undefined, maxPrice: searchParams.get('maxPrice') ? Number(searchParams.get('maxPrice')) : undefined, capacity: searchParams.get('capacity') ? Number(searchParams.get('capacity')) : undefined, page: searchParams.get('page') ? Number(searchParams.get('page')) : 1, limit: 12, }; const response = await getRooms(params); if (response.status === 'success' && response.data) { setRooms(response.data.rooms || []); if (response.data.pagination) { setPagination(response.data.pagination); } } else { throw new Error('Failed to fetch rooms'); } } catch (err) { console.error('Error fetching rooms:', err); setError('Unable to load room list. Please try again.'); } finally { setLoading(false); } }; fetchRooms(); }, [searchParams]); return (
{/* Full-width hero section */}
{/* Back Button */} Back to home {/* Page Header */}

Our Rooms & Suites

Discover our collection of luxurious accommodations, each designed to provide an exceptional stay

{/* Full-width content area */}
{/* Mobile Filter Toggle Button */}
{/* Filter Sidebar - Collapsible on mobile, sidebar on desktop */} {/* Main Content - Full width on mobile, 9 columns on desktop */}
{loading && (
{Array.from({ length: 6 }).map((_, index) => ( ))}
)} {error && !loading && (

{error}

)} {!loading && !error && rooms.length === 0 && (

No matching rooms found

Please try adjusting the filters or search differently

)} {!loading && !error && rooms.length > 0 && ( <> {/* Results Count */}

Showing {rooms.length} of{' '} {pagination.total} rooms

{/* Responsive grid: 1 col mobile, 2 cols tablet, 3 cols desktop */}
{rooms.map((room) => ( ))}
{pagination.totalPages > 1 && (
)} )}
); }; export default RoomListPage;