"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.convertChildrenToData = convertChildrenToData;

var _vue = require("vue");

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var _propsUtil = require("../_util/props-util");

var _excluded = ["default"],
    _excluded2 = ["value"];

function convertChildrenToData(nodes) {
  return (0, _propsUtil.flattenChildren)(nodes).map(function (node) {
    if (!(0, _propsUtil.isValidElement)(node) || !node.type) {
      return null;
    }

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

    var children = d ? d() : [];
    var key = node.key,
        _node$props = node.props,
        value = _node$props.value,
        restProps = (0, _objectWithoutProperties2.default)(_node$props, _excluded2);
    var data = (0, _objectSpread2.default)({
      key: key,
      value: value
    }, restProps);
    Object.keys(restSlot).forEach(function (p) {
      if (typeof restSlot[p] === 'function') {
        data[p] = (0, _vue.createVNode)(_vue.Fragment, null, [restSlot[p]()]);
      }
    });
    var childData = convertChildrenToData(children);

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

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