/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

function getNodeDepth(columns, depthMap) {
  let depth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
  let maxDepth = depth;
  for (let i = 0, len = columns.length; i < len; i++) {
    var _col$children;
    const col = columns[i];
    depthMap.set(col, depth);
    if (col !== null && col !== void 0 && (_col$children = col.children) !== null && _col$children !== void 0 && _col$children.length) {
      const deep = getNodeDepth(col.children, depthMap, depth + 1);
      if (deep > maxDepth) maxDepth = deep;
    }
  }
  return maxDepth;
}
function getChildrenNodeWidth(node) {
  let count = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  let countNew = count;
  const childrenList = (node === null || node === void 0 ? void 0 : node.children) || [];
  for (let i = 0, len = childrenList.length; i < len; i++) {
    const item = childrenList[i];
    if (item.children) countNew = getChildrenNodeWidth(item, countNew);else countNew += 1;
  }
  return countNew;
}
function getThRowspanAndColspan(columns) {
  const depthMap = /* @__PURE__ */new Map();
  const columnsDepth = getNodeDepth(columns, depthMap);
  const rowspanAndColspanMap = /* @__PURE__ */new Map();
  const loop = (nodes, leafColumns2) => {
    for (let i = 0, len = nodes.length; i < len; i++) {
      var _col$children2;
      const col = nodes[i];
      const rowspan = col.children ? 1 : columnsDepth - depthMap.get(col) + 1;
      const colspan = col.children ? getChildrenNodeWidth(col) : 1;
      const span = {};
      rowspan > 1 && (span.rowspan = rowspan);
      colspan > 1 && (span.colspan = colspan);
      rowspanAndColspanMap.set(col, span);
      if (col !== null && col !== void 0 && (_col$children2 = col.children) !== null && _col$children2 !== void 0 && _col$children2.length) loop(col.children, leafColumns2);else leafColumns2.push(col);
    }
  };
  const leafColumns = [];
  loop(columns, leafColumns);
  return {
    rowspanAndColspanMap,
    leafColumns
  };
}
function getThList(columns) {
  const loop = (nodes, thRows) => {
    var _children;
    let thRowData = [];
    let children = [];
    for (let i = 0, len = nodes.length; i < len; i++) {
      var _node$children;
      const node = nodes[i];
      const thList = [node];
      thRowData = thRowData.concat(thList);
      if (node !== null && node !== void 0 && (_node$children = node.children) !== null && _node$children !== void 0 && _node$children.length) children = children.concat(node.children);
    }
    if ((_children = children) !== null && _children !== void 0 && _children.length) loop(children, thRows);
    thRows.push(thRowData);
    return thRowData;
  };
  let list = [];
  loop(columns, list);
  list = list.reverse();
  return list;
}

export { getChildrenNodeWidth, getNodeDepth, getThList, getThRowspanAndColspan };
//# sourceMappingURL=useMultiHeader.js.map
