"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "createFocusScope", {
    enumerable: true,
    get: function() {
        return createFocusScope;
    }
});
const _focusDetector = require("./utils/focusDetector");
const _constants = require("./constants");
function createFocusScope(hotInstance, container, options = {}) {
    const mergedOptions = {
        shortcutsContextName: _constants.DEFAULT_SHORTCUTS_CONTEXT,
        type: _constants.SCOPE_TYPES.INLINE,
        contains: (target)=>target === container || container.contains(target),
        runOnlyIf: ()=>true,
        enableFocusCatchers: true,
        ...options
    };
    const focusCatchers = mergedOptions.enableFocusCatchers === false ? null : (0, _focusDetector.installFocusDetector)(hotInstance, container);
    /**
   * Checks if the target element is within the scope boundaries.
   *
   * @param {HTMLElement} target The target element to check.
   * @returns {boolean}
   */ const contains = (target)=>{
        return mergedOptions.contains(target);
    };
    /**
   * Disables the focus catchers.
   */ const deactivateFocusCatchers = ()=>{
        focusCatchers?.deactivate();
    };
    /**
   * Enables the focus catchers.
   */ const activateFocusCatchers = ()=>{
        focusCatchers?.activate();
    };
    /**
   * Activates the scope.
   *
   * @param {'unknown' | 'click' | 'tab_from_above' | 'tab_from_below'} activationSource The source of the activation.
   */ const activate = (activationSource = _constants.FOCUS_SOURCES.UNKNOWN)=>{
        mergedOptions.onActivate?.(activationSource);
    };
    /**
   * Deactivates the scope.
   */ const deactivate = ()=>{
        mergedOptions.onDeactivate?.();
    };
    /**
   * Enables the scope so the scope container can be focused.
   */ const enable = ()=>{
        container.removeAttribute('inert');
    };
    /**
   * Disables the scope so the scope container can't be focused.
   */ const disable = ()=>{
        container.setAttribute('inert', 'true');
    };
    /**
   * Destroys the scope.
   */ const destroy = ()=>{
        focusCatchers?.destroy();
    };
    return {
        getType: ()=>mergedOptions.type,
        hasContainerDetached: ()=>!hotInstance.rootWrapperElement.contains(container),
        getShortcutsContextName: ()=>mergedOptions.shortcutsContextName,
        runOnlyIf: ()=>mergedOptions.runOnlyIf(),
        contains,
        activate,
        deactivate,
        activateFocusCatchers,
        deactivateFocusCatchers,
        enable,
        disable,
        destroy
    };
}
