"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useDays = exports.useDex = exports.useAsset = exports.useChain = exports.useSearchParam = void 0;
var react_router_dom_1 = require("react-router-dom");
var react_1 = require("react");
function useSearchParam() {
    var _search = (0, react_router_dom_1.useLocation)().search;
    var history = (0, react_router_dom_1.useHistory)();
    var urlSearchParams = new URLSearchParams(_search);
    var get = (0, react_1.useCallback)(function (key, defaultValue) {
        var value = urlSearchParams === null || urlSearchParams === void 0 ? void 0 : urlSearchParams.get(key);
        if (!value && defaultValue)
            return defaultValue;
        return value;
    }, [urlSearchParams]);
    var editSearchParam = (0, react_1.useCallback)(function (name, value, defaultValue) {
        var newSearchParams = urlSearchParams;
        if (value === null || value === defaultValue)
            newSearchParams === null || newSearchParams === void 0 ? void 0 : newSearchParams.delete(name);
        else
            newSearchParams.set(name, value);
        return "?".concat(newSearchParams === null || newSearchParams === void 0 ? void 0 : newSearchParams.toString());
    }, [urlSearchParams]);
    function pushNewSearch(name, value, defaultValue) {
        var newSearch = editSearchParam(name, value, defaultValue);
        history.push({ search: newSearch });
    }
    return { get: get, editSearchParam: editSearchParam, pushNewSearch: pushNewSearch, search: _search };
}
exports.useSearchParam = useSearchParam;
function useChain() {
    return useSearchParam().get('chain');
}
exports.useChain = useChain;
function useAsset() {
    return useSearchParam().get('asset');
}
exports.useAsset = useAsset;
function useDex() {
    return useSearchParam().get('dex');
}
exports.useDex = useDex;
function useDays() {
    return useSearchParam().get('days');
}
exports.useDays = useDays;
//# sourceMappingURL=router.js.map