import React, { useState, useEffect } from 'react'; import { useParams, useNavigate, Link } from 'react-router-dom'; import { Users, MapPin, DollarSign, ArrowLeft, } from 'lucide-react'; import { getRoomById, type Room } from '../../services/api/roomService'; import RoomGallery from '../../components/rooms/RoomGallery'; import RoomAmenities from '../../components/rooms/RoomAmenities'; import ReviewSection from '../../components/rooms/ReviewSection'; import RatingStars from '../../components/rooms/RatingStars'; const RoomDetailPage: React.FC = () => { const { id } = useParams<{ id: string }>(); const navigate = useNavigate(); const [room, setRoom] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { if (id) { fetchRoomDetail(Number(id)); } }, [id]); const fetchRoomDetail = async (roomId: number) => { try { setLoading(true); setError(null); const response = await getRoomById(roomId); // backend uses `status: 'success'` (not `success`), accept both if ((response as any).success || (response as any).status === 'success') { if (response.data && response.data.room) { setRoom(response.data.room); } else { throw new Error('Failed to fetch room details'); } } else { throw new Error('Failed to fetch room details'); } } catch (err: any) { console.error('Error fetching room:', err); const message = err.response?.data?.message || 'Unable to load room information'; setError(message); } finally { setLoading(false); } }; if (loading) { return (
); } if (error || !room) { return (

{error || 'Room not found'}

); } const roomType = room.room_type; const formattedPrice = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', }).format(roomType?.base_price || 0); return (
{/* Back Button */} Back to room list {/* Image Gallery */}
{/* Room Information */}
{/* Main Info */}
{/* Title & Basic Info */}

{roomType?.name}

Room {room.room_number} - Floor {room.floor}
{roomType?.capacity || 0} guests
{room.average_rating != null && (
({room.total_reviews || 0} đánh giá)
)}
{/* Status Badge */}
{room.status === 'available' ? 'Available' : room.status === 'occupied' ? 'Booked' : 'Maintenance'}
{/* Description */} {roomType?.description && (

Room Description

{roomType.description}

)} {/* Amenities */}

Amenities

0) ? room.amenities : (roomType?.amenities || []) } />
{/* Booking Card */}
{/* Reviews Section */}
); }; export default RoomDetailPage;