import { Leaf, ChildrenAnalyzer } from "@contember/react-multipass-rendering";
import { DataGridColumn } from "../base/DataGridColumn.js";
class BoxedGridColumnProps {
  constructor(value) {
    this.value = value;
  }
}
const gridColumnLeaf = new Leaf((node) => new BoxedGridColumnProps(node.props), DataGridColumn);
const gridTemplateAnalyzer = new ChildrenAnalyzer([gridColumnLeaf], {
  ignoreUnhandledNodes: false,
  unhandledNodeErrorMessage: `DataGrid: encountered an illegal child node.`
});
const extractDataGridColumns = (nodes) => {
  const processed = gridTemplateAnalyzer.processChildren(nodes, void 0);
  let counter = 0;
  const suffixes = {};
  const getColumnKey = (column) => {
    if (column.columnKey) {
      return column.columnKey;
    }
    if (!("field" in column) || typeof column.field !== "string") {
      return `column__${++counter}`;
    }
    const name = column.field;
    if (name in suffixes) {
      return `${name}_${++suffixes[name]}`;
    }
    suffixes[name] = 0;
    return name;
  };
  return new Map(processed.map((column) => {
    const key = getColumnKey(column.value);
    return [key, column.value];
  }));
};
export { extractDataGridColumns };
//# sourceMappingURL=gridTemplateAnalyzer.js.map
