import { Cloud, Moon, Rain, Snow, Storm, Sun, Wind } from './Icons'; import { NumericText } from './NumericText'; import { weatherAvailable, weatherCondition } from './lib/weather.mjs'; import type { Weather } from './types'; const icons = { cloud: Cloud, moon: Moon, rain: Rain, snow: Snow, storm: Storm, sun: Sun }; const hourFormat = new Intl.DateTimeFormat('ru', { timeZone: 'Europe/Minsk', hour: '2-digit', minute: '2-digit' }); const degrees = (value: number) => `${Math.round(value) > 0 ? '+' : ''}${Math.round(value)}°`; function WeatherIcon({ code, isDay = true, size = 32 }: { code: number; isDay?: boolean; size?: number }) { const condition = weatherCondition(code, isDay); const Icon = icons[condition.icon as keyof typeof icons]; return ; } export function WeatherSummary({ data, now, failed }: { data: Weather | null; now: number; failed: boolean }) { if (!weatherAvailable(data, now) || !data) return null; return
{weatherCondition(data.code, data.isDay).label}{failed && сохранено}
; } export function WeatherCard({ data, now, loading, failed, demo }: { data: Weather | null; now: number; loading: boolean; failed: boolean; demo: boolean }) { const available = weatherAvailable(data, now); if (!available || !data) return <>

Погода

{demo ? 'Погода доступна с реальными данными остановки.' : loading ? 'Получаем прогноз…' : 'Прогноз сейчас недоступен.'}

{data ? 'Сохранённый прогноз устарел' : 'Погода обновится при подключении'}
; const hours = data.hourly.filter(hour => Date.parse(hour.at) > now).slice(0, 3); const probability = hours.length ? Math.max(...hours.map(hour => hour.precipitationProbability)) : null; return <>

Погода

СЕЙЧАС

{weatherCondition(data.code, data.isDay).label}

Ощущается как м/с
{!!hours.length &&
{hours.map(hour =>
%осадки
)}
} {probability !== null &&
Осадки в ближайшие 3 часа: %
}
{failed ? 'Сохранено' : 'Обновлено'} в {hourFormat.format(Date.parse(data.updatedAt))}Open-Meteo · CC BY 4.0
; }