"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useUpdateQueryParameters = useUpdateQueryParameters;
const Query_1 = require("hooks/Query");
const react_router_dom_1 = require("react-router-dom");
function useUpdateQueryParameters(hashNavigation = true) {
    const navigate = (0, react_router_dom_1.useNavigate)();
    const hashQuery = (0, Query_1.useHashQuery)();
    return (queryParameters) => {
        for (const key in queryParameters) {
            hashQuery.set(key, queryParameters[key]);
        }
        // We can't rely on relative navigation because react-router will navigate relative to the path that was
        // captured when the hook first rendered. We need to explicitly navigate to the current path.
        const hashUrl = new URL(window.location.hash.slice(1), window.location.origin);
        navigate({
            pathname: hashNavigation ? hashUrl.pathname : undefined,
            search: hashQuery.toString(),
        }, { replace: true });
    };
}
//# sourceMappingURL=UpdateQueryParameters.js.map