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 * as echarts from 'echarts';
import { useContext, useState } from 'react';
import { VmBarCharts, VmFactor, VmLineCharts, VmWrapper } from "../../../../_components";
import useSettings from "../../../../_hooks/useSettings";
import { secondToFormatTime, secondToFormatTimeArray, transformRgb } from "../../../../_util";
import { BaseService } from "../../../api";
import Info from "../../../components/Info";
import darkDurationIcon from "../../../imgs/factor/dark_duration.png";
import darkRunIcon from "../../../imgs/factor/dark_run.png";
import durationIcon from "../../../imgs/factor/duration.png";
import runIcon from "../../../imgs/factor/run.png";
import { CarContext } from "../../../index";
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 _BaseService$useDaily = BaseService.useDailyCarRun(id, dayjs(date).subtract(6, 'day').format('YYYY-MM-DD'), dayjs(date).format('YYYY-MM-DD')),
    dailyCarRunRes = _BaseService$useDaily.dailyCarRunRes,
    loading = _BaseService$useDaily.loading;
  var todayInfo = _.last(dailyCarRunRes);
  var xAxis = _.map(dailyCarRunRes, 'reportDate');
  var blueColor = '#1677FF';
  var greenColor = '#0FB964';
  var colorOpacity = 0.2;
  if (isDark) {
    blueColor = '#0095FF';
    greenColor = '#36AB78';
    colorOpacity = 0.6;
  }
  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: 198
          },
          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: [40, 40],
              children: [/*#__PURE__*/_jsxs(Col, {
                span: 12,
                children: [/*#__PURE__*/_jsx(VmFactor, {
                  name: '行驶里程',
                  unit: 'km',
                  img: isDark ? darkRunIcon : runIcon,
                  value: (todayInfo === null || todayInfo === void 0 ? void 0 : todayInfo.sumMileage) || 0
                }), /*#__PURE__*/_jsx("div", {
                  style: {
                    height: 45,
                    marginTop: 15
                  },
                  children: /*#__PURE__*/_jsx(VmLineCharts, {
                    showLegend: false,
                    dataList: [{
                      name: '行驶里程',
                      data: _.map(dailyCarRunRes, 'sumMileage'),
                      color: transformRgb(blueColor, colorOpacity),
                      smooth: true,
                      symbol: 'none',
                      areaStyle: {
                        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                          offset: 0,
                          color: transformRgb(blueColor, colorOpacity)
                        },
                        // 半透明
                        {
                          offset: 1,
                          color: transformRgb(blueColor, 0)
                        } // 更透明
                        ])
                      }
                    }],
                    xAxis: xAxis,
                    gridOption: {
                      top: 0,
                      left: 0,
                      right: 0,
                      bottom: -10
                    },
                    xAxisOption: {
                      show: false,
                      boundaryGap: false
                    },
                    yAxisOption: {
                      show: false
                    },
                    unit: 'km'
                  })
                })]
              }), /*#__PURE__*/_jsxs(Col, {
                span: 12,
                children: [/*#__PURE__*/_jsx(VmFactor, {
                  name: '行驶时长',
                  unit: '',
                  value: secondToFormatTimeArray((todayInfo === null || todayInfo === void 0 ? void 0 : todayInfo.driveDuration) / 1000),
                  img: isDark ? darkDurationIcon : durationIcon
                }), /*#__PURE__*/_jsx("div", {
                  style: {
                    height: 45,
                    marginTop: 15
                  },
                  children: /*#__PURE__*/_jsx(VmLineCharts, {
                    showLegend: false,
                    tooltipOption: {
                      valueFormatter: function valueFormatter(value) {
                        return "".concat(secondToFormatTime(value / 1000));
                      }
                    },
                    dataList: [{
                      name: '行驶时长',
                      data: _.map(dailyCarRunRes, 'driveDuration'),
                      color: transformRgb(greenColor, colorOpacity),
                      smooth: true,
                      symbol: 'none',
                      areaStyle: {
                        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                          offset: 0,
                          color: transformRgb(greenColor, colorOpacity)
                        },
                        // 半透明
                        {
                          offset: 1,
                          color: transformRgb(greenColor, 0)
                        } // 更透明
                        ])
                      }
                    }],
                    xAxis: xAxis,
                    gridOption: {
                      top: 0,
                      left: 0,
                      right: 0,
                      bottom: -10
                    },
                    xAxisOption: {
                      show: false,
                      boundaryGap: false
                    },
                    yAxisOption: {
                      show: false
                    }
                  })
                })]
              })]
            })
          })
        }), /*#__PURE__*/_jsx("div", {
          className: 'vtx-car-info-right-wrap-bottom',
          children: /*#__PURE__*/_jsx(VmWrapper, {
            title: '近7天运行分析',
            children: /*#__PURE__*/_jsx(VmBarCharts, {
              dataList: [{
                name: '行驶里程',
                data: _.map(dailyCarRunRes, 'sumMileage'),
                color: 'geekblue'
              }],
              xAxis: xAxis,
              unit: 'km',
              yAxisList: [{
                key: '',
                unit: 'km',
                name: '(km)'
              }],
              loading: loading
            })
          })
        })]
      })
    })]
  });
};
export default BaseInfo;