'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _Alert = require('../Alert');

var _Alert2 = _interopRequireDefault(_Alert);

var _Wrapper = require('./Wrapper');

var _Wrapper2 = _interopRequireDefault(_Wrapper);

var _Title = require('./Title');

var _Title2 = _interopRequireDefault(_Title);

var _Body = require('./Body');

var _Body2 = _interopRequireDefault(_Body);

var _Footer = require('./Footer');

var _Footer2 = _interopRequireDefault(_Footer);

var _ButtonsWrapper = require('./ButtonsWrapper');

var _ButtonsWrapper2 = _interopRequireDefault(_ButtonsWrapper);

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

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

var propTypes = {
  title: _propTypes2.default.string,
  mandatory: _propTypes2.default.string,
  hint: _propTypes2.default.string,
  children: _propTypes2.default.node.isRequired,
  error: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.array, _propTypes2.default.node]),
  titleCentered: _propTypes2.default.bool,
  padding: _propTypes2.default.bool,
  icon: _propTypes2.default.string
};

var defaultProps = {
  title: null,
  mandatory: null,
  hint: null,
  error: null,
  titleCentered: false,
  padding: false,
  icon: null
};

var Form = function Form(_ref) {
  var title = _ref.title,
      titleCentered = _ref.titleCentered,
      children = _ref.children,
      mandatory = _ref.mandatory,
      hint = _ref.hint,
      error = _ref.error,
      padding = _ref.padding,
      icon = _ref.icon,
      props = _objectWithoutProperties(_ref, ['title', 'titleCentered', 'children', 'mandatory', 'hint', 'error', 'padding', 'icon']);

  return _react2.default.createElement(
    _Wrapper2.default,
    _extends({ padding: padding }, props),
    !!title && _react2.default.createElement(
      _Title2.default,
      { center: titleCentered, icon: icon },
      title
    ),
    !!children && _react2.default.createElement(
      _Body2.default,
      null,
      children
    ),
    (!!mandatory || !!hint || !!error) && _react2.default.createElement(
      _Footer2.default,
      null,
      !!error && _react2.default.createElement(
        _Alert2.default,
        { type: 'danger' },
        error
      ),
      !!hint && _react2.default.createElement(
        'p',
        { className: 'flive_form_hint' },
        hint
      ),
      !!mandatory && _react2.default.createElement(
        'p',
        { className: 'flive_form_mandatory' },
        mandatory
      )
    )
  );
};

Form.propTypes = propTypes;
Form.defaultProps = defaultProps;

Form.Wrapper = _Wrapper2.default;
Form.Title = _Title2.default;
Form.Body = _Body2.default;
Form.Footer = _Footer2.default;
Form.ButtonsWrapper = _ButtonsWrapper2.default;

exports.default = Form;
module.exports = exports['default'];