"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "hideColumn", {
    enumerable: true,
    get: function() {
        return hideColumn;
    }
});
const _templateLiteralTag = require("../../../../helpers/templateLiteralTag");
const _errors = require("../../../../helpers/errors");
function hideColumn(nodeToProcess, gridColumnIndex) {
    if (!Number.isInteger(gridColumnIndex)) {
        (0, _errors.throwWithCause)('The passed gridColumnIndex argument has invalid type.');
    }
    if (nodeToProcess.childs.length > 0) {
        (0, _errors.throwWithCause)((0, _templateLiteralTag.toSingleLine)`The passed node is not the last node on the tree. Only for\x20
the last node, the hide column modification can be applied.`);
    }
    const { crossHiddenColumns } = nodeToProcess.data;
    if (crossHiddenColumns.includes(gridColumnIndex)) {
        return;
    }
    let isCollapsibleNode = false;
    nodeToProcess.walkUp((node)=>{
        const { data: { collapsible } } = node;
        if (collapsible) {
            isCollapsibleNode = true;
            return false; // Cancel tree traversing
        }
    });
    // TODO: When the node is collapsible do not hide the column. Currently collapsible headers
    // does not work with hidden columns (hidden index map types).
    if (isCollapsibleNode) {
        return;
    }
    nodeToProcess.walkUp((node)=>{
        const { data } = node;
        data.crossHiddenColumns.push(gridColumnIndex);
        if (data.colspan > 1) {
            data.colspan -= 1;
        } else {
            data.isHidden = true;
        }
    });
}
