import { Col, Row } from 'antd';
import * as echarts from 'echarts';
import _ from 'lodash';
import { useContext } from 'react';
import { VmBarCharts, VmFactor, VmLineCharts, VmWrapper } from "../../../../_components";
import useSettings from "../../../../_hooks/useSettings";
import { LjzyService } from "../../../api";
import carNumIcon from "../../../imgs/factor/car_num.png";
import darkCarNumIcon from "../../../imgs/factor/dark_car_num.png";
import darkJclIcon from "../../../imgs/factor/dark_jcl.png";
import jclIcon from "../../../imgs/factor/jcl.png";
import { CarContext } from "../../../index";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
var Summary = function Summary(_ref) {
  var startDate = _ref.startDate,
    endDate = _ref.endDate;
  var _useSettings = useSettings(),
    isDark = _useSettings.isDark;
  var _useContext = useContext(CarContext),
    id = _useContext.id,
    info = _useContext.info;
  var _LjzyService$useGetCa = LjzyService.useGetCarSumByDate({
      carCode: info === null || info === void 0 ? void 0 : info.carCode,
      startDate: startDate,
      endDate: endDate
    }),
    taskDaySummary = _LjzyService$useGetCa.taskDaySummary,
    loading = _LjzyService$useGetCa.loading;
  var totalCarNums = _.sumBy(taskDaySummary, 'carNums');
  var dailyCompletePercent = _.sumBy(taskDaySummary, 'netWeight').toFixed(2);
  var xAxis = _.map(taskDaySummary, 'date');
  return /*#__PURE__*/_jsx(VmWrapper, {
    title: '作业汇总',
    children: /*#__PURE__*/_jsxs(Row, {
      gutter: [20, 20],
      children: [/*#__PURE__*/_jsx(Col, {
        flex: '1',
        children: /*#__PURE__*/_jsxs(Row, {
          align: 'middle',
          justify: 'center',
          children: [/*#__PURE__*/_jsx(VmFactor, {
            name: '总进场车次',
            unit: '次',
            value: totalCarNums,
            img: isDark ? darkCarNumIcon : carNumIcon
          }), /*#__PURE__*/_jsx(VmBarCharts, {
            dataList: [{
              name: '进场车次',
              data: _.map(taskDaySummary, 'carNums')
            }],
            unit: '次',
            xAxis: xAxis,
            yAxisList: [{
              unit: '次',
              name: '(次)',
              key: ''
            }],
            loading: loading,
            height: 160,
            showLegend: false,
            gridOptions: {
              top: 30
            }
          })]
        })
      }), /*#__PURE__*/_jsx(Col, {
        flex: '1',
        children: /*#__PURE__*/_jsxs(Row, {
          align: 'middle',
          justify: 'center',
          children: [/*#__PURE__*/_jsx(VmFactor, {
            name: '总进场量',
            unit: '吨',
            value: dailyCompletePercent,
            img: isDark ? darkJclIcon : jclIcon
          }), /*#__PURE__*/_jsx(VmLineCharts, {
            dataList: [{
              name: '进场量',
              data: _.map(taskDaySummary, 'netWeight'),
              color: '#0FB964',
              smooth: true,
              symbol: 'none',
              areaStyle: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                  offset: 0,
                  color: 'rgba(15, 185, 100, 0.30)'
                },
                // 半透明
                {
                  offset: 1,
                  color: 'rgba(15, 185, 100, 0)'
                } // 更透明
                ])
              }
            }],
            xAxis: xAxis,
            unit: '吨',
            loading: loading,
            height: 160,
            showLegend: false,
            gridOption: {
              top: 30
            }
          })]
        })
      })]
    })
  });
};
export default Summary;