import { Col, Row } from 'antd';
import _ from 'lodash';
import { useContext } from 'react';
import { VmLineCharts, VmPieCharts, VmWrapper } from "../../../../_components";
import { Hw2Service } 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 _Hw2Service$useAlarmS = Hw2Service.useAlarmSummary(id, "".concat(startDate), "".concat(endDate)),
    alarmSummary = _Hw2Service$useAlarmS.alarmSummary,
    loading = _Hw2Service$useAlarmS.loading;
  var _ref2 = alarmSummary || {},
    _ref2$typeSummary = _ref2.typeSummary,
    typeSummary = _ref2$typeSummary === void 0 ? [] : _ref2$typeSummary,
    _ref2$daySummary = _ref2.daySummary,
    daySummary = _ref2$daySummary === void 0 ? [] : _ref2$daySummary;
  var dataList = [];
  var groupByLabel = _.groupBy(daySummary, 'typeName');
  Object.keys(groupByLabel).forEach(function (label) {
    var data = _.sortBy(groupByLabel[label], 'date');
    dataList.push({
      name: label,
      data: _.map(data, 'num')
    });
  });
  var xAxis = _.sortBy(_.uniqBy(daySummary, 'date'), 'date').map(function (item) {
    return item.date;
  });
  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: typeSummary.map(function (item) {
            return {
              name: item.typeName,
              value: item.num
            };
          }),
          name: '报警类型',
          title: '报警总次数',
          total: _.sum(typeSummary.map(function (item) {
            return item.num;
          })),
          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;