import { ROUTE_PREFIX_TRIMMED } from "@/router/constants/route-prefix";

export function buildManualUrl(nextPage) {
    const queries = nextPage.params;
    const querystring = buildSearchParams(queries);

    const url = `${window.top.location.origin}/${ROUTE_PREFIX_TRIMMED}${nextPage.path}${querystring}`;

    return url;
}

export function buildSearchParams(paramList) {
    if (!paramList) {
        return "";
    }

    const keys = Object.keys(paramList);
    if (keys?.length > 0) {
        const queryFormattedParams = keys.map((k) => `${k}=${paramList[k]}`);

        const querystring = queryFormattedParams.reduce((a, b) => `${a}&${b}`);

        return `?${querystring}`;
    }

    return "";
}
