"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ClickOutside = void 0;
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const ClickOutside = (_a) => {
    var { mouseEvents = ['click'], onOutsideClick, children } = _a, restProps = tslib_1.__rest(_a, ["mouseEvents", "onOutsideClick", "children"]);
    const $containerEl = react_1.default.useRef(null);
    const globalClickSpy = react_1.default.useCallback((e) => {
        if ($containerEl.current && e.target && !$containerEl.current.contains(e.target)) {
            onOutsideClick(e);
        }
    }, [onOutsideClick]);
    react_1.default.useEffect(() => {
        mouseEvents.forEach((event) => {
            window.addEventListener(event, globalClickSpy, true);
        });
        return () => {
            mouseEvents.forEach((event) => {
                window.removeEventListener(event, globalClickSpy, true);
            });
        };
    }, [mouseEvents]);
    return (react_1.default.createElement("div", Object.assign({}, restProps, { ref: $containerEl }), children));
};
exports.ClickOutside = ClickOutside;
//# sourceMappingURL=index.js.map