import { useMemo, useRef } from "react";
import { useLocation } from "react-router-dom";
//#region src/hooks/useQueryParams.tsx
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]);
	return useMemo(() => {
		const result = {};
		for (const key in memoizedParams) {
			const param = memoizedParams[key];
			const value = queryParams.get(param);
			if (value === "1" || value === "true") result[key] = true;
			else if (value === "0" || value === "false") result[key] = false;
			else if (value === "") result[key] = true;
			else result[key] = void 0;
		}
		return result;
	}, [queryParams, memoizedParams]);
}
//#endregion
export { useQueryParamBoolean, useQueryParamBooleans, useQueryParams };
