"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

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

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

var _propTypes = _interopRequireDefault(require("prop-types"));

var echarts = _interopRequireWildcard(require("echarts"));

var _useSettings3 = _interopRequireDefault(require("../vm-hooks/useSettings"));

require("./style");

var _theme = require("./theme");

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

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

var ChartTitle = function ChartTitle(props) {
  var title = props.title;

  var _useSettings = (0, _useSettings3["default"])(),
      theme = _useSettings.theme;

  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "chart-title ".concat(theme)
  }, title);
};
/**
 * echarts容器
 * @param props
 */


exports.ChartTitle = ChartTitle;

var VMChart = function VMChart(props) {
  console.log(props.option);
  var _props$defaultOption = props.defaultOption,
      defaultOption = _props$defaultOption === void 0 ? true : _props$defaultOption;
  var ref = (0, _react.useRef)(null);

  var _useSettings2 = (0, _useSettings3["default"])(),
      isDark = _useSettings2.isDark;

  (0, _react.useEffect)(function () {
    var myChart = echarts.init(ref.current, 'VMTheme');
    var option = props.option;

    if (defaultOption) {
      (0, _theme.setPresetOptions)(option, isDark);
    }

    myChart.setOption(option);

    var chartResize = function chartResize() {
      myChart.resize();
    };

    window.addEventListener('resize', chartResize);
    return function () {
      window.removeEventListener('resize', chartResize);
    };
  }, [props.option]);
  if (!props.option) return null;
  return /*#__PURE__*/_react["default"].createElement("div", {
    ref: ref,
    style: {
      height: props.height,
      width: props.width
    }
  });
};

VMChart.propTypes = {
  defaultOption: _propTypes["default"].any,
  option: _propTypes["default"].any,
  height: _propTypes["default"].number,
  width: _propTypes["default"].number
};
ChartTitle.propTypes = {
  title: _propTypes["default"].string
};
var _default = VMChart;
exports["default"] = _default;
//# sourceMappingURL=index.js.map
