function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
/**
 * 车辆-报警信息
 */

import { useSetState } from 'ahooks';
import dayjs from 'dayjs';
import { useEffect } from 'react';
import { VmExtraTab, VmWrapper } from "../../../_components";
import { AlarmService } from "../../api";
import Charts from "./Charts";
import "./index.less";
import List from "./List";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
var AlarmInfo = function AlarmInfo(props) {
  var id = props.id,
    _props$service = props.service,
    service = _props$service === void 0 ? '' : _props$service;
  var _useSetState = useSetState({
      startDate: dayjs().startOf('M').format('YYYY-MM-DD'),
      endDate: dayjs().format('YYYY-MM-DD'),
      tabKey: 'chart',
      alarmTypeCode: 'all'
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var startDate = state.startDate,
    endDate = state.endDate,
    alarmTypeCode = state.alarmTypeCode;
  var _AlarmService$useAlar = AlarmService.useAlarmType(id, "".concat(startDate, " 00:00:00"), "".concat(endDate, " 23:59:59"), service),
    alarmTypeRes = _AlarmService$useAlar.alarmTypeRes;
  var _AlarmService$useAlar2 = AlarmService.useAlarmAnalysis(id, startDate, endDate, service),
    alarmAnalysisRes = _AlarmService$useAlar2.alarmAnalysisRes;
  useEffect(function () {
    if (alarmTypeRes !== null && alarmTypeRes !== void 0 && alarmTypeRes.length) {
      setState({
        alarmTypeCode: alarmTypeRes[0].key
      });
    }
  }, [JSON.stringify(alarmTypeRes)]);
  var handleDateChange = function handleDateChange(start, end) {
    setState({
      startDate: start,
      endDate: end
    });
  };
  return /*#__PURE__*/_jsxs("div", {
    className: "staff-alarm",
    children: [/*#__PURE__*/_jsx(VmWrapper, {
      title: "\u62A5\u8B66\u6C47\u603B\u5206\u6790",
      dateValue: [dayjs(startDate), dayjs(endDate)],
      filterType: "rangePicker",
      filterChange: function filterChange(dates) {
        return dates && handleDateChange(dayjs(dates[0]).format('YYYY-MM-DD'), dayjs(dates[1]).format('YYYY-MM-DD'));
      },
      style: {
        marginBottom: 16
      },
      children: /*#__PURE__*/_jsx(Charts, {
        chartData: alarmTypeRes,
        lineData: alarmAnalysisRes
      })
    }), /*#__PURE__*/_jsx(VmWrapper, {
      title: "\u62A5\u8B66\u660E\u7EC6",
      extra: /*#__PURE__*/_jsx(VmExtraTab, {
        data: alarmTypeRes === null || alarmTypeRes === void 0 ? void 0 : alarmTypeRes.map(function (ele) {
          return {
            key: ele.key,
            title: ele.label
          };
        }),
        value: alarmTypeCode,
        onChange: function onChange(key) {
          setState({
            alarmTypeCode: key
          });
        }
      }),
      children: /*#__PURE__*/_jsx(List, {
        id: id,
        startDate: startDate,
        endDate: endDate,
        alarmTabs: alarmTypeRes,
        service: service,
        alarmTypeCode: alarmTypeCode
      })
    })]
  });
};
export default AlarmInfo;