"use strict";

exports.__esModule = true;
exports.default = exports.FormPage = exports.FormContext = void 0;
var _react = _interopRequireWildcard(require("react"));
var _styles = require("@material-ui/core/styles");
var _propTypes = _interopRequireDefault(require("prop-types"));
var _withScrollBox = _interopRequireDefault(require("../../hocs/withScrollBox"));
var _FormElement = _interopRequireDefault(require("./FormElement"));
var _FieldElements = _interopRequireDefault(require("./FieldElements"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();
(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();
var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};
var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};
var useStyles = (0, _styles.makeStyles)(function () {
  return {
    wrapper: {
      display: "flex",
      marginBottom: 20
    }
  };
});
var splitFields = function splitFields(fields, cols) {
  if (cols <= 1) return [fields];
  var elmsPerCol = Math.ceil(fields.length / cols);
  return fields.reduce(function (current, field, index) {
    if (index % elmsPerCol === 0) {
      current.push([field]);
    } else {
      current[current.length - 1].push(field);
    }
    return current;
  }, []);
};
var FormContext = exports.FormContext = (0, _react.createContext)();
FormContext.displayName = "FormContext";
var FormPage = exports.FormPage = function FormPage(_ref) {
  var formName = _ref.formName,
    _ref$cols = _ref.cols,
    cols = _ref$cols === void 0 ? [1, 1, 1] : _ref$cols,
    getUpdater = _ref.getUpdater,
    fields = _ref.fields,
    values = _ref.values,
    wide = _ref.wide;
  var classes = useStyles();
  var colSpans = wide ? [] : cols;
  var colFields = splitFields(fields, colSpans.length);
  return /*#__PURE__*/_react.default.createElement(FormContext.Provider, {
    value: {
      values: values,
      formName: formName
    }
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: classes.wrapper
  }, colFields.map(function (fields, index) {
    return /*#__PURE__*/_react.default.createElement(_FormElement.default, {
      key: index,
      spanWidth: colSpans[index] || 1
    }, /*#__PURE__*/_react.default.createElement(_FieldElements.default, {
      getUpdater: getUpdater,
      fields: fields
    }));
  })));
};
__signature__(FormPage, "useStyles{classes}", function () {
  return [useStyles];
});
__signature__(FormPage, "useStyles{classes}", function () {
  return [useStyles];
});
var WiredForm = (0, _withScrollBox.default)(FormPage);
WiredForm.propTypes = {
  getUpdater: _propTypes.default.func.isRequired,
  fields: _propTypes.default.arrayOf(_propTypes.default.object).isRequired,
  values: _propTypes.default.object.isRequired,
  wide: _propTypes.default.bool
};
var _default = WiredForm;
var _default2 = _default;
var _default3 = exports.default = _default2;
;
(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
  if (!reactHotLoader) {
    return;
  }
  reactHotLoader.register(useStyles, "useStyles", "/home/vsts/work/1/s/src/components/Form/Form.js");
  reactHotLoader.register(splitFields, "splitFields", "/home/vsts/work/1/s/src/components/Form/Form.js");
  reactHotLoader.register(FormContext, "FormContext", "/home/vsts/work/1/s/src/components/Form/Form.js");
  reactHotLoader.register(FormPage, "FormPage", "/home/vsts/work/1/s/src/components/Form/Form.js");
  reactHotLoader.register(WiredForm, "WiredForm", "/home/vsts/work/1/s/src/components/Form/Form.js");
  reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/components/Form/Form.js");
})();
;
(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();
;
(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
  if (!reactHotLoader) {
    return;
  }
  reactHotLoader.register(useStyles, "useStyles", "/home/vsts/work/1/s/src/components/Form/Form.js");
  reactHotLoader.register(splitFields, "splitFields", "/home/vsts/work/1/s/src/components/Form/Form.js");
  reactHotLoader.register(FormContext, "FormContext", "/home/vsts/work/1/s/src/components/Form/Form.js");
  reactHotLoader.register(FormPage, "FormPage", "/home/vsts/work/1/s/src/components/Form/Form.js");
  reactHotLoader.register(WiredForm, "WiredForm", "/home/vsts/work/1/s/src/components/Form/Form.js");
  reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/components/Form/Form.js");
})();
;
(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();