"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
var _useSettings = _interopRequireDefault(require("../vm-hooks/useSettings"));
var _utils = require("@vtx/utils");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
var getOption = function getOption(_ref) {
  var _ref$data = _ref.data,
    data = _ref$data === void 0 ? [] : _ref$data,
    _ref$name = _ref.name,
    name = _ref$name === void 0 ? '' : _ref$name,
    isDark = _ref.isDark;
  var textColor = isDark ? '#fff' : '#929292';
  var bgColor = isDark ? '#0C2A48' : '#fff';
  var borderColor = isDark ? '#1E4771' : '#fff';
  return {
    color: ['#0E85FF', '#49FF81', '#26D4FF', '#F5D629', '#C97CFF'],
    tooltip: {
      trigger: 'item',
      backgroundColor: bgColor,
      borderColor: borderColor,
      textStyle: {
        color: textColor
      }
    },
    legend: {
      type: 'scroll',
      orient: 'vertical',
      top: 0,
      right: 10,
      itemWidth: 10,
      itemHeight: 10,
      textStyle: {
        color: textColor
      }
    },
    grid: {
      top: 0,
      left: 0,
      right: 0,
      bottom: 0,
      containLabel: true
    },
    series: [{
      name: name,
      type: 'pie',
      radius: '90%',
      center: ['26%', '50%'],
      data: data,
      label: {
        show: false,
        color: textColor
      }
    }]
  };
};
var Pie = function Pie(_ref2) {
  var data = _ref2.data,
    name = _ref2.name,
    style = _ref2.style,
    echartClick = _ref2.echartClick,
    exportShow = _ref2.exportShow;
  var echarts_react = (0, _react.useRef)(null);
  var _UseSettings = (0, _useSettings["default"])(),
    isDark = _UseSettings.isDark;
  // 保存为图片
  var saveImage = function saveImage() {
    var _a;
    var echartsInstance = (_a = echarts_react === null || echarts_react === void 0 ? void 0 : echarts_react.current) === null || _a === void 0 ? void 0 : _a.getEchartsInstance();
    if (echartsInstance) {
      var imgUrl = echartsInstance.getDataURL({
        pixelRatio: 1,
        backgroundColor: '#fff',
        excludeComponents: [
        //保存图表时忽略的工具组件,默认忽略工具栏
        'toolbox'],
        type: 'png' //图片类型支持png和jpeg
      });
      (0, _utils.downloadFile)(imgUrl, '图片', 'blob');
    }
  };
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, exportShow && (/*#__PURE__*/_react["default"].createElement("div", {
    className: "btn-wrap"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "btn",
    onClick: function onClick() {
      saveImage();
    }
  }, "\u5BFC\u51FA\u56FE\u7247"))), /*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    ref: echarts_react,
    onEvents: {
      click: echartClick
    },
    option: getOption({
      data: data,
      name: name,
      isDark: isDark
    }),
    notMerge: true,
    lazyUpdate: true,
    style: Object.assign({
      height: '100%'
    }, style)
  }));
};
var _default = exports["default"] = Pie;
//# sourceMappingURL=Pie.js.map
