// src/hooks/useQueryParams.tsx
import { useMemo, useRef } from "react";
import { useLocation } from "react-router-dom";
function useQueryParams() {
  const { search } = useLocation();
  return useMemo(() => new URLSearchParams(search), [search]);
}
function useQueryParamBoolean(param) {
  const queryParams = useQueryParams();
  return useMemo(() => queryParams.get(param) === "1", [queryParams, param]);
}
function useQueryParamBooleans(params) {
  const queryParams = useQueryParams();
  const prevParams = useRef(params);
  const memoizedParams = useMemo(() => {
    if (JSON.stringify(params) !== JSON.stringify(prevParams.current)) {
      prevParams.current = params;
    }
    return prevParams.current;
  }, [params]);
  const value = useMemo(() => {
    const result = {};
    for (const key in memoizedParams) {
      const param = memoizedParams[key];
      const value2 = queryParams.get(param);
      if (value2 === "1" || value2 === "true") {
        result[key] = true;
      } else if (value2 === "0" || value2 === "false") {
        result[key] = false;
      } else if (value2 === "") {
        result[key] = true;
      } else {
        result[key] = void 0;
      }
    }
    return result;
  }, [queryParams, memoizedParams]);
  return value;
}

export {
  useQueryParams,
  useQueryParamBoolean,
  useQueryParamBooleans
};
