"use client"; import { useQueryState } from "@/app/lib/useQueryState"; /** * Active tab kept in the URL: the first of `values` is the default and is absent from the URL; * an unknown value falls back to it. Other params (each tab's prefixed filters) are untouched; * `dropKeys` removes unprefixed params that belong to the old tab (e.g. `page`). */ export function useTabParam(key: string, values: readonly [T, ...T[]]) { const [params, setParams] = useQueryState(); const raw = params.get(key); const tab = values.find(v => v === raw) ?? values[0]; const setTab = (value: string, dropKeys: string[] = []) => setParams(prev => { const next = new URLSearchParams(prev); if (value === values[0]) next.delete(key); else next.set(key, value); for (const k of dropKeys) next.delete(k); return next; }); return [tab, setTab] as const; }