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); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import { Row, Spin } from 'antd';
import ReactEcharts from 'echarts-for-react';
import { isEmpty } from 'lodash';
import useSettings from "../../_hooks/useSettings";
import VmEmpty from "../vm-empty";
import { jsx as _jsx } from "react/jsx-runtime";
var LineCharts = function LineCharts(_ref) {
  var _ref$dataList = _ref.dataList,
    dataList = _ref$dataList === void 0 ? [] : _ref$dataList,
    loading = _ref.loading,
    _ref$unit = _ref.unit,
    unit = _ref$unit === void 0 ? '' : _ref$unit,
    _ref$xAxis = _ref.xAxis,
    xAxis = _ref$xAxis === void 0 ? [] : _ref$xAxis,
    _ref$yMax = _ref.yMax,
    yMax = _ref$yMax === void 0 ? null : _ref$yMax,
    _ref$height = _ref.height,
    height = _ref$height === void 0 ? '100%' : _ref$height,
    _ref$showLegend = _ref.showLegend,
    showLegend = _ref$showLegend === void 0 ? true : _ref$showLegend,
    _ref$showDataZoom = _ref.showDataZoom,
    showDataZoom = _ref$showDataZoom === void 0 ? false : _ref$showDataZoom,
    _ref$gridOption = _ref.gridOption,
    gridOption = _ref$gridOption === void 0 ? {} : _ref$gridOption,
    _ref$xAxisOption = _ref.xAxisOption,
    xAxisOption = _ref$xAxisOption === void 0 ? {} : _ref$xAxisOption,
    _ref$yAxisOption = _ref.yAxisOption,
    yAxisOption = _ref$yAxisOption === void 0 ? {} : _ref$yAxisOption,
    _ref$tooltipOption = _ref.tooltipOption,
    tooltipOption = _ref$tooltipOption === void 0 ? {} : _ref$tooltipOption,
    _ref$legendOption = _ref.legendOption,
    legendOption = _ref$legendOption === void 0 ? {} : _ref$legendOption;
  var _useSettings = useSettings(),
    chartFontColor = _useSettings.chartFontColor,
    chartLineColor = _useSettings.chartLineColor,
    theme = _useSettings.theme;
  var lineColors = ['#438EF7', '#53CB74', '#FABB43', '#FF8746', '#31C5E9', '#7DDF9F', '#B894F9', '#FC4F66', '#5D75FF'];
  var option = {
    tooltip: _objectSpread({
      trigger: 'axis',
      valueFormatter: function valueFormatter(value) {
        return "".concat(value).concat(unit);
      },
      position: function position(point, _params, _dom, _rect, size) {
        // 固定在顶部
        var leftSize = point[0] - size.contentSize[0];
        return [point[0] + size.contentSize[0] > size.viewSize[0] ? leftSize < 0 ? '35%' : leftSize : point[0], '0%'];
      }
    }, tooltipOption),
    dataZoom: [{
      type: 'slider',
      show: showDataZoom,
      bottom: 20,
      fillerColor: theme === 'light' ? 'rgba(22, 119, 255, 0.10)' : 'rgba(0, 157, 255, 0.10)',
      textStyle: {
        color: chartFontColor
      }
    }],
    legend: _objectSpread({
      show: showLegend,
      right: dataList.length === 1 ? '5%' : 'center',
      type: 'scroll',
      itemGap: 8,
      itemHeight: 2,
      itemWidth: 16,
      textStyle: {
        color: chartFontColor
      },
      itemStyle: {
        opacity: 0
      },
      pageTextStyle: {
        color: chartFontColor
      },
      pageIconColor: theme === 'light' ? '#2f4554' : '#018aff',
      pageIconInactiveColor: theme === 'light' ? '#aaa' : '#0b588e'
    }, legendOption),
    grid: _objectSpread({
      left: 50,
      right: 50,
      bottom: showDataZoom ? 50 : 20
    }, gridOption),
    xAxis: _objectSpread({
      type: 'category',
      data: xAxis,
      axisPointer: {
        type: 'shadow'
      },
      axisTick: {
        show: false
      },
      axisLabel: {
        color: chartFontColor
      },
      axisLine: {
        show: false
      }
    }, xAxisOption),
    yAxis: _objectSpread({
      type: 'value',
      name: unit ? "(".concat(unit, ")") : '',
      min: 0,
      max: yMax,
      nameTextStyle: {
        color: chartFontColor,
        padding: [0, 30, 0, 0]
      },
      splitNumber: 5,
      axisTick: {
        show: false
      },
      axisLabel: {
        color: chartFontColor
      },
      splitLine: {
        lineStyle: {
          type: 'dashed',
          color: chartLineColor
        }
      }
    }, yAxisOption),
    series: dataList.map(function (item, index) {
      var color = item.color || lineColors[index % lineColors.length];
      return _objectSpread({
        type: 'line',
        symbolSize: 4,
        lineStyle: {
          color: color
        },
        itemStyle: {
          color: color
        }
      }, item);
    })
  };
  return loading ? /*#__PURE__*/_jsx(Row, {
    style: {
      height: height
    },
    align: 'middle',
    justify: 'center',
    children: /*#__PURE__*/_jsx(Spin, {})
  }) : isEmpty(dataList) ? /*#__PURE__*/_jsx(Row, {
    style: {
      height: height
    },
    align: 'middle',
    justify: 'center',
    children: /*#__PURE__*/_jsx(VmEmpty, {
      type: "NO_CHART"
    })
  }) : /*#__PURE__*/_jsx(ReactEcharts, {
    option: option,
    notMerge: true,
    lazyUpdate: true,
    style: {
      height: height,
      width: '100%'
    }
  });
};
export default LineCharts;