/* eslint-disable comma-dangle */
/* eslint-disable implicit-arrow-linebreak */
import { omit, pipe, mergeDeepLeft } from "ramda";
const fragmentParamsSeparatorRegEx = /[&;]/;
const fragmentParamsSeparator = ";";
export const getHashParams = (hash = decodeURIComponent(window.location.hash.substr(1))) => {
    if (hash.length === 0) {
        return {};
    }
    const params = hash.split(fragmentParamsSeparatorRegEx);
    const response = params.reduce((acc, current) => {
        const parts = current.split("=");
        const [param, value] = parts;
        acc[param] = value;
        return acc;
    }, {});
    return response;
};
export const makeHashFromObject = (params) => {
    const entries = Object.entries(params);
    if (entries.length === 0) {
        return "";
    }
    return entries
        .map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
        .join(fragmentParamsSeparator);
};
export const getFilteredHash = (excludedParams, hash = decodeURIComponent(window.location.hash.substr(1))) => {
    const filteredParams = omit(excludedParams, getHashParams(hash));
    return makeHashFromObject(filteredParams);
};
export const getUniqueParamsHash = pipe(getHashParams, makeHashFromObject);
export const setHashParams = (params) => {
    const allParams = getHashParams();
    const allParamsResult = mergeDeepLeft(params, allParams);
    window.history.replaceState(window.history.state, "", `#${makeHashFromObject(allParamsResult)}`);
};
export const getHashParam = (param, hash = decodeURIComponent(window.location.hash.substr(1))) => getHashParams(hash)[param];
export const hasHashParam = (param, hash = decodeURIComponent(window.location.hash.substr(1))) => getHashParams(hash)[param] !== undefined;
export const removeHashParams = (params) => {
    window.history.replaceState(window.history.state, "", `#${getFilteredHash(params)}`);
};
//# sourceMappingURL=hash-utils.js.map