import _Popover from "antd/es/popover";
import _extends from "@babel/runtime/helpers/extends";
import _Tooltip from "antd/es/tooltip";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import React from "react";
import "./css.less";
var BigText = /*#__PURE__*/function (_React$Component) {
  _inheritsLoose(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,
        text = _this$props.text,
        copyable = _this$props.copyable;
      if (typeof text === 'string') {
        var input = document.createElement('input');
        input.setAttribute('readonly', 'readonly');
        input.setAttribute('value', text);
        document.body.appendChild(input);
        input.select();
        input.setSelectionRange(0, text.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.createElement("div", {
      className: "big-text " + this.className + " " + (props.className || ''),
      style: {
        width: props.width || '100%',
        height: props.height || '70px'
      }
    }, /*#__PURE__*/React.createElement("span", {
      title: props.type === 'ignore' && props.text ? '详情查看' : '',
      className: "text big-text-" + (props.type || '')
    }, /*#__PURE__*/React.createElement(_Tooltip, {
      placement: props.theme,
      title: props.text
    }, this.props.text || '大段文字')), /*#__PURE__*/React.createElement("span", {
      className: "btn-arr"
    }, showCopy && /*#__PURE__*/React.createElement("span", {
      className: "c-btn copy-btn",
      onClick: this.copy
    }, "\u590D\u5236"), props.type === 'ignore' ? '' : /*#__PURE__*/React.createElement("span", {
      className: "c-btn more-btn",
      onClick: function onClick() {
        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();
    console.log('content====', content);
    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.createElement(_Popover, _extends({
        trigger: "click",
        content: props.text
      }, props.tooltip || {}), content);
    }
    return content;
  };
  return BigText;
}(React.Component);
BigText.defaultProps = {
  copyable: true,
  type: 'more'
};
export { BigText as default };