"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _react = _interopRequireDefault(require("react"));

var _reactDom = _interopRequireDefault(require("react-dom"));

var _customTooltip = _interopRequireDefault(require("./custom-tooltip"));

var _getLocale = require("../../../utils/getLocale");

var _wordscloud = _interopRequireDefault(require("../plots/wordscloud"));

require("./index.css");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

var defaultWordsCouldDate = new Array(10).fill([{
  text: (0, _getLocale.getLocale)("Menu_Title_OKRs"),
  value: 10
}, {
  text: "对齐",
  value: 3
}, {
  text: (0, _getLocale.getLocale)("Mod_Objective"),
  value: 3
}, {
  text: (0, _getLocale.getLocale)("Mod_KeyResults"),
  value: 1
}, {
  text: "聚焦",
  value: 1
}, {
  text: "执行",
  value: 2
}, {
  text: (0, _getLocale.getLocale)("OKR_MyO_Butt_Update"),
  value: 2
}, {
  text: (0, _getLocale.getLocale)("Feed_Tab_Title_Progress"),
  value: 2
}, {
  text: (0, _getLocale.getLocale)("OKR_MyO_E_Pop_Coordination"),
  value: 2
}, {
  text: "execute",
  value: 1
}, {
  text: "objective",
  value: 4
}]).reduce(function (a, b) {
  return [].concat(_toConsumableArray(a), _toConsumableArray(b));
});

function TitaWordsCloud(props) {
  var styles = props.styles,
      wordsData = props.wordsData,
      ImageMask = props.ImageMask,
      fontSize = props.fontSize;
  var config = {
    data: wordsData.length ? wordsData : defaultWordsCouldDate,
    wordField: "text",
    // 单词字段名
    weightField: "value",
    // 大小字段名
    colorField: "text",
    // 颜色字段名
    color: ["#2879ff", "#FFA99E", "#26D8F0", "#3D26F0", "#62d600", "#9EC3FF", "#4D90ff", "#00D685", "#A226F0", "#2879FF", "#F0A326"],
    autoFit: true,
    imageMask: ImageMask,
    wordStyle: {
      fontFamily: "Avenir",
      fontSize: fontSize
    },
    limitInPlot: true,
    // state: {
    //     active: {
    //         style: {
    //             lineWidth: 0,
    //             shadowBlur: 4,
    //             shadowColor: 'rgba(0,0,0,0.3)',
    //         },
    //     },
    // },
    tooltip: {
      customContent: function customContent(_title, items) {
        if (items.length === 0) {
          return "<div></div>";
        }

        var mountElement = document.createElement("div");
        mountElement.className = "g2-tooltip";

        _reactDom["default"].render( /*#__PURE__*/_react["default"].createElement(_customTooltip["default"], {
          data: items
        }), mountElement);

        return mountElement;
      }
    },
    interactions: [{
      type: "tooltip",
      enable: wordsData.length !== 0
    }]
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    style: _objectSpread({
      opacity: "".concat(wordsData.length === 0 ? 0.3 : 1)
    }, styles),
    className: "".concat(wordsData.length === 0 && "words-cloud-mock-data")
  }, /*#__PURE__*/_react["default"].createElement(_wordscloud["default"], config));
}

TitaWordsCloud.defaultProps = {
  styles: {
    width: "100%",
    height: "100%",
    minHeight: "200px",
    minWidth: "300px"
  },
  ImageMask: "",
  fontSize: [8, 64]
};
var _default = TitaWordsCloud;
exports["default"] = _default;