"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 echarts = _interopRequireWildcard(require("echarts"));
var _useSettings2 = _interopRequireDefault(require("../../../vm-hooks/useSettings"));
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
var _vmNodata = _interopRequireDefault(require("../../../vm-nodata"));
var _groupBy = _interopRequireDefault(require("lodash/groupBy"));
var _moment = _interopRequireDefault(require("moment"));
var _numberPrecision = _interopRequireDefault(require("number-precision"));
var _lodash = require("lodash");
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 FactoryCharts = function FactoryCharts(_ref) {
  var _ref$list = _ref.list,
    list = _ref$list === void 0 ? [] : _ref$list;
  var _useSettings = (0, _useSettings2["default"])(),
    theme = _useSettings.theme,
    chartFontColor = _useSettings.chartFontColor;
  var _useMemo = (0, _react.useMemo)(function () {
      var xData = [];
      var carCountData = [];
      var netWeightData = [];
      var groupByDate = (0, _groupBy["default"])(list, function (item) {
        return (0, _moment["default"])(item.grossDateTime).format('YYYY-MM-DD');
      });
      (0, _lodash.sortBy)(Object.keys(groupByDate)).forEach(function (date) {
        var count = groupByDate[date].length;
        var netWeightTotal = 0;
        groupByDate[date].forEach(function (item) {
          netWeightTotal = _numberPrecision["default"].plus(netWeightTotal, item.netWeight);
        });
        xData.push(date);
        carCountData.push("\u2000".concat(count));
        netWeightData.push(netWeightTotal);
      });
      return {
        xData: xData,
        carCountData: carCountData,
        netWeightData: netWeightData
      };
    }, [JSON.stringify(list)]),
    xData = _useMemo.xData,
    carCountData = _useMemo.carCountData,
    netWeightData = _useMemo.netWeightData;
  var option = {
    tooltip: {
      trigger: 'axis',
      valueFormatter: function valueFormatter(value) {
        return "".concat(value).concat(String(value).includes("\u2000") ? '次' : 'kg');
      }
    },
    grid: {
      left: '8%',
      right: '6%',
      bottom: 20
    },
    legend: {
      align: 'left',
      itemGap: 8,
      itemWidth: 10,
      itemHeight: 10,
      textStyle: {
        color: theme === 'blue' ? '#fff' : chartFontColor
      },
      data: ['进厂量', '进厂车次']
    },
    xAxis: [{
      type: 'category',
      data: xData,
      boundaryGap: true,
      axisPointer: {
        type: 'shadow'
      },
      axisTick: {
        show: false
      },
      axisLabel: {
        color: theme === 'blue' ? '#fff' : chartFontColor
      }
    }],
    yAxis: [{
      type: 'value',
      name: '进厂量(kg)',
      min: 0,
      nameTextStyle: {
        color: theme === 'blue' ? '#fff' : chartFontColor
      },
      splitNumber: 5,
      axisTick: {
        show: false
      },
      axisLabel: {
        color: theme === 'blue' ? '#fff' : chartFontColor
      },
      splitLine: {
        lineStyle: {
          type: 'dashed',
          color: 'rgba(151,151,151,0.28)'
        }
      }
    }, {
      type: 'value',
      name: '进厂车次(次)',
      min: 0,
      nameTextStyle: {
        color: theme === 'blue' ? '#fff' : chartFontColor
      },
      splitNumber: 5,
      axisTick: {
        show: false
      },
      axisLabel: {
        color: theme === 'blue' ? '#fff' : chartFontColor
      },
      splitLine: {
        lineStyle: {
          type: 'dashed',
          color: 'rgba(151,151,151,0.28)'
        }
      }
    }],
    series: [{
      name: '进厂量',
      type: 'bar',
      barWidth: 8,
      data: netWeightData,
      itemStyle: {
        color: theme === 'dark' ? new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
          offset: 0,
          color: '#1B89FF'
        }, {
          offset: 1,
          color: '#51D0FF'
        }]) : '#1890FF'
      }
    }, {
      name: '进厂车次',
      type: 'bar',
      barWidth: 8,
      data: carCountData,
      yAxisIndex: 1,
      itemStyle: {
        color: theme === 'dark' ? new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
          offset: 0,
          color: '#00A983'
        }, {
          offset: 1,
          color: '#44FFD1'
        }]) : theme === 'blue' ? '#fff' : '#73DEB3'
      }
    }]
  };
  return (list === null || list === void 0 ? void 0 : list.length) > 0 ? (/*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    option: option,
    notMerge: true,
    lazyUpdate: true,
    style: {
      height: 300,
      width: '100%'
    }
  })) : (/*#__PURE__*/_react["default"].createElement(_vmNodata["default"], null));
};
var _default = exports["default"] = FactoryCharts;
//# sourceMappingURL=FactoryCharts.js.map
