"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var HaikuComponent_1 = require("./../HaikuComponent");
var OBJECT_TYPE = 'object';
var HAIKU_ID_ATTRIBUTE = 'haiku-id';
var DEFAULT_TIMELINE_NAME = 'Default';
function isBytecode(thing) {
    return thing && typeof thing === OBJECT_TYPE && thing.template && thing.timelines;
}
function initializeComponentTree(element, component, context, instance) {
    if (isBytecode(element.elementName)) {
        var flexId = element.attributes && (element.attributes[HAIKU_ID_ATTRIBUTE] || element.attributes.id);
        if (instance) {
            element.__instance = instance;
        }
        if (!element.__instance) {
            element.__instance = new HaikuComponent_1.default(element.elementName, context, {
                options: context.config.options,
            }, {
                nested: true,
            });
            element.__instance.startTimeline(DEFAULT_TIMELINE_NAME);
        }
        element.__instance.__element = element;
        component._nestedComponentElements[flexId] = element;
    }
    if (element.children && element.children.length > 0) {
        for (var i = 0; i < element.children.length; i++) {
            initializeComponentTree(element.children[i], component, context, instance);
        }
    }
}
exports.default = initializeComponentTree;
//# sourceMappingURL=initializeComponentTree.js.map