import { useNavigate } from "@tanstack/react-router";
import { useLingui } from "@lingui/react/macro";
import { createTournament } from "@/features/tournaments/server";
import { TournamentInput } from "@/features/tournaments/types";
import { logger } from "../";
import { useServerMutation } from "@/lib/tanstack-query/hooks";

const useCreateTournament = () => {
  const navigate = useNavigate();
  const { t } = useLingui();

  return useServerMutation({
    mutationFn: (data: TournamentInput) => createTournament({ data }),
    onMutate: (data) => {
      logger.info('Creating tournament', data);
    },
    onSuccess: () => {
      navigate({ to: '/tournaments' });
    },
    successMessage: t`Tournament created successfully!`,
  });
};

export default useCreateTournament;
