import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["default"],
    _excluded2 = ["value"];
import { createVNode as _createVNode, Fragment as _Fragment } from "vue";
import { flattenChildren, isValidElement } from '../_util/props-util';
export function convertChildrenToData(nodes) {
  return flattenChildren(nodes).map(function (node) {
    if (!isValidElement(node) || !node.type) {
      return null;
    }

    var _ref = node.children || {},
        d = _ref.default,
        restSlot = _objectWithoutProperties(_ref, _excluded);

    var children = d ? d() : [];

    var key = node.key,
        _node$props = node.props,
        value = _node$props.value,
        restProps = _objectWithoutProperties(_node$props, _excluded2);

    var data = _objectSpread({
      key: key,
      value: value
    }, restProps);

    Object.keys(restSlot).forEach(function (p) {
      if (typeof restSlot[p] === 'function') {
        data[p] = _createVNode(_Fragment, null, [restSlot[p]()]);
      }
    });
    var childData = convertChildrenToData(children);

    if (childData.length) {
      data.children = childData;
    }

    return data;
  }).filter(function (data) {
    return data;
  });
}