"use strict";

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

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

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

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

var _lodash = require("lodash");

var _ = _interopRequireDefault(require(".."));

var _excluded = ["config"];

var _default = function _default(_ref) {
  var config = _ref.config,
      otherProps = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
  var properties = config.elements.map(function (element) {
    return [element.key, (0, _["default"])((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, otherProps), {}, {
      config: element
    }))];
  });
  return {
    schema: {
      type: 'object',
      properties: Object.fromEntries(properties.map(function (_ref2) {
        var _ref3 = (0, _slicedToArray2["default"])(_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: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, Object.fromEntries(properties.map(function (_ref6) {
      var _ref7 = (0, _slicedToArray2["default"])(_ref6, 2),
          name = _ref7[0],
          uiSchema = _ref7[1].uiSchema;

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

        return key;
      }))
    })
  };
};

exports["default"] = _default;
//# sourceMappingURL=form.cjs.map