var _excluded = ["help", "span", "ellipsis", "required", "children"],
  _excluded2 = ["span", "ellipsis"];
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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; }
import React, { useImperativeHandle, forwardRef, useRef, useContext } from 'react';
import FormContext from "./../FormContext";
import Div from "./../../Letter/Base";

// 内库使用-start
import Toast from "./../../../Toast";
// 内库使用-end

/* 测试使用-start
import { Toast } from 'seedsui-react'
测试使用-end */

var FormLabel = /*#__PURE__*/forwardRef(function (_ref, ref) {
  var help = _ref.help,
    span = _ref.span,
    ellipsis = _ref.ellipsis,
    required = _ref.required,
    children = _ref.children,
    props = _objectWithoutProperties(_ref, _excluded);
  // 获取全局配置
  var _useContext = useContext(FormContext),
    layout = _useContext.layout,
    labelCol = _useContext.labelCol;
  var rootRef = useRef(null);

  // Expose
  useImperativeHandle(ref, function () {
    return {
      rootDOM: rootRef.current,
      getRootDOM: function getRootDOM() {
        return rootRef.current;
      }
    };
  });
  var _ref2 = labelCol || {},
    globalSpan = _ref2.span,
    globalEllipsis = _ref2.ellipsis,
    labelColProps = _objectWithoutProperties(_ref2, _excluded2);
  return /*#__PURE__*/React.createElement("div", _extends({}, labelColProps, props, {
    className: "form-item-label".concat(props.className ? ' ' + props.className : '').concat(layout === 'horizontal' ? " col col-".concat(span || globalSpan || 8) : ''),
    ref: rootRef
  }), /*#__PURE__*/React.createElement(Div, {
    className: "form-item-label-text",
    ellipsis: ellipsis || globalEllipsis
  }, children), help && /*#__PURE__*/React.createElement("i", {
    className: "form-item-help",
    onClick: function onClick() {
      Toast.show({
        content: help
      });
    }
  }), required && /*#__PURE__*/React.createElement("span", {
    className: "form-item-required"
  }, "*"));
});
export default FormLabel;