"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useBodyClick = void 0;
const useBodyClick = () => {
    const removeEvent = (event, target = document) => {
        target === null || target === void 0 ? void 0 : target.removeEventListener('click', event);
    };
    const onBodyClick = (event, target = document) => {
        const mappedEvent = (e) => {
            return event(e);
        };
        target === null || target === void 0 ? void 0 : target.addEventListener('click', mappedEvent);
        return {
            remove: () => {
                target && removeEvent(mappedEvent, target);
            },
        };
    };
    const onBodyClickExcept = (event, ignore, target = document) => {
        const response = onBodyClick((e) => {
            var _a;
            for (const element of e.composedPath()) {
                if ((_a = element.isSameNode) === null || _a === void 0 ? void 0 : _a.call(element, ignore)) {
                    // Preventing the event from taking place, as it's in the ignored list.
                    return;
                }
            }
            // Assuming target click isn't in the ignore area, proceed with the event
            event(e);
        }, target);
        return response;
    };
    return { onBodyClick, onBodyClickExcept };
};
exports.useBodyClick = useBodyClick;
//# sourceMappingURL=BodyClickHook.js.map