"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const Semifunctional_1 = require("../../../../../Class/Semifunctional");
const _ids_1 = require("../../../../_ids");
const globalComponent_1 = require("../../../../globalComponent");
class Observe extends Semifunctional_1.Semifunctional {
    constructor(system) {
        super({
            fi: ['component', 'observer'],
            fo: [],
            i: ['done'],
            o: ['entry'],
        }, {
            input: {
                component: {
                    ref: true,
                },
            },
        }, system, _ids_1.ID_OBSERVE);
    }
    f({ observer, component }, done) {
        return __awaiter(this, void 0, void 0, function* () {
            const { api: { document: {}, }, } = this.__system;
            // component.emit('call', { method: 'target', data: [] })
            const globalId = component.getGlobalId();
            const _component = yield (0, globalComponent_1.firstGlobalComponentPromise)(this.__system, globalId);
            const leaf = _component.getFirstRootLeaf();
            if (leaf.$element instanceof Text) {
                done(undefined, 'cannot observe text node');
                return;
            }
            observer.observe(leaf.$element, (entry) => {
                this._output.entry.push(entry);
            });
        });
    }
    d() {
        // TODO
    }
}
exports.default = Observe;
//# sourceMappingURL=index.js.map