import { useCallback, useEffect, useRef } from "react";
export function useAgentStopGuardState(input) {
    const { setIsStopGuardActive } = input;
    const isStoppingRef = useRef(false);
    const stopGuardReleaseTimeoutRef = useRef(null);
    const clearStopGuard = useCallback(() => {
        isStoppingRef.current = false;
        setIsStopGuardActive(false);
        if (stopGuardReleaseTimeoutRef.current) {
            clearTimeout(stopGuardReleaseTimeoutRef.current);
            stopGuardReleaseTimeoutRef.current = null;
        }
    }, [setIsStopGuardActive]);
    const armStopGuard = useCallback(() => {
        isStoppingRef.current = true;
        setIsStopGuardActive(true);
        if (stopGuardReleaseTimeoutRef.current) {
            clearTimeout(stopGuardReleaseTimeoutRef.current);
        }
        stopGuardReleaseTimeoutRef.current = setTimeout(() => {
            stopGuardReleaseTimeoutRef.current = null;
            isStoppingRef.current = false;
            setIsStopGuardActive(false);
        }, 30000);
    }, [setIsStopGuardActive]);
    useEffect(() => {
        return () => {
            if (stopGuardReleaseTimeoutRef.current) {
                clearTimeout(stopGuardReleaseTimeoutRef.current);
                stopGuardReleaseTimeoutRef.current = null;
            }
        };
    }, []);
    return {
        isStoppingRef,
        clearStopGuard,
        armStopGuard,
    };
}
//# sourceMappingURL=useAgentStopGuardState.js.map