"use client"; import { useRouter, useSearchParams } from "next/navigation"; import { useState } from "react"; interface Props { costCentres: { ref: string; name: string }[]; } export function ApprovalsSearch({ costCentres }: Props) { const router = useRouter(); const sp = useSearchParams(); const [q, setQ] = useState(sp.get("q") ?? ""); const [costCentreRef, setCostCentreRef] = useState(sp.get("costCentreRef") ?? ""); const [dateFrom, setDateFrom] = useState(sp.get("dateFrom") ?? ""); const [dateTo, setDateTo] = useState(sp.get("dateTo") ?? ""); function apply() { const params = new URLSearchParams(); if (q.trim()) params.set("q", q.trim()); if (costCentreRef) params.set("costCentreRef", costCentreRef); if (dateFrom) params.set("dateFrom", dateFrom); if (dateTo) params.set("dateTo", dateTo); router.push(`/approvals?${params.toString()}`); } function clear() { setQ(""); setCostCentreRef(""); setDateFrom(""); setDateTo(""); router.push("/approvals"); } const hasFilters = q || costCentreRef || dateFrom || dateTo; return (