"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var echarts = _interopRequireWildcard(require("echarts"));
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
var _vmCharts = require("../../../vm-charts");
var _api = require("../../api");
var _vmSubTitle = _interopRequireDefault(require("../../../vm-sub-title"));
var _vmButton = _interopRequireDefault(require("../../../vm-button"));
var _moment = _interopRequireDefault(require("moment"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
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(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0) { ; } } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
var GarbageType;
(function (GarbageType) {
  GarbageType["KEHUISHOU"] = "\u53EF\u56DE\u6536\u7269";
  GarbageType["CHUYU"] = "\u53A8\u4F59\u5783\u573E";
  GarbageType["QITA"] = "\u5176\u4ED6\u5783\u573E";
  GarbageType["YOUHAI"] = "\u6709\u5BB3\u5783\u573E";
})(GarbageType || (GarbageType = {}));
var GarbageTypeColor;
(function (GarbageTypeColor) {
  GarbageTypeColor["KEHUISHOU"] = "#6BB8FF";
  GarbageTypeColor["CHUYU"] = "#46DA91";
  GarbageTypeColor["QITA"] = "#C4C4C4";
  GarbageTypeColor["YOUHAI"] = "#FF8288";
})(GarbageTypeColor || (GarbageTypeColor = {}));
var GarbageSummary = function GarbageSummary(_ref) {
  var type = _ref.type,
    data = _ref.data;
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
  var imgSrc = '',
    bucketSrc = '',
    bgSrc = '',
    color = '',
    count = 0,
    weight = 0;
  switch (type) {
    case GarbageType.KEHUISHOU:
      imgSrc = require('../../imgs/khsw.png');
      bucketSrc = require('../../imgs/bucket-khsw.png');
      bgSrc = require('../../imgs/khsw-bg.png');
      color = GarbageTypeColor.KEHUISHOU;
      count = ((_b = (_a = data === null || data === void 0 ? void 0 : data.find) === null || _a === void 0 ? void 0 : _a.call(data, function (item) {
        return item.garbageTypeCode === 'KEHUISHOU';
      })) === null || _b === void 0 ? void 0 : _b.throwCount) || 0;
      weight = ((_d = (_c = data === null || data === void 0 ? void 0 : data.find) === null || _c === void 0 ? void 0 : _c.call(data, function (item) {
        return item.garbageTypeCode === 'KEHUISHOU';
      })) === null || _d === void 0 ? void 0 : _d.weight) || 0;
      break;
    case GarbageType.CHUYU:
      imgSrc = require('../../imgs/cylj.png');
      bucketSrc = require('../../imgs/bucket-cylj.png');
      bgSrc = require('../../imgs/cylj-bg.png');
      color = GarbageTypeColor.CHUYU;
      count = ((_f = (_e = data === null || data === void 0 ? void 0 : data.find) === null || _e === void 0 ? void 0 : _e.call(data, function (item) {
        return item.garbageTypeCode === 'CHUYU';
      })) === null || _f === void 0 ? void 0 : _f.throwCount) || 0;
      weight = ((_h = (_g = data === null || data === void 0 ? void 0 : data.find) === null || _g === void 0 ? void 0 : _g.call(data, function (item) {
        return item.garbageTypeCode === 'CHUYU';
      })) === null || _h === void 0 ? void 0 : _h.weight) || 0;
      break;
    case GarbageType.QITA:
      imgSrc = require('../../imgs/qtlj.png');
      bucketSrc = require('../../imgs/bucket-qtlj.png');
      bgSrc = require('../../imgs/qtlj-bg.png');
      color = GarbageTypeColor.QITA;
      count = ((_k = (_j = data === null || data === void 0 ? void 0 : data.find) === null || _j === void 0 ? void 0 : _j.call(data, function (item) {
        return item.garbageTypeCode === 'QITA';
      })) === null || _k === void 0 ? void 0 : _k.throwCount) || 0;
      weight = ((_m = (_l = data === null || data === void 0 ? void 0 : data.find) === null || _l === void 0 ? void 0 : _l.call(data, function (item) {
        return item.garbageTypeCode === 'QITA';
      })) === null || _m === void 0 ? void 0 : _m.weight) || 0;
      break;
    case GarbageType.YOUHAI:
      imgSrc = require('../../imgs/yhlj.png');
      bucketSrc = require('../../imgs/bucket-yhlj.png');
      bgSrc = require('../../imgs/yhlj-bg.png');
      color = GarbageTypeColor.YOUHAI;
      count = ((_p = (_o = data === null || data === void 0 ? void 0 : data.find) === null || _o === void 0 ? void 0 : _o.call(data, function (item) {
        return item.garbageTypeCode === 'YOUHAI';
      })) === null || _p === void 0 ? void 0 : _p.throwCount) || 0;
      weight = ((_r = (_q = data === null || data === void 0 ? void 0 : data.find) === null || _q === void 0 ? void 0 : _q.call(data, function (item) {
        return item.garbageTypeCode === 'YOUHAI';
      })) === null || _r === void 0 ? void 0 : _r.weight) || 0;
      break;
    default:
      break;
  }
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "garbage-summary",
    style: {
      background: "url(".concat(bgSrc, ")")
    }
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "garbage-summary-bucket",
    style: {
      background: "url(".concat(bucketSrc, ")")
    }
  }, /*#__PURE__*/_react["default"].createElement("img", {
    src: imgSrc
  })), /*#__PURE__*/_react["default"].createElement("p", {
    style: {
      color: color
    }
  }, type), /*#__PURE__*/_react["default"].createElement("p", null, /*#__PURE__*/_react["default"].createElement("span", null, count !== null && count !== void 0 ? count : 0), "\u6B21"), /*#__PURE__*/_react["default"].createElement("p", null, /*#__PURE__*/_react["default"].createElement("span", null, weight !== null && weight !== void 0 ? weight : 0), "kg"));
};
function getBarOption(data) {
  var _a, _b, _c;
  var arr = (_a = data === null || data === void 0 ? void 0 : data.filter) === null || _a === void 0 ? void 0 : _a.call(data, function (item) {
    return item.day === (0, _moment["default"])().format('YYYY-MM-DD');
  });
  return {
    tooltip: {
      trigger: 'item'
    },
    legend: {
      top: 0,
      left: 'center',
      textStyle: {
        color: '#fff'
      }
    },
    grid: {
      top: 40,
      left: 30,
      right: 0,
      bottom: 50
    },
    xAxis: {
      data: (_b = arr === null || arr === void 0 ? void 0 : arr.map) === null || _b === void 0 ? void 0 : _b.call(arr, function (item) {
        return item.throwPointName;
      }),
      axisLabel: {
        color: '#DAF1FF',
        interval: 0
      },
      axisTick: {
        show: false
      },
      axisLine: {
        show: false
      },
      z: 10
    },
    yAxis: {
      name: '单位：次',
      nameTextStyle: {
        color: '#fff'
      },
      axisLine: {
        show: false
      },
      axisTick: {
        show: false
      },
      axisLabel: {
        color: '#fff'
      },
      splitLine: {
        lineStyle: {
          type: 'dashed',
          color: 'rgba(255,255,255,0.2)'
        }
      }
    },
    series: [{
      name: '',
      type: 'bar',
      barWidth: 12,
      itemStyle: {
        normal: {
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
            offset: 0,
            color: '#51F2FF'
          }, {
            offset: 1,
            color: '#1B89FF'
          }]),
          label: {
            show: true,
            position: 'top',
            textStyle: {
              color: '#56FCFF'
            }
          }
        }
      },
      data: (_c = arr === null || arr === void 0 ? void 0 : arr.map) === null || _c === void 0 ? void 0 : _c.call(arr, function (item) {
        return item.throwCount;
      })
    }]
  };
}
function getDistributeChartData(data) {
  return data.filter(function (item) {
    return item.date;
  }).map(function (item) {
    var _split = (item.date || '').split(' '),
      _split2 = _slicedToArray(_split, 2),
      date = _split2[0],
      hour = _split2[1];
    return {
      date: date,
      hour: hour,
      value: item.throwCount || 0
    };
  });
}
var Left = function Left(_ref2) {
  var classPrefix = _ref2.classPrefix,
    id = _ref2.id;
  var _useState = (0, _react.useState)('point'),
    _useState2 = _slicedToArray(_useState, 2),
    chartType = _useState2[0],
    setChartType = _useState2[1];
  var sumByGarbageType = _api.overViewService.throwSumByGarbageType({
    housingEstateId: id
  });
  var sumByPoint = _api.overViewService.throwSumByDayAndPoint({
    housingEstateId: id
  });
  var sumByHour = _api.overViewService.throwSumByHour({
    housingEstateId: id
  });
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(classPrefix, "-hot")
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTitle["default"], {
    title: "\u6295\u653E\u70ED\u5EA6"
  }), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(classPrefix, "-hot-summary")
  }, /*#__PURE__*/_react["default"].createElement(GarbageSummary, {
    type: GarbageType.KEHUISHOU,
    data: sumByGarbageType
  }), /*#__PURE__*/_react["default"].createElement(GarbageSummary, {
    type: GarbageType.CHUYU,
    data: sumByGarbageType
  }), /*#__PURE__*/_react["default"].createElement(GarbageSummary, {
    type: GarbageType.QITA,
    data: sumByGarbageType
  }), /*#__PURE__*/_react["default"].createElement(GarbageSummary, {
    type: GarbageType.YOUHAI,
    data: sumByGarbageType
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(classPrefix, "-hot-buttons")
  }, /*#__PURE__*/_react["default"].createElement(_vmButton["default"], {
    onClick: function onClick() {
      return setChartType('point');
    },
    name: "\u70B9\u4F4D\u5206\u5E03",
    style: {
      marginRight: 10
    },
    active: chartType === 'point'
  }), /*#__PURE__*/_react["default"].createElement(_vmButton["default"], {
    onClick: function onClick() {
      return setChartType('hour');
    },
    name: "24h\u5206\u5E03",
    active: chartType === 'hour'
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(classPrefix, "-hot-chart")
  }, chartType === 'point' && /*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    option: getBarOption(sumByPoint || []),
    style: {
      height: '100%',
      width: '100%'
    }
  }), chartType === 'hour' && /*#__PURE__*/_react["default"].createElement(_vmCharts.Distribute1, {
    data: getDistributeChartData(sumByHour || [])
  })));
};
var _default = Left;
exports["default"] = _default;
//# sourceMappingURL=Hot.js.map
