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 { useSetState } from 'ahooks';
import dayjs from 'dayjs';
import { VmCalendar, VmCalendarInner, VmWrapper } from "../../../_components";
import useSettings from "../../../_hooks/useSettings";
import { BaseService, CalendarService } from "../../api";
import blockA from "../../../_imgs/block_alarm.png";
import blockN from "../../../_imgs/block_normal.png";
import car from "../../imgs/c_car.png";
import jcl from "../../imgs/c_jcl.png";
import "./index.less";
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
var Charts = function Charts(_ref) {
  var code = _ref.code;
  var _useSettings = useSettings(),
    isDark = _useSettings.isDark;
  var _useSetState = useSetState({
      date: dayjs(),
      data: []
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var date = state.date;
  var _CalendarService$useF = CalendarService.useFetchData(code, date.startOf('M').format('YYYY-MM-DD'), date.endOf('M').format('YYYY-MM-DD')),
    data1 = _CalendarService$useF.data1;
  var _CalendarService$useF2 = CalendarService.useFetchData2(code, date.startOf('M').format('YYYY-MM-DD 00:00:00'), date.endOf('M').format('YYYY-MM-DD 23:59:59')),
    data2 = _CalendarService$useF2.data2;
  var _BaseService$useSitua = BaseService.useSituationSummary(code, date.format('YYYY-MM-DD'), date.format('YYYY-MM-DD')),
    situationRes = _BaseService$useSitua.situationRes;
  var dateCellRender = function dateCellRender(value) {
    var _data2$filter;
    var obj1 = (data1 === null || data1 === void 0 ? void 0 : data1.find(function (ele) {
      return ele.date === value.format('YYYY-MM-DD');
    })) || {}; // carNums、netWeight
    var obj2 = (data2 === null || data2 === void 0 || (_data2$filter = data2.filter(function (ele) {
      return !dayjs(ele.date).isAfter(dayjs(), 'day');
    }) // 筛选出当前日期之前的数据
    ) === null || _data2$filter === void 0 ? void 0 : _data2$filter.find(function (ele) {
      return ele.date === value.format('YYYY-MM-DD');
    })) || {}; // alarmNum、beenNormal
    var hasLm = (obj1 === null || obj1 === void 0 ? void 0 : obj1.netWeight) > 0;
    var isOverWeight = (obj1 === null || obj1 === void 0 ? void 0 : obj1.netWeight) / 1000 > (situationRes === null || situationRes === void 0 ? void 0 : situationRes.handleAbility); // 进厂量是否超过设计能力
    var isNormal = obj2 === null || obj2 === void 0 ? void 0 : obj2.beenNormal;
    var showTip = Object.prototype.hasOwnProperty.call(obj2, 'beenNormal');
    return /*#__PURE__*/_jsxs("div", {
      className: "df-calendar-cell",
      children: [!!data2 && /*#__PURE__*/_jsxs("div", {
        className: "df-calendar-cell-head",
        style: {
          color: isNormal ? '#0FB964' : '#F5222D',
          top: hasLm ? '-30px' : '-22px'
        },
        children: [showTip && /*#__PURE__*/_jsx("img", {
          src: isNormal ? blockN : blockA
        }), showTip ? isNormal ? '正常' : '异常' : '']
      }), hasLm && /*#__PURE__*/_jsxs(_Fragment, {
        children: [/*#__PURE__*/_jsx(VmCalendarInner, {
          type: "blue",
          img: jcl,
          isAlarm: isOverWeight,
          value: (((obj1 === null || obj1 === void 0 ? void 0 : obj1.netWeight) || 0) / 1000).toFixed(2),
          style: {
            width: '139px',
            justifyContent: 'space-between',
            margin: '8px 0',
            color: '#0FB964'
          }
        }), /*#__PURE__*/_jsx(VmCalendarInner, {
          type: "green",
          img: car,
          value: (obj1 === null || obj1 === void 0 ? void 0 : obj1.carNums) || 0,
          style: {
            width: '139px',
            justifyContent: 'space-between'
          }
        })]
      })]
    });
  };
  return /*#__PURE__*/_jsx("div", {
    className: "df-calendar ".concat(isDark ? 'dark' : ''),
    children: /*#__PURE__*/_jsxs(VmWrapper, {
      title: "\u8FD0\u884C\u603B\u89C8",
      needChange: false,
      filterType: "monthPicker",
      dateValue: date,
      filterChange: function filterChange(dates) {
        return dates && setState({
          date: dates
        });
      },
      disabledDate: function disabledDate(current) {
        return current && current > dayjs().endOf('M');
      },
      contentStyle: {
        marginBottom: 16,
        height: '440px'
      },
      children: [/*#__PURE__*/_jsx("div", {
        className: "df-calendar-head",
        children: [{
          name: '进场量(吨)',
          img: jcl,
          type: 'blue'
        }, {
          name: '车次',
          img: car,
          type: 'green'
        }, {
          name: '工况正常',
          imgType: 'normal'
        }, {
          name: '工况异常',
          imgType: 'alarm'
        }].map(function (item, index) {
          return /*#__PURE__*/_jsx(VmCalendarInner, _objectSpread(_objectSpread({}, item), {}, {
            value: item.name
          }), index);
        })
      }), /*#__PURE__*/_jsx("div", {
        className: "df-calendar-content",
        children: /*#__PURE__*/_jsx(VmCalendar, {
          dateCellRender: dateCellRender,
          value: date
        })
      })]
    })
  });
};
export default Charts;