"use client";

import { useRouter } from "next/navigation";
import { useMemo } from "react";
import { withBuildId } from "@/lib/update";

// Drop-in replacement for next/navigation's useRouter().
export function useVersionedRouter() {
    const router = useRouter();

    return useMemo(
        () => ({
            ...router,
            push: (href: string, options?: Parameters<typeof router.push>[1]) =>
                router.push(withBuildId(href), options),
            replace: (href: string, options?: Parameters<typeof router.replace>[1]) =>
                router.replace(withBuildId(href), options),
        }),
        [router]
    );
}
