"use strict";

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); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
exports.getDistributeChartData = getDistributeChartData;
var _react = _interopRequireWildcard(require("react"));
var echarts = _interopRequireWildcard(require("echarts"));
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
var _components = require("@vtx/components");
var _utils = require("@vtx/utils");
var _vmCharts = require("../../../vm-charts");
var _api = require("../../api");
var _vmSubTitle = _interopRequireDefault(require("../../../vm-sub-title"));
var _vmButton = _interopRequireDefault(require("../../../vm-button"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
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 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,
    garbageIcons = _ref.garbageIcons;
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7;
  var imgSrc = '',
    bucketSrc = '',
    bgSrc = '',
    color = '',
    count = 0,
    weight = 0,
    title = '';
  switch (type) {
    case GarbageType.KEHUISHOU:
      imgSrc = (_c = (_b = JSON.parse(((_a = garbageIcons === null || garbageIcons === void 0 ? void 0 : garbageIcons.find(function (ele) {
        return ele.code === 'KEHUISHOU';
      })) === null || _a === void 0 ? void 0 : _a.kanbanIcon) || '[]')) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.id;
      bucketSrc = require('../../imgs/bucket-khsw.png');
      bgSrc = require('../../imgs/khsw-bg.png');
      color = GarbageTypeColor.KEHUISHOU;
      count = ((_e = (_d = data === null || data === void 0 ? void 0 : data.find) === null || _d === void 0 ? void 0 : _d.call(data, function (item) {
        return item.garbageTypeCode === 'KEHUISHOU';
      })) === null || _e === void 0 ? void 0 : _e.throwCount) || 0;
      weight = ((_g = (_f = data === null || data === void 0 ? void 0 : data.find) === null || _f === void 0 ? void 0 : _f.call(data, function (item) {
        return item.garbageTypeCode === 'KEHUISHOU';
      })) === null || _g === void 0 ? void 0 : _g.weight) || 0;
      title = (_h = garbageIcons === null || garbageIcons === void 0 ? void 0 : garbageIcons.find(function (ele) {
        return ele.code === 'KEHUISHOU';
      })) === null || _h === void 0 ? void 0 : _h.name;
      break;
    case GarbageType.CHUYU:
      imgSrc = (_l = (_k = JSON.parse(((_j = garbageIcons === null || garbageIcons === void 0 ? void 0 : garbageIcons.find(function (ele) {
        return ele.code === 'CHUYU';
      })) === null || _j === void 0 ? void 0 : _j.kanbanIcon) || '[]')) === null || _k === void 0 ? void 0 : _k[0]) === null || _l === void 0 ? void 0 : _l.id;
      bucketSrc = require('../../imgs/bucket-cylj.png');
      bgSrc = require('../../imgs/cylj-bg.png');
      color = GarbageTypeColor.CHUYU;
      count = ((_o = (_m = data === null || data === void 0 ? void 0 : data.find) === null || _m === void 0 ? void 0 : _m.call(data, function (item) {
        return item.garbageTypeCode === 'CHUYU';
      })) === null || _o === void 0 ? void 0 : _o.throwCount) || 0;
      weight = ((_q = (_p = data === null || data === void 0 ? void 0 : data.find) === null || _p === void 0 ? void 0 : _p.call(data, function (item) {
        return item.garbageTypeCode === 'CHUYU';
      })) === null || _q === void 0 ? void 0 : _q.weight) || 0;
      title = (_r = garbageIcons === null || garbageIcons === void 0 ? void 0 : garbageIcons.find(function (ele) {
        return ele.code === 'CHUYU';
      })) === null || _r === void 0 ? void 0 : _r.name;
      break;
    case GarbageType.QITA:
      imgSrc = (_u = (_t = JSON.parse(((_s = garbageIcons === null || garbageIcons === void 0 ? void 0 : garbageIcons.find(function (ele) {
        return ele.code === 'QITA';
      })) === null || _s === void 0 ? void 0 : _s.kanbanIcon) || '[]')) === null || _t === void 0 ? void 0 : _t[0]) === null || _u === void 0 ? void 0 : _u.id;
      bucketSrc = require('../../imgs/bucket-qtlj.png');
      bgSrc = require('../../imgs/qtlj-bg.png');
      color = GarbageTypeColor.QITA;
      count = ((_w = (_v = data === null || data === void 0 ? void 0 : data.find) === null || _v === void 0 ? void 0 : _v.call(data, function (item) {
        return item.garbageTypeCode === 'QITA';
      })) === null || _w === void 0 ? void 0 : _w.throwCount) || 0;
      weight = ((_y = (_x = data === null || data === void 0 ? void 0 : data.find) === null || _x === void 0 ? void 0 : _x.call(data, function (item) {
        return item.garbageTypeCode === 'QITA';
      })) === null || _y === void 0 ? void 0 : _y.weight) || 0;
      title = (_z = garbageIcons === null || garbageIcons === void 0 ? void 0 : garbageIcons.find(function (ele) {
        return ele.code === 'QITA';
      })) === null || _z === void 0 ? void 0 : _z.name;
      break;
    case GarbageType.YOUHAI:
      imgSrc = (_2 = (_1 = JSON.parse(((_0 = garbageIcons === null || garbageIcons === void 0 ? void 0 : garbageIcons.find(function (ele) {
        return ele.code === 'YOUHAI';
      })) === null || _0 === void 0 ? void 0 : _0.kanbanIcon) || '[]')) === null || _1 === void 0 ? void 0 : _1[0]) === null || _2 === void 0 ? void 0 : _2.id;
      bucketSrc = require('../../imgs/bucket-yhlj.png');
      bgSrc = require('../../imgs/yhlj-bg.png');
      color = GarbageTypeColor.YOUHAI;
      count = ((_4 = (_3 = data === null || data === void 0 ? void 0 : data.find) === null || _3 === void 0 ? void 0 : _3.call(data, function (item) {
        return item.garbageTypeCode === 'YOUHAI';
      })) === null || _4 === void 0 ? void 0 : _4.throwCount) || 0;
      weight = ((_6 = (_5 = data === null || data === void 0 ? void 0 : data.find) === null || _5 === void 0 ? void 0 : _5.call(data, function (item) {
        return item.garbageTypeCode === 'YOUHAI';
      })) === null || _6 === void 0 ? void 0 : _6.weight) || 0;
      title = (_7 = garbageIcons === null || garbageIcons === void 0 ? void 0 : garbageIcons.find(function (ele) {
        return ele.code === 'YOUHAI';
      })) === null || _7 === void 0 ? void 0 : _7.name;
      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(_components.VtxImage, {
    src: "/cloudFile/common/downloadFile?id=".concat(imgSrc, "&token=").concat((0, _utils.getVtxToken)('token')),
    style: {
      width: 24
    }
  })), /*#__PURE__*/_react["default"].createElement("p", {
    style: {
      color: color
    }
  }, title), /*#__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;
  return {
    tooltip: {
      trigger: 'item',
      formatter: '{b}: {c0}次'
    },
    legend: {
      top: 0,
      left: 'center',
      textStyle: {
        color: '#fff'
      }
    },
    grid: {
      top: 40,
      left: 20,
      right: 0,
      bottom: 0,
      containLabel: true
    },
    xAxis: {
      data: (_a = data === null || data === void 0 ? void 0 : data.map) === null || _a === void 0 ? void 0 : _a.call(data, 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'
            },
            formatter: '{c} 次'
          }
        }
      },
      data: (_b = data === null || data === void 0 ? void 0 : data.map) === null || _b === void 0 ? void 0 : _b.call(data, 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,
    garbageIcons = _ref2.garbageIcons;
  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.throwSumByPointOneWeek({
    housingEstateId: id
  });
  // 24小时分布
  var sumByHour = _api.overViewService.throwSumByHour({
    housingEstateId: id
  });
  var garbageTypeCodes = (sumByGarbageType || []).map(function (item) {
    return item.garbageTypeCode;
  });
  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")
  }, garbageTypeCodes.includes('KEHUISHOU') && /*#__PURE__*/_react["default"].createElement(GarbageSummary, {
    type: GarbageType.KEHUISHOU,
    data: sumByGarbageType,
    garbageIcons: garbageIcons
  }), garbageTypeCodes.includes('CHUYU') && /*#__PURE__*/_react["default"].createElement(GarbageSummary, {
    type: GarbageType.CHUYU,
    data: sumByGarbageType,
    garbageIcons: garbageIcons
  }), garbageTypeCodes.includes('QITA') && /*#__PURE__*/_react["default"].createElement(GarbageSummary, {
    type: GarbageType.QITA,
    data: sumByGarbageType,
    garbageIcons: garbageIcons
  }), garbageTypeCodes.includes('YOUHAI') && /*#__PURE__*/_react["default"].createElement(GarbageSummary, {
    type: GarbageType.YOUHAI,
    data: sumByGarbageType,
    garbageIcons: garbageIcons
  })), /*#__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 = exports["default"] = Left;
//# sourceMappingURL=Hot.js.map
