"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.localComponentClassFromSpec = localComponentClassFromSpec;
const fromSpec_1 = require("../spec/fromSpec");
const spec_1 = require("../spec/util/spec");
const AsyncGraph_1 = require("../types/interface/async/AsyncGraph");
const componentClassFromSpec_1 = require("./componentClassFromSpec");
function localComponentClassFromSpec(spec) {
    const Class = (0, componentClassFromSpec_1.componentClassFromSpec)(spec, {}, {});
    return class Component_ extends Class {
        constructor($props, $system, $element) {
            super($props, $system, $element);
            const graph = (0, fromSpec_1.graphFromSpec)($system, spec, $system.specs);
            for (const pinId in $props) {
                const data = $props[pinId];
                graph.setPinData('input', pinId, data);
            }
            (0, spec_1.forEachGraphSpecPinOfType)(spec, 'output', (outputId) => {
                const output = graph.getOutput(outputId);
                output.addListener('data', (data) => {
                    this.$output[outputId] = data;
                    this.dispatchEvent(outputId, data);
                });
                output.addListener('drop', () => {
                    delete this.$output[outputId];
                });
            });
            const $graph = (0, AsyncGraph_1.AsyncGraph)(graph);
            this.connect($graph);
            graph.play();
        }
    };
}
//# sourceMappingURL=unitComponentClassFromSpec.js.map