"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AsyncEE = exports.AsyncEERef = exports.AsyncEEWatch = exports.AsyncEECall = exports.AsyncEEGet = void 0;
const _1 = require("../../../Class/$");
const _emitter_1 = require("../../../component/$emitter");
const AsyncEEGet = (emitter) => {
    return {
        $eventNames(data, callback) {
            const eventNames = emitter.eventNames();
            callback(eventNames);
        },
    };
};
exports.AsyncEEGet = AsyncEEGet;
const AsyncEECall = (emitter) => {
    return {
        $emit({ type, data }, callback) {
            emitter.emit(type, data);
            callback();
        },
    };
};
exports.AsyncEECall = AsyncEECall;
const AsyncEEWatch = (emitter) => {
    return {
        $addListener({ event }, callback) {
            return emitter.addListener(event, (...args) => {
                args = args.map((arg) => {
                    if (arg instanceof _1.$) {
                        return { globalId: arg.getGlobalId(), __: arg.getInterface() };
                    }
                    else {
                        return arg;
                    }
                });
                callback(args);
            });
        },
    };
};
exports.AsyncEEWatch = AsyncEEWatch;
const AsyncEERef = (emitter) => {
    return {
        $refEmitter({}) {
            return (0, _emitter_1.$refEmitter)(emitter, emitter.__system.async);
        },
    };
};
exports.AsyncEERef = AsyncEERef;
const AsyncEE = (emitter) => {
    return {
        ...(0, exports.AsyncEEGet)(emitter),
        ...(0, exports.AsyncEECall)(emitter),
        ...(0, exports.AsyncEEWatch)(emitter),
        ...(0, exports.AsyncEERef)(emitter),
    };
};
exports.AsyncEE = AsyncEE;
//# sourceMappingURL=AsyncEE.js.map