import { Col, Row } from 'antd';
import _ from 'lodash';
import { useContext } from 'react';
import { VmLineCharts, VmPieCharts, VmWrapper } from "../../../../_components";
import { JxhService } from "../../../api";
import { CarContext } from "../../../index";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
var StaticInfo = function StaticInfo(_ref) {
  var startDate = _ref.startDate,
    endDate = _ref.endDate;
  var _useContext = useContext(CarContext),
    id = _useContext.id;
  var _JxhService$useJXHAla = JxhService.useJXHAlarmStatistics(id, "".concat(startDate, " 00:00:00"), "".concat(endDate, " 23:59:59")),
    alarmTypes = _JxhService$useJXHAla.alarmTypes,
    loading = _JxhService$useJXHAla.loading;
  var _JxhService$useSingle = JxhService.useSingleCarAlarmStatistics(id, "".concat(startDate, " 00:00:00"), "".concat(endDate, " 23:59:59")),
    alarmStatistic = _JxhService$useSingle.alarmStatistic;
  var _ref2 = (alarmTypes === null || alarmTypes === void 0 ? void 0 : alarmTypes.eventNum) || {},
    _ref2$CarEmptyRun = _ref2.CarEmptyRun,
    CarEmptyRun = _ref2$CarEmptyRun === void 0 ? 0 : _ref2$CarEmptyRun,
    _ref2$CarOverSpeed = _ref2.CarOverSpeed,
    CarOverSpeed = _ref2$CarOverSpeed === void 0 ? 0 : _ref2$CarOverSpeed;
  var dataList = [];
  var groupByLabel = _.groupBy(alarmStatistic, 'alarmTypeName');
  Object.keys(groupByLabel).forEach(function (label) {
    var data = _.sortBy(groupByLabel[label], 'alarmDate');
    dataList.push({
      name: label,
      data: _.map(data, 'num')
    });
  });
  var xAxis = _.sortBy(_.uniqBy(alarmStatistic, 'alarmDate'), 'alarmDate').map(function (item) {
    return item.alarmDate;
  });
  return /*#__PURE__*/_jsxs(Row, {
    gutter: [16, 16],
    style: {
      height: 360
    },
    children: [/*#__PURE__*/_jsx(Col, {
      span: 12,
      style: {
        height: '100%'
      },
      children: /*#__PURE__*/_jsx(VmWrapper, {
        title: '报警汇总',
        children: /*#__PURE__*/_jsx(VmPieCharts, {
          dataList: [{
            name: '空驶',
            value: CarEmptyRun
          }, {
            name: '超速',
            value: CarOverSpeed
          }],
          name: '报警类型',
          title: '报警总次数',
          total: CarEmptyRun + CarOverSpeed,
          loading: loading,
          unit: '次'
        })
      })
    }), /*#__PURE__*/_jsx(Col, {
      span: 12,
      style: {
        height: '100%'
      },
      children: /*#__PURE__*/_jsx(VmWrapper, {
        title: '报警趋势分析',
        children: /*#__PURE__*/_jsx(VmLineCharts, {
          xAxis: xAxis,
          dataList: dataList,
          unit: "\u6B21",
          loading: loading,
          legendOption: {
            width: '95%'
          },
          gridOption: {
            top: 70
          }
        })
      })
    })]
  });
};
export default StaticInfo;