import { useQuery } from 'react-query';

import { useDebounce } from '@material-hu/hooks/useDebounce';

import { getUserListToAcknowledge } from 'src/services/users';

import { peopleSearchKeys } from 'src/components/dashboard/people/queries';

const LIMIT = 20;
const PAGE = 1;

export const useGetAcknowledged = (search: string) => {
  const debouncedSearch = useDebounce(search);

  return useQuery({
    queryKey: peopleSearchKeys.acknowledgementsSearchPeople(debouncedSearch),
    queryFn: () => getUserListToAcknowledge(debouncedSearch, PAGE, LIMIT),
    select: response => response.data.items,
    staleTime: 60000,
  });
};
