import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import * as React from 'react';
import classNames from 'classnames';
import Col from '../grid/col';
import Tooltip from '../tooltip';
import QuestionCircle from '../icon/QuestionCircle';
import { FormContext } from './context';

var FormItemLabel = function FormItemLabel(_ref) {
  var prefixCls = _ref.prefixCls,
      label = _ref.label,
      htmlFor = _ref.htmlFor,
      labelCol = _ref.labelCol,
      _ref$labelAlign = _ref.labelAlign,
      labelAlign = _ref$labelAlign === void 0 ? 'left' : _ref$labelAlign,
      required = _ref.required,
      tooltip = _ref.tooltip;
  if (!label) return null;
  return /*#__PURE__*/React.createElement(FormContext.Consumer, {
    key: "label"
  }, function (_ref2) {
    var contextLabelAlign = _ref2.labelAlign,
        contextLabelCol = _ref2.labelCol;
    var mergedLabelCol = labelCol || contextLabelCol || {};
    var mergedLabelAlign = labelAlign || contextLabelAlign;
    var labelClsBasic = "".concat(prefixCls, "-item-label");
    var labelColClassName = classNames(labelClsBasic, mergedLabelAlign === 'left' && "".concat(labelClsBasic, "-left"), mergedLabelCol.className);
    var labelChildren = label;
    var labelClassName = classNames(_defineProperty({}, "".concat(prefixCls, "-item-required"), required));
    return /*#__PURE__*/React.createElement(Col, _extends({}, mergedLabelCol, {
      className: labelColClassName
    }), /*#__PURE__*/React.createElement("label", {
      htmlFor: htmlFor,
      className: labelClassName,
      title: typeof label === 'string' ? label : ''
    }, labelChildren), tooltip && /*#__PURE__*/React.createElement(Tooltip, {
      title: tooltip
    }, /*#__PURE__*/React.createElement(QuestionCircle, {
      className: "".concat(prefixCls, "-item-tooltip")
    })));
  });
};

export default FormItemLabel;