'use client'; import { usePathname, useRouter, useSearchParams } from 'next/navigation'; import { useState } from 'react'; /** * "As of" date picker for the History tab. Writes `?tab=history&asof=YYYY-MM-DD` (keeping other params) so the * server renders the entity's attributes as known at that date (`GET /entities/{slug}/asof`). */ export function AsOfPicker({ value }: { value?: string }) { const router = useRouter(); const pathname = usePathname(); const sp = useSearchParams(); const [date, setDate] = useState(value ?? ''); const today = new Date().toISOString().slice(0, 10); const go = (d: string | null) => { const next = new URLSearchParams(sp.toString()); next.set('tab', 'history'); if (d) next.set('asof', d); else next.delete('asof'); router.replace(`${pathname}?${next.toString()}`, { scroll: false }); }; return (
); }