"use client"; import { useMemo, useState } from "react"; import { Search, Waves } from "lucide-react"; import { useHydroStations } from "@/hooks/use-hydro"; import { HydroStationCard } from "@/components/hydro/hydro-station-card"; import { Button } from "@/components/ui/button"; import { PageLoadingSkeleton } from "@/components/states/loading-skeleton"; import { ErrorState } from "@/components/states/error-state"; import { EmptyState } from "@/components/states/empty-state"; import { useI18n } from "@/lib/i18n"; const PAGE_SIZE = 48; export function HydroPage() { const { locale, t } = useI18n(); const { data: stations, isPending, isError, refetch } = useHydroStations(); const [query, setQuery] = useState(""); const [visibleCount, setVisibleCount] = useState(PAGE_SIZE); const filteredStations = useMemo(() => (stations ?? []).filter((station) => { const haystack = `${station.name} ${station.river ?? ""} ${station.province ?? ""}`.toLocaleLowerCase(locale); return haystack.includes(query.trim().toLocaleLowerCase(locale)); }), [locale, query, stations]); if (isPending) return ; if (isError) return refetch()} description={t("hydro.error")} />; return ( {t("hydro.section")} {t("hydro.title")} {t("hydro.description")} {t("hydro.searchLabel")} { setQuery(event.target.value); setVisibleCount(PAGE_SIZE); }} placeholder={t("hydro.searchPlaceholder")} className="w-full rounded-2xl border border-white/40 bg-white/45 py-3 pl-10 pr-4 text-sm placeholder:text-slate-500 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-sky-500 dark:border-white/10 dark:bg-white/5" /> {t("hydro.results", { total: filteredStations.length, visible: Math.min(visibleCount, filteredStations.length) })} {!filteredStations.length ? : ( <> {filteredStations.slice(0, visibleCount).map((station, index) => )} {visibleCount < filteredStations.length && setVisibleCount((count) => count + PAGE_SIZE)}>{t("hydro.more")}} > )} ); }
{t("hydro.section")}
{t("hydro.description")}
{t("hydro.results", { total: filteredStations.length, visible: Math.min(visibleCount, filteredStations.length) })}