import { useCallback, useMemo, useRef } from "react";
import { selectPendingApprovals } from "./agentSessionSelectors";
export function useAgentPendingApprovals(state) {
    const allPendingApprovalsRef = useRef([]);
    const allPendingApprovals = useMemo(() => {
        const pending = selectPendingApprovals(state);
        const prev = allPendingApprovalsRef.current;
        if (prev.length === pending.length) {
            let same = true;
            for (let i = 0; i < pending.length; i++) {
                const a = prev[i];
                const b = pending[i];
                if (a?.toolCallId !== b?.toolCallId ||
                    a?.messageId !== b?.messageId ||
                    a?.dbMessageId !== b?.dbMessageId ||
                    a?.riskLevel !== b?.riskLevel ||
                    a?.functionName !== b?.functionName ||
                    a?.summary !== b?.summary) {
                    same = false;
                    break;
                }
            }
            if (same)
                return prev;
        }
        allPendingApprovalsRef.current = pending;
        return pending;
    }, [state]);
    const hasPendingApprovals = useCallback(() => {
        return allPendingApprovals.length > 0;
    }, [allPendingApprovals]);
    return {
        allPendingApprovals,
        hasPendingApprovals,
    };
}
//# sourceMappingURL=useAgentPendingApprovals.js.map