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 { Col, Row } from 'antd';
import dayjs from 'dayjs';
import { useContext, useMemo, useState } from 'react';
import { VmBarCharts, VmFactor, VmProgress, VmWrapper } from "../../../../_components";
import useSettings from "../../../../_hooks/useSettings";
import { secondToFormatTimeArray } from "../../../../_util";
import { Hw2Service } from "../../../api";
import Info from "../../../components/Info";
import { CarContext } from "../../../index";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
var Hw2BaseInfo = function Hw2BaseInfo() {
  var _useContext = useContext(CarContext),
    id = _useContext.id,
    startDate = _useContext.startDate,
    detail = _useContext.detail;
  var isUnmanned = (detail === null || detail === void 0 ? void 0 : detail.driveMode) === 'unmanned';
  var _useState = useState(dayjs(startDate)),
    _useState2 = _slicedToArray(_useState, 2),
    date = _useState2[0],
    setDate = _useState2[1];
  return /*#__PURE__*/_jsxs(Row, {
    gutter: [16, 16],
    style: {
      height: '100%'
    },
    children: [/*#__PURE__*/_jsx(Info, {}), /*#__PURE__*/_jsx(Col, {
      flex: '1',
      style: {
        minWidth: 0,
        height: '100%'
      },
      children: /*#__PURE__*/_jsxs("div", {
        className: 'vtx-car-info-right-wrap',
        children: [/*#__PURE__*/_jsx("div", {
          style: {
            height: 243
          },
          children: /*#__PURE__*/_jsx(VmWrapper, {
            title: '运行信息',
            filterType: "datePicker",
            dateValue: date,
            filterChange: setDate,
            disabledDate: function disabledDate(current) {
              return current && current > dayjs().endOf('day');
            },
            children: /*#__PURE__*/_jsx(BaseWork, {
              id: id,
              date: date,
              isUnmanned: isUnmanned
            })
          })
        }), /*#__PURE__*/_jsx("div", {
          className: 'vtx-car-info-right-wrap-bottom',
          children: /*#__PURE__*/_jsx(VmWrapper, {
            title: '近7天运行分析',
            children: /*#__PURE__*/_jsx(BaseAnalysis, {
              id: id,
              date: date,
              isUnmanned: isUnmanned
            })
          })
        })]
      })
    })]
  });
};

// 机械化运行信息-默认
function BaseWork(_ref) {
  var id = _ref.id,
    date = _ref.date,
    isUnmanned = _ref.isUnmanned;
  var _useSettings = useSettings(),
    isDark = _useSettings.isDark;
  var _Hw2Service$useWorkIn = Hw2Service.useWorkInfo(id, dayjs(date).format('YYYY-MM-DD')),
    workInfo = _Hw2Service$useWorkIn.workInfo;
  return /*#__PURE__*/_jsx(Row, {
    gutter: [47, 47],
    align: 'middle',
    style: {
      height: '100%',
      marginLeft: 30
    },
    children: /*#__PURE__*/_jsx(Col, {
      flex: '1',
      children: /*#__PURE__*/_jsxs(Row, {
        gutter: [34, 34],
        children: [/*#__PURE__*/_jsx(Col, {
          flex: '108px',
          children: /*#__PURE__*/_jsx(VmProgress.Circle, {
            rate: (workInfo === null || workInfo === void 0 ? void 0 : workInfo.completeRate) || 0,
            name: '完成率'
          })
        }), /*#__PURE__*/_jsxs(Col, {
          flex: '1',
          children: [/*#__PURE__*/_jsx(VmFactor, {
            name: '排班里程',
            unit: 'km',
            type: 'sm',
            value: (workInfo === null || workInfo === void 0 ? void 0 : workInfo.planMileage) || 0,
            fontType: 'blue',
            img: isDark ? require("../../../imgs/calendar/dark_mileage.png") : require("../../../imgs/calendar/blue_mileage.png")
          }), /*#__PURE__*/_jsx(VmFactor, {
            name: '作业里程',
            unit: 'km',
            type: 'sm',
            fontType: 'green',
            value: (workInfo === null || workInfo === void 0 ? void 0 : workInfo.workMileage) || 0,
            img: isDark ? require("../../../imgs/calendar/dark_green_mileage.png") : require("../../../imgs/calendar/green_mileage.png")
          })]
        }), /*#__PURE__*/_jsxs(Col, {
          flex: '1',
          children: [/*#__PURE__*/_jsx(VmFactor, {
            name: '行驶时长',
            type: 'sm',
            value: secondToFormatTimeArray(((workInfo === null || workInfo === void 0 ? void 0 : workInfo.driveDuration) || 0) / 1000),
            fontType: 'blue',
            img: isDark ? require("../../../imgs/clock_dark.png") : require("../../../imgs/clock.png")
          }), /*#__PURE__*/_jsx(VmFactor, {
            name: '作业时长',
            type: 'sm',
            value: secondToFormatTimeArray(((workInfo === null || workInfo === void 0 ? void 0 : workInfo.workDuration) || 0) / 1000),
            fontType: 'green',
            img: isDark ? require("../../../imgs/clock_green_dark.png") : require("../../../imgs/clock_green.png")
          })]
        }), isUnmanned && /*#__PURE__*/_jsxs(Col, {
          flex: '1',
          children: [/*#__PURE__*/_jsx(VmFactor, {
            name: '总电耗',
            unit: 'kwh',
            type: 'sm',
            value: (workInfo === null || workInfo === void 0 ? void 0 : workInfo.electricity) || 0,
            fontType: 'yellow',
            img: isDark ? require("../../../imgs/butter_dark.png") : require("../../../imgs/butter.png")
          }), /*#__PURE__*/_jsx(VmFactor, {
            name: '总水耗',
            unit: 'L',
            type: 'sm',
            fontType: 'green',
            value: (workInfo === null || workInfo === void 0 ? void 0 : workInfo.water) || 0,
            img: isDark ? require("../../../imgs/water_dark.png") : require("../../../imgs/water.png")
          })]
        })]
      })
    })
  });
}

