import { useQuery } from "@tanstack/react-query";

import { client } from "@/lib/rpc";

interface UseGetAvailableUsersProps {
  workspaceId: string;
}

export const useGetAvailableUsers = ({ workspaceId }: UseGetAvailableUsersProps) => {
  const query = useQuery({
    queryKey: ["available-users", workspaceId],
    queryFn: async () => {
      const response = await client.api.members.available.$get({
        query: { workspaceId },
      });

      if (!response.ok) {
        throw new Error("Failed to fetch available users");
      }

      const { data } = await response.json();
      return data;
    },
    enabled: !!workspaceId,
  });

  return query;
}; 