/**
 * modules/core/eventBus.js — Bus de eventos mínimo (patón ARQ.bus).
 * Depende de: ninguno.
 */
(function (g) {
    if (g.eventBus && typeof g.eventBus.emit === 'function') return;
    var listeners = {};
    g.eventBus = {
        on: function (ev, fn) {
            if (!listeners[ev]) listeners[ev] = [];
            listeners[ev].push(fn);
            return function () {
                g.eventBus.off(ev, fn);
            };
        },
        off: function (ev, fn) {
            if (!listeners[ev]) return;
            listeners[ev] = listeners[ev].filter(function (f) {
                return f !== fn;
            });
        },
        emit: function (ev, payload) {
            (listeners[ev] || []).forEach(function (fn) {
                try {
                    fn(payload);
                } catch (e) {
                    console.error(e);
                }
            });
        },
    };
})(typeof window !== 'undefined' ? window : this);
