'use client' import { useState, useEffect } from 'react' import { useMedusaProducts } from '@/hooks/useMedusaProducts' import Image from 'next/image' import Link from 'next/link' import { BedDouble } from 'lucide-react' const CURRENCY_SYMBOLS: Record = { zar: 'R', usd: '$', eur: '€', gbp: '£', kes: 'KSh', ngn: '₦', ghs: '₵' } const formatPrice = (amount: number, code?: string) => { const sym = CURRENCY_SYMBOLS[(code ?? '').toLowerCase()] ?? (code?.toUpperCase() ?? '') return `${sym}${(amount / 100).toFixed(0)}` } interface Category { id: string; name: string } export default function RoomsPage() { const { products: rooms, loading, error } = useMedusaProducts(50) const [categories, setCategories] = useState([]) const [activeCategory, setActiveCategory] = useState(null) useEffect(() => { fetch('/api/medusa/store/product-categories?limit=20', { headers: { 'x-publishable-api-key': process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY || '' }, }) .then(r => r.json()) .then(d => setCategories(d.product_categories || [])) .catch(() => {}) }, []) const filtered = activeCategory ? rooms.filter(r => (r as any).categories?.some((c: any) => c.id === activeCategory)) : rooms if (loading) return
if (error) return

Failed to load rooms.

return (

Our Rooms

{categories.length > 0 && (
{categories.map(cat => ( ))}
)} {filtered.length === 0 ? (

No rooms available.

) : (
{filtered.map((room) => { const variant = room.variants?.[0] const price = variant?.prices?.[0] return (
{room.thumbnail && (
{room.title}
)}

{room.title}

{room.description &&

{room.description}

} {price &&

{formatPrice(price.amount, price.currency_code)}/night

} Book This Room
) })}
)}
) }