'use client' import { useState, useEffect } from 'react' import { Droplets, Wind, Thermometer, X } from 'lucide-react' interface WeatherData { temp: string desc: string humidity: string windSpeed: string feelsLike: string forecast?: { date: string; maxTemp: string; minTemp: string; desc: string }[] } interface SensorData { temperature: number humidity: number pm25: number } interface TopBarProps { weather: WeatherData | null sensors: SensorData | null } function getWeatherIcon(desc: string): string { const d = desc?.toLowerCase() || '' if (d.includes('ясно') || d.includes('солнеч')) return '☀️' if (d.includes('облач')) return '⛅' if (d.includes('пасмурн')) return '☁️' if (d.includes('дождь') || d.includes('морос')) return '🌧️' if (d.includes('снег')) return '❄️' if (d.includes('гроз')) return '⛈️' return '🌤️' } function formatTime(date: Date): string { return date.toLocaleTimeString('ru-RU', { hour: '2-digit', minute: '2-digit' }) } function formatDate(date: Date): string { const weekday = date.toLocaleDateString('ru-RU', { weekday: 'long' }) const day = date.getDate() const month = date.toLocaleDateString('ru-RU', { month: 'long' }) return `${weekday}, ${day} ${month}` } export default function TopBar({ weather, sensors }: TopBarProps) { const [time, setTime] = useState(() => new Date()) const [showModal, setShowModal] = useState(false) useEffect(() => { const t = setInterval(() => setTime(new Date()), 1000) return () => clearInterval(t) }, []) return ( <>
{/* Left: time + date */}
{formatTime(time)} {formatDate(time)}
{/* Right: sensors + weather */}
{/* Room sensors */} {sensors && (
{sensors.temperature}° {sensors.humidity}% {sensors.pm25}
)} {/* Weather widget */} {weather && ( )}
{/* Weather Modal */} {showModal && weather && (
setShowModal(false)} style={{ position: 'fixed', inset: 0, background: 'rgba(0,0,0,0.7)', backdropFilter: 'blur(12px)', zIndex: 100, display: 'flex', alignItems: 'center', justifyContent: 'center', }} >
e.stopPropagation()} style={{ background: 'rgba(18, 18, 35, 0.95)', backdropFilter: 'blur(40px)', border: '1px solid rgba(255,255,255,0.08)', borderRadius: 24, padding: 32, minWidth: 360, maxWidth: 420, boxShadow: '0 25px 60px rgba(0,0,0,0.5)', }} >
{getWeatherIcon(weather.desc)}
{weather.temp}°
{weather.desc}
{[ { icon: , label: 'Влажность', value: `${weather.humidity}%` }, { icon: , label: 'Ветер', value: `${weather.windSpeed} км/ч` }, { icon: , label: 'Ощущается', value: `${weather.feelsLike}°` }, ].map(item => (
{item.icon}
{item.value}
{item.label}
))}
{weather.forecast && weather.forecast.length > 0 && ( <>
Прогноз
{weather.forecast.map(day => { const d = new Date(day.date) const label = d.toLocaleDateString('ru-RU', { weekday: 'short', day: 'numeric', month: 'short' }) return (
{label} {getWeatherIcon(day.desc)} {day.desc} {day.maxTemp}° / {day.minTemp}°
) })}
)}
)} ) }