"use client";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { useTeamContext } from "../contexts/TeamContext.js";
function useTeamUpdate(teamId) {
  const queryClient = useQueryClient();
  const { refreshTeams } = useTeamContext();
  return useMutation({
    mutationFn: async (payload) => {
      const response = await fetch(`/api/v1/teams/${teamId}`, {
        method: "PATCH",
        headers: {
          "Content-Type": "application/json"
        },
        body: JSON.stringify(payload)
      });
      const data = await response.json();
      if (!response.ok) {
        throw new Error(data.error || "Failed to update team");
      }
      return data;
    },
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: ["teams"] });
      queryClient.invalidateQueries({ queryKey: ["team", teamId] });
      refreshTeams();
    }
  });
}
export {
  useTeamUpdate
};