// 机械化近7天运行分析-默认
function BaseAnalysis(_ref2) {
  var id = _ref2.id,
    date = _ref2.date,
    isUnmanned = _ref2.isUnmanned;
  var _Hw2Service$useWorkCa = Hw2Service.useWorkCalendar(id, dayjs(date).subtract(6, 'day').format('YYYY-MM-DD'), dayjs(date).format('YYYY-MM-DD')),
    workCalendar = _Hw2Service$useWorkCa.workCalendar,
    loadingJxh = _Hw2Service$useWorkCa.loading;
  var _useMemo = useMemo(function () {
      var xAxis = [];
      var planMileageList = [];
      var workMileageList = [];
      var completeRateList = [];
      var electricityList = [];
      workCalendar.forEach(function (item) {
        var date = item.date,
          planMileage = item.planMileage,
          workMileage = item.workMileage,
          completeRate = item.completeRate,
          electricity = item.electricity;
        xAxis.push(date);
        planMileageList.push("\u2000".concat(planMileage));
        workMileageList.push("\u2000".concat(workMileage));
        completeRateList.push(completeRate);
        electricityList.push(electricity);
      });
      return {
        xAxis: xAxis,
        planMileageList: planMileageList,
        workMileageList: workMileageList,
        completeRateList: completeRateList,
        electricityList: electricityList
      };
    }, [workCalendar]),
    xAxis = _useMemo.xAxis,
    planMileageList = _useMemo.planMileageList,
    workMileageList = _useMemo.workMileageList,
    completeRateList = _useMemo.completeRateList,
    electricityList = _useMemo.electricityList;
  return /*#__PURE__*/_jsx(VmBarCharts, {
    dataList: [{
      name: '排班里程',
      data: planMileageList
    }, {
      name: '作业里程',
      data: workMileageList,
      color: 'green'
    }],
    xAxis: xAxis,
    unit: '%',
    yAxisList: [{
      key: "\u2000",
      unit: 'km',
      name: '(km)'
    }, {
      key: '',
      unit: isUnmanned ? 'kwh' : '%',
      name: isUnmanned ? '(kwh)' : '(%)'
    }],
    lineList: [{
      name: isUnmanned ? '总电耗' : '完成率',
      data: isUnmanned ? electricityList : completeRateList,
      yAxisIndex: 1,
      color: isUnmanned ? '#FFAB0C' : ''
    }],
    loading: loadingJxh
  });
}
export default Hw2BaseInfo;