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 _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
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 { QuestionCircleOutlined } from '@ant-design/icons';
import { Space, Tabs, Tooltip } from 'antd';
import dayjs from 'dayjs';
import { keyBy } from 'lodash';
import { useContext, useState } from 'react';
import { VmBarCharts, VmCalendar, VmCalendarInner, VmCalendarPercent, VmTable, VmTabs, VmWrapper } from "../../../../_components";
import useSettings from "../../../../_hooks/useSettings";
import { secondToFormatTime } from "../../../../_util";
import { Hw2Service } from "../../../api";
import darkElectricityIcon from "../../../imgs/calendar/dark_electricity.png";
import darkWorkMileageIcon from "../../../imgs/calendar/dark_green_mileage.png";
import darkMileageIcon from "../../../imgs/calendar/dark_mileage.png";
import darkOilIcon from "../../../imgs/calendar/dark_oil.png";
import darkTransitionIcon from "../../../imgs/calendar/dark_transition.png";
import darkWaterIcon from "../../../imgs/calendar/dark_water.png";
import lightElectricityIcon from "../../../imgs/calendar/electricity.png";
import lightWorkMileageIcon from "../../../imgs/calendar/green_mileage.png";
import lightMileageIcon from "../../../imgs/calendar/mileage.png";
import lightOilIcon from "../../../imgs/calendar/oil.png";
import lightTransitionIcon from "../../../imgs/calendar/transition.png";
import lightWaterIcon from "../../../imgs/calendar/water.png";
import { CarContext } from "../../../index";
import "./index.less";
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
var TabPane = Tabs.TabPane;
var Hw2StaticInfo = function Hw2StaticInfo() {
  var _useState = useState('calendar'),
    _useState2 = _slicedToArray(_useState, 2),
    type = _useState2[0],
    setType = _useState2[1];
  var _useContext = useContext(CarContext),
    id = _useContext.id,
    detail = _useContext.detail;
  var isUnmanned = (detail === null || detail === void 0 ? void 0 : detail.driveMode) === 'unmanned';
  var _useState3 = useState(dayjs()),
    _useState4 = _slicedToArray(_useState3, 2),
    month = _useState4[0],
    setMonth = _useState4[1];
  var common = {
    type: type,
    id: id,
    month: month
  };
  return /*#__PURE__*/_jsx(VmWrapper, {
    title: '作业分析',
    needChange: true,
    showCalendar: true,
    onChange: setType,
    filterType: "monthPicker",
    dateValue: month,
    filterChange: setMonth,
    disabledDate: function disabledDate(current) {
      return current && current > dayjs().endOf('M');
    },
    children: /*#__PURE__*/_jsx(Calendar, _objectSpread(_objectSpread({}, common), {}, {
      isUnmanned: isUnmanned
    }))
  });
};

// 作业率图例
function RateLegend() {
  return /*#__PURE__*/_jsxs(Space, {
    children: [/*#__PURE__*/_jsx("div", {
      children: "\u5B8C\u6210\u7387\uFF1A"
    }), /*#__PURE__*/_jsx("div", {
      className: 'vtx-car-calendar-complete-legend',
      style: {
        background: 'var(--gray-color)'
      }
    }), /*#__PURE__*/_jsx("div", {
      children: "0%"
    }), /*#__PURE__*/_jsx("div", {
      className: 'vtx-car-calendar-complete-legend',
      style: {
        background: 'var(--red-color)'
      }
    }), /*#__PURE__*/_jsx("div", {
      children: "(0%-50%]"
    }), /*#__PURE__*/_jsx("div", {
      className: 'vtx-car-calendar-complete-legend',
      style: {
        background: 'var(--yellow-color)'
      }
    }), /*#__PURE__*/_jsx("div", {
      children: "(50%-80%]"
    }), /*#__PURE__*/_jsx("div", {
      className: 'vtx-car-calendar-complete-legend',
      style: {
        background: 'var(--blue-color)'
      }
    }), /*#__PURE__*/_jsx("div", {
      children: "(80%-100%]"
    }), /*#__PURE__*/_jsx("div", {
      className: 'vtx-car-calendar-complete-legend',
      style: {
        background: 'var(--green-color)'
      }
    }), /*#__PURE__*/_jsx("div", {
      children: "100%"
    })]
  });
}

