export function getQuerystringParameter(key) {
    const queryString = window.location.search;
    const urlParams = new URLSearchParams(queryString);
    const lowerCaseParams = new URLSearchParams();
    for (const [name, value] of urlParams) {
        lowerCaseParams.append(name.toLowerCase(), value);
    }

    return lowerCaseParams.get(key) ? lowerCaseParams.get(key) : null;
}

// if you add the fmgPage to the querystringobject before calling, then pass true for skipFmgPageName
export function buildQuerystringObject(qso, skipFmgPageName = false) {
    const queryString = window.location.search;
    const urlParams = new URLSearchParams(queryString);

    for (const [name, value] of urlParams) {
        if (name.toLowerCase() === "fmgpage" && skipFmgPageName) {
            continue;
        }
        qso[name] = value;
    }
    return qso;
}
