"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 _zh_CN = _interopRequireDefault(require("antd/lib/calendar/locale/zh_CN.js"));
var _util = require("../../../util");
var _calendarMile = _interopRequireDefault(require("../../imgs/calendar-mile.png"));
var _calendarHour = _interopRequireDefault(require("../../imgs/calendar-hour.png"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
var Charts = function Charts(_ref) {
  var data = _ref.data,
    onTdClick = _ref.onTdClick,
    onCancel = _ref.onCancel,
    date = _ref.date,
    theme = _ref.theme;
  var getListData = function getListData(value) {
    var listData;
    if ((data === null || data === void 0 ? void 0 : data.length) > 0) {
      var list = data.map(function (ele) {
        return {
          reportDate: ele.reportDate ? (0, _moment["default"])(ele.reportDate).valueOf() : '',
          sumMileage: ele.sumMileage,
          driveDuration: (0, _util.secondToFormatTime)((ele === null || ele === void 0 ? void 0 : ele.driveDuration) / 1000 || 0)
        };
      });
      var obj = list.find(function (ele) {
        return ele.reportDate === (0, _moment["default"])(value.format('YYYY-MM-DD')).valueOf();
      });
      if ((obj === null || obj === void 0 ? void 0 : obj.sumMileage) > 0) {
        listData = {
          sumMileage: "".concat(obj.sumMileage, "km"),
          driveDuration: obj.driveDuration,
          reportDate: obj.reportDate
        };
      }
    }
    return listData || {};
  };
  var dateCellRender = function dateCellRender(value) {
    var listData = getListData(value);
    return /*#__PURE__*/_react["default"].createElement("div", {
      className: "car-calendar",
      style: {
        background: (listData === null || listData === void 0 ? void 0 : listData.sumMileage) ? theme === 'blue' ? 'linear-gradient( 180deg, rgba(0,144,255,0.5) 0%, rgba(0,144,255,0) 100%)' : 'linear-gradient(180deg, rgba(115, 255, 191, 0.8), rgba(0,0,0,0.1))' : 'transparent'
      },
      onClick: function onClick() {
        if (onTdClick) {
          try {
            onCancel && onCancel();
            onTdClick(value.format('YYYY-MM-DD'));
          } catch (error) {
            //
          }
        }
      }
    }, (listData === null || listData === void 0 ? void 0 : listData.sumMileage) && (/*#__PURE__*/_react["default"].createElement("div", {
      className: "car-calendar-item"
    }, /*#__PURE__*/_react["default"].createElement("img", {
      src: _calendarMile["default"]
    }), /*#__PURE__*/_react["default"].createElement("div", null, listData === null || listData === void 0 ? void 0 : listData.sumMileage))), (listData === null || listData === void 0 ? void 0 : listData.driveDuration) && (/*#__PURE__*/_react["default"].createElement("div", {
      className: "car-calendar-item"
    }, /*#__PURE__*/_react["default"].createElement("img", {
      src: _calendarHour["default"]
    }), /*#__PURE__*/_react["default"].createElement("div", null, listData === null || listData === void 0 ? void 0 : listData.driveDuration))));
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "car-alarm-charts"
  }, /*#__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=Charts.js.map
