import { useQuery } from 'react-query';

import { goalsKeys } from '../queries';
import { getGoalCyclesConfiguration } from '../services';
import { type GoalCyclesConfiguration } from '../types';

export const useGoalFeaturesConfig = () => {
  const { data, isLoading } = useQuery(
    goalsKeys.allConfiguration(),
    getGoalCyclesConfiguration,
    {
      select: (response: { data: GoalCyclesConfiguration }) => response.data,
    },
  );

  const goalFlowEnabled = data?.goalFlowEnabled || false;
  const mathFormulasEnabled = data?.mathFormulasEnabled ?? false;
  const bossCanEditPublishedObjectives =
    data?.bossCanEditPublishedObjectives ?? false;

  return {
    isApprovalFlowEnabled: goalFlowEnabled,
    isMathFormulasEnabled: mathFormulasEnabled,
    isBossCanEditPublishedObjectives: bossCanEditPublishedObjectives,
    isLoadingGoalFeaturesConfig: isLoading,
  };
};
