"use client"; import { motion } from "framer-motion"; import { AlertTriangle, Droplets, Gauge, MapPin, Navigation, Umbrella, Wind } from "lucide-react"; import { calculateFeelsLike, formatDateTime, formatHumidity, formatPressure, formatRainfall, formatTemperature, formatWind, getWeatherDescription, getWeatherMoodFromData, moodAccentClass, } from "@/lib/weather-utils"; import type { SynopStation } from "@/types/imgw"; import type { ImgwCurrentWeather } from "@/types/imgw-current"; import { WeatherIcon } from "@/components/weather/weather-icon"; import { WeatherEffects } from "@/components/weather/weather-effects"; import { useI18n } from "@/lib/i18n"; export function WeatherHero({ station, currentWeather, currentWeatherLoading = false, locationName, distanceKm }: { station: SynopStation; currentWeather?: ImgwCurrentWeather | null; currentWeatherLoading?: boolean; locationName?: string; distanceKm?: number }) { const { language, t } = useI18n(); const displayedLocationName = locationName ?? station.name; const hasFullHybridAnalysis = currentWeather?.coverage === "full" || currentWeather?.coverage === "hourly"; const hasPartialHybridAnalysis = currentWeather?.coverage === "precipitation-only"; const hasDistantFallback = !hasFullHybridAnalysis && !currentWeatherLoading && distanceKm !== undefined && distanceKm >= 30; const displayedStation = currentWeather ? { ...station, measuredAt: hasFullHybridAnalysis ? currentWeather.measuredAt : station.measuredAt, temperature: currentWeather.temperature ?? station.temperature, windSpeed: currentWeather.windSpeed ?? station.windSpeed, windDirection: currentWeather.windDirection ?? station.windDirection, humidity: currentWeather.humidity ?? station.humidity, pressure: currentWeather.pressure ?? station.pressure, rainfall: currentWeather.precipitation10m ?? station.rainfall, } : station; const mood = getWeatherMoodFromData(displayedStation); const moodAccent = moodAccentClass(mood); const feelsLike = currentWeather?.feelsLike ?? calculateFeelsLike(displayedStation.temperature, displayedStation.humidity, displayedStation.windSpeed); const metrics = [ { icon: Droplets, label: t("weather.humidity"), value: formatHumidity(displayedStation.humidity, language) }, { icon: Wind, label: t("weather.wind"), value: formatWind(displayedStation.windSpeed, null, language) }, { icon: Umbrella, label: currentWeather?.precipitation10m !== null && currentWeather?.precipitation10m !== undefined ? t("weather.rainfall10m") : t("weather.rainfallTotal"), value: formatRainfall(displayedStation.rainfall, language) }, { icon: Gauge, label: t("weather.pressure"), value: formatPressure(displayedStation.pressure, language) }, ]; return (
{displayedLocationName} {getWeatherDescription(displayedStation, language, currentWeather?.condition)}

{currentWeatherLoading ? t("location.heroHybridLoading", { station: station.name }) : hasFullHybridAnalysis ? t("location.heroHybridSource", { location: displayedLocationName }) : hasPartialHybridAnalysis ? t("location.heroHybridPartial", { station: station.name, distance: distanceKm ?? 0 }) : locationName ? t("location.heroStationFallbackWithDistance", { station: station.name, distance: distanceKm ?? 0 }) : t("location.heroStationFallback", { station: station.name })}

{hasFullHybridAnalysis && locationName &&

{t("location.heroNearestStation", { station: station.name, distance: distanceKm ?? 0 })}

} {hasDistantFallback &&

{t("location.heroDistantFallback")}

}
{formatTemperature(displayedStation.temperature, language)}

{getWeatherDescription(displayedStation, language, currentWeather?.condition)}

{t("weather.feelsLike")} {formatTemperature(feelsLike, language)} · {t("weather.measurement")} {formatDateTime(displayedStation.measuredAt, language)}

{metrics.map(({ icon: Icon, label, value }) => (
{label}

{value}

))}
{displayedStation.windDirection !== null && (

{t("weather.windDirection")}: {displayedStation.windDirection}°

)}
); }