import { useQuery } from 'react-query';

import { librariesKeys } from '../queries';
import { getArticles } from '../services';
import { type Article } from '../types';

const selectRootArticles = (
  response: Awaited<ReturnType<typeof getArticles>>,
): Article[] => response.data.items ?? [];

export const useGetRootArticles = () => {
  return useQuery({
    queryKey: librariesKeys.article.rootList(),
    queryFn: getArticles,
    select: selectRootArticles,
  });
};
