import { mean } from 'lodash';
import { VmBarCharts, VmEmpty, VmFactorList, VmWrapper } from "../../../../_components";
import useSettings from "../../../../_hooks/useSettings";
import { useUnit } from "../../../api";
import pjrcc_dark from "../../../imgs/jzlj/pjrcc_dark.png";
import pjrcc_light from "../../../imgs/jzlj/pjrcc_light.png";
import pjryl_dark from "../../../imgs/jzlj/pjryl_dark.png";
import pjryl_light from "../../../imgs/jzlj/pjryl_light.png";
import "./index.less";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
export default function Chart(_ref) {
  var _ref$dataList = _ref.dataList,
    dataList = _ref$dataList === void 0 ? [] : _ref$dataList;
  var _useSettings = useSettings(),
    isDark = _useSettings.isDark;
  var _useUnit = useUnit(),
    unitStr = _useUnit.unitStr;
  var ylData = dataList.map(function (item) {
    return item.weight;
  });
  var ylDataAvg = ylData !== null && ylData !== void 0 && ylData.length ? mean(ylData).toFixed(2) : '0';
  var ccData = dataList.map(function (item) {
    return item.count;
  });
  var ccDataAvg = ccData !== null && ccData !== void 0 && ccData.length ? mean(ccData).toFixed(2) : '0';
  var dataList_top = [{
    name: '平均日运量',
    unit: unitStr,
    value: ylDataAvg,
    img: isDark ? pjryl_dark : pjryl_light,
    fontType: 'blue',
    unitStyle: {
      fontSize: 14
    },
    style: {
      flex: 1,
      justifyContent: 'center'
    }
  }, {
    name: '平均日车次',
    unit: '次',
    value: ccDataAvg,
    img: isDark ? pjrcc_dark : pjrcc_light,
    fontType: 'blue',
    unitStyle: {
      fontSize: 14
    },
    style: {
      flex: 1,
      justifyContent: 'center'
    }
  }];
  return /*#__PURE__*/_jsxs(VmWrapper, {
    showTitle: false,
    style: {
      border: 0
    },
    children: [/*#__PURE__*/_jsx(VmFactorList, {
      list: dataList_top,
      style: {
        background: 'unset'
      }
    }), /*#__PURE__*/_jsx("div", {
      style: {
        height: 'calc(100% - 70px)'
      },
      children: dataList !== null && dataList !== void 0 && dataList.length ? /*#__PURE__*/_jsx(VmBarCharts, {
        dataList: [{
          name: '运量',
          data: dataList.map(function (item) {
            return "\u2000".concat(item.weight);
          }),
          color: 'geekblue',
          yAxisIndex: 1
        }],
        xAxis: dataList.map(function (item) {
          return item.date;
        }),
        yAxisList: [{
          key: "\u2001",
          unit: '次',
          name: '(次)'
        }, {
          key: "\u2000",
          unit: unitStr,
          name: "(".concat(unitStr, ")")
        }],
        lineList: [{
          name: '车次',
          data: dataList.map(function (item) {
            return "\u2001".concat(item.count);
          }),
          color: '#0FB964',
          yAxisIndex: 0
        }],
        barBorderRadius: [4, 4, 0, 0]
      }) : /*#__PURE__*/_jsx(VmEmpty, {
        type: "NO_CHART"
      })
    })]
  });
}