import { useAuth } from 'src/contexts/JWTContext';
import useCommunityFeature from 'src/hooks/useCommunityFeature';
import { CommunityFeature } from 'src/types/communityFeatures';

const useCanViewGroupsInsights = (
  isGroupAdmin: boolean,
  postUserId?: number,
) => {
  const { user } = useAuth();
  const canViewStats = useCommunityFeature(CommunityFeature.VIEW_POST_STATS);

  return canViewStats && (isGroupAdmin || user?.id === postUserId);
};

export default useCanViewGroupsInsights;