// 获取效率颜色
function getRateColor() {
  var percent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  var color = 'gray';
  if (percent > 0 && percent <= 50) {
    color = 'red';
  } else if (percent > 50 && percent <= 80) {
    color = 'yellow';
  } else if (percent > 80 && percent < 100) {
    color = 'blue';
  } else if (percent >= 100) {
    color = 'green';
  }
  return color;
}

// 机械化作业日历-默认
function Calendar(_ref) {
  var type = _ref.type,
    id = _ref.id,
    month = _ref.month,
    isUnmanned = _ref.isUnmanned;
  var _useSettings = useSettings(),
    isDark = _useSettings.isDark;
  var _useState5 = useState('complete'),
    _useState6 = _slicedToArray(_useState5, 2),
    activeType = _useState6[0],
    setActiveType = _useState6[1];
  var _Hw2Service$useWorkCa = Hw2Service.useWorkCalendar(id, month.startOf('M').format('YYYY-MM-DD'), month.endOf('M').format('YYYY-MM-DD')),
    _Hw2Service$useWorkCa2 = _Hw2Service$useWorkCa.workCalendar,
    dailyData = _Hw2Service$useWorkCa2 === void 0 ? [] : _Hw2Service$useWorkCa2,
    loading = _Hw2Service$useWorkCa.loading;
  var keyByDate = keyBy(dailyData || [], 'date');
  var mileageIcon = lightMileageIcon;
  var workMileageIcon = lightWorkMileageIcon;
  var oilIcon = lightOilIcon;
  var electricityIcon = lightElectricityIcon;
  var waterIcon = lightWaterIcon;
  var transitionIcon = lightTransitionIcon;
  if (isDark) {
    mileageIcon = darkMileageIcon;
    workMileageIcon = darkWorkMileageIcon;
    oilIcon = darkOilIcon;
    electricityIcon = darkElectricityIcon;
    waterIcon = darkWaterIcon;
    transitionIcon = darkTransitionIcon;
  }
  // 列表字段-默认
  var BaseColumns = [{
    title: '作业日期',
    dataIndex: 'date',
    key: 'date',
    width: 100,
    fixed: 'left'
  }, {
    title: '作业开始时间',
    dataIndex: 'workStartTime',
    key: 'workStartTime',
    render: function render(text) {
      return /*#__PURE__*/_jsx("span", {
        children: text || '-'
      });
    },
    sorter: function sorter(a, b) {
      return a.workStartTime > b.workStartTime ? 1 : -1;
    },
    width: 160
  }, {
    title: '作业结束时间',
    dataIndex: 'workEndTime',
    key: 'workEndTime',
    render: function render(text) {
      return /*#__PURE__*/_jsx("span", {
        children: text || '-'
      });
    },
    sorter: function sorter(a, b) {
      return a.workEndTime > b.workEndTime ? 1 : -1;
    },
    width: 160
  }, {
    title: '作业时长',
    dataIndex: 'workDuration',
    key: 'workDuration',
    render: function render(text) {
      return /*#__PURE__*/_jsx("span", {
        children: secondToFormatTime((text || 0) / 1000) || '-'
      });
    },
    width: 100
  }, {
    title: '行驶时长',
    dataIndex: 'driveDuration',
    key: 'driveDuration',
    render: function render(text) {
      return /*#__PURE__*/_jsx("span", {
        children: secondToFormatTime((text || 0) / 1000) || '-'
      });
    },
    width: 100
  }, {
    title: '排班里程(km)',
    dataIndex: 'planMileage',
    key: 'planMileage',
    render: function render(text) {
      return /*#__PURE__*/_jsx("span", {
        children: text || '-'
      });
    },
    align: 'right',
    width: 120
  }, {
    title: '作业里程(km)',
    dataIndex: 'workMileage',
    key: 'workMileage',
    render: function render(text) {
      return /*#__PURE__*/_jsx("span", {
        children: text || '-'
      });
    },
    align: 'right',
    width: 120
  }].concat(_toConsumableArray(isUnmanned ? [{
    title: '行驶里程(km)',
    dataIndex: 'driveMileage',
    key: 'driveMileage',
    render: function render(text) {
      return /*#__PURE__*/_jsx("span", {
        children: text || '-'
      });
    },
    align: 'right',
    width: 120
  }] : []), [{
    title: '电耗(Kwh)',
    dataIndex: 'electricity',
    key: 'electricity',
    render: function render(text) {
      return /*#__PURE__*/_jsx("span", {
        children: text || '-'
      });
    },
    align: 'right',
    width: 100
  }, {
    title: '水耗(L)',
    dataIndex: 'water',
    key: 'water',
    render: function render(text) {
      return /*#__PURE__*/_jsx("span", {
        children: text || '-'
      });
    },
    align: 'right',
    width: 100
  }], _toConsumableArray(isUnmanned ? [] : [{
    title: '油耗(L)',
    dataIndex: 'oil',
    key: 'oil',
    render: function render(text) {
      return /*#__PURE__*/_jsx("span", {
        children: text || '-'
      });
    },
    align: 'right',
    width: 110
  }]));
  var tableProps = {
    pagination: false,
    dataSource: dailyData
  };
  var dateCellRender = function dateCellRender(value) {
    var date = dayjs(value).format('YYYY-MM-DD');
    var item = keyByDate[date];
    if (!item) {
      return null;
    }
    var completeRate = item.completeRate,
      planMileage = item.planMileage,
      workMileage = item.workMileage,
      water = item.water,
      oil = item.oil,
      electricity = item.electricity,
      transitionMileage = item.transitionMileage,
      driveMileage = item.driveMileage;
    var color = getRateColor(completeRate);
    return /*#__PURE__*/_jsxs(_Fragment, {
      children: [activeType === 'complete' && /*#__PURE__*/_jsx(VmCalendarPercent, {
        percent: completeRate,
        color: color
      }), activeType === 'complete' ? /*#__PURE__*/_jsxs(_Fragment, {
        children: [/*#__PURE__*/_jsx(VmCalendarInner, {
          type: "blue",
          img: mileageIcon,
          value: planMileage,
          style: {
            width: '139px',
            justifyContent: 'space-between',
            margin: '8px 0'
          }
        }), /*#__PURE__*/_jsx(VmCalendarInner, {
          type: "green",
          img: workMileageIcon,
          value: workMileage,
          style: {
            width: '139px',
            justifyContent: 'space-between'
          }
        })]
      }) : activeType === 'work' ? /*#__PURE__*/_jsxs(_Fragment, {
        children: [/*#__PURE__*/_jsx(VmCalendarInner, {
          type: "blue",
          img: mileageIcon,
          value: driveMileage,
          style: {
            width: '139px',
            justifyContent: 'space-between',
            margin: '8px 0'
          }
        }), /*#__PURE__*/_jsx(VmCalendarInner, {
          type: "green",
          img: transitionIcon,
          value: transitionMileage,
          style: {
            width: '139px',
            justifyContent: 'space-between'
          }
        })]
      }) : /*#__PURE__*/_jsxs(_Fragment, {
        children: [/*#__PURE__*/_jsx(VmCalendarInner, {
          type: "yellow",
          img: electricityIcon,
          value: electricity,
          style: {
            width: '139px',
            justifyContent: 'space-between',
            margin: '8px 0'
          }
        }), /*#__PURE__*/_jsx(VmCalendarInner, {
          type: "green",
          img: waterIcon,
          value: water,
          style: {
            width: '139px',
            justifyContent: 'space-between',
            margin: '8px 0'
          }
        }), !isUnmanned && /*#__PURE__*/_jsx(VmCalendarInner, {
          type: "blue",
          img: oilIcon,
          value: oil,
          style: {
            width: '139px',
            justifyContent: 'space-between'
          }
        })]
      })]
    });
  };
  return /*#__PURE__*/_jsxs(_Fragment, {
    children: [type === 'calendar' && /*#__PURE__*/_jsx("div", {
      className: 'vtx-car-static-content-type',
      children: /*#__PURE__*/_jsxs(VmTabs, {
        activeKey: activeType,
        onChange: setActiveType,
        children: [/*#__PURE__*/_jsx(TabPane, {
          tab: "\u5B8C\u6210\u7387"
        }, "complete"), isUnmanned && /*#__PURE__*/_jsx(TabPane, {
          tab: "\u8FD0\u884C"
        }, "work"), /*#__PURE__*/_jsx(TabPane, {
          tab: "\u80FD\u8017"
        }, "energy")]
      })
    }), type === 'calendar' && /*#__PURE__*/_jsxs(_Fragment, {
      children: [/*#__PURE__*/_jsxs("div", {
        className: 'vtx-car-calendar-head',
        children: [(activeType === 'complete' ? [{
          name: '排班里程（km）',
          img: mileageIcon,
          type: 'blue'
        }, {
          name: '作业里程（km）',
          img: workMileageIcon,
          type: 'green'
        }] : activeType === 'work' ? [{
          name: '行驶里程（km）',
          img: mileageIcon,
          type: 'blue'
        }, {
          name: '转场里程（km）',
          img: transitionIcon,
          type: 'yellow'
        }] : [{
          name: '电耗(Kwh)',
          img: electricityIcon,
          type: 'yellow'
        }, {
          name: '水耗(L)',
          img: waterIcon,
          type: 'green'
        }].concat(_toConsumableArray(isUnmanned ? [] : [{
          name: '油耗(L)',
          img: oilIcon,
          type: 'blue'
        }]))).map(function (item, index) {
          return /*#__PURE__*/_jsx(VmCalendarInner, _objectSpread(_objectSpread({}, item), {}, {
            value: item.name
          }), index);
        }), activeType === 'complete' && /*#__PURE__*/_jsx(RateLegend, {})]
      }), /*#__PURE__*/_jsx("div", {
        style: {
          flex: 1,
          minHeight: 0
        },
        children: /*#__PURE__*/_jsx(VmCalendar, {
          dateCellRender: dateCellRender,
          value: month,
          height: activeType === 'energy' && !isUnmanned ? 122 : 86
        })
      })]
    }), type === 'list' && /*#__PURE__*/_jsx(VmTable, _objectSpread({
      columns: BaseColumns.concat({
        title: /*#__PURE__*/_jsxs(Space, {
          children: [/*#__PURE__*/_jsx("span", {
            children: "\u5B8C\u6210\u7387"
          }), /*#__PURE__*/_jsx(Tooltip, {
            title: "\u4F5C\u4E1A\u91CC\u7A0B/\u6392\u73ED\u91CC\u7A0B",
            children: /*#__PURE__*/_jsx(QuestionCircleOutlined, {})
          })]
        }),
        dataIndex: 'completeRate',
        key: 'completeRate',
        render: function render(text) {
          return /*#__PURE__*/_jsx("span", {
            children: (text || 0) + '%'
          });
        },
        align: 'right',
        width: 100,
        fixed: 'right'
      }),
      rowKey: "id",
      indexFixed: true
    }, tableProps)), type === 'chart' && /*#__PURE__*/_jsxs(_Fragment, {
      children: [/*#__PURE__*/_jsx("div", {
        children: "\u4F5C\u4E1A\u60C5\u51B5"
      }), /*#__PURE__*/_jsx(VmBarCharts, {
        dataList: [{
          name: '排班里程',
          data: dailyData.map(function (item) {
            return "\u2000".concat(item.planMileage);
          })
        }, {
          name: '作业里程',
          data: dailyData.map(function (item) {
            return "\u2000".concat(item.workMileage);
          }),
          color: 'green'
        }].concat(_toConsumableArray(isUnmanned ? [{
          name: '行驶里程',
          data: dailyData.map(function (item) {
            return "\u2000".concat(item.driveMileage);
          }),
          color: 'blue'
        }] : [])),
        unit: '%',
        xAxis: dailyData.map(function (item) {
          return item.date;
        }),
        yAxisList: [{
          key: "\u2000",
          unit: 'km',
          name: '(km)'
        }, {
          key: '',
          unit: '%',
          name: '(%)'
        }],
        lineList: [{
          name: '完成率',
          data: dailyData.map(function (item) {
            return item.completeRate;
          }),
          yAxisIndex: 1,
          color: isDark ? '#13F97A' : '#0FB964'
        }],
        loading: loading
      }), /*#__PURE__*/_jsx("div", {
        children: "\u80FD\u8017\u60C5\u51B5"
      }), /*#__PURE__*/_jsx(VmBarCharts, {
        lineList: [{
          name: '水耗',
          data: dailyData.map(function (item) {
            return "\u2000".concat(item.water);
          }),
          color: '#FFAB0C'
        }, _defineProperty({
          name: '电耗',
          data: dailyData.map(function (item) {
            return "".concat(item.electricity);
          }),
          color: 'green',
          yAxisIndex: 1
        }, "color", '#0FB964')].concat(_toConsumableArray(isUnmanned ? [] : [{
          name: '油耗',
          data: dailyData.map(function (item) {
            return "\u2000".concat(item.oil);
          }),
          color: 'blue'
        }])),
        unit: 'kwh',
        xAxis: dailyData.map(function (item) {
          return item.date;
        }),
        yAxisList: [{
          key: "\u2000",
          unit: 'L',
          name: '(L)'
        }, {
          key: '',
          unit: 'kwh',
          name: '(kwh)'
        }],
        loading: loading
      })]
    })]
  });
}
export default Hw2StaticInfo;