/**
 * Parses the search query string from the current URL and returns the parsed query parameters.
 *
 * @param options - Optional options to pass to the `queryString.parse` function.
 * @returns The parsed query parameters.
 */

import qs from "query-string";
import { isClient } from "../isClient";

type TParseLocationOptions = qs.ParseOptions;

const search = isClient() ? window.location.search : "";

export const getSearchQuery = <T extends Record<string, unknown>>(
  options?: TParseLocationOptions
): T => {
  return qs.parse(search, {
    parseNumbers: true,
    parseBooleans: true,
    arrayFormat: "comma",
    ...options,
  }) as T;
};
