import { useNavigate } from "@tanstack/react-router";
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();
  
  return useServerMutation({
    mutationFn: (data: TournamentInput) => createTournament({ data }),
    onMutate: (data) => {
      logger.info('Creating tournament', data);
    },
    onSuccess: () => {
      navigate({ to: '/tournaments' });
    },
    successMessage: 'Tournament created successfully!',
  });
};

export default useCreateTournament;
