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 { transformRgb } from "../../../../_util";
import { LjzyService } from "../../../api";
import Info from "../../../components/Info";
import carNumIcon from "../../../imgs/factor/car_num.png";
import darkCarNumIcon from "../../../imgs/factor/dark_car_num.png";
import darkJclIcon from "../../../imgs/factor/dark_jcl.png";
import jclIcon from "../../../imgs/factor/jcl.png";
import { CarContext } from "../../../index";
import "./index.less";
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(dayjs(startDate)),
    _useState2 = _slicedToArray(_useState, 2),
    date = _useState2[0],
    setDate = _useState2[1];
  var _LjzyService$useGetCa = LjzyService.useGetCarSumByDate({
      carCode: info === null || info === void 0 ? void 0 : info.carCode,
      startDate: dayjs(date).subtract(6, 'day').format('YYYY-MM-DD'),
      endDate: dayjs(date).format('YYYY-MM-DD')
    }),
    taskDaySummary = _LjzyService$useGetCa.taskDaySummary,
    loading = _LjzyService$useGetCa.loading;
  var xAxis = _.map(taskDaySummary, 'date');
  var todayInfo = _.last(taskDaySummary) || {};
  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: 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: [40, 40],
              children: [/*#__PURE__*/_jsxs(Col, {
                span: 12,
                children: [/*#__PURE__*/_jsx(VmFactor, {
                  name: '进场车次',
                  unit: '次',
                  img: isDark ? darkCarNumIcon : carNumIcon,
                  value: (todayInfo === null || todayInfo === void 0 ? void 0 : todayInfo.carNums) || 0
                }), /*#__PURE__*/_jsx("div", {
                  style: {
                    height: 45,
                    marginTop: 15
                  },
                  children: /*#__PURE__*/_jsx(VmLineCharts, {
                    showLegend: false,
                    dataList: [{
                      name: '进场车次',
                      data: _.map(taskDaySummary, 'carNums'),
                      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: '次'
                  })
                })]
              }), /*#__PURE__*/_jsxs(Col, {
                span: 12,
                children: [/*#__PURE__*/_jsx(VmFactor, {
                  name: '进场量',
                  unit: '吨',
                  value: todayInfo === null || todayInfo === void 0 ? void 0 : todayInfo.netWeight,
                  img: isDark ? darkJclIcon : jclIcon
                }), /*#__PURE__*/_jsx("div", {
                  style: {
                    height: 45,
                    marginTop: 15
                  },
                  children: /*#__PURE__*/_jsx(VmLineCharts, {
                    showLegend: false,
                    dataList: [{
                      name: '进场量',
                      data: _.map(taskDaySummary, 'netWeight'),
                      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
                    },
                    unit: '吨'
                  })
                })]
              })]
            })
          })
        }), /*#__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, 'netWeight'),
                color: 'geekblue'
              }],
              xAxis: _.map(taskDaySummary, 'date'),
              yAxisList: [{
                key: '',
                unit: '吨',
                name: '(吨)'
              }, {
                key: "\u2000",
                unit: '次',
                name: '(次)'
              }],
              unit: '吨',
              lineList: [{
                name: '进场车次',
                data: _.map(taskDaySummary, function (item) {
                  return "\u2000".concat(item.carNums);
                }),
                color: isDark ? '#13F97A' : '#0FB964',
                yAxisIndex: 1
              }],
              loading: loading
            })
          })
        })]
      })
    })]
  });
};
export default BaseInfo;