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

const useUnenrollFreeAgent = (isRegional?: boolean) => {
  const queryClient = useQueryClient();
  const { t } = useLingui();

  return useServerMutation({
    mutationFn: (data: { tournamentId: string, playerId: string }) => {
      return unenrollFreeAgent({ data });
    },
    onSuccess: (data, { tournamentId }) => {
      queryClient.invalidateQueries({ queryKey: tournamentKeys.free_agents(tournamentId) });
    },
    successMessage: isRegional ? t`You've been removed from regionals!` : t`You've been removed as a free agent.`,
  });
};

export default useUnenrollFreeAgent;
