function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
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 { CcService } from "../../../api";
import Info from "../../../components/Info";
import { CarContext } from "../../../index";
import "./index.less";
import np from 'number-precision';
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;
  var _useSettings = useSettings(),
    isDark = _useSettings.isDark;
  var _useState = useState(dayjs(startDate)),
    _useState2 = _slicedToArray(_useState, 2),
    date = _useState2[0],
    setDate = _useState2[1];
  var _CcService$useTaskDay = CcService.useTaskDaySummary({
      carId: id,
      startDay: dayjs(date).subtract(6, 'day').format('YYYY-MM-DD'),
      endDay: dayjs(date).format('YYYY-MM-DD')
    }),
    taskDaySummary = _CcService$useTaskDay.taskDaySummary,
    loading = _CcService$useTaskDay.loading;
  var todayInfo = _.last(taskDaySummary) || {};
  var yesterdayTaskInfo = taskDaySummary[taskDaySummary.length - 2] || {};
  var data = [{
    name: '计划收集点位',
    unit: '个',
    value: todayInfo === null || todayInfo === void 0 ? void 0 : todayInfo.syPointNum,
    img: isDark ? require("../../../imgs/dark_point.png") : require("../../../imgs/point.png"),
    fontType: 'blue'
  }, {
    name: '计划内已收',
    unit: '个',
    value: todayInfo === null || todayInfo === void 0 ? void 0 : todayInfo.ysSyPointNum,
    img: isDark ? require("../../../imgs/dark_ys_point.png") : require("../../../imgs/ys_point.png"),
    fontType: 'green'
  }, {
    name: '计划内未收',
    unit: '个',
    value: np.minus((todayInfo === null || todayInfo === void 0 ? void 0 : todayInfo.syPointNum) || 0, (todayInfo === null || todayInfo === void 0 ? void 0 : todayInfo.ysSyPointNum) || 0),
    img: isDark ? require("../../../imgs/dark_ws_point.png") : require("../../../imgs/ws_point.png"),
    fontType: 'yellow'
  }, {
    name: '计划外已收',
    unit: '个',
    value: todayInfo === null || todayInfo === void 0 ? void 0 : todayInfo.unplannedTaskNum,
    img: isDark ? require("../../../imgs/dark_unplanned_point.png") : require("../../../imgs/unplanned_point.png"),
    fontType: 'cyan'
  }, {
    name: '收集桶数',
    unit: '桶',
    value: todayInfo === null || todayInfo === void 0 ? void 0 : todayInfo.ysTrashBinNum,
    compare: true,
    compareValue: np.minus(todayInfo.ysTrashBinNum || 0, yesterdayTaskInfo.ysTrashBinNum || 0),
    img: isDark ? require("../../../imgs/dark_trash.png") : require("../../../imgs/trash.png"),
    fontType: 'blue'
  }, {
    name: '收集重量',
    unit: 'kg',
    value: todayInfo === null || todayInfo === void 0 ? void 0 : todayInfo.weight,
    compare: true,
    compareValue: np.minus(todayInfo.weight || 0, yesterdayTaskInfo.weight || 0),
    img: isDark ? require("../../../imgs/dark_weight.png") : require("../../../imgs/weight.png"),
    fontType: 'blue'
  }];
  return /*#__PURE__*/_jsxs(Row, {
    gutter: [16, 16],
    style: {
      height: '100%'
    },
    children: [/*#__PURE__*/_jsx(Info, {}), /*#__PURE__*/_jsx(Col, {
      flex: '1',
      style: {
        minWidth: 0
      },
      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__*/_jsxs(Row, {
              gutter: [47, 47],
              align: 'middle',
              style: {
                height: '100%',
                marginLeft: 30
              },
              children: [/*#__PURE__*/_jsx(Col, {
                flex: '112px',
                children: /*#__PURE__*/_jsx(VmProgress.Circle, {
                  rate: todayInfo.completePercent || 0,
                  name: '完成率'
                })
              }), /*#__PURE__*/_jsx(Col, {
                flex: '1',
                children: /*#__PURE__*/_jsx(Row, {
                  gutter: [0, 27],
                  children: data.map(function (item) {
                    return /*#__PURE__*/_jsx(Col, {
                      span: 8,
                      children: /*#__PURE__*/_jsx(VmFactor, _objectSpread(_objectSpread({}, item), {}, {
                        type: 'sm'
                      }))
                    }, item.name);
                  })
                })
              })]
            })
          })
        }), /*#__PURE__*/_jsx("div", {
          className: 'vtx-car-info-right-wrap-bottom',
          children: /*#__PURE__*/_jsx(VmWrapper, {
            title: '近7天运行分析',
            children: /*#__PURE__*/_jsx(VmBarCharts, {
              dataList: [{
                name: '计划收集点位',
                data: _.map(taskDaySummary, 'syPointNum'),
                color: 'geekblue'
              }, {
                name: '计划内已收',
                data: _.map(taskDaySummary, 'ysSyPointNum'),
                color: 'green'
              }, {
                name: '计划外已收',
                data: _.map(taskDaySummary, 'unplannedTaskNum'),
                color: 'blue'
              }],
              xAxis: _.map(taskDaySummary, 'taskDay'),
              yAxisList: [{
                key: '',
                unit: '个',
                name: '(个)'
              }, {
                key: "\u2000",
                unit: '%',
                name: '(%)'
              }],
              unit: '个',
              lineList: [{
                name: '任务完成率',
                data: _.map(taskDaySummary, function (item) {
                  return "\u2000".concat(item.completePercent);
                }),
                color: isDark ? '#13F97A' : '#0FB964',
                yAxisIndex: 1
              }],
              loading: loading
            })
          })
        })]
      })
    })]
  });
};
export default BaseInfo;