"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const bundle_1 = require("../../../../../bundle");
const Holder_1 = require("../../../../../Class/Holder");
const UCGEE_1 = require("../../../../../types/interface/UCGEE");
const weakMerge_1 = require("../../../../../weakMerge");
const wrap_1 = require("../../../../../wrap");
const _ids_1 = require("../../../../_ids");
class Start extends Holder_1.Holder {
    constructor(system) {
        super({
            fi: ['graph', 'system', 'opt'],
            fo: ['graph'],
            i: [],
            o: [],
        }, {
            input: {
                system: {
                    ref: true,
                },
            },
            output: {
                graph: {
                    ref: true,
                },
            },
        }, system, _ids_1.ID_START);
    }
    f({ graph: Graph, system, opt }, done) {
        var _a;
        const { paused } = opt || {};
        const { __bundle } = Graph;
        const id = __bundle.unit.id;
        const spec = ((_a = this.__system.getSpec(id)) !== null && _a !== void 0 ? _a : __bundle.specs[id]);
        const bundle = (0, bundle_1.bundleSpec)(spec, (0, weakMerge_1.weakMerge)(__bundle.specs, this.__system.specs));
        const _ = UCGEE_1.UCGEE;
        const $graph = system.$newGraph({ bundle, _ });
        const graph = (0, wrap_1.$wrap)(this.__system, $graph, _);
        if (!paused) {
            graph.$play({});
        }
        if (!paused) {
            graph.$play({});
        }
        this._graph = graph;
        done({ graph });
    }
    d() {
        if (this._graph) {
            this._graph = undefined;
        }
    }
}
exports.default = Start;
//# sourceMappingURL=index.js.map