import { useEffect } from "react";
export function useAgentCostLimitWatcher(input) {
    const { agent, sessionCostLimitExceeded, sessionLiveTotalCost, actions } = input;
    useEffect(() => {
        if (!agent) {
            if (sessionCostLimitExceeded) {
                actions.replaceCostLimitExceeded(null);
            }
            return;
        }
        const statusIndicatesLimit = agent.status === "costLimitReached";
        const effectiveTotalCost = agent.totalCost || sessionLiveTotalCost || 0;
        const costExceedsLimit = agent.costLimit &&
            effectiveTotalCost > 0 &&
            effectiveTotalCost > agent.costLimit;
        if (statusIndicatesLimit || costExceedsLimit) {
            const totalCost = effectiveTotalCost;
            const costLimit = agent.costLimit || 0;
            if (sessionCostLimitExceeded?.totalCost !== totalCost ||
                sessionCostLimitExceeded?.costLimit !== costLimit) {
                actions.replaceCostLimitExceeded({
                    totalCost,
                    costLimit,
                    initialCostLimit: costLimit,
                });
            }
            return;
        }
        const prev = sessionCostLimitExceeded;
        if (!prev) {
            return;
        }
        const costLimit = agent.costLimit || prev.costLimit || 0;
        const currentCost = effectiveTotalCost;
        if (costLimit > 0 && currentCost > 0 && currentCost <= costLimit) {
            actions.replaceCostLimitExceeded(null);
            return;
        }
        if (currentCost > 0 &&
            currentCost > costLimit &&
            (prev.totalCost !== currentCost || prev.costLimit !== costLimit)) {
            actions.replaceCostLimitExceeded({
                totalCost: currentCost,
                costLimit,
                initialCostLimit: prev.initialCostLimit,
            });
        }
    }, [
        actions,
        agent,
        agent?.costLimit,
        agent?.status,
        agent?.totalCost,
        sessionCostLimitExceeded,
        sessionLiveTotalCost,
    ]);
}
//# sourceMappingURL=useAgentCostLimitWatcher.js.map