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 { mean } from 'lodash';
import { useContext, useState } from 'react';
import { VmBarCharts, VmEmpty, VmFactorList, VmWrapper } from "../../../../_components";
import useSettings from "../../../../_hooks/useSettings";
import { JzljService } from "../../../api";
import Info from "../../../components/Info";
import { CarContext } from "../../../index";
import "./index.less";
import pjrcc_dark from "../../../imgs/jzlj/pjrcc_dark.png";
import pjrcc_light from "../../../imgs/jzlj/pjrcc_light.png";
import pjryl_dark from "../../../imgs/jzlj/pjryl_dark.png";
import pjryl_light from "../../../imgs/jzlj/pjryl_light.png";
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 _useSettings = useSettings(),
    isDark = _useSettings.isDark;
  var _useState = useState(startDate ? dayjs(startDate) : dayjs()),
    _useState2 = _slicedToArray(_useState, 2),
    date = _useState2[0],
    setDate = _useState2[1];
  var _JzljService$useZlOth = JzljService.useZlOtherInfo({
      id: id,
      startDate: dayjs(date).format('YYYY-MM-DD'),
      endDate: dayjs(date).format('YYYY-MM-DD')
    }),
    zlOtherInfoData = _JzljService$useZlOth.zlOtherInfoData;
  var _JzljService$useDaily = JzljService.useDailyCarRun({
      id: id,
      startDate: dayjs(date).format('YYYY-MM-DD'),
      endDate: dayjs(date).format('YYYY-MM-DD')
    }),
    dailyCarRunData = _JzljService$useDaily.dailyCarRunData;
  var _JzljService$useUnit = JzljService.useUnit(),
    unitStr = _JzljService$useUnit.unitStr;
  var extraList = [{
    name: '生效中处置证',
    unit: '张',
    value: (zlOtherInfoData === null || zlOtherInfoData === void 0 ? void 0 : zlOtherInfoData.sxzczzCount) || 0,
    fontType: 'blue',
    unitStyle: {
      fontSize: 14
    }
  }];
  var itemStyle = {
    flex: 1,
    justifyContent: 'center',
    textAlign: 'center'
  };
  var yxxxList_top = [
  // {
  //   name: '核算行驶里程',
  //   unit: 'km',
  //   value: dailyCarRunData?.sumMileage || 0,
  //   fontType: 'blue',
  //   style: itemStyle,
  // },
  {
    name: '完成联单数',
    unit: '单',
    value: (zlOtherInfoData === null || zlOtherInfoData === void 0 ? void 0 : zlOtherInfoData.orderCount) || 0,
    style: itemStyle
  }, {
    name: '路线偏移报警数',
    unit: '条',
    value: (zlOtherInfoData === null || zlOtherInfoData === void 0 ? void 0 : zlOtherInfoData.lxplAlarmCount) || 0,
    fontType: 'red',
    style: itemStyle,
    unitStyle: {
      fontSize: 14
    }
  }];
  var yxxxList_bottom = [
  // {
  //   name: '作业时长',
  //   unit: '',
  //   value: secondToFormatTime(
  //     (dailyCarRunData?.driveDuration ?? 0) / 1000 || 0,
  //   ),
  //   fontType: 'blue',
  //   style: itemStyle,
  // },
  {
    name: '已运输量',
    unit: unitStr,
    value: (zlOtherInfoData === null || zlOtherInfoData === void 0 ? void 0 : zlOtherInfoData.yysWeight) || 0,
    style: itemStyle
  }, {
    name: '停车超时报警数',
    unit: '条',
    value: (zlOtherInfoData === null || zlOtherInfoData === void 0 ? void 0 : zlOtherInfoData.tccsAlarmCount) || 0,
    fontType: 'red',
    style: itemStyle,
    unitStyle: {
      fontSize: 14
    }
  }];
  var _JzljService$useYxfx = JzljService.useYxfx({
      id: id,
      startDate: dayjs().subtract(6, 'days').format('YYYY-MM-DD'),
      endDate: dayjs().format('YYYY-MM-DD')
    }),
    _JzljService$useYxfx$ = _JzljService$useYxfx.yxfxData,
    yxfxData = _JzljService$useYxfx$ === void 0 ? [] : _JzljService$useYxfx$;
  var ylData = yxfxData.map(function (item) {
    return item.weight;
  });
  var ylDataAvg = ylData !== null && ylData !== void 0 && ylData.length ? mean(ylData).toFixed(2) : '0';
  var ccData = yxfxData.map(function (item) {
    return item.count;
  });
  var ccDataAvg = ccData !== null && ccData !== void 0 && ccData.length ? mean(ccData).toFixed(2) : '0';
  var yxfxList = [{
    name: '平均日运量',
    unit: unitStr,
    value: ylDataAvg,
    img: isDark ? pjryl_dark : pjryl_light,
    fontType: 'blue',
    unitStyle: {
      fontSize: 14
    },
    style: {
      flex: 1,
      justifyContent: 'center'
    }
  }, {
    name: '平均日车次',
    unit: '次',
    value: ccDataAvg,
    img: isDark ? pjrcc_dark : pjrcc_light,
    fontType: 'blue',
    unitStyle: {
      fontSize: 14
    },
    style: {
      flex: 1,
      justifyContent: 'center'
    }
  }];
  return /*#__PURE__*/_jsxs(Row, {
    gutter: [16, 16],
    style: {
      height: '100%'
    },
    className: "vtx-jzlj-car-base",
    children: [/*#__PURE__*/_jsx(Info, {
      showQrCode: true,
      extraList: extraList,
      showListImg: false
    }), /*#__PURE__*/_jsx(Col, {
      flex: '1',
      style: {
        height: '100%'
      },
      children: /*#__PURE__*/_jsxs("div", {
        className: "vtx-jzlj-car-base-right",
        children: [/*#__PURE__*/_jsx("div", {
          className: "vtx-jzlj-car-base-right-top",
          children: /*#__PURE__*/_jsxs(VmWrapper, {
            title: '运行信息',
            filterType: "datePicker",
            dateValue: date,
            filterChange: setDate,
            disabledDate: function disabledDate(current) {
              return current && current > dayjs().endOf('day');
            },
            children: [/*#__PURE__*/_jsx(VmFactorList, {
              list: yxxxList_top,
              style: {
                backgroundColor: 'unset'
              }
            }), /*#__PURE__*/_jsx(VmFactorList, {
              list: yxxxList_bottom,
              style: {
                backgroundColor: 'unset'
              }
            })]
          })
        }), /*#__PURE__*/_jsx("div", {
          className: "vtx-jzlj-car-base-right-bottom",
          children: /*#__PURE__*/_jsxs(VmWrapper, {
            title: '近7天运行分析',
            children: [/*#__PURE__*/_jsx(VmFactorList, {
              list: yxfxList,
              style: {
                background: 'unset'
              }
            }), /*#__PURE__*/_jsx("div", {
              className: "vtx-jzlj-car-base-right-bottom-chart",
              children: yxfxData !== null && yxfxData !== void 0 && yxfxData.length ? /*#__PURE__*/_jsx(VmBarCharts, {
                dataList: [{
                  name: '运量',
                  data: yxfxData.map(function (item) {
                    return "\u2000".concat(item.weight);
                  }),
                  color: 'geekblue',
                  yAxisIndex: 1
                }],
                xAxis: yxfxData.map(function (item) {
                  return item.date;
                }),
                yAxisList: [{
                  key: "\u2001",
                  unit: '次',
                  name: '(次)'
                }, {
                  key: "\u2000",
                  unit: unitStr,
                  name: "(".concat(unitStr, ")")
                }],
                lineList: [{
                  name: '车次',
                  data: yxfxData.map(function (item) {
                    return "\u2001".concat(item.count);
                  }),
                  color: '#0FB964',
                  yAxisIndex: 0
                }],
                barBorderRadius: [4, 4, 0, 0],
                gridOptions: {
                  top: 30
                }
              }) : /*#__PURE__*/_jsx(VmEmpty, {
                type: "NO_CHART"
              })
            })]
          })
        })]
      })
    })]
  });
};
export default BaseInfo;

// 秒转化为时间的格式化字符串
export function secondToFormatTime(times) {
  if (times <= 0) return '0';
  var timeStr = '';
  var remain = times;
  var days = Math.floor(remain / (24 * 60 * 60));
  if (days) timeStr += "".concat(days, "\u5929");
  remain = remain % (24 * 60 * 60);
  var hours = Math.floor(remain / (60 * 60));
  if (hours) timeStr += "".concat(hours, "h");
  remain = remain % (60 * 60);
  var minutes = Math.floor(remain / 60);
  if (minutes) timeStr += "".concat(minutes, "min");
  remain = remain % 60;
  var seconds = Math.floor(remain);
  if (seconds) timeStr += "".concat(seconds, "s");
  return timeStr;
}