"use client"; import { useMemo } from "react"; import { AlertTriangle, BellRing, CloudSun, RefreshCw } from "lucide-react"; import { EmptyState } from "@/components/states/empty-state"; import { LoadingSkeleton } from "@/components/states/loading-skeleton"; import { Button } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; import { useForecast } from "@/hooks/use-forecast"; import { useWarnings } from "@/hooks/use-warnings"; import { DEFAULT_STATION_ID } from "@/lib/constants"; import { useI18n } from "@/lib/i18n"; import { getProvinceForSelection } from "@/lib/provinces"; import { useWeatherStore } from "@/lib/store"; import { buildTomorrowWeatherBrief, buildWeatherBrief } from "@/lib/weather-brief"; export function WeatherBriefCard({ latitude, longitude, locationName }: { latitude?: number; longitude?: number; locationName: string }) { const { language, t } = useI18n(); const { data: forecast, isPending, isError, refetch } = useForecast(latitude, longitude); const { data: warnings = [] } = useWarnings(); const selectedStationId = useWeatherStore((state) => state.selectedStationId); const selectedLocation = useWeatherStore((state) => state.selectedLocation); const windSpeedUnit = useWeatherStore((state) => state.windSpeedUnit); const province = getProvinceForSelection(selectedLocation?.province, selectedStationId ?? DEFAULT_STATION_ID); const brief = useMemo(() => { if (!forecast) return null; return buildWeatherBrief({ forecast, warnings, province, countyTeryt: selectedLocation?.countyTeryt, locationName, language, windSpeedUnit }); }, [forecast, language, locationName, province, selectedLocation?.countyTeryt, warnings, windSpeedUnit]); const tomorrowBrief = useMemo(() => { if (!forecast) return null; return buildTomorrowWeatherBrief({ forecast, warnings, province, countyTeryt: selectedLocation?.countyTeryt, locationName, language, windSpeedUnit }); }, [forecast, language, locationName, province, selectedLocation?.countyTeryt, warnings, windSpeedUnit]); if (!Number.isFinite(latitude) || !Number.isFinite(longitude) || isPending) { return ; } if (isError || !forecast) { return ( {t("brief.error")} refetch()}> {t("common.retry")} ); } if (!brief) { return ; } const isWarning = brief.severity === "warning"; return ( {isWarning ? : } {t("brief.label")} {brief.headline} {t("brief.description", { location: locationName })} {brief.body.slice(0, 4).map((line) => ( {line} ))} {tomorrowBrief && ( {t("brief.tomorrowLabel")} {tomorrowBrief.headline} {tomorrowBrief.body.slice(0, 3).map((line) => ( {line} ))} )} {t("brief.pushHint")} ); }
{t("brief.error")}
{t("brief.label")}
{t("brief.description", { location: locationName })}
{t("brief.tomorrowLabel")}
{t("brief.pushHint")}