import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["config"];
import { uniq } from 'lodash';
import configToProps from '..';
export default (function (_ref) {
  var config = _ref.config,
      otherProps = _objectWithoutProperties(_ref, _excluded);

  var properties = config.elements.map(function (element) {
    return [element.key, configToProps(_objectSpread(_objectSpread({}, otherProps), {}, {
      config: element
    }))];
  });
  return {
    schema: {
      type: 'object',
      properties: Object.fromEntries(properties.map(function (_ref2) {
        var _ref3 = _slicedToArray(_ref2, 2),
            name = _ref3[0],
            schema = _ref3[1].schema;

        return [name, schema];
      })),
      required: config.elements.filter(function (_ref4) {
        var required = _ref4.required;
        return required;
      }).map(function (_ref5) {
        var key = _ref5.key;
        return key;
      })
    },
    uiSchema: _objectSpread(_objectSpread({}, Object.fromEntries(properties.map(function (_ref6) {
      var _ref7 = _slicedToArray(_ref6, 2),
          name = _ref7[0],
          uiSchema = _ref7[1].uiSchema;

      return [name, uiSchema];
    }))), {}, {
      // Ensure the order of the elements is remained.
      'ui:order': uniq(properties.map(function (_ref8) {
        var _ref9 = _slicedToArray(_ref8, 1),
            key = _ref9[0];

        return key;
      }))
    })
  };
});
//# sourceMappingURL=form.js.map