import { useQueryClient } from "@tanstack/react-query";
import { useLingui } from "@lingui/react/macro";
import { unenrollTeam } from "@/features/tournaments/server";
import { useServerMutation } from "@/lib/tanstack-query/hooks";

const useUnenrollTeam = () => {
  const queryClient = useQueryClient();
  const { t } = useLingui();

  return useServerMutation({
    mutationFn: (data: { tournamentId: string, teamId: string }) => {
      return unenrollTeam({ data });
    },
    onSuccess: (_, { tournamentId }) => {
      queryClient.invalidateQueries({ queryKey: ['tournaments', 'details', tournamentId] });
      queryClient.invalidateQueries({ queryKey: ['tournaments', 'unenrolled', tournamentId] });
    },
    successMessage: t`Team unenrolled successfully.`,
  });
};

export default useUnenrollTeam;
