"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _antd = require("antd");
var _moment = _interopRequireDefault(require("moment"));
require("moment/locale/zh-cn");
var _ahooks = require("ahooks");
var _zh_CN = _interopRequireDefault(require("antd/lib/calendar/locale/zh_CN.js"));
var _vmFilter = require("../../../vm-filter");
var _useSettings2 = _interopRequireDefault(require("../../../vm-hooks/useSettings"));
var _vmWrapper = _interopRequireDefault(require("../../../vm-wrapper"));
var _api = require("../../api");
require("./index.less");
var _c_jcl = _interopRequireDefault(require("../../imgs/c_jcl.png"));
var _c_car = _interopRequireDefault(require("../../imgs/c_car.png"));
var _block_normal = _interopRequireDefault(require("../../imgs/block_normal.png"));
var _block_alarm = _interopRequireDefault(require("../../imgs/block_alarm.png"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _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(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
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(r) { if (Array.isArray(r)) return r; }
var Charts = function Charts(_ref) {
  var code = _ref.code;
  var _useSettings = (0, _useSettings2["default"])(),
    isDark = _useSettings.isDark;
  var _useSetState = (0, _ahooks.useSetState)({
      date: (0, _moment["default"])(),
      data: []
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var date = state.date;
  var _CalendarService$useF = _api.CalendarService.useFetchData(code, (0, _moment["default"])(date).startOf('M').format('YYYY-MM-DD'), (0, _moment["default"])(date).endOf('M').format('YYYY-MM-DD')),
    data1 = _CalendarService$useF.data1;
  var _CalendarService$useF2 = _api.CalendarService.useFetchData2(code, (0, _moment["default"])(date).startOf('M').format('YYYY-MM-DD 00:00:00'), (0, _moment["default"])(date).endOf('M').format('YYYY-MM-DD 23:59:59')),
    data2 = _CalendarService$useF2.data2;
  var _BaseService$useSitua = _api.BaseService.useSituationSummary(code, (0, _moment["default"])(date).format('YYYY-MM-DD'), (0, _moment["default"])(date).format('YYYY-MM-DD')),
    situationRes = _BaseService$useSitua.situationRes;
  var dateCellRender = function dateCellRender(value) {
    var _a;
    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 = ((_a = data2 === null || data2 === void 0 ? void 0 : data2.filter(function (ele) {
      return !(0, _moment["default"])(ele.date).isAfter((0, _moment["default"])(), 'day');
    }) // 筛选出当前日期之前的数据
    ) === null || _a === void 0 ? void 0 : _a.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__*/_react["default"].createElement("div", {
      className: "df-calendar-cell"
    }, !!data2 && (/*#__PURE__*/_react["default"].createElement("div", {
      className: "df-calendar-cell-head",
      style: {
        color: isNormal ? '#0FB964' : '#F5222D',
        top: hasLm ? '-30px' : '-22px'
      }
    }, showTip && /*#__PURE__*/_react["default"].createElement("img", {
      src: isNormal ? _block_normal["default"] : _block_alarm["default"]
    }), showTip ? isNormal ? '正常' : '异常' : '')), hasLm && (/*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
      className: "df-calendar-head-item blueBg",
      style: {
        width: '139px',
        justifyContent: 'space-between',
        margin: '8px 0',
        color: '#0FB964'
      }
    }, /*#__PURE__*/_react["default"].createElement("img", {
      src: _c_jcl["default"]
    }), /*#__PURE__*/_react["default"].createElement("div", {
      style: isOverWeight ? {
        color: '#F5222D'
      } : {}
    }, ((obj1 === null || obj1 === void 0 ? void 0 : obj1.netWeight) / 1000).toFixed(2))), /*#__PURE__*/_react["default"].createElement("div", {
      className: "df-calendar-head-item greenBg",
      style: {
        width: '139px',
        justifyContent: 'space-between'
      }
    }, /*#__PURE__*/_react["default"].createElement("img", {
      src: _c_car["default"]
    }), /*#__PURE__*/_react["default"].createElement("div", null, obj1 === null || obj1 === void 0 ? void 0 : obj1.carNums)))));
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "df-calendar ".concat(isDark ? 'dark' : '')
  }, /*#__PURE__*/_react["default"].createElement(_vmWrapper["default"], {
    title: "\u8FD0\u884C\u603B\u89C8",
    needChange: false,
    extra: /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_vmFilter.VMMonthPicker, {
      value: (0, _moment["default"])(date),
      onChange: function onChange(dates) {
        return dates && setState({
          date: dates
        });
      },
      disabledDate: function disabledDate(current) {
        return current && current > (0, _moment["default"])().endOf('M');
      }
    }))
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "df-calendar-head"
  }, [{
    name: '进场量(吨)',
    img: _c_jcl["default"],
    className: 'blueBg'
  }, {
    name: '车次',
    img: _c_car["default"],
    className: 'greenBg'
  }, {
    name: '工况正常',
    img: _block_normal["default"]
  }, {
    name: '工况异常',
    img: _block_alarm["default"]
  }].map(function (item, index) {
    return /*#__PURE__*/_react["default"].createElement("div", {
      className: "df-calendar-head-item ".concat(item.className),
      key: index
    }, /*#__PURE__*/_react["default"].createElement("img", {
      src: item.img
    }), /*#__PURE__*/_react["default"].createElement("div", null, item.name));
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "df-calendar-content"
  }, /*#__PURE__*/_react["default"].createElement(_antd.Calendar, {
    headerRender: function headerRender() {
      return null;
    },
    dateCellRender: dateCellRender,
    locale: _zh_CN["default"],
    value: date
  }))));
};
var _default = exports["default"] = Charts;
//# sourceMappingURL=index.js.map
