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, useState } from 'react';
import { VmBarCharts, VmFactor, VmProgress, VmWrapper } from "../../../../_components";
import useSettings from "../../../../_hooks/useSettings";
import { secondToFormatTimeArray } from "../../../../_util";
import { JxhService } from "../../../api";
import Info from "../../../components/Info";
import { CarContext } from "../../../index";
import Unmanned from "../../Unmanned";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
var BaseInfo = function BaseInfo() {
  var _useContext = useContext(CarContext),
    id = _useContext.id,
    startDate = _useContext.startDate,
    info = _useContext.info;
  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: (info === null || info === void 0 ? void 0 : info.driveMode) === 'unmanned' ? /*#__PURE__*/_jsx(Unmanned.WorkInfo, {
              id: id,
              date: date
            }) : /*#__PURE__*/_jsx(BaseWork, {
              id: id,
              date: date
            })
          })
        }), /*#__PURE__*/_jsx("div", {
          className: 'vtx-car-info-right-wrap-bottom',
          children: /*#__PURE__*/_jsx(VmWrapper, {
            title: '近7天运行分析',
            children: (info === null || info === void 0 ? void 0 : info.driveMode) === 'unmanned' ? /*#__PURE__*/_jsx(Unmanned.Analysis, {
              id: id,
              date: date
            }) : /*#__PURE__*/_jsx(BaseAnalysis, {
              id: id,
              date: date
            })
          })
        })]
      })
    })]
  });
};

// 机械化运行信息-默认
function BaseWork(_ref) {
  var id = _ref.id,
    date = _ref.date;
  var _useSettings = useSettings(),
    isDark = _useSettings.isDark;
  var _JxhService$useWorkSu = JxhService.useWorkSummaryJxh(id, dayjs(date).format('YYYY-MM-DD'), dayjs(date).format('YYYY-MM-DD'), true),
    workSummaryJxhRes = _JxhService$useWorkSu.workSummaryJxhRes,
    loading = _JxhService$useWorkSu.loading;
  var averageSpeed = ((workSummaryJxhRes === null || workSummaryJxhRes === void 0 ? void 0 : workSummaryJxhRes.workMileage) || 0) / (workSummaryJxhRes !== null && workSummaryJxhRes !== void 0 && workSummaryJxhRes.workDuration ? workSummaryJxhRes.workDuration % (24 * 60 * 60) / 60 / 60 : 1);
  return /*#__PURE__*/_jsxs(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: (workSummaryJxhRes === null || workSummaryJxhRes === void 0 ? void 0 : workSummaryJxhRes.workRate) || 0,
            name: '有效作业率'
          })
        }), /*#__PURE__*/_jsxs(Col, {
          flex: '1',
          children: [/*#__PURE__*/_jsx(VmFactor, {
            name: '行驶里程',
            unit: 'km',
            type: 'sm',
            value: (workSummaryJxhRes === null || workSummaryJxhRes === void 0 ? void 0 : workSummaryJxhRes.driveMileage) || 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: (workSummaryJxhRes === null || workSummaryJxhRes === void 0 ? void 0 : workSummaryJxhRes.workMileage) || 0,
            img: isDark ? require("../../../imgs/calendar/dark_green_mileage.png") : require("../../../imgs/calendar/mileage.png")
          })]
        })]
      })
    }), /*#__PURE__*/_jsx(Col, {
      flex: '1',
      children: /*#__PURE__*/_jsxs(Row, {
        gutter: [34, 34],
        children: [/*#__PURE__*/_jsx(Col, {
          flex: '108px',
          children: /*#__PURE__*/_jsx(VmProgress.Circle, {
            type: 'dashboard',
            rate: averageSpeed / 200 * 100,
            name: '作业均速',
            unit: 'km/h',
            info: averageSpeed.toFixed(2)
          })
        }), /*#__PURE__*/_jsxs(Col, {
          flex: '1',
          children: [/*#__PURE__*/_jsx(VmFactor, {
            name: '作业时长',
            type: 'sm',
            value: secondToFormatTimeArray((workSummaryJxhRes === null || workSummaryJxhRes === void 0 ? void 0 : workSummaryJxhRes.workDuration) || 0),
            fontType: 'cyan',
            img: isDark ? require("../../../imgs/calendar/cyan_duration.png") : require("../../../imgs/calendar/blue_duration.png")
          }), /*#__PURE__*/_jsx(VmFactor, {
            name: '作业超速时长',
            type: 'sm',
            isError: true,
            value: secondToFormatTimeArray((workSummaryJxhRes === null || workSummaryJxhRes === void 0 ? void 0 : workSummaryJxhRes.overSpeedDuration) || 0),
            fontType: 'red',
            img: isDark ? require("../../../imgs/calendar/dark_alarm.png") : require("../../../imgs/calendar/alarm.png")
          })]
        })]
      })
    })]
  });
}

// 机械化近7天运行分析-默认
function BaseAnalysis(_ref2) {
  var id = _ref2.id,
    date = _ref2.date;
  var _JxhService$useWorkAn = JxhService.useWorkAnaJxh(id, dayjs(date).subtract(6, 'day').format('YYYY-MM-DD'), dayjs(date).format('YYYY-MM-DD')),
    workAnaJxhRes = _JxhService$useWorkAn.workAnaJxhRes,
    loadingJxh = _JxhService$useWorkAn.loading;
  var xAxis = (workAnaJxhRes === null || workAnaJxhRes === void 0 ? void 0 : workAnaJxhRes.names) || [];
  var extraData = workAnaJxhRes === null || workAnaJxhRes === void 0 ? void 0 : workAnaJxhRes.extraData;
  return /*#__PURE__*/_jsx(VmBarCharts, {
    dataList: [{
      name: '核算作业里程',
      data: ((workAnaJxhRes === null || workAnaJxhRes === void 0 ? void 0 : workAnaJxhRes.values.length) > 0 ? workAnaJxhRes === null || workAnaJxhRes === void 0 ? void 0 : workAnaJxhRes.values[0] : []).map(function (item) {
        return "\u2000".concat(item);
      })
    }],
    xAxis: xAxis,
    unit: '%',
    yAxisList: [{
      key: "\u2000",
      unit: 'km',
      name: '(km)'
    }].concat([extraData !== null && extraData > 0 ? {
      key: '',
      unit: '%',
      name: '(%)'
    } : {}]),
    lineList: extraData !== null && extraData > 0 ? [{
      name: '有效完成率',
      data: (workAnaJxhRes === null || workAnaJxhRes === void 0 ? void 0 : workAnaJxhRes.values.length) > 0 ? workAnaJxhRes === null || workAnaJxhRes === void 0 ? void 0 : workAnaJxhRes.values[1] : [],
      yAxisIndex: 1
    }] : [],
    loading: loadingJxh
  });
}
export default BaseInfo;