"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useMembership = void 0;
var _tsSdkReactNative = require("@amityco/ts-sdk-react-native");
var _toastSlice = require("../../../../../core/stores/slices/toastSlice");
var _native = require("@react-navigation/native");
var _reactQuery = require("@tanstack/react-query");
var _react = require("react");
const useMembership = ({
  community
}) => {
  const {
    showToast
  } = (0, _toastSlice.useToast)();
  const [activeTab, setActiveTab] = (0, _react.useState)('members');
  const navigation = (0, _native.useNavigation)();
  const {
    mutateAsync: addMembers
  } = (0, _reactQuery.useMutation)({
    mutationFn: userIds => _tsSdkReactNative.CommunityRepository.Membership.addMembers(community.communityId, userIds),
    onSuccess: () => {
      navigation.goBack();
      showToast({
        type: 'success',
        message: 'Successfully added member to this community.'
      });
    },
    onError: () => {
      showToast({
        type: 'failed',
        message: 'Failed to add member. Please try again.'
      });
    }
  });
  const onAddMember = async users => {
    await addMembers(users.map(user => user.userId));
  };
  return {
    navigation,
    onAddMember,
    activeTab,
    setActiveTab
  };
};
exports.useMembership = useMembership;
//# sourceMappingURL=useMembership.js.map