"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useFollowUser = void 0;
var _reactNative = require("react-native");
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 useFollowUser = () => {
  const {
    showToast
  } = (0, _toastSlice.useToast)();
  const {
    mutate: followMutate,
    isPending: isFollowPending
  } = (0, _reactQuery.useMutation)({
    mutationFn: _tsSdkReactNative.UserRepository.Relationship.follow
  });
  const {
    mutate: unfollowMutate,
    isPending: isUnfollowPending
  } = (0, _reactQuery.useMutation)({
    mutationFn: _tsSdkReactNative.UserRepository.Relationship.unfollow
  });
  const followUser = userId => {
    followMutate(userId, {
      onError: () => {
        _reactNative.Alert.alert(_constants.ALERT.USER.FOLLOW.TITLE, _constants.ALERT.USER.FOLLOW.MESSAGE, [{
          text: _constants.ALERT.ACTION.OK
        }]);
      }
    });
  };
  const unfollow = userId => unfollowMutate(userId, {
    onError: () => showToast({
      type: 'informative',
      message: _constants.TOAST.USER.UNFOLLOW.FAILED
    })
  });
  const unfollowUser = (userId, options) => {
    if (options !== null && options !== void 0 && options.confirm) {
      _reactNative.Alert.alert(_constants.ALERT.USER.UNFOLLOW.TITLE, _constants.ALERT.USER.UNFOLLOW.MESSAGE, [{
        text: _constants.ALERT.ACTION.CANCEL,
        style: 'cancel'
      }, {
        text: _constants.ALERT.ACTION.UNFOLLOW,
        style: 'destructive',
        onPress: () => unfollow(userId)
      }]);
    } else {
      unfollow(userId);
    }
  };
  return {
    followUser,
    unfollowUser,
    isLoading: isFollowPending || isUnfollowPending
  };
};
exports.useFollowUser = useFollowUser;
//# sourceMappingURL=useFollowUser.js.map