/**
 * ldesign v0.2.22
 * (c) 2022/12/7 16:21 built by swimly
 * @license MIT
 */

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

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++) {
    const col = columns[i];
    depthMap.set(col, depth);
    if (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?.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++) {
      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?.children?.length) loop(col.children, leafColumns2);else leafColumns2.push(col);
    }
  };
  const leafColumns = [];
  loop(columns, leafColumns);
  return {
    rowspanAndColspanMap,
    leafColumns
  };
}
function getThList(columns) {
  const loop = (nodes, thRows) => {
    let thRowData = [];
    let children = [];
    for (let i = 0, len = nodes.length; i < len; i++) {
      const node = nodes[i];
      const thList = [node];
      thRowData = thRowData.concat(thList);
      if (node?.children?.length) children = children.concat(node.children);
    }
    if (children?.length) loop(children, thRows);
    thRows.push(thRowData);
    return thRowData;
  };
  let list = [];
  loop(columns, list);
  list = list.reverse();
  return list;
}

exports.getChildrenNodeWidth = getChildrenNodeWidth;
exports.getNodeDepth = getNodeDepth;
exports.getThList = getThList;
exports.getThRowspanAndColspan = getThRowspanAndColspan;
//# sourceMappingURL=useMultiHeader.js.map
