"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.genCopyable = void 0;
require("antd/lib/typography/style");
var _typography = _interopRequireDefault(require("antd/lib/typography"));
var _react = _interopRequireDefault(require("react"));
var _jsxRuntime = require("react/jsx-runtime");
const isNeedTranText = item => {
  var _item$valueType;
  if (item !== null && item !== void 0 && (_item$valueType = item.valueType) !== null && _item$valueType !== void 0 && _item$valueType.toString().startsWith('date')) {
    return true;
  }
  if ((item === null || item === void 0 ? void 0 : item.valueType) === 'select' || item !== null && item !== void 0 && item.valueEnum) {
    return true;
  }
  return false;
};

/**
 * 生成 Copyable 或 Ellipsis 的 dom
 *
 * @param dom
 * @param item
 * @param text
 */
const genCopyable = (dom, item, text) => {
  if (item.copyable || item.ellipsis) {
    const copyable = item.copyable && text ? {
      text,
      tooltips: ['', '']
    } : undefined;

    /** 有些 valueType 需要设置copy的为string */
    const needTranText = isNeedTranText(item);
    const ellipsis = item.ellipsis && text ? {
      tooltip: needTranText ? /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: "pro-table-tooltip-text",
        children: dom
      }) : text
    } : false;
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_typography.default.Text, {
      style: {
        width: '100%',
        margin: 0,
        padding: 0
      },
      title: "",
      copyable: copyable,
      ellipsis: ellipsis,
      children: dom
    });
  }
  return dom;
};
exports.genCopyable = genCopyable;