import { CommunityRepository } from '@amityco/ts-sdk-react-native';
import { useToast } from '../../../../../core/stores/slices/toastSlice';
import { useNavigation } from '@react-navigation/native';
import { useMutation } from '@tanstack/react-query';
import { useState } from 'react';
export const useMembership = ({
  community
}) => {
  const {
    showToast
  } = useToast();
  const [activeTab, setActiveTab] = useState('members');
  const navigation = useNavigation();
  const {
    mutateAsync: addMembers
  } = useMutation({
    mutationFn: userIds => 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
  };
};
//# sourceMappingURL=useMembership.js.map