"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.renderStringList = exports.renderStringTree = exports.TREE_LINE_CHARACTERS = exports.OutputFormatsEnum = void 0;
var OutputFormatsEnum;
(function (OutputFormatsEnum) {
    OutputFormatsEnum["text"] = "text";
    OutputFormatsEnum["tree"] = "tree";
    OutputFormatsEnum["json"] = "json";
    OutputFormatsEnum["yaml"] = "yaml";
})(OutputFormatsEnum = exports.OutputFormatsEnum || (exports.OutputFormatsEnum = {}));
exports.TREE_LINE_CHARACTERS = ["│", "├", "└", "─"];
function renderStringTree(tree, renderMethod, depth, levelPrefix) {
    let output = "";
    let currentDepth = (depth !== null && depth !== void 0 ? depth : -1) + 1;
    // let defaultRenderMethod = (text: string) => { output = output.concat(text, "\n"); };
    // let render = renderMethod ?? defaultRenderMethod;
    if (tree.length === 0) {
        output = "[none]";
    }
    for (let idx = 0; idx < tree.length; idx++) {
        let branch = tree[idx];
        let lines = "";
        if (currentDepth > 0) {
            lines = (idx === tree.length - 1) ? "└─" : "├─";
            if (currentDepth > 1) {
                // lines = "│  ".repeat(currentDepth - 1).concat(lines);  // TODO: cant show the vertical if its the last branch of that ancestor
                lines = (levelPrefix !== null && levelPrefix !== void 0 ? levelPrefix : "").concat(lines); // TODO: cant show the vertical if its the last branch of that ancestor
            }
            lines = lines.concat(" ");
        }
        let thisLine = lines.concat(branch.text);
        output = output.concat(thisLine, "\n");
        if (renderMethod)
            renderMethod(thisLine, branch);
        if (branch.children !== undefined && branch.children.length > 0) {
            let newPrefix = "";
            if (currentDepth > 0) {
                let mySiblingConnector = (idx === tree.length - 1) ? " " : "│";
                newPrefix = (levelPrefix !== null && levelPrefix !== void 0 ? levelPrefix : "").concat(mySiblingConnector, "  ");
            }
            output = output.concat(renderStringTree(branch.children, renderMethod, currentDepth, newPrefix));
        }
    }
    return output;
}
exports.renderStringTree = renderStringTree;
function renderStringList(values, renderMethod) {
    try {
        let output = "";
        if (values.length === 0) {
            output = "[none]";
        }
        for (let text of values) {
            let thisLine = text.concat("\n");
            output = output.concat(thisLine);
            if (renderMethod)
                renderMethod(thisLine);
        }
        return output;
    }
    catch (err) {
        throw err;
    }
}
exports.renderStringList = renderStringList;
//# sourceMappingURL=render-methods.js.map