"use client";
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
import { TeamsAPI } from "../lib/teams/teams.api.js";
import { teamsKeys } from "../lib/teams/teams.keys.js";
function useTeams() {
  const queryClient = useQueryClient();
  const { data: teams = [], isLoading, error } = useQuery({
    queryKey: teamsKeys.user(),
    queryFn: TeamsAPI.getUserTeams,
    staleTime: 5 * 60 * 1e3
    // 5 minutes
  });
  const createTeamMutation = useMutation({
    mutationFn: async (teamData) => {
      return TeamsAPI.createTeam(teamData);
    },
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: teamsKeys.user() });
      queryClient.invalidateQueries({ queryKey: teamsKeys.admin() });
    }
  });
  return {
    teams,
    isLoading,
    error,
    createTeam: createTeamMutation.mutate,
    createTeamAsync: createTeamMutation.mutateAsync,
    isCreating: createTeamMutation.isPending
  };
}
export {
  useTeams
};
