"use strict";

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

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

var _pie = _interopRequireDefault(require("../plots/pie"));

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

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

function _extends() { _extends = Object.assign || 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 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 TitaPieChart(props) {
  var _props$size = props.size,
      size = _props$size === void 0 ? {
    width: "400px",
    height: "300px"
  } : _props$size,
      Data = props.Data,
      _props$handlePieLegen = props.handlePieLegendClick,
      handlePieLegendClick = _props$handlePieLegen === void 0 ? function () {} : _props$handlePieLegen;
  var totalData = 0;
  Data.map(function (item) {
    return totalData += item.value;
  }); // data要发请求取到

  var config = {
    data: Data,
    appendPadding: 0,
    angleField: "value",
    colorField: "type",
    color: ["l(0) 0:#94C2FD 1:#5B8FF9", "l(0) 0:#FFCE6B 1:#FAAD14", "l(0) 0:#FF9C9C 1:#F36E6E", "l(0) 0:#96A9C4 1:#7585A2"],
    radius: 1,
    innerRadius: 0.65,
    // 线出来对标注
    label: false,
    legend: {
      position: "right",
      layout: "vertical",
      itemHeight: 20,
      itemSpacing: 20,
      itemName: {
        style: {
          cursor: "pointer"
        }
      }
    },
    // 交互的配置
    interactions: [{
      type: "tooltip"
    }, {
      type: "element-selected",
      enable: false
    }, {
      type: "element-active",
      enable: false
    }, {
      type: "legend-visible-filter",
      enable: false
    }, {
      type: "legend-filter",
      enable: false
    }],
    // 状态样式/default/active/selected/inactive
    state: {
      active: {
        // animate: { duration: 100, easing: 'easeLinear' },
        style: {
          lineWidth: 0
        }
      }
    },
    // 环里面：
    statistic: {
      title: {
        style: {
          whiteSpace: "pre-wrap",
          overflow: "hidden",
          textOverflow: "ellipsis",
          color: "#A4ACB9",
          fontSize: "12px"
        },
        offsetY: -10,
        content: (0, _getLocale.getLocale)("HP_Onumber")
      },
      content: {
        style: {
          whiteSpace: "pre-wrap",
          overflow: "hidden",
          textOverflow: "ellipsis",
          color: "#3F4755",
          fontSize: "24px",
          fontWeight: "500"
        },
        content: totalData
      }
    }
  }; //

  return /*#__PURE__*/_react["default"].createElement("div", {
    style: _objectSpread({
      display: "flex",
      alignItems: "center",
      justifyContent: "center"
    }, size)
  }, /*#__PURE__*/_react["default"].createElement(_pie["default"], _extends({}, config, {
    onReady: function onReady(plot) {
      plot.on("legend-item:click", handlePieLegendClick);
    }
  })));
}