"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Holder_1 = require("../../../../../Class/Holder");
const makeEventListener_1 = require("../../../../../client/makeEventListener");
const Event_1 = require("../../../../../wrap/Event");
const _ids_1 = require("../../../../_ids");
const globalComponent_1 = require("../../../../globalComponent");
class Listener extends Holder_1.Holder {
    constructor(system) {
        super({
            fi: ['component', 'event'],
            fo: ['data', 'event'],
            i: [],
            o: [],
        }, {
            input: {
                component: {
                    ref: true,
                },
            },
            output: {
                event: {
                    ref: true,
                },
            },
        }, system, _ids_1.ID_LISTENER);
        this._unlisten = undefined;
    }
    async f({ component, event }) {
        const listener = (data, event_) => {
            const $event = (0, Event_1.wrapEvent)(event_, data, this.__system);
            this._output.event.push($event);
            this._output.data.push(data);
        };
        const globalId = component.getGlobalId();
        const component_ = (await (0, globalComponent_1.firstGlobalComponentPromise)(this.__system, globalId));
        const listener_ = (0, makeEventListener_1.makeUIEventListener)(event, listener);
        this._unlisten = component_.addEventListener(listener_);
    }
    d() {
        if (this._unlisten) {
            this._unlisten();
            this._unlisten = undefined;
        }
    }
}
exports.default = Listener;
//# sourceMappingURL=index.js.map