"use strict";
/**
 * Copyright (c) Haiku 2016-2018. All rights reserved.
 */
Object.defineProperty(exports, "__esModule", { value: true });
var BasicUtils_1 = require("./BasicUtils");
var objectPath_1 = require("./objectPath");
function flattenTree(node, options, unique, list, depth, index) {
    if (unique === void 0) { unique = true; }
    if (list === void 0) { list = []; }
    if (depth === void 0) { depth = 0; }
    if (index === void 0) { index = 0; }
    list.push(node);
    if (typeof node !== 'string') {
        node.__depth = depth;
        node.__index = index;
    }
    // Don't recurse down into the children of nested components, which should be 'invisible' to us.
    // Nested components are indicated when their name is not a string, e.g. a component descriptor.
    if (depth < 1 || typeof node[options.name] === 'string') {
        var children = objectPath_1.default(node, options.children);
        if (!children || children.length < 1 || typeof children === 'string') {
            return list;
        }
        if (Array.isArray(children)) {
            for (var i = 0; i < children.length; i++) {
                flattenTree(children[i], options, /*unique=*/ false, list, depth + 1, i);
            }
        }
        else if (typeof children === 'object') {
            children.__depth = depth + 1;
            children.__index = 0;
            list.push(children);
            return list;
        }
    }
    return unique ? BasicUtils_1.default.uniq(list) : list;
}
exports.default = flattenTree;
//# sourceMappingURL=manaFlattenTree.js.map