import { Col, Row } from 'antd';
import * as echarts from 'echarts';
import _ from 'lodash';
import { useContext } from 'react';
import { VmBarCharts, VmCardStatistics, VmFactor, VmLineCharts, VmWrapper } from "../../../../_components";
import useSettings from "../../../../_hooks/useSettings";
import { CcService } from "../../../api";
import darkTrashBg from "../../../imgs/dark_trash_bg.png";
import darkWeightBg from "../../../imgs/dark_weight_bg.png";
import darkPercentIcon from "../../../imgs/factor/dark_percent.png";
import darkPointIcon from "../../../imgs/factor/dark_point.png";
import percentIcon from "../../../imgs/factor/percent.png";
import pointIcon from "../../../imgs/factor/point.png";
import trashBg from "../../../imgs/trash_bg.png";
import weightBg from "../../../imgs/weight_bg.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;
  var _CcService$useTaskDay = CcService.useTaskDaySummary({
      carId: id,
      startDay: startDate,
      endDay: endDate
    }),
    taskDaySummary = _CcService$useTaskDay.taskDaySummary,
    loading = _CcService$useTaskDay.loading;
  var ysPointList = taskDaySummary.map(function (item) {
    return item.ysSyPointNum + item.unplannedTaskNum;
  });
  var totalYsPoint = _.sum(ysPointList);
  var dailyCompletePercent = (_.sumBy(taskDaySummary, 'completePercent') / taskDaySummary.length).toFixed(2);
  var totalYsTrashBinNum = _.sumBy(taskDaySummary, 'ysTrashBinNum').toFixed(0);
  var totalWeightNum = Number(_.sumBy(taskDaySummary, 'weight').toFixed(2));
  var xAxis = _.map(taskDaySummary, 'taskDay');
  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: totalYsPoint,
            img: isDark ? darkPointIcon : pointIcon
          }), /*#__PURE__*/_jsx(VmBarCharts, {
            dataList: [{
              name: '收集点位',
              data: ysPointList
            }],
            xAxis: xAxis,
            unit: '个',
            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 ? darkPercentIcon : percentIcon
          }), /*#__PURE__*/_jsx(VmLineCharts, {
            dataList: [{
              name: '任务完成率',
              data: _.map(taskDaySummary, 'completePercent'),
              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
            }
          })]
        })
      }), /*#__PURE__*/_jsx(Col, {
        flex: '208px',
        children: /*#__PURE__*/_jsxs(Row, {
          gutter: [24, 24],
          children: [/*#__PURE__*/_jsx(Col, {
            span: 24,
            children: /*#__PURE__*/_jsx(VmCardStatistics, {
              label: '收集总桶数',
              unit: '个',
              value: totalYsTrashBinNum,
              img: isDark ? darkTrashBg : trashBg
            })
          }), /*#__PURE__*/_jsx(Col, {
            span: 24,
            children: /*#__PURE__*/_jsx(VmCardStatistics, {
              label: '收集总重量',
              unit: 'kg',
              value: totalWeightNum,
              img: isDark ? darkWeightBg : weightBg
            })
          })]
        })
      })]
    })
  });
};
export default Summary;