'use client' import { useRouter } from 'next/navigation' import { useCityMap, CityMapRoom } from '@/hooks/useCityMap' import { useGlobalPresence } from '@/hooks/useGlobalPresence' import { cn } from '@/lib/utils' import { MessageSquare, Zap, FlaskConical, Hammer, HandMetal, Users, Bot, Loader2 } from 'lucide-react' import { AgentPresence } from '@/lib/global-presence' // Icon mapping const iconMap: Record = { 'message-square': MessageSquare, 'zap': Zap, 'flask-conical': FlaskConical, 'hammer': Hammer, 'hand-wave': HandMetal, } // Color mapping to Tailwind classes const colorMap: Record = { cyan: 'from-cyan-500/20 to-cyan-600/10 border-cyan-500/30 hover:border-cyan-400/50', green: 'from-green-500/20 to-green-600/10 border-green-500/30 hover:border-green-400/50', orange: 'from-orange-500/20 to-orange-600/10 border-orange-500/30 hover:border-orange-400/50', purple: 'from-purple-500/20 to-purple-600/10 border-purple-500/30 hover:border-purple-400/50', yellow: 'from-yellow-500/20 to-yellow-600/10 border-yellow-500/30 hover:border-yellow-400/50', blue: 'from-blue-500/20 to-blue-600/10 border-blue-500/30 hover:border-blue-400/50', } const textColorMap: Record = { cyan: 'text-cyan-400', green: 'text-green-400', orange: 'text-orange-400', purple: 'text-purple-400', yellow: 'text-yellow-400', blue: 'text-blue-400', } interface RoomTileProps { room: CityMapRoom online: number typing: number agents: AgentPresence[] cellSize: number onClick: () => void } function RoomTile({ room, online, typing, agents, cellSize, onClick }: RoomTileProps) { const Icon = iconMap[room.icon || 'message-square'] || MessageSquare const colorClass = colorMap[room.color || 'cyan'] || colorMap.cyan const textColor = textColorMap[room.color || 'cyan'] || textColorMap.cyan // Calculate brightness based on online count const brightness = Math.min(1, 0.3 + (online * 0.15)) return ( ) } export function CityMap() { const router = useRouter() const { config, rooms, loading, error } = useCityMap() const { cityOnline, roomsPresence, agents } = useGlobalPresence() if (loading) { return (
Завантаження мапи...
) } if (error) { return (

Помилка завантаження мапи: {error}

) } if (!config || rooms.length === 0) { return (

Мапа міста порожня

) } const cellSize = config.cell_size const mapWidth = config.grid_width * cellSize const mapHeight = config.grid_height * cellSize // Count online agents const onlineAgents = agents.filter(a => a.status === 'online' || a.status === 'busy') return (
{/* Header */}

Мапа Міста

{cityOnline} онлайн
{onlineAgents.length} агентів
{/* Map container */}
{/* Grid background */}
{/* Room tiles */} {rooms.map((room) => { const presence = roomsPresence[room.id] const roomAgents = agents.filter(a => a.room_id === room.id) return ( router.push(`/city/${room.slug}`)} /> ) })}
{/* Legend */}
Public
Social
Science
Builders
) }