"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useFocusTrapEffect = void 0;
const focus_trap_1 = require("focus-trap");
const react_1 = require("react");
/**
 * Хук для удержания фокуса внутри указанного контейнера.
 * Опции соответствуют конфигурации focus-trap.
 */
const useFocusTrapEffect = ({ ref, isActive, ...options }) => {
    const trapRef = (0, react_1.useRef)(null);
    (0, react_1.useEffect)(() => {
        const node = ref.current;
        if (!isActive || !node) {
            trapRef.current?.deactivate();
            trapRef.current = null;
            return;
        }
        const trap = (0, focus_trap_1.createFocusTrap)(node, options);
        trapRef.current = trap;
        trap.activate();
        return () => {
            trap.deactivate();
            trapRef.current = null;
        };
    }, [isActive, ref]);
};
exports.useFocusTrapEffect = useFocusTrapEffect;
