import { useAuth } from 'src/contexts/JWTContext';
import { type FeatureFlags } from 'src/types/featureFlags';

/**
 * Hook to get a feature flag value from backend
 * @param code - The feature flag code
 * @returns The feature flag value
 */
const useFeatureFlag = <T = boolean>(code: keyof typeof FeatureFlags): T => {
  const { featureFlags } = useAuth();
  const featureFlag = featureFlags?.[code];
  return featureFlag as T;
};

export default useFeatureFlag;
