"use strict";

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

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

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

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

var _defaultStyle = _interopRequireDefault(require("part:@sanity/components/formfields/default-style"));

var _default = _interopRequireDefault(require("part:@sanity/components/labels/default"));

var _status = _interopRequireDefault(require("part:@sanity/components/validation/status"));

var _FieldStatus = _interopRequireDefault(require("../fieldsets/FieldStatus"));

var _presence = require("../presence");

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

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

class DefaultFormField extends _react.default.PureComponent {
  render() {
    var _this$props = this.props,
        level = _this$props.level,
        label = _this$props.label,
        labelFor = _this$props.labelFor,
        description = _this$props.description,
        children = _this$props.children,
        inline = _this$props.inline,
        wrapped = _this$props.wrapped,
        classNameProp = _this$props.className,
        markers = _this$props.markers,
        presence = _this$props.presence;
    var levelClass = "level_".concat(level);
    var className = (0, _classnames.default)(classNameProp, inline ? _defaultStyle.default.inline : _defaultStyle.default.block, _defaultStyle.default[levelClass], wrapped && _defaultStyle.default.wrapped);
    return /*#__PURE__*/_react.default.createElement("div", {
      className: className
    }, /*#__PURE__*/_react.default.createElement("label", {
      className: _defaultStyle.default.inner,
      htmlFor: labelFor
    }, label && /*#__PURE__*/_react.default.createElement("div", {
      className: _defaultStyle.default.header
    }, /*#__PURE__*/_react.default.createElement("div", {
      className: _defaultStyle.default.headerMain
    }, /*#__PURE__*/_react.default.createElement("div", {
      className: _defaultStyle.default.title
    }, label && /*#__PURE__*/_react.default.createElement(_default.default, {
      className: _defaultStyle.default.label,
      level: level
    }, label), /*#__PURE__*/_react.default.createElement(_status.default, {
      markers: markers
    })), description && /*#__PURE__*/_react.default.createElement("div", {
      className: _defaultStyle.default.description
    }, description)), /*#__PURE__*/_react.default.createElement(_FieldStatus.default, null, /*#__PURE__*/_react.default.createElement(_presence.FieldPresence, {
      presence: presence
    })))), /*#__PURE__*/_react.default.createElement("div", {
      className: _defaultStyle.default.content
    }, children));
  }

}

exports.default = DefaultFormField;

_defineProperty(DefaultFormField, "propTypes", {
  label: _propTypes.default.string,
  className: _propTypes.default.string,
  inline: _propTypes.default.bool,
  description: _propTypes.default.string,
  level: _propTypes.default.number,
  children: _propTypes.default.node,
  wrapped: _propTypes.default.bool,
  labelFor: _propTypes.default.string,
  markers: _propTypes.default.arrayOf(_propTypes.default.shape({
    type: _propTypes.default.string
  })),
  presence: _propTypes.default.any
});

_defineProperty(DefaultFormField, "defaultProps", {
  children: undefined,
  className: undefined,
  description: undefined,
  label: undefined,
  labelFor: undefined,
  level: 1,
  inline: false,
  markers: [],
  wrapped: false
});