import { useQuery } from 'react-query';

import useGeneralError from 'src/hooks/useGeneralError';
import { documentsKeys } from 'src/pages/dashboard/documents/queries';
import { getFolder } from 'src/services/documents';
import { useLokaliseTranslation } from 'src/utils/i18n';

export const useDocument = (folderId, isEnabled = true) => {
  const showGeneralError = useGeneralError();
  const { t } = useLokaliseTranslation('documents');

  return useQuery(
    documentsKeys.folder.detail(folderId),
    () => getFolder(folderId),
    {
      onError: err =>
        showGeneralError(err, t('ERROR_LOADING_PENDING_DOCUMENT_ITEM')),
      enabled: isEnabled,
    },
  );
};

export default useDocument;
