import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { AgentCapacityBanner, AgentErrorBanner } from "./AgentBanners";
import { MACHINE_CAPACITY_REASON } from "../../agentMessageHelpers";
import { toUserFacingAgentErrorMessage } from "../../../services/agentErrorMessage";
export function AgentRunStatusBanners({ agent, agentStub, error, lastRunStatusReason, }) {
    const currentAgent = agent || agentStub;
    const capacityMessage = lastRunStatusReason === MACHINE_CAPACITY_REASON
        ? currentAgent?.statusMessage ||
            "Waiting for capacity. The agent will start automatically when a slot becomes available."
        : null;
    const errorMessage = getErrorBannerMessage(currentAgent, error);
    return (_jsxs(_Fragment, { children: [capacityMessage ? (_jsx(AgentCapacityBanner, { message: capacityMessage })) : null, errorMessage ? _jsx(AgentErrorBanner, { message: errorMessage }) : null] }));
}
function getErrorBannerMessage(currentAgent, error) {
    const isErrorStatus = currentAgent?.status === "error";
    const isWaitingForInputStatus = currentAgent?.status === "waitingForInput";
    const isWaitingForApprovalStatus = currentAgent?.status === "waitingForApproval";
    const isTerminalWithError = !isErrorStatus &&
        !!currentAgent?.statusMessage &&
        currentAgent?.status !== "running" &&
        currentAgent?.status !== "new" &&
        !isWaitingForInputStatus &&
        !isWaitingForApprovalStatus;
    const rawErrorMessage = (isErrorStatus || isTerminalWithError
        ? currentAgent?.statusMessage
        : null) || error;
    if (!rawErrorMessage) {
        return null;
    }
    return toUserFacingAgentErrorMessage(rawErrorMessage) || rawErrorMessage;
}
//# sourceMappingURL=AgentRunStatusBanners.js.map