'use client' import { useState, useEffect } from 'react' import { Droplets, Wind, Thermometer, X } from 'lucide-react' import WeatherAnimation from '@/components/WeatherAnimation' 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 haConnected?: boolean } function getWeatherIcon(desc: string): string { const d = desc?.toLowerCase() || '' if (d.includes('ясно') || d.includes('солнеч')) return '☀️' 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 '⛈️' 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}` } function getWindDesc(ms: number): string { if (ms <= 1) return 'Штиль' if (ms <= 3) return 'Тихий' if (ms <= 5) return 'Лёгкий' if (ms <= 8) return 'Умеренный' if (ms <= 11) return 'Свежий' if (ms <= 14) return 'Сильный' return 'Шторм' } export default function TopBar({ weather, sensors, haConnected }: TopBarProps) { const [time, setTime] = useState(() => new Date()) const [showModal, setShowModal] = useState(false) useEffect(() => { const t = setInterval(() => setTime(new Date()), 1000) return () => clearInterval(t) }, []) const windMs = weather ? parseInt(weather.windSpeed) || 0 : 0 return ( <>
{/* Left: time + date */}
{formatTime(time)} {formatDate(time)}
{/* Right: sensors + weather */}
{/* HA status */}
{sensors && (
{sensors.temperature}° {sensors.humidity}% {sensors.pm25}
)} {weather && ( )}
{/* Weather Modal */} {showModal && weather && (
setShowModal(false)} style={{ position: 'fixed', inset: 0, background: 'rgba(0,0,0,0.65)', backdropFilter: 'blur(12px)', zIndex: 100, display: 'flex', alignItems: 'center', justifyContent: 'center', }} >
e.stopPropagation()} style={{ background: 'rgba(16,16,30,0.97)', backdropFilter: 'blur(40px)', border: '1px solid rgba(255,255,255,0.07)', borderRadius: 28, width: 480, maxWidth: '95vw', overflow: 'hidden', boxShadow: '0 30px 90px rgba(0,0,0,0.6)', }} > {/* Hero section */}
{/* Background emoji */}
{weather.temp}°
{weather.desc}
{/* Details */}
{/* Stats grid */}
{[ { icon: , bg: 'rgba(251,146,60,0.1)', label: 'Ощущается', value: `${weather.feelsLike}°`, }, { icon: , bg: 'rgba(59,130,246,0.1)', label: 'Влажность', value: `${weather.humidity}%`, }, { icon: , bg: 'rgba(34,211,238,0.1)', label: getWindDesc(windMs), value: `${weather.windSpeed} м/с`, }, ].map(item => (
{item.icon}
{item.value}
{item.label}
))}
{/* Forecast */} {weather.forecast && weather.forecast.length > 0 && ( <>
Прогноз на неделю
{weather.forecast.map(day => { const d = new Date(day.date) const isToday = d.toDateString() === new Date().toDateString() const weekday = d.toLocaleDateString('ru-RU', { weekday: 'long' }) const dateStr = d.toLocaleDateString('ru-RU', { day: 'numeric', month: 'short' }) return (
{/* Icon */} {/* Day info */}
{isToday ? 'Сегодня' : weekday}
{dateStr} · {day.desc}
{/* Temps */}
{day.maxTemp}° {day.minTemp}°
) })}
)}
)} ) }