"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useUserFlaggedByMeQuery = void 0;
var _tsSdkReactNative = require("@amityco/ts-sdk-react-native");
var _reactQuery = require("@tanstack/react-query");
var _toastSlice = require("../../../core/stores/slices/toastSlice");
var _constants = require("../../../core/constants");
const useUserFlaggedByMeQuery = ({
  userId,
  enabled
}) => {
  const {
    showToast
  } = (0, _toastSlice.useToast)();
  const {
    data: isFlaggedByMe,
    isLoading,
    refetch
  } = (0, _reactQuery.useQuery)({
    queryKey: ['UserRepository', 'isUserFlaggedByMe', userId],
    queryFn: () => _tsSdkReactNative.UserRepository.isUserFlaggedByMe(userId),
    enabled: enabled && !!userId
  });
  const {
    mutate: flagUserMutate
  } = (0, _reactQuery.useMutation)({
    mutationFn: _tsSdkReactNative.UserRepository.flagUser
  });
  const {
    mutate: unflagUserMutate
  } = (0, _reactQuery.useMutation)({
    mutationFn: _tsSdkReactNative.UserRepository.unflagUser
  });
  const reportUser = targetUserId => {
    flagUserMutate(targetUserId, {
      onSuccess: () => {
        refetch();
        showToast({
          type: 'success',
          message: _constants.TOAST.USER.REPORT.SUCCESS
        });
      },
      onError: () => showToast({
        type: 'informative',
        message: _constants.TOAST.USER.REPORT.FAILED
      })
    });
  };
  const unreportUser = targetUserId => {
    unflagUserMutate(targetUserId, {
      onSuccess: () => {
        refetch();
        showToast({
          type: 'success',
          message: _constants.TOAST.USER.UNREPORT.SUCCESS
        });
      },
      onError: () => showToast({
        type: 'informative',
        message: _constants.TOAST.USER.UNREPORT.FAILED
      })
    });
  };
  return {
    isLoading,
    isFlaggedByMe,
    reportUser,
    unreportUser
  };
};
exports.useUserFlaggedByMeQuery = useUserFlaggedByMeQuery;
//# sourceMappingURL=useFlagUserQuery.js.map