"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.default = exports.getVariant = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));

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

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

var _Col = _interopRequireDefault(require("../Col"));

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

var _Box = _interopRequireDefault(require("../Box"));

var _Label = _interopRequireDefault(require("../Label"));

var _SuperFieldHint = _interopRequireDefault(require("../SuperFieldHint"));

var getVariant = function getVariant(_ref) {
  var hasError = _ref.hasError,
      readOnly = _ref.readOnly,
      disabled = _ref.disabled;

  if (hasError) {
    return 'danger';
  }

  if (disabled || readOnly) {
    return 'disabled';
  }
};

exports.getVariant = getVariant;

var FormGroup = function FormGroup(_ref2) {
  var children = _ref2.children,
      disabled = _ref2.disabled,
      readOnly = _ref2.readOnly,
      hasError = _ref2.hasError,
      hint = _ref2.hint,
      legend = _ref2.legend,
      label = _ref2.label,
      id = _ref2.id,
      name = _ref2.name,
      rest = (0, _objectWithoutPropertiesLoose2.default)(_ref2, ["children", "disabled", "readOnly", "hasError", "hint", "legend", "label", "id", "name"]);
  return (
    /*#__PURE__*/
    _react.default.createElement(_Box.default, {
      as: "fieldset",
      variant: getVariant({
        hasError: hasError,
        readOnly: readOnly,
        disabled: disabled
      }),
      sx: {
        border: 'none',
        appearance: 'none',
        p: 0
      }
    },
    /*#__PURE__*/
    _react.default.createElement(_Row.default, (0, _extends2.default)({
      flexWrap: "wrap",
      alignItems: "center",
      justifyContent: "center"
    }, rest),
    /*#__PURE__*/
    _react.default.createElement(_Col.default, {
      span: [12, 12, 5, 4],
      pb: [2, 2, 0]
    },
    /*#__PURE__*/
    _react.default.createElement(_Label.default, {
      htmlFor: legend ? void 0 : id,
      as: legend ? 'legend' : 'label',
      sx: {
        width: '100%',
        p: 0
      }
    }, legend || label)),
    /*#__PURE__*/
    _react.default.createElement(_Col.default, {
      span: [12, 12, 7, 8]
    }, children)),
    /*#__PURE__*/
    _react.default.createElement(_Row.default, null,
    /*#__PURE__*/
    _react.default.createElement(_Col.default, {
      span: 12
    }, hint ?
    /*#__PURE__*/
    _react.default.createElement(_SuperFieldHint.default, null, hint) : null)))
  );
};

process.env.NODE_ENV !== "production" ? FormGroup.propTypes = {
  /** Children to be rendered in the main container. */
  children: _propTypes.default.node,

  /** Disabled state */
  disabled: _propTypes.default.bool,

  /** Error state */
  hasError: _propTypes.default.bool,
  hint: _propTypes.default.node,
  id: _propTypes.default.string,
  label: _propTypes.default.node,
  legend: _propTypes.default.node,

  /** Read-only state */
  readOnly: _propTypes.default.bool
} : void 0;
var _default = FormGroup;
exports.default = _default;