import { useQuery } from 'react-query';

import { getManagerSurveyDetail } from '../services';
import { Nullable, SurveyResponse } from '../types';

import { LokaliseTFunction } from 'src/utils/i18n';

import { pxKeys } from '../queries';
import { parseManagerSurvey } from '../utils';

type Options = {
  surveyId: Nullable<SurveyResponse['id']>;
  t: LokaliseTFunction;
};

const useManagerSurveyDetail = ({ surveyId, t }: Options) => {
  return useQuery({
    queryKey: pxKeys.managerSurveyDetail(surveyId!),
    queryFn: () => getManagerSurveyDetail(surveyId!),
    select: response => {
      const { data } = response;
      return parseManagerSurvey({ data, t });
    },
    enabled: !!surveyId,
  });
};

export default useManagerSurveyDetail;
