"use client"; import { usePathname, useRouter, useSearchParams } from "next/navigation"; import { useEffect, useState } from "react"; import { FILTER_SELECT_CLASS } from "@/components/ui/Field"; import { SearchInput } from "@/components/ui/SearchInput"; type EmployeeFiltersProps = { divisions: { id: string; name: string }[]; locations: { id: string; name: string }[]; }; // Aktiv and Langzeitabwesenheit are separate statuses — somebody on a // long-term absence is employed but not active. The combined entry is // offered explicitly, named after the two it selects rather than calling // the pair "aktiv". The stored value is still 'Karenz' (see lib/absence.ts). const STATUS_OPTIONS = [ { value: "Aktiv", label: "Aktiv" }, { value: "Karenz", label: "Langzeitabwesenheit" }, { value: "Aktiv,Karenz", label: "Aktiv + Langzeitabwesenheit (beschäftigt)" }, { value: "Geplant", label: "Geplant" }, { value: "Ausgetreten", label: "Ausgetreten" }, ] as const; export function EmployeeFilters({ divisions, locations }: EmployeeFiltersProps) { const router = useRouter(); const pathname = usePathname(); const searchParams = useSearchParams(); const [q, setQ] = useState(searchParams.get("q") ?? ""); useEffect(() => { const handle = setTimeout(() => { const current = new URLSearchParams(searchParams.toString()); if (q) current.set("q", q); else current.delete("q"); current.delete("page"); const next = current.toString(); if (next !== searchParams.toString()) router.push(`${pathname}?${next}`); }, 300); return () => clearTimeout(handle); // eslint-disable-next-line react-hooks/exhaustive-deps }, [q]); function updateParam(key: string, value: string) { const params = new URLSearchParams(searchParams.toString()); if (value) params.set(key, value); else params.delete(key); params.delete("page"); router.push(`${pathname}?${params.toString()}`); } return (