"use strict";

exports.__esModule = true;
exports.default = exports.FormPage = exports.FormContext = exports.Wrapper = void 0;

var _react = _interopRequireWildcard(require("react"));

var _styledComponents = _interopRequireDefault(require("styled-components"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _withScrollBox = _interopRequireDefault(require("../../hocs/withScrollBox"));

var _FormElement = _interopRequireDefault(require("./FormElement"));

var _FieldElements = _interopRequireDefault(require("./FieldElements"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

(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 Wrapper = _styledComponents.default.div.withConfig({
  displayName: "Form__Wrapper",
  componentId: "sc-6q0epb-0"
})(["display:flex;margin-bottom:20px;"]);

exports.Wrapper = Wrapper;

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 = (0, _react.createContext)();
exports.FormContext = FormContext;
FormContext.displayName = "FormContext";

var 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 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(Wrapper, null, 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
    }));
  })));
};

exports.FormPage = FormPage;
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 = _default2;
exports.default = _default3;
;

(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;

  if (!reactHotLoader) {
    return;
  }

  reactHotLoader.register(Wrapper, "Wrapper", "/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(Wrapper, "Wrapper", "/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);
})();