"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeCustomListener = makeCustomListener;
exports.listenCustom = listenCustom;
const __1 = require("..");
const stopPropagation_1 = require("../../stopPropagation");
function makeCustomListener(type, listener, global = false) {
    return (component) => {
        return listenCustom(type, component, listener, global);
    };
}
function listenCustom(type, component, listener, global = false) {
    const { $system, $element } = component;
    const _type = `_${type}`;
    const { customEvent, context } = $system;
    if (!customEvent.has(type)) {
        for (const c of context) {
            (0, stopPropagation_1.stopByPropagation)(c.$element, _type);
        }
        customEvent.add(type);
    }
    const _listener = (_event) => {
        const { detail } = _event;
        listener(detail, _event);
    };
    const unlisten = (0, __1._addEventListener)(_type, $element, _listener, global);
    return unlisten;
}
//# sourceMappingURL=index.js.map