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 _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; }
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 * as echarts from 'echarts';
import ReactEcharts from 'echarts-for-react';
import useSettings from "../../_hooks/useSettings";
import { jsx as _jsx } from "react/jsx-runtime";
var BarCharts = function BarCharts(_ref) {
  var _ref$dataList = _ref.dataList,
    dataList = _ref$dataList === void 0 ? [] : _ref$dataList,
    xAxis = _ref.xAxis,
    _ref$yAxisList = _ref.yAxisList,
    yAxisList = _ref$yAxisList === void 0 ? [] : _ref$yAxisList,
    _ref$lineList = _ref.lineList,
    lineList = _ref$lineList === void 0 ? [] : _ref$lineList,
    loading = _ref.loading,
    _ref$height = _ref.height,
    height = _ref$height === void 0 ? '100%' : _ref$height,
    _ref$unit = _ref.unit,
    unit = _ref$unit === void 0 ? '' : _ref$unit,
    _ref$showLegend = _ref.showLegend,
    showLegend = _ref$showLegend === void 0 ? true : _ref$showLegend,
    _ref$gridOptions = _ref.gridOptions,
    gridOptions = _ref$gridOptions === void 0 ? {} : _ref$gridOptions,
    _ref$otherProps = _ref.otherProps,
    otherProps = _ref$otherProps === void 0 ? {} : _ref$otherProps,
    _ref$tooltipProps = _ref.tooltipProps,
    tooltipProps = _ref$tooltipProps === void 0 ? {} : _ref$tooltipProps,
    _ref$barBorderRadius = _ref.barBorderRadius,
    barBorderRadius = _ref$barBorderRadius === void 0 ? [0, 0, 0, 0] : _ref$barBorderRadius;
  var lineColors = ['#1FB64D'];
  var _useSettings = useSettings(),
    chartFontColor = _useSettings.chartFontColor,
    isDark = _useSettings.isDark,
    chartLineColor = _useSettings.chartLineColor;
  var geekblue = ['rgba(22, 119, 255, 1)', 'rgba(22, 119, 255, 0)'];
  var green = ['rgba(15, 185, 100, 1)', 'rgba(15, 185, 100, 0)'];
  var blue = ['rgba(25, 201, 255, 1)', 'rgba(25, 201, 255, 0)'];
  if (isDark) {
    geekblue = ['rgba(0, 157, 255, 1)', 'rgba(0, 157, 255, 0)'];
    green = ['rgba(19, 249, 122, 1)', 'rgba(19, 249, 122, 0)'];
    blue = ['rgba(49, 253, 248, 1)', 'rgba(49, 253, 248, 0)'];
  }
  var barColorsMap = {
    geekblue: geekblue,
    green: green,
    blue: blue
  };
  var option = _objectSpread({
    tooltip: _objectSpread({
      trigger: 'axis',
      valueFormatter: function valueFormatter(value) {
        var _findUnit;
        var findUnit = yAxisList === null || yAxisList === void 0 ? void 0 : yAxisList[0];
        if ((yAxisList === null || yAxisList === void 0 ? void 0 : yAxisList.length) > 1) {
          findUnit = yAxisList.find(function (item) {
            return item.key && String(value).includes(item.key);
          });
        }
        return "".concat(value).concat(((_findUnit = findUnit) === null || _findUnit === void 0 ? void 0 : _findUnit.unit) || 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%'];
      }
    }, tooltipProps),
    legend: {
      right: 'center',
      itemGap: 8,
      itemHeight: 8,
      itemWidth: 8,
      textStyle: {
        color: chartFontColor
      },
      show: showLegend
    },
    grid: _objectSpread({
      left: 50,
      right: 50,
      bottom: 20
    }, gridOptions),
    xAxis: {
      type: 'category',
      data: xAxis,
      axisPointer: {
        type: 'shadow'
      },
      axisTick: {
        show: false
      },
      axisLabel: {
        color: chartFontColor
      },
      axisLine: {
        show: false
      }
    },
    yAxis: yAxisList.map(function (item, index) {
      return {
        type: 'value',
        name: item.name,
        // min: 0,
        nameTextStyle: {
          color: chartFontColor,
          padding: index === 0 ? [0, 30, 0, 0] : [0, 0, 0, 30]
        },
        splitNumber: 5,
        axisTick: {
          show: false
        },
        axisLabel: {
          color: chartFontColor
        },
        splitLine: {
          lineStyle: {
            type: 'dashed',
            color: chartLineColor
          }
        }
      };
    }),
    series: [].concat(_toConsumableArray(dataList.map(function (item) {
      var colors = barColorsMap[item.color || 'geekblue'];
      return {
        name: item.name,
        type: 'bar',
        data: item.data,
        yAxisIndex: item.yAxisIndex || 0,
        barWidth: 18,
        itemStyle: {
          color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
            offset: 1,
            color: colors[0]
          }, {
            offset: 0,
            color: colors[1]
          }]),
          borderRadius: barBorderRadius || [0, 0, 0, 0]
        }
      };
    })), _toConsumableArray(lineList.map(function (item, index) {
      var color = item.color || lineColors[index % lineColors.length];
      return _objectSpread({
        name: item.name,
        type: 'line',
        data: item.data,
        barWidth: 18,
        yAxisIndex: item.yAxisIndex || 0,
        symbolSize: 4,
        lineStyle: {
          color: color
        },
        itemStyle: {
          color: color
        },
        smooth: true
      }, item);
    })))
  }, otherProps);
  return loading ? /*#__PURE__*/_jsx(Row, {
    style: {
      height: height
    },
    align: 'middle',
    justify: 'center',
    children: /*#__PURE__*/_jsx(Spin, {})
  }) : /*#__PURE__*/_jsx(ReactEcharts, {
    option: option,
    notMerge: true,
    lazyUpdate: true,
    style: {
      height: height || '100%',
      width: '100%'
    }
  });
};
export default BarCharts;