import { aggregateAcrossTeams, formatAggregationResult, loopGet, } from "../lib/loop-api.js";
export async function teamAvailability(params) {
    const { accountId, agentId, searchDate, teamName } = params;
    const result = await aggregateAcrossTeams(accountId, "team", "loop-team-availability", async (apiKey, team) => {
        const path = `/team/${encodeURIComponent(agentId)}/availability/${encodeURIComponent(searchDate)}`;
        const data = await loopGet(apiKey, path, "loop-team-availability", team);
        return Array.isArray(data) ? data : [];
    }, { teamName });
    return formatAggregationResult(result, (slot) => {
        const start = slot.start ? formatTime(slot.start) : "?";
        const end = slot.end ? formatTime(slot.end) : "?";
        return `- ${start} — ${end}`;
    }, `availability slots for ${searchDate}`);
}
function formatTime(iso) {
    const timePart = iso.split("T")[1];
    return timePart ? timePart.slice(0, 5) : iso;
}
//# sourceMappingURL=team-availability.js.map