import { searchGroups } from "@esri/arcgis-rest-portal";
import { getEvent } from "./api/events";
/**
 * Fetches the groups an event is shared with
 * @param eventId The ID of the event to fetch the groups for
 * @param context An IArcGISContext object
 * @returns
 */
export async function getEventGroups(eventId, context) {
    const { editGroups: editGroupIds, readGroups: readGroupIds } = await getEvent(Object.assign({ eventId }, context.hubRequestOptions));
    const search = (ids) => ids.length
        ? searchGroups(Object.assign({ q: `id:(${ids.join(" OR ")})`, num: ids.length }, context.requestOptions))
        : Promise.resolve({ results: [] });
    const [{ results: readGroups }, { results: editGroups }] = await Promise.all([readGroupIds, editGroupIds].map(search));
    return [...readGroups, ...editGroups];
}
//# sourceMappingURL=getEventGroups.js.map