"use client";
import { Map, MapPinned } from "lucide-react";
import { useWarnings } from "@/hooks/use-warnings";
import { WarningCard } from "@/components/warnings/warning-card";
import { PageLoadingSkeleton } from "@/components/states/loading-skeleton";
import { EmptyState } from "@/components/states/empty-state";
import { ErrorState } from "@/components/states/error-state";
import { DEFAULT_STATION_ID } from "@/lib/constants";
import { useI18n } from "@/lib/i18n";
import { formatProvinceName, getProvinceForStation, normalizeProvinceName } from "@/lib/provinces";
import { useWeatherStore } from "@/lib/store";
import type { WeatherWarning } from "@/types/imgw";
function WarningGrid({ warnings, indexOffset = 0 }: { warnings: WeatherWarning[]; indexOffset?: number }) {
return (
{warnings.map((warning, index) => )}
);
}
export function WarningsPanel() {
const { language, t } = useI18n();
const { data: warnings, isPending, isError, refetch } = useWarnings();
const selectedStationId = useWeatherStore((state) => state.selectedStationId);
const selectedLocation = useWeatherStore((state) => state.selectedLocation);
if (isPending) return ;
if (isError) return refetch()} description={t("warnings.error")} />;
if (!warnings?.length) return ;
const province = normalizeProvinceName(selectedLocation?.province)
?? getProvinceForStation(selectedStationId ?? DEFAULT_STATION_ID);
if (!province) return ;
const provinceLabel = formatProvinceName(province, language);
const localWarnings = warnings.filter((warning) => warning.provinces.includes(province));
const otherWarnings = warnings.filter((warning) => !warning.provinces.includes(province));
return (
{t("warnings.myProvince")}
{provinceLabel}
{t("warnings.myProvinceDescription", { province: provinceLabel })}
{localWarnings.length
?
: }
{otherWarnings.length > 0 && (
{t("warnings.otherRegions")}
{t("warnings.otherRegionsDescription")}
)}
);
}