import { useState, useMemo } from 'react'; import { useSeoMeta } from '@unhead/react'; import { Layout } from '@/components/Layout'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { Skeleton } from '@/components/ui/skeleton'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@/components/ui/select'; import { useSkateSpots } from '@/hooks/useSkateSpots'; import { useFoodSpots } from '@/hooks/useFoodSpots'; import { Utensils, MapPin, Phone, Globe, Clock, Navigation, Coffee, Beer, ChefHat, } from 'lucide-react'; import type { FoodSpot } from '@/lib/types'; import { sanitizeUrl, sanitizeTel } from '@/lib/sanitizeUrl'; const FOOD_TYPE_ICONS: Record> = { restaurant: ChefHat, cafe: Coffee, fast_food: Utensils, bar: Beer, pub: Beer, food_court: Utensils, }; const FOOD_TYPE_LABELS: Record = { restaurant: 'Restaurant', cafe: 'Café', fast_food: 'Fast Food', bar: 'Bar', pub: 'Pub', food_court: 'Food Court', }; function FoodSpotCard({ spot }: { spot: FoodSpot }) { const Icon = FOOD_TYPE_ICONS[spot.type] || Utensils; const handleDirections = () => { window.open( `https://www.google.com/maps/dir/?api=1&destination=${spot.lat},${spot.lng}`, '_blank' ); }; return (
{spot.name}
{FOOD_TYPE_LABELS[spot.type] || spot.type} {spot.cuisine && ( {spot.cuisine} )}
{spot.distance !== undefined && ( {spot.distance < 1 ? `${Math.round(spot.distance * 1000)}m` : `${spot.distance.toFixed(1)}km`} )}
{spot.address && (
{spot.address}
)} {spot.openingHours && (
{spot.openingHours}
)}
{spot.phone && sanitizeTel(spot.phone) && ( )} {spot.website && sanitizeUrl(spot.website) && ( )}
); } function FoodSpotSkeleton() { return (
); } export default function FoodPage() { useSeoMeta({ title: 'Food Near Spots - SkateSpots', description: 'Find restaurants, cafés, and food options near skateboarding spots.', }); const { data: spots, isLoading: spotsLoading } = useSkateSpots(50); const [selectedSpotId, setSelectedSpotId] = useState(null); const selectedSpot = useMemo(() => { if (!selectedSpotId || !spots) return null; return spots.find((s) => s.id === selectedSpotId) || null; }, [selectedSpotId, spots]); const { data: foodSpots, isLoading: foodLoading, } = useFoodSpots(selectedSpot?.geohash, 1); return (
{/* Header */}

Food Near Spots

Find places to eat near your favorite skate spots

{/* Spot selector */}
{selectedSpot && (
Location:{' '} {selectedSpot.location || 'Unknown'}
)}
{/* Food results */} {!selectedSpotId ? (

Select a Skate Spot

Choose a skate spot from the dropdown above to find nearby restaurants, cafés, and other food options.

) : foodLoading ? (
{Array.from({ length: 6 }).map((_, i) => ( ))}
) : foodSpots && foodSpots.length > 0 ? ( <>

{foodSpots.length} place{foodSpots.length !== 1 ? 's' : ''} found within 1km of {selectedSpot?.title}

{foodSpots.map((spot) => ( ))}
) : (

No Food Spots Found

We couldn't find any restaurants or cafés within 1km of this spot. Try selecting a different location.

)}
); }