import '../../../utils/index.mjs';
import { flattenChildren } from '../../../utils/vue/props.mjs';
import { camelize } from '../../../utils/lang/camelize.mjs';

function getColumnKey(column, defaultKey) {
  if ("key" in column && column.key !== void 0 && column.key !== null)
    return column.key;
  if (column.dataIndex)
    return Array.isArray(column.dataIndex) ? column.dataIndex.join(".") : column.dataIndex;
  return defaultKey;
}
function getColumnPos(index, pos) {
  return pos ? `${pos}-${index}` : `${index}`;
}
function renderColumnTitle(title, props) {
  if (typeof title === "function")
    return title(props);
  return title;
}
function convertChildrenToColumns(elements = []) {
  const flattenElements = flattenChildren(elements);
  const columns = [];
  flattenElements.forEach((element) => {
    var _a, _b, _c, _d;
    if (!element)
      return;
    const key = element.key;
    const style = ((_a = element.props) == null ? void 0 : _a.style) || {};
    const cls = ((_b = element.props) == null ? void 0 : _b.class) || "";
    const props = element.props || {};
    for (const [k, v] of Object.entries(props))
      props[camelize(k)] = v;
    const { default: children, ...restSlots } = element.children || {};
    const column = { ...restSlots, ...props, style, class: cls };
    if (key)
      column.key = key;
    if ((_c = element.type) == null ? void 0 : _c.__ANT_TABLE_COLUMN_GROUP) {
      column.children = convertChildrenToColumns(
        typeof children === "function" ? children() : children
      );
    } else {
      const customRender = (_d = element.children) == null ? void 0 : _d.default;
      column.customRender = column.customRender || customRender;
    }
    columns.push(column);
  });
  return columns;
}

export { convertChildrenToColumns, getColumnKey, getColumnPos, renderColumnTitle };
//# sourceMappingURL=util.mjs.map
