"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _formiga = require("formiga");
var _FFormButtons = _interopRequireDefault(require("./FFormButtons"));
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; }
var FForm = props => {
  var {
    id,
    children,
    className,
    onSave,
    onCancel,
    colors,
    icons,
    labels,
    autoDisable,
    disabled,
    renderButtons,
    inline,
    getElements
  } = props;
  var {
    ref,
    valid,
    elements
  } = (0, _formiga.useForm)();
  (0, _react.useEffect)(() => {
    if (getElements) {
      getElements(valid, elements);
    }
  }, [valid, elements, getElements]);
  return /*#__PURE__*/_react.default.createElement("form", {
    ref: ref,
    id: id,
    className: "formiga-reactstrap-form ".concat(className != undefined ? className : '', " ").concat(inline == true ? 'inline' : ''),
    noValidate: true
  }, /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, children, renderButtons == undefined ? /*#__PURE__*/_react.default.createElement(_FFormButtons.default, {
    onSave: onSave != undefined ? ev => onSave(valid, elements, ev) : undefined,
    onCancel: onCancel != undefined ? ev => onCancel(valid, elements, ev) : undefined,
    colors: colors,
    icons: icons,
    labels: labels,
    autoDisable: autoDisable,
    disabled: disabled,
    valid: valid,
    elements: elements
  }) : renderButtons(valid, elements)));
};
FForm.propTypes = {
  className: _propTypes.default.string,
  id: _propTypes.default.string,
  colors: _propTypes.default.arrayOf(_propTypes.default.string),
  icons: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.element, _propTypes.default.func])),
  labels: _propTypes.default.arrayOf(_propTypes.default.string),
  onSave: _propTypes.default.func,
  onCancel: _propTypes.default.func,
  autoDisable: _propTypes.default.bool,
  disabled: _propTypes.default.oneOfType([_propTypes.default.bool, _propTypes.default.func]),
  renderButtons: _propTypes.default.func,
  inline: _propTypes.default.bool,
  getElements: _propTypes.default.func
};
FForm.defaultProps = {
  icons: ['ban', 'save'],
  autoDisable: true,
  inline: false
};
var _default = FForm;
exports.default = _default;