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 _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 _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 _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 _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; }
import { QuestionCircleOutlined } from '@ant-design/icons';
import { JxhService } from "../../../api";
import { Space, Tooltip } from 'antd';
import dayjs from 'dayjs';
import { keyBy } from 'lodash';
import { VmBarCharts, VmCalendar, VmCalendarInner, VmCalendarPercent, VmTable } from "../../../../_components";
import useSettings from "../../../../_hooks/useSettings";
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
var butter_dark = require("../../../imgs/butter_dark.png");
var butter = require("../../../imgs/butter.png");
var water_dark = require("../../../imgs/water_dark.png");
var water = require("../../../imgs/water.png");
var track_dark = require("../../../imgs/track_dark.png");
var track = require("../../../imgs/track.png");
export default function (_ref) {
  var id = _ref.id,
    month = _ref.month,
    type = _ref.type,
    legend = _ref.legend,
    getRateColor = _ref.getRateColor,
    _ref$baseColumns = _ref.baseColumns,
    baseColumns = _ref$baseColumns === void 0 ? [] : _ref$baseColumns;
  var _useSettings = useSettings(),
    isDark = _useSettings.isDark,
    chartFontColor = _useSettings.chartFontColor;
  var _JxhService$useCarWor = JxhService.useCarWorkDailyReport(id, month.startOf('M').format('YYYY-MM-DD'), month.endOf('M').format('YYYY-MM-DD')),
    _JxhService$useCarWor2 = _JxhService$useCarWor.dailyData,
    dailyData = _JxhService$useCarWor2 === void 0 ? [] : _JxhService$useCarWor2,
    loading = _JxhService$useCarWor.loading;
  var keyByDate = keyBy(dailyData || [], 'workDate');
  console.log(keyByDate);
  var dateCellRender = function dateCellRender(value) {
    var date = dayjs(value).format('YYYY-MM-DD');
    var item = keyByDate[date];
    if (!item) {
      return null;
    }
    // let percent = 50;
    var color = getRateColor(item.percent);
    return /*#__PURE__*/_jsxs(_Fragment, {
      children: [/*#__PURE__*/_jsx(VmCalendarPercent, {
        percent: item.percent,
        color: color
      }), /*#__PURE__*/_jsx(VmCalendarInner, {
        type: "blue",
        img: isDark ? track_dark : track,
        value: "".concat((item === null || item === void 0 ? void 0 : item.workMileage) || 0, "/").concat((item === null || item === void 0 ? void 0 : item.driveMileage) || 0),
        style: {
          width: '139px',
          justifyContent: 'space-between',
          margin: '4px 0'
        }
      }), /*#__PURE__*/_jsx(VmCalendarInner, {
        type: "yellow",
        img: isDark ? butter_dark : butter,
        value: (item === null || item === void 0 ? void 0 : item.electricityExpendTotal) || 0,
        style: {
          width: '139px',
          justifyContent: 'space-between',
          margin: '4px 0'
        }
      }), /*#__PURE__*/_jsx(VmCalendarInner, {
        type: "green",
        img: isDark ? water_dark : water,
        value: (item === null || item === void 0 ? void 0 : item.waterExpendTotal) || 0,
        style: {
          width: '139px',
          justifyContent: 'space-between'
        }
      })]
    });
  };
  var tableProps = {
    pagination: false,
    dataSource: []
  };
  var columns = [].concat(_toConsumableArray(baseColumns), [{
    title: /*#__PURE__*/_jsxs(Space, {
      children: [/*#__PURE__*/_jsx("span", {
        children: "\u5B8C\u6210\u7387"
      }), /*#__PURE__*/_jsx(Tooltip, {
        title: "\u6838\u7B97\u4F5C\u4E1A\u91CC\u7A0B/\u884C\u9A76\u91CC\u7A0B",
        children: /*#__PURE__*/_jsx(QuestionCircleOutlined, {})
      })]
    }),
    dataIndex: 'percent',
    key: 'percent',
    render: function render(text) {
      return /*#__PURE__*/_jsx("span", {
        children: (text || 0) + '%'
      });
    },
    align: 'right',
    width: 100
  }, {
    title: '总电耗(kwh)',
    dataIndex: 'butter',
    key: 'butter',
    align: 'right',
    width: 100
  }, {
    title: '总水耗(L)',
    dataIndex: 'water',
    key: 'water',
    align: 'right',
    width: 100
  }]);
  return /*#__PURE__*/_jsxs(_Fragment, {
    children: [type === 'calendar' && /*#__PURE__*/_jsxs(_Fragment, {
      children: [/*#__PURE__*/_jsxs("div", {
        className: 'vtx-car-calendar-head',
        children: [[{
          name: '总电耗（kwh）',
          img: isDark ? butter_dark : butter,
          type: 'yellow'
        }, {
          name: '总水耗（L）',
          img: isDark ? water_dark : water,
          type: 'green'
        }, {
          name: '核算作业里程/行驶里程（km）',
          img: isDark ? track_dark : track,
          type: 'blue'
        }].map(function (item, index) {
          return /*#__PURE__*/_jsx(VmCalendarInner, _objectSpread(_objectSpread({}, item), {}, {
            value: item.name
          }), index);
        }), legend]
      }), /*#__PURE__*/_jsx("div", {
        style: {
          flex: 1,
          minHeight: 0
        },
        children: /*#__PURE__*/_jsx(VmCalendar, {
          dateCellRender: dateCellRender,
          value: month
        })
      })]
    }), type === 'list' && /*#__PURE__*/_jsx(VmTable, _objectSpread({
      columns: columns,
      rowKey: "id"
    }, tableProps)), type === 'chart' && /*#__PURE__*/_jsxs(_Fragment, {
      children: [/*#__PURE__*/_jsx("div", {
        style: {
          height: '50%'
        },
        children: /*#__PURE__*/_jsx(VmBarCharts, {
          dataList: [{
            name: '规划里程',
            data: [20, 50, 63, 51, 23],
            yAxisIndex: 0,
            color: 'geekblue'
          }, {
            name: '核算作业里程',
            data: [20, 50, 63, 51, 23],
            yAxisIndex: 0,
            color: 'green'
          }, {
            name: '行驶里程',
            data: [20, 50, 63, 51, 23],
            yAxisIndex: 0,
            color: 'blue'
          }],
          lineList: [{
            name: '完成率',
            data: [2, 2, 4, 1, 5],
            yAxisIndex: 1,
            color: '#0FB964'
          }],
          xAxis: ['2025-01', '2025-02', '2025-03', '2025-04', '2025-05'],
          yAxisList: [{
            unit: 'km',
            name: '(km)'
          }, {
            unit: '%',
            name: '(%)'
          }],
          otherProps: {
            title: {
              top: 0,
              left: 0,
              text: '作业情况',
              textStyle: {
                fontSize: 14,
                color: chartFontColor,
                fontWeight: 400
              }
            }
          },
          tooltipProps: {
            formatter: function formatter(params) {
              var _params$;
              var html = '';
              params === null || params === void 0 || params.forEach(function (item) {
                html += "".concat(item.marker, "<div style=\"min-width: 120px;display: inline-block;line-height: 26px;\">").concat(item.seriesName, "</div><span style=\"font-weight: 600;text-align: right;\">").concat(item.value).concat(item.seriesName === '完成率' ? '%' : 'km', "</span><br/>");
              });
              return html ? "".concat(params === null || params === void 0 || (_params$ = params[0]) === null || _params$ === void 0 ? void 0 : _params$.axisValue, "<br/>").concat(html) : '';
            }
          }
        })
      }), /*#__PURE__*/_jsx("div", {
        style: {
          height: '50%'
        },
        children: /*#__PURE__*/_jsx(VmBarCharts, {
          lineList: [{
            name: '平均电量消耗',
            data: [2, 2, 4, 1, 5],
            yAxisIndex: 0,
            color: '#FFAB0C'
          }, {
            name: '平均水量消耗',
            data: [20, 50, 63, 51, 23],
            yAxisIndex: 1,
            color: '#0FB964'
          }],
          xAxis: [1, 2, 3, 4, 5],
          yAxisList: [{
            unit: 'kwh',
            name: '(kwh)'
          }, {
            unit: 'L',
            name: '(L)'
          }],
          otherProps: {
            title: {
              top: 0,
              left: 0,
              text: '能耗情况',
              textStyle: {
                fontSize: 14,
                color: chartFontColor,
                fontWeight: 400
              }
            }
          },
          tooltipProps: {
            formatter: function formatter(params) {
              var _params$2;
              var html = '';
              params === null || params === void 0 || params.forEach(function (item) {
                html += "".concat(item.marker, "<div style=\"min-width: 120px;display: inline-block;line-height: 26px;\">").concat(item.seriesName, "</div><span style=\"font-weight: 600;text-align: right;\">").concat(item.value).concat(item.seriesName === '平均水量消耗' ? 'L' : 'kwh', "</span><br/>");
              });
              return html ? "".concat(params === null || params === void 0 || (_params$2 = params[0]) === null || _params$2 === void 0 ? void 0 : _params$2.axisValue, "<br/>").concat(html) : '';
            }
          }
        })
      })]
    })]
  });
}