"use strict";

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

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

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

var _HelpPopover = _interopRequireDefault(require("../HelpPopover"));

var _Section = _interopRequireDefault(require("./Section"));

var _Item = _interopRequireDefault(require("./Item"));

var _Row = _interopRequireDefault(require("./Row"));

var _classnames = _interopRequireDefault(require("classnames"));

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

function _extends() { _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; }; return _extends.apply(this, arguments); }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

var Form = function Form(_ref) {
  var children = _ref.children,
      className = _ref.className,
      description = _ref.description,
      helpIcon = _ref.helpIcon,
      popoverText = _ref.popoverText,
      popoverTitle = _ref.popoverTitle,
      testSection = _ref.testSection,
      title = _ref.title,
      props = _objectWithoutProperties(_ref, ["children", "className", "description", "helpIcon", "popoverText", "popoverTitle", "testSection", "title"]);

  var formTitleClasses = (0, _classnames["default"])({
    "push--bottom": description,
    "push-double--bottom": !description
  });
  return _react["default"].createElement("form", _extends({
    "data-test-section": testSection,
    className: (0, _classnames["default"])("oui-form-fields", className)
  }, props), title && _react["default"].createElement("h2", {
    className: formTitleClasses
  }, title, helpIcon && _react["default"].createElement(_HelpPopover["default"], {
    popoverTitle: popoverTitle,
    horizontalAttachment: "left",
    verticalAttachment: "middle"
  }, _react["default"].createElement("p", null, popoverText))), description && _react["default"].createElement("p", {
    className: "push-double--bottom epsilon"
  }, description), children);
};

Form.Section = _Section["default"];
Form.Item = _Item["default"];
Form.Row = _Row["default"];
Form.propTypes = {
  children: _propTypes["default"].node.isRequired,

  /** CSS class names. */
  className: _propTypes["default"].string,

  /** Description for Form */
  description: _propTypes["default"].node,

  /** Indicates whether to include a help popover */
  helpIcon: _propTypes["default"].bool,

  /** Text for popover */
  popoverText: _propTypes["default"].string,

  /** Title for popover */
  popoverTitle: _propTypes["default"].string,
  testSection: _propTypes["default"].string,

  /** Title for Form */
  title: _propTypes["default"].string
};
var _default = Form;
exports["default"] = _default;