'use client'; import { useCallback } from 'react'; import { useForm } from 'react-hook-form'; import { useRouter, useSearchParams } from 'next/navigation'; import Link from 'next/link'; import { Plus } from 'lucide-react'; import { Badge } from '@kit/ui/badge'; import { Button } from '@kit/ui/button'; import { Card, CardContent, CardHeader, CardTitle } from '@kit/ui/card'; import { Input } from '@kit/ui/input'; import { WATER_TYPE_LABELS } from '../lib/fischerei-constants'; interface WatersDataTableProps { data: Array>; total: number; page: number; pageSize: number; account: string; } const WATER_TYPE_OPTIONS = [ { value: '', label: 'Alle Typen' }, { value: 'fluss', label: 'Fluss' }, { value: 'bach', label: 'Bach' }, { value: 'see', label: 'See' }, { value: 'teich', label: 'Teich' }, { value: 'weiher', label: 'Weiher' }, { value: 'kanal', label: 'Kanal' }, { value: 'stausee', label: 'Stausee' }, { value: 'baggersee', label: 'Baggersee' }, { value: 'sonstige', label: 'Sonstige' }, ] as const; export function WatersDataTable({ data, total, page, pageSize, account, }: WatersDataTableProps) { const router = useRouter(); const searchParams = useSearchParams(); const currentSearch = searchParams.get('q') ?? ''; const currentType = searchParams.get('type') ?? ''; const totalPages = Math.max(1, Math.ceil(total / pageSize)); const form = useForm({ defaultValues: { search: currentSearch }, }); const updateParams = useCallback( (updates: Record) => { const params = new URLSearchParams(searchParams.toString()); for (const [key, value] of Object.entries(updates)) { if (value) { params.set(key, value); } else { params.delete(key); } } if (!('page' in updates)) { params.delete('page'); } router.push(`?${params.toString()}`); }, [router, searchParams], ); const handleSearch = useCallback( (e: React.FormEvent) => { e.preventDefault(); updateParams({ q: form.getValues('search') }); }, [form, updateParams], ); const handleTypeChange = useCallback( (e: React.ChangeEvent) => { updateParams({ type: e.target.value }); }, [updateParams], ); const handlePageChange = useCallback( (newPage: number) => { updateParams({ page: String(newPage) }); }, [updateParams], ); return (
{/* Toolbar */}
{/* Table */} Gewässer ({total}) {data.length === 0 ? (

Keine Gewässer vorhanden

Erstellen Sie Ihr erstes Gewässer, um loszulegen.

) : (
{data.map((water) => ( router.push( `/home/${account}/fischerei/waters/${String(water.id)}`, ) } > ))}
Name Kurzname Typ Fläche (ha) Ort
{String(water.name)} {String(water.short_name ?? '—')} {WATER_TYPE_LABELS[String(water.water_type)] ?? String(water.water_type)} {water.surface_area_ha != null ? `${Number(water.surface_area_ha).toLocaleString('de-DE')} ha` : '—'} {String(water.location ?? '—')}
)} {/* Pagination */} {totalPages > 1 && (

Seite {page} von {totalPages} ({total} Einträge)

)}
); }