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 { unmannedRealByCarId } from "../../../api";
import { Col, Row, Space } from 'antd';
import { useEffect, useState } from 'react';
import { VmProgress } from "../../../..//_components";
import useSettings from "../../../../_hooks/useSettings";
import butter from "../../../imgs/butter.png";
import butter_dark from "../../../imgs/butter_dark.png";
import water from "../../../imgs/water.png";
import water_dark from "../../../imgs/water_dark.png";
import "./index.less";
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
function Monitor(_ref) {
  var carId = _ref.carId;
  var _useSettings = useSettings(),
    isDark = _useSettings.isDark;
  var _useState = useState({}),
    _useState2 = _slicedToArray(_useState, 2),
    detail = _useState2[0],
    setDetail = _useState2[1];
  useEffect(function () {
    if (carId) unmannedRealByCarId({
      carId: carId,
      mainDevice: true
    }).then(function (res) {
      if ((res === null || res === void 0 ? void 0 : res.result) === 0) {
        setDetail((res === null || res === void 0 ? void 0 : res.data) || {});
      }
    });
  }, [carId]);
  return /*#__PURE__*/_jsx("div", {
    className: "unmaned_factor_bg",
    children: /*#__PURE__*/_jsxs(Row, {
      children: [/*#__PURE__*/_jsx(Col, {
        span: 8,
        children: /*#__PURE__*/_jsx(Item, {
          icon: isDark ? butter_dark : butter,
          unit: "%",
          value: (detail === null || detail === void 0 ? void 0 : detail.surplusElectricity) || 0,
          rate: (detail === null || detail === void 0 ? void 0 : detail.surplusElectricity) || 0,
          strokeColor: ['#FFA700', '#FFC637']
        })
      }), /*#__PURE__*/_jsx(Col, {
        span: 8,
        children: /*#__PURE__*/_jsxs("div", {
          className: "unmaned_factor_simple",
          children: [/*#__PURE__*/_jsx("div", {
            children: (detail === null || detail === void 0 ? void 0 : detail.mileage) || 0
          }), /*#__PURE__*/_jsx("div", {
            className: "unit",
            children: '今日行驶(km)'
          })]
        })
      }), /*#__PURE__*/_jsx(Col, {
        span: 8,
        children: /*#__PURE__*/_jsx(Item, {
          icon: isDark ? water_dark : water,
          unit: "L",
          value: (detail === null || detail === void 0 ? void 0 : detail.surplusWater) || 0,
          rate: (detail === null || detail === void 0 ? void 0 : detail.surplusWater) || 0,
          strokeColor: ['#00CF5D', '#04EC6C']
        })
      })]
    })
  });
}
function Item(_ref2) {
  var icon = _ref2.icon,
    value = _ref2.value,
    unit = _ref2.unit,
    rate = _ref2.rate,
    strokeColor = _ref2.strokeColor;
  return /*#__PURE__*/_jsxs(_Fragment, {
    children: [/*#__PURE__*/_jsxs(Row, {
      justify: 'space-between',
      align: "middle",
      children: [/*#__PURE__*/_jsx("img", {
        src: icon,
        className: "unmaned_factor_icon"
      }), /*#__PURE__*/_jsxs(Space, {
        align: "center",
        size: 1,
        children: [value || 0, unit || '']
      })]
    }), /*#__PURE__*/_jsx(VmProgress.Line, {
      rate: rate,
      strokeColor: strokeColor
    })]
  });
}
export default Monitor;