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 dayjs from 'dayjs';
import { keyBy } from 'lodash';
import { useContext, useState } from 'react';
import { VmBarCharts, VmCalendar, VmCalendarInner, VmTable, VmWrapper } from "../../../../_components";
import useSettings from "../../../../_hooks/useSettings";
import { LjzyService } from "../../../api";
import lightCarNumIcon from "../../../imgs/calendar/car_num.png";
import darkCarNumIcon from "../../../imgs/calendar/dark_car_num.png";
import darkJclIcon from "../../../imgs/calendar/dark_jcl.png";
import lightJclIcon from "../../../imgs/calendar/jcl.png";
import { CarContext } from "../../../index";
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
var StaticInfo = function StaticInfo() {
  var _useSettings = useSettings(),
    isDark = _useSettings.isDark;
  var _useState = useState('calendar'),
    _useState2 = _slicedToArray(_useState, 2),
    type = _useState2[0],
    setType = _useState2[1];
  var _useContext = useContext(CarContext),
    id = _useContext.id,
    info = _useContext.info;
  var _useState3 = useState(dayjs()),
    _useState4 = _slicedToArray(_useState3, 2),
    month = _useState4[0],
    setMonth = _useState4[1];
  var _LjzyService$useGetCa = LjzyService.useGetCarSumByDateAndDisposeUnit({
      carCode: info === null || info === void 0 ? void 0 : info.carCode,
      startDate: month.startOf('M').format('YYYY-MM-DD'),
      endDate: dayjs().isSame(month, 'month') ? dayjs().format('YYYY-MM-DD') : month.endOf('M').format('YYYY-MM-DD')
    }),
    taskDaySummary = _LjzyService$useGetCa.taskDaySummary,
    loading = _LjzyService$useGetCa.loading;
  var keyByDate = keyBy(taskDaySummary || [], 'date');
  var carNumIcon = lightCarNumIcon;
  var jclIcon = lightJclIcon;
  if (isDark) {
    carNumIcon = darkCarNumIcon;
    jclIcon = darkJclIcon;
  }
  var columns = [{
    title: '作业日期',
    dataIndex: 'date',
    key: 'date',
    sorter: function sorter(a, b) {
      return a.date > b.date ? 1 : -1;
    }
  }, {
    title: '处置终端',
    dataIndex: 'disposeUnitName',
    key: 'disposeUnitName',
    render: function render(text) {
      return /*#__PURE__*/_jsx("span", {
        children: text !== null && text !== void 0 ? text : '-'
      });
    }
  }, {
    title: '进场车次（次）',
    dataIndex: 'carNums',
    key: 'carNums',
    align: 'right',
    render: function render(text) {
      return /*#__PURE__*/_jsx("span", {
        children: text !== null && text !== void 0 ? text : '-'
      });
    }
  }, {
    title: '进场量（吨）',
    dataIndex: 'netWeight',
    key: 'netWeight',
    align: 'right',
    render: function render(text) {
      return /*#__PURE__*/_jsx("span", {
        children: text !== null && text !== void 0 ? text : '-'
      });
    }
  }];
  var tableProps = {
    pagination: false,
    dataSource: _.orderBy(taskDaySummary, 'date', 'desc')
  };
  var dateCellRender = function dateCellRender(value) {
    var date = dayjs(value).format('YYYY-MM-DD');
    var item = keyByDate[date];
    if (!item) {
      return null;
    }
    var netWeight = item.netWeight,
      carNums = item.carNums;
    return /*#__PURE__*/_jsxs(_Fragment, {
      children: [/*#__PURE__*/_jsx(VmCalendarInner, {
        type: "blue",
        img: jclIcon,
        value: carNums,
        style: {
          width: '139px',
          justifyContent: 'space-between',
          margin: '8px 0'
        }
      }), /*#__PURE__*/_jsx(VmCalendarInner, {
        type: "green",
        img: carNumIcon,
        value: netWeight,
        style: {
          width: '139px',
          justifyContent: 'space-between',
          margin: '8px 0'
        }
      })]
    });
  };
  return /*#__PURE__*/_jsxs(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: [type === 'calendar' && /*#__PURE__*/_jsxs(_Fragment, {
      children: [/*#__PURE__*/_jsx("div", {
        className: 'vtx-car-calendar-head',
        children: [{
          name: '进场量(吨)',
          img: jclIcon,
          type: 'blue'
        }, {
          name: '进场车次',
          img: carNumIcon,
          type: 'green'
        }].map(function (item, index) {
          return /*#__PURE__*/_jsx(VmCalendarInner, _objectSpread(_objectSpread({}, item), {}, {
            value: item.name
          }), index);
        })
      }), /*#__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__*/_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 StaticInfo;