import { Alert } from 'react-native';
import { UserRepository } from '@amityco/ts-sdk-react-native';
import { useMutation } from '@tanstack/react-query';
import { useToast } from '../../../core/stores/slices/toastSlice';
import { ALERT, TOAST } from '../../../core/constants';
export const useFollowUser = () => {
  const {
    showToast
  } = useToast();
  const {
    mutate: followMutate,
    isPending: isFollowPending
  } = useMutation({
    mutationFn: UserRepository.Relationship.follow
  });
  const {
    mutate: unfollowMutate,
    isPending: isUnfollowPending
  } = useMutation({
    mutationFn: UserRepository.Relationship.unfollow
  });
  const followUser = userId => {
    followMutate(userId, {
      onError: () => {
        Alert.alert(ALERT.USER.FOLLOW.TITLE, ALERT.USER.FOLLOW.MESSAGE, [{
          text: ALERT.ACTION.OK
        }]);
      }
    });
  };
  const unfollow = userId => unfollowMutate(userId, {
    onError: () => showToast({
      type: 'informative',
      message: TOAST.USER.UNFOLLOW.FAILED
    })
  });
  const unfollowUser = (userId, options) => {
    if (options !== null && options !== void 0 && options.confirm) {
      Alert.alert(ALERT.USER.UNFOLLOW.TITLE, ALERT.USER.UNFOLLOW.MESSAGE, [{
        text: ALERT.ACTION.CANCEL,
        style: 'cancel'
      }, {
        text: ALERT.ACTION.UNFOLLOW,
        style: 'destructive',
        onPress: () => unfollow(userId)
      }]);
    } else {
      unfollow(userId);
    }
  };
  return {
    followUser,
    unfollowUser,
    isLoading: isFollowPending || isUnfollowPending
  };
};
//# sourceMappingURL=useFollowUser.js.map