"use client"; import { useState, useEffect } from "react"; import { motion } from "framer-motion"; import ThemeToggle from "./ThemeToggle"; function getWeatherEmoji(code: string): string { const c = parseInt(code); if (c === 113) return "☀️"; if (c === 116) return "⛅"; if (c === 119 || c === 122) return "☁️"; if (c >= 176 && c <= 182) return "🌦️"; if (c >= 185 && c <= 200) return "🌧️"; if (c >= 200 && c <= 210) return "⛈️"; if (c >= 210 && c <= 260) return "❄️"; if (c >= 260 && c <= 300) return "🌨️"; if (c >= 300 && c <= 400) return "🌧️"; return "🌤️"; } interface Props { isDark: boolean; onToggleTheme: () => void; weather: any; } export default function TopBar({ isDark, onToggleTheme, weather }: Props) { const [time, setTime] = useState(""); const [date, setDate] = useState(""); useEffect(() => { const update = () => { const now = new Date(); setTime( now.toLocaleTimeString("ru-RU", { hour: "2-digit", minute: "2-digit" }) ); setDate( now.toLocaleDateString("ru-RU", { weekday: "short", day: "numeric", month: "long", }) ); }; update(); const id = setInterval(update, 1000); return () => clearInterval(id); }, []); return ( {/* Time & Date */}
{time} {date}
{/* Weather pill */} {weather && ( {getWeatherEmoji(weather.weatherCode)}
{weather.temp}°C
{weather.desc}
)} {/* Theme toggle */}
{weather?.demo && ( Demo )}
); }