import { useLingui } from "@lingui/react/macro";
import { updateTeam } from "@/features/teams/server";
import { TeamUpdateInput } from "@/features/teams/types";
import { useServerMutation } from "@/lib/tanstack-query/hooks";
import { logger } from "@/lib/logger";

const useUpdateTeam = (teamId: string) => {
  const { t } = useLingui();

  return useServerMutation({
    mutationFn: (data: TeamUpdateInput) =>
      updateTeam({ data: { id: teamId, updates: data } }),
    onMutate: (data) => {
      logger.info('Updating team', { teamId, updates: Object.keys(data) });
    },
    successMessage: t`Team updated successfully!`,
  });
};

export default useUpdateTeam;