'use client'
import { useState, useEffect } from 'react'
import { Droplets, Wind, Thermometer, X, CloudRain, Snowflake, CloudLightning, Cloud, Sun, CloudSun } 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
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 (
<>