import { Col, Row } from 'antd';
import { keyBy } from 'lodash';
import sumBy from 'lodash/sumBy';
import { useContext, useMemo } from 'react';
import { VmLineCharts, VmPieCharts, VmWrapper } from "../../../../_components";
import { BaseService } from "../../../api";
import { CarContext } from "../../../index";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
var StaticInfo = function StaticInfo(_ref) {
  var _todayRunRes$alarmGro;
  var startDate = _ref.startDate,
    endDate = _ref.endDate;
  var _useContext = useContext(CarContext),
    id = _useContext.id;
  var _BaseService$useGetSe = BaseService.useGetSetInfo(),
    setInfo = _BaseService$useGetSe.setInfo;
  var _BaseService$useToday = BaseService.useTodayRun(id, startDate, endDate, 'GPS'),
    todayRunRes = _BaseService$useToday.todayRunRes,
    loading = _BaseService$useToday.loading;
  var pieData = (todayRunRes === null || todayRunRes === void 0 || (_todayRunRes$alarmGro = todayRunRes.alarmGroupByType) === null || _todayRunRes$alarmGro === void 0 ? void 0 : _todayRunRes$alarmGro.items) || [];
  var total = 0;
  var list = [];
  if ((pieData === null || pieData === void 0 ? void 0 : pieData.length) > 0) {
    total = sumBy(pieData, function (o) {
      return o.count;
    });
    list = pieData.map(function (ele) {
      return {
        name: ele.alarmTypeName,
        value: ele.count
      };
    });
  }
  var lineData = (todayRunRes === null || todayRunRes === void 0 ? void 0 : todayRunRes.alarmGroupByDayChart) || {};
  var strategyTypeMap = keyBy((setInfo === null || setInfo === void 0 ? void 0 : setInfo.strategyTypeList) || [], 'name');
  var dataList = useMemo(function () {
    var dataList = [];
    (lineData.values || []).forEach(function (item, index) {
      var _strategyTypeMap$name;
      var name = (lineData.legends || [])[index];
      if ((_strategyTypeMap$name = strategyTypeMap[name]) !== null && _strategyTypeMap$name !== void 0 && _strategyTypeMap$name.isOn) {
        dataList.push({
          name: name,
          data: item
        });
      }
    });
    return dataList;
  }, [lineData, strategyTypeMap]);
  return /*#__PURE__*/_jsxs(Row, {
    gutter: [16, 16],
    style: {
      height: 360
    },
    children: [/*#__PURE__*/_jsx(Col, {
      span: 12,
      children: /*#__PURE__*/_jsx(VmWrapper, {
        title: '报警汇总',
        children: /*#__PURE__*/_jsx(VmPieCharts, {
          dataList: list,
          name: '报警类型',
          title: '报警总次数',
          total: total,
          loading: loading,
          unit: '次'
        })
      })
    }), /*#__PURE__*/_jsx(Col, {
      span: 12,
      children: /*#__PURE__*/_jsx(VmWrapper, {
        title: '报警趋势分析',
        children: /*#__PURE__*/_jsx(VmLineCharts, {
          xAxis: lineData.names || [],
          dataList: dataList,
          unit: "\u6B21",
          loading: loading,
          legendOption: {
            width: '95%'
          },
          gridOption: {
            top: 70
          }
        })
      })
    })]
  });
};
export default StaticInfo;