"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _popover = _interopRequireDefault(require("antd/lib/popover"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
var _react = _interopRequireDefault(require("react"));
require("./css.less");
var BigText = /*#__PURE__*/function (_React$Component) {
  (0, _inheritsLoose2["default"])(BigText, _React$Component);
  function BigText() {
    var _this;
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
    _this.className = '';
    _this.copy = function () {
      var _this$props = _this.props,
        children = _this$props.children,
        copyable = _this$props.copyable;
      if (typeof children === 'string') {
        var input = document.createElement('input');
        input.setAttribute('readonly', 'readonly');
        input.setAttribute('value', children);
        document.body.appendChild(input);
        input.select();
        input.setSelectionRange(0, children.length);
        if (document.execCommand('copy')) document.execCommand('copy');
        document.body.removeChild(input);
        if (typeof copyable === 'object' && copyable.onCopy && typeof copyable.onCopy === 'function') {
          copyable.onCopy();
        }
      }
    };
    return _this;
  }
  var _proto = BigText.prototype;
  _proto.renderContent = function renderContent() {
    var _this2 = this;
    var props = this.props;
    var showCopy = props.copyable && (this.className || props.copyable.alwaysShow);
    return /*#__PURE__*/_react["default"].createElement("div", {
      className: "big-text " + this.className + " " + (props.className || ''),
      style: props.style || {}
    }, /*#__PURE__*/_react["default"].createElement("span", {
      title: props.type === 'ignore' && props.children ? '详情查看' : '',
      className: "text big-text-" + (props.type || '')
    }, this.props.children), /*#__PURE__*/_react["default"].createElement("span", {
      className: "btn-arr"
    }, showCopy && /*#__PURE__*/_react["default"].createElement("span", {
      className: "c-btn copy-btn",
      onClick: this.copy
    }, "\u590D\u5236"), props.type === 'ignore' ? '' : /*#__PURE__*/_react["default"].createElement("span", {
      className: "c-btn more-btn",
      onClick: function onClick() {
        console.log('className', _this2.className);
        var show = _this2.props.showMore ? _this2.props.showMore() : true;
        show && (_this2.className = _this2.className ? '' : 'show-more');
        _this2.setState({});
      }
    }, this.className ? '收起' : '显示更多')));
  };
  _proto.render = function render() {
    var props = this.props;
    var content = this.renderContent();
    if (props.type === 'ignore') {
      var _props$tooltip$noshow, _props$tooltip;
      if ((_props$tooltip$noshow = (_props$tooltip = props.tooltip) === null || _props$tooltip === void 0 ? void 0 : _props$tooltip.noshow) !== null && _props$tooltip$noshow !== void 0 ? _props$tooltip$noshow : false) {
        return content;
      }
      return /*#__PURE__*/_react["default"].createElement(_popover["default"], (0, _extends2["default"])({
        trigger: "click",
        content: props.children
      }, props.tooltip || {}), content);
    }
    return content;
  };
  return BigText;
}(_react["default"].Component);
exports["default"] = BigText;
BigText.defaultProps = {
  copyable: false,
  type: 'ignore'
};