"use strict";
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
const Element_1 = require("../../../../../Class/Element");
const spec_1 = require("../../../../../client/spec");
const fromBundle_1 = require("../../../../../spec/fromBundle");
const fromSpec_1 = require("../../../../../spec/fromSpec");
const _ids_1 = require("../../../../_ids");
class Editor extends Element_1.Element_ {
    constructor(system) {
        super({
            i: [
                'graph',
                'style',
                'disabled',
                'fullwindow',
                'frame',
                'zoom',
                'controls',
                'attr',
            ],
            o: ['graph'],
        }, {
            input: {
                graph: {
                    ref: true,
                },
                frame: {
                    ref: true,
                },
            },
            output: {
                graph: {
                    ref: true,
                },
            },
        }, system, _ids_1.ID_EDITOR);
        this.__ = ['U', 'C', 'V', 'J', 'G'];
        const { specs, classes } = system;
        const spec = system.newSpec((0, spec_1.emptySpec)({ id: (0, spec_1.newSpecId)(specs) }));
        const Class = (0, fromSpec_1.fromSpec)(spec, specs, classes, {});
        const fallback_graph = new Class(system);
        this._fallback_graph = fallback_graph;
        this._input.graph.push(this._fallback_graph);
        this._output.graph.push(this._fallback_graph);
        this._fallback_graph.play();
    }
    onRefInputInvalid(name) {
        // console.log('Editor', 'onRefInputInvalid', name)
        if (name === 'graph') {
            //
        }
    }
    onRefInputData(name, data) {
        super.onRefInputData(name, data);
        // console.log('Editor', 'onRefInputData', name, data)
        if (name === 'graph') {
            this._graph = data;
            this._output.graph.push(data);
        }
    }
    onRefInputDrop(name) {
        super.onRefInputDrop(name);
        // console.log('Editor', 'onRefInputDrop', name)
        if (name === 'graph') {
            this._graph = this._fallback_graph;
            this._input.graph.push(this._fallback_graph);
            this._output.graph.push(this._fallback_graph);
        }
    }
    onRefOutputData(name, data) {
        // console.log('Editor', 'onRefOutputData', name, data)
    }
    snapshotSelf() {
        const bundle = this._fallback_graph.getUnitBundleSpec();
        return Object.assign(Object.assign({}, super.snapshotSelf()), { _fallback_graph: bundle });
    }
    restoreSelf(state) {
        const { _fallback_graph } = state, rest = __rest(state, ["_fallback_graph"]);
        super.restoreSelf(rest);
        const Class = (0, fromBundle_1.fromBundle)(_fallback_graph, this.__system.specs, {});
        const graph = new Class(this.__system);
        this._fallback_graph = graph;
    }
}
exports.default = Editor;
//# sourceMappingURL=index.js.map