"use client";
import { useQuery } from "@tanstack/react-query";
import { TeamsAPI } from "../../lib/teams/teams.api.js";
import { teamsKeys } from "../../lib/teams/teams.keys.js";
function useTeamSearch(search = "", enabled = true) {
  var _a, _b, _c;
  const query = useQuery({
    queryKey: teamsKeys.adminSearch(search),
    queryFn: () => TeamsAPI.getAdminTeams({
      search: search || void 0,
      type: "user",
      // Exclude system admin team
      limit: 100
      // Enough for dropdown
    }),
    enabled,
    staleTime: 30 * 1e3
    // 30 seconds
  });
  return {
    /** List of teams matching search */
    teams: ((_a = query.data) == null ? void 0 : _a.teams) ?? [],
    /** Total count of user teams */
    totalCount: ((_c = (_b = query.data) == null ? void 0 : _b.counts) == null ? void 0 : _c.user) ?? 0,
    /** Loading state */
    isLoading: query.isLoading,
    /** Fetching state (for search updates) */
    isFetching: query.isFetching,
    /** Error if any */
    error: query.error
  };
}
export {
  useTeamSearch
};
