"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;
var _antd = require("antd");
var _react = _interopRequireWildcard(require("react"));
var _components = require("@vtx/components");
var _ahooks = require("ahooks");
var _dayjs = _interopRequireDefault(require("dayjs"));
var _icons = require("@ant-design/icons");
var _api = require("../../api");
var _lodash = _interopRequireWildcard(require("lodash"));
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
var _vmNodata = _interopRequireDefault(require("../../../vm-nodata"));
var echarts = _interopRequireWildcard(require("echarts"));
var _config = require("../../config");
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 _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
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 VtxRangePicker = _components.VtxDatePicker.VtxRangePicker,
  VtxMonthPicker = _components.VtxDatePicker.VtxMonthPicker,
  VtxYearPicker = _components.VtxDatePicker.VtxYearPicker;
var Option = _components.VtxSelect.Option;
var Chart = function Chart(_ref) {
  var deviceIds = _ref.deviceIds,
    monitorItemIds = _ref.monitorItemIds;
  var _useSetState = (0, _ahooks.useSetState)({
      timeType: 'danTime',
      danTimeType: '24h',
      duoTimeType: 'day',
      duoTimeList: [{
        time: (0, _dayjs["default"])().format('YYYY-MM-DD')
      }],
      danTimeStartTime: (0, _dayjs["default"])().format('YYYY-MM-DD'),
      danTimeEndTime: (0, _dayjs["default"])().format('YYYY-MM-DD'),
      month: (0, _dayjs["default"])(),
      year: (0, _dayjs["default"])(),
      collectFrequency: ''
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var timeType = state.timeType,
    danTimeEndTime = state.danTimeEndTime,
    duoTimeType = state.duoTimeType,
    duoTimeList = state.duoTimeList,
    danTimeType = state.danTimeType,
    danTimeStartTime = state.danTimeStartTime,
    month = state.month,
    year = state.year,
    collectFrequency = state.collectFrequency;
  var handleDuoTimeList = function handleDuoTimeList(index, value) {
    var newDuoTimeList = JSON.parse(JSON.stringify(duoTimeList));
    newDuoTimeList[index].time = value;
    setState({
      duoTimeList: newDuoTimeList
    });
  };
  var _useState = (0, _react.useState)(null),
    _useState2 = _slicedToArray(_useState, 2),
    dates = _useState2[0],
    setDates = _useState2[1];
  (0, _react.useEffect)(function () {
    if ((0, _lodash.isEmpty)(deviceIds) || (0, _lodash.isEmpty)(monitorItemIds)) {
      return;
    }
    setState({
      collectFrequency: ''
    });
  }, [JSON.stringify(deviceIds), JSON.stringify(monitorItemIds)]);
  var _BaseService$useColle = _api.BaseService.useCollectList({
      deviceIds: deviceIds,
      monitorItemIds: monitorItemIds
    }),
    _BaseService$useColle2 = _BaseService$useColle.data,
    collectList = _BaseService$useColle2 === void 0 ? [] : _BaseService$useColle2;
  (0, _react.useEffect)(function () {
    var _a;
    if (!(0, _lodash.isEmpty)(collectList)) {
      setState({
        collectFrequency: (_a = collectList === null || collectList === void 0 ? void 0 : collectList[0]) === null || _a === void 0 ? void 0 : _a.id
      });
    }
  }, [JSON.stringify(collectList)]);
  var _BaseService$useGetAn = _api.BaseService.useGetAnalysis({
      timeType: timeType,
      danTimeEndTime: danTimeEndTime,
      duoTimeType: duoTimeType,
      duoTimeList: duoTimeList,
      danTimeType: danTimeType,
      danTimeStartTime: danTimeStartTime,
      month: month,
      year: year,
      collectFrequency: collectFrequency,
      deviceIds: deviceIds,
      monitorItemIds: monitorItemIds
    }),
    chartDataList = _BaseService$useGetAn.data,
    loading = _BaseService$useGetAn.loading;
  var isHasChartData = function isHasChartData() {
    var isHasData = true;
    if (chartDataList.length) {
      isHasData = true;
      if (timeType === 'danTime') {
        if (chartDataList.some(function (item) {
          return item.values && item.values.length;
        })) {
          isHasData = true;
        } else {
          isHasData = false;
        }
      } else {
        if (chartDataList.some(function (item) {
          return item.list && item.list.length;
        })) {
          isHasData = true;
        } else {
          isHasData = false;
        }
      }
    } else {
      isHasData = false;
    }
    return isHasData;
  };
  var isHasChartItemData = function isHasChartItemData(item) {
    // console.log(item);
    var isHasData = true;
    if (timeType === 'danTime') {
      if (item.values.length) {
        isHasData = true;
      } else {
        isHasData = false;
      }
    } else {
      if (item.length) {
        isHasData = true;
        if (item.some(function (each) {
          return each.values.length;
        })) {
          isHasData = true;
        } else {
          isHasData = false;
        }
      } else {
        isHasData = false;
      }
    }
    return isHasData;
  };
  var newList = isHasChartData() ? chartDataList.filter(function (item) {
    return isHasChartItemData(timeType === 'danTime' ? item : item.list);
  }) : null;
  var getGroupDanOption = function getGroupDanOption(list) {
    var xData = _lodash["default"].uniq(_lodash["default"].flatMap(list, 'xData').sort());
    var offsetList = [];
    list.forEach(function (_unused, index) {
      var maxLength = 0;
      if (index === 0) {
        offsetList.push(0);
        return;
      }
      var item = list[index - 1];
      item.yData.map(function (v) {
        maxLength = Math.max(maxLength, v.length);
      });
      offsetList.push(_lodash["default"].last(offsetList) || 0 + (maxLength * 10 + 20));
    });
    var legendData = [];
    list.forEach(function (item, index) {
      if (item.showMode === 'stack') {
        var _state = _lodash["default"].map(_lodash["default"].uniqBy(item.dataList, 'value'));
        var _colors = ['#73a0fa', '#73deb3'];
        var stateColor = {};
        _state.forEach(function (v, index) {
          stateColor[v.value] = _colors[index % 2];
        });
        legendData.push.apply(legendData, _toConsumableArray((_state || []).map(function (item) {
          return {
            name: item.value,
            itemStyle: {
              color: stateColor[item.value]
            }
          };
        })));
      } else {
        legendData.push({
          name: item.newName || item.name || '',
          itemStyle: {
            color: _config.colors[index % 5].lineColor
          }
        });
      }
    });
    return {
      color: _config.colors.map(function (color) {
        return color.lineColor;
      }),
      grid: {
        top: 70,
        left: 100 + offsetList.length * 10,
        right: 50,
        bottom: 50,
        containLabel: true
      },
      toolbox: {
        show: true,
        feature: {
          saveAsImage: {
            show: true
          }
        }
      },
      legend: {
        type: 'scroll',
        itemWidth: 17,
        itemHeight: 10,
        textStyle: {
          color: '#000000A5'
        },
        top: 35,
        left: 'center'
      },
      tooltip: {
        trigger: 'axis',
        formatter: function formatter(data) {
          var circle = "<span style=\"display:inline-block;margin-right:5px;border-radius:50%;width:10px;height:10px;left:5px;background-color:";
          var result = "";
          data.map(function (v) {
            var info = list.find(function (item) {
              return item.name === v.seriesName;
            }) || {};
            if (v.componentSubType === 'custom') {
              result += "".concat(circle + v.color, "\"></span>").concat(v.name, "\uFF1A").concat(v.value.slice(1).join('~')).concat(info.unit || '', "<br/>");
            } else {
              result += "".concat(circle + _config.colors[v.seriesIndex % 5].lineColor, "\"></span>").concat(v.seriesName, "\uFF1A").concat(v.value).concat(info.unit || '', "<br/>");
            }
          });
          return result;
        }
      },
      xAxis: [{
        type: 'category',
        boundaryGap: false,
        axisLine: {
          show: true,
          lineStyle: {
            color: 'color:"#000000A5"'
          }
        },
        axisLabel: {
          textStyle: {
            color: '#000000A5',
            fontSize: 12
          }
        },
        axisTick: {
          show: false
        },
        data: xData
      }],
      yAxis: list.map(function (item, index) {
        return {
          name: "".concat(item.newName || item.name || '').concat(item.unit ? "(".concat(item.unit, ")") : ''),
          minInterval: 1,
          offset: offsetList[index],
          position: 'left',
          // maxInterval: 5,
          nameTextStyle: {
            color: _config.colors[index % 5].lineColor
          },
          nameLocation: 'middle',
          nameGap: 0,
          splitLine: {
            lineStyle: {
              color: '#E8E8E8',
              type: 'dashed'
            }
          },
          axisLine: {
            show: true,
            color: _config.colors[index % 5].lineColor
          },
          axisLabel: {
            color: _config.colors[index % 5].lineColor,
            margin: 20
          },
          axisTick: {
            show: false
          }
        };
      }),
      series: list.flatMap(function (item, index) {
        if (item.showMode === 'stack') {
          var _state2 = _lodash["default"].map(_lodash["default"].uniqBy(item.dataList, 'value'));
          var _colors2 = ['#73a0fa', '#73deb3'];
          var stateColor = {};
          _state2.forEach(function (v, index) {
            stateColor[v.value] = _colors2[index % 2];
          });
          return [].concat(_toConsumableArray((_state2 || []).map(function (v) {
            return {
              name: v.value,
              type: 'bar',
              data: [],
              yAxisIndex: index,
              markLine: {
                symbol: ['none', 'none'],
                data: (item.markLine || []).filter(function (_unused, i) {
                  return i !== 0;
                }).map(function (m, i) {
                  return {
                    name: (0, _dayjs["default"])(m.data).format('YYYY-MM-DD'),
                    xAxis: "(".concat(i + 1, ")").concat((0, _dayjs["default"])(m.data).format('HH:mm')),
                    lineStyle: {
                      color: '#4159A7'
                    },
                    label: {
                      position: 'end',
                      formatter: '{b}'
                    }
                  };
                })
              }
            };
          })), [{
            type: 'custom',
            yAxisIndex: index,
            renderItem: function renderItem(params, api) {
              var categoryIndex = api.value(0);
              var start = api.coord([api.value(1), categoryIndex]);
              var end = api.coord([api.value(2), categoryIndex]);
              var height = 18;
              return {
                type: 'rect',
                shape: echarts.graphic.clipRectByRect({
                  x: start[0],
                  y: start[1] - height / 2,
                  width: end[0] - start[0],
                  height: height
                }, {
                  x: params.coordSys.x,
                  y: params.coordSys.y,
                  width: params.coordSys.width,
                  height: params.coordSys.height
                }),
                style: api.style()
              };
            },
            encode: {
              x: [1, 2],
              y: 0
            },
            data: (item.dataList || []).map(function (item, index, arr) {
              var _a;
              return {
                itemStyle: {
                  normal: {
                    color: stateColor[item.originValue]
                  }
                },
                color: stateColor[item.originValue],
                name: item.value,
                label: item.value,
                value: [0, item.date, (_a = arr[index + 1]) === null || _a === void 0 ? void 0 : _a.date]
              };
            })
          }]);
        }
        return [{
          type: item.showMode,
          name: item.newName || item.name || '',
          data: (item.yData || []).map(function (y, i) {
            return {
              value: Number(y).toFixed(2),
              name: item.xData[i]
            };
          }),
          animationEasing: 'linear',
          animationDuration: 2000,
          smooth: true,
          // symbol: 'none',
          symbolSize: 1,
          xAxisIndex: 0,
          yAxisIndex: index,
          itemStyle: {
            normal: {
              lineStyle: {
                color: _config.colors[index % 5].lineColor,
                width: 2
              },
              areaStyle: {
                color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
                  offset: 0,
                  color: _config.colors[index % 5].areaColor0
                }, {
                  offset: 1,
                  color: _config.colors[index % 5].areaColor1
                }])
              }
            }
          }
        }];
      })
    };
  };
  var getGroupDuoOption = function getGroupDuoOption(list) {
    var newList = list.map(function (item) {
      var xData = _lodash["default"].uniq(_lodash["default"].flatMap(item.list, 'xData').sort());
      var yData = xData.map(function (x) {
        var _a;
        var values = ((_a = item.list.find(function (i) {
          return i.values.find(function (v) {
            return v.x === x;
          });
        })) === null || _a === void 0 ? void 0 : _a.values) || [];
        var keyByValues = _lodash["default"].keyBy(values, 'x');
        return keyByValues[x].y;
      });
      return Object.assign(Object.assign({}, item.list[0]), {
        yData: yData,
        newName: '',
        xData: xData
      });
    });
    var xData = _lodash["default"].uniq(_lodash["default"].flatMap(newList, 'xData').sort());
    var offsetList = [];
    newList.forEach(function (_unused, index) {
      var maxLength = 0;
      if (index === 0) {
        offsetList.push(0);
        return;
      }
      var item = newList[index - 1];
      item.yData.map(function (v) {
        maxLength = Math.max(maxLength, v.length);
      });
      offsetList.push(_lodash["default"].last(offsetList) || 0 + maxLength * 10);
    });
    return {
      color: _config.colors.map(function (color) {
        return color.lineColor;
      }),
      grid: {
        top: 70,
        left: 100 + offsetList.length * 10,
        right: 50,
        bottom: 50,
        containLabel: true
      },
      toolbox: {
        show: true,
        feature: {
          saveAsImage: {
            show: true
          }
        }
      },
      legend: {
        itemWidth: 17,
        itemHeight: 10,
        textStyle: {
          color: '#000000A5'
        },
        top: 35,
        left: 'center'
      },
      tooltip: {
        trigger: 'axis',
        formatter: function formatter(data) {
          var circle = "<span style=\"display:inline-block;margin-right:5px;border-radius:50%;width:10px;height:10px;left:5px;background-color:";
          var result = "".concat(data[0].name, "<br/>");
          data.map(function (v) {
            var info = newList.find(function (item) {
              return item.name === v.seriesName;
            }) || {};
            result += "".concat(circle + _config.colors[v.seriesIndex % 5].lineColor, "\"></span>").concat(v.seriesName, "\uFF1A").concat(v.value).concat(info.unit || '', "<br/>");
          });
          return result;
        }
      },
      xAxis: [{
        type: 'category',
        boundaryGap: false,
        axisLine: {
          show: true,
          lineStyle: {
            color: 'color:"#000000A5"'
          }
        },
        axisLabel: {
          textStyle: {
            color: '#000000A5',
            fontSize: 12
          }
        },
        axisTick: {
          show: false
        },
        data: xData
      }],
      yAxis: newList.map(function (item, index) {
        return {
          name: "".concat(item.newName || item.name || '').concat(item.unit ? "(".concat(item.unit, ")") : ''),
          minInterval: 1,
          offset: offsetList[index],
          position: 'left',
          // maxInterval: 5,
          nameTextStyle: {
            color: _config.colors[index % 5].lineColor
          },
          nameLocation: 'middle',
          nameGap: 0,
          splitLine: {
            lineStyle: {
              color: '#E8E8E8',
              type: 'dashed'
            }
          },
          axisLine: {
            show: true,
            color: _config.colors[index % 5].lineColor
          },
          axisLabel: {
            color: _config.colors[index % 5].lineColor,
            margin: 20
          },
          axisTick: {
            show: false
          }
        };
      }),
      series: newList.flatMap(function (item, index) {
        if (item.showMode === 'stack') {
          var _state3 = _lodash["default"].map(_lodash["default"].uniqBy(item.dataList, 'value'));
          return [].concat(_toConsumableArray((_state3 || []).map(function (v) {
            return {
              name: v.value,
              type: 'bar',
              data: [],
              yAxisIndex: index,
              markLine: {
                symbol: ['none', 'none'],
                data: (item.markLine || []).filter(function (_unused, i) {
                  return i !== 0;
                }).map(function (m, i) {
                  return {
                    name: (0, _dayjs["default"])(m.data).format('YYYY-MM-DD'),
                    xAxis: "(".concat(i + 1, ")").concat((0, _dayjs["default"])(m.data).format('HH:mm')),
                    lineStyle: {
                      color: '#4159A7'
                    },
                    label: {
                      position: 'end',
                      formatter: '{b}'
                    }
                  };
                })
              }
            };
          })), [{
            type: 'custom',
            yAxisIndex: index,
            renderItem: function renderItem(params, api) {
              var categoryIndex = api.value(0);
              var start = api.coord([api.value(1), categoryIndex]);
              var end = api.coord([api.value(2), categoryIndex]);
              var height = 18;
              return {
                type: 'rect',
                shape: echarts.graphic.clipRectByRect({
                  x: start[0],
                  y: start[1] - height / 2,
                  width: end[0] - start[0],
                  height: height
                }, {
                  x: params.coordSys.x,
                  y: params.coordSys.y,
                  width: params.coordSys.width,
                  height: params.coordSys.height
                }),
                style: api.style()
              };
            },
            encode: {
              x: [1, 2],
              y: 0
            },
            data: (item.dataList || []).map(function (item, index, arr) {
              var _a;
              return {
                itemStyle: {
                  normal: {
                    color: _config.colors[item.originValue]
                  }
                },
                color: _config.colors[item.originValue],
                name: item.value,
                label: item.value,
                value: [0, item.date, (_a = arr[index + 1]) === null || _a === void 0 ? void 0 : _a.date]
              };
            })
          }]);
        }
        return [{
          type: 'line',
          name: item.newName || item.name || '',
          data: (item.yData || []).map(function (y, i) {
            return {
              value: Number(y).toFixed(2),
              name: item.xData[i]
            };
          }),
          animationEasing: 'linear',
          animationDuration: 2000,
          smooth: true,
          // symbol: 'none',
          symbolSize: 5,
          xAxisIndex: 0,
          yAxisIndex: index,
          itemStyle: {
            normal: {
              lineStyle: {
                color: _config.colors[index % 5].lineColor,
                width: 2
              },
              areaStyle: {
                color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
                  offset: 0,
                  color: _config.colors[index % 5].areaColor0
                }, {
                  offset: 1,
                  color: _config.colors[index % 5].areaColor1
                }])
              }
            }
          }
        }];
      })
    };
  };
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_antd.Space, null, /*#__PURE__*/_react["default"].createElement("span", null, "\u65F6\u95F4\uFF1A"), /*#__PURE__*/_react["default"].createElement(_components.VtxSelect, {
    allowClear: false,
    style: {
      width: 100
    },
    value: timeType,
    onChange: function onChange(e) {
      setState({
        timeType: e
      });
    }
  }, /*#__PURE__*/_react["default"].createElement(Option, {
    value: 'danTime'
  }, "\u5355\u65F6\u6BB5"), /*#__PURE__*/_react["default"].createElement(Option, {
    value: 'duoTime'
  }, "\u591A\u65F6\u6BB5")), timeType === 'danTime' ? (/*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_antd.Radio.Group, {
    optionType: "button",
    value: danTimeType,
    onChange: function onChange(_ref2) {
      var value = _ref2.target.value;
      setState({
        danTimeType: value
      });
    }
  }, [
  // { label: '近1小时', value: '1h' },
  {
    label: '24小时',
    value: '24h'
  }, {
    label: '3天',
    value: '3days'
  }, {
    label: '7天',
    value: '7days'
  }].concat(_toConsumableArray(collectFrequency === 'day' ? [{
    label: '月',
    value: 'month'
  }] : []), _toConsumableArray(collectFrequency === 'month' ? [{
    label: '年',
    value: 'year'
  }] : []), [{
    label: '自定义',
    value: 'self'
  }]).map(function (item) {
    return item.value === 'self' ? (/*#__PURE__*/_react["default"].createElement(_antd.Popover, {
      content: /*#__PURE__*/_react["default"].createElement(VtxRangePicker, {
        allowClear: false,
        style: {
          marginLeft: 10
        },
        value: dates || [danTimeStartTime, danTimeEndTime],
        onChange: function onChange(_unused, dateStr) {
          setState({
            danTimeStartTime: dateStr[0],
            danTimeEndTime: dateStr[1]
          });
        },
        onCalendarChange: function onCalendarChange(val) {
          setDates(val);
        },
        onOpenChange: function onOpenChange(open) {
          if (open) {
            setDates([]);
          } else {
            setDates(null);
          }
        },
        disabledDate: function disabledDate(current) {
          var day = collectFrequency === 'day' ? 31 : 7;
          if (!dates) {
            return false;
          }
          var tooLate = dates[0] && current.diff(dates[0], 'days') > day;
          var tooEarly = dates[1] && dates[1].diff(current, 'days') > day;
          return !!tooEarly || !!tooLate;
        }
      }),
      trigger: "click"
    }, /*#__PURE__*/_react["default"].createElement(_antd.Radio.Button, {
      value: item.value
    }, item.label))) : item.value === 'month' ? (/*#__PURE__*/_react["default"].createElement(_antd.Popover, {
      content: /*#__PURE__*/_react["default"].createElement(VtxMonthPicker, {
        allowClear: false,
        style: {
          marginLeft: 10
        },
        value: month,
        onChange: function onChange(date) {
          setState({
            month: date
          });
        }
      }),
      trigger: "click"
    }, /*#__PURE__*/_react["default"].createElement(_antd.Radio.Button, {
      value: item.value
    }, item.label))) : item.value === 'year' ? (/*#__PURE__*/_react["default"].createElement(_antd.Popover, {
      content: /*#__PURE__*/_react["default"].createElement(VtxYearPicker, {
        allowClear: false,
        style: {
          marginLeft: 10
        },
        value: year,
        onChange: function onChange(date) {
          setState({
            year: date
          });
        },
        disabledDate: function disabledDate(current) {
          return current && current >= (0, _dayjs["default"])().startOf('day');
        }
      }),
      trigger: "click"
    }, /*#__PURE__*/_react["default"].createElement(_antd.Radio.Button, {
      value: item.value
    }, item.label))) : (/*#__PURE__*/_react["default"].createElement(_antd.Radio.Button, {
      value: item.value
    }, item.label));
  })), /*#__PURE__*/_react["default"].createElement(_antd.Tooltip, {
    title: collectFrequency === 'day' ? '自定义时间仅支持查30天' : '自定义时间仅支持查七天'
  }, /*#__PURE__*/_react["default"].createElement(_icons.QuestionCircleOutlined, {
    style: {
      marginLeft: 8,
      fontSize: 16
    }
  })))) : (/*#__PURE__*/_react["default"].createElement("div", {
    style: {
      marginLeft: 10
    }
  }, /*#__PURE__*/_react["default"].createElement(_antd.Radio.Group, {
    options: collectFrequency === 'realtime' ? [{
      label: '日',
      value: 'day'
    }] : [{
      label: '日',
      value: 'day'
    }, {
      label: '月',
      value: 'month'
    }],
    optionType: "button",
    value: duoTimeType,
    onChange: function onChange(_ref3) {
      var value = _ref3.target.value;
      setState({
        duoTimeType: value
      });
    }
  }), duoTimeList.length === 5 ? null : (/*#__PURE__*/_react["default"].createElement(_antd.Button, {
    type: "primary",
    icon: /*#__PURE__*/_react["default"].createElement(_icons.PlusOutlined, null),
    style: {
      marginLeft: 20
    },
    onClick: function onClick() {
      var _a;
      var lastDate = (_a = duoTimeList[(duoTimeList === null || duoTimeList === void 0 ? void 0 : duoTimeList.length) - 1]) === null || _a === void 0 ? void 0 : _a.time;
      var newDate = (0, _dayjs["default"])(lastDate).subtract(1, duoTimeType === 'day' ? 'days' : 'months').format(duoTimeType === 'day' ? 'YYYY-MM-DD' : 'YYYY-MM');
      setState({
        duoTimeList: [].concat(_toConsumableArray(duoTimeList), [{
          time: newDate
        }])
      });
    }
  }, "\u65B0\u589E")))), /*#__PURE__*/_react["default"].createElement("span", null, "\u91C7\u96C6\u5468\u671F\uFF1A"), /*#__PURE__*/_react["default"].createElement(_components.VtxSelect, {
    allowClear: false,
    style: {
      width: 200
    },
    onChange: function onChange(e) {
      return setState({
        collectFrequency: e
      });
    },
    value: collectFrequency
  }, collectList.map(function (item) {
    return /*#__PURE__*/_react["default"].createElement(Option, {
      key: item.id
    }, item.name);
  }))), /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      marginTop: 8
    }
  }, timeType === 'duoTime' && duoTimeList.map(function (item, index) {
    return /*#__PURE__*/_react["default"].createElement("span", {
      style: {
        marginLeft: 20,
        position: 'relative'
      },
      key: index
    }, duoTimeType === 'day' ? (/*#__PURE__*/_react["default"].createElement(_components.VtxDatePicker, {
      allowClear: false,
      value: item.time,
      onChange: function onChange(_unused, dateStr) {
        handleDuoTimeList(index, dateStr);
      }
    })) : (/*#__PURE__*/_react["default"].createElement(VtxMonthPicker, {
      allowClear: false,
      value: item.time,
      onChange: function onChange(_, dateStr) {
        handleDuoTimeList(index, dateStr);
      }
    })), index === 0 ? null : (/*#__PURE__*/_react["default"].createElement(_icons.CloseCircleOutlined, {
      style: {
        color: '#bbb8b8',
        position: 'absolute',
        top: -7,
        right: -15,
        cursor: 'pointer'
      },
      onClick: function onClick() {
        setState({
          duoTimeList: duoTimeList.filter(function (_unused, timeIndex) {
            return timeIndex !== index;
          })
        });
      }
    })));
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "vtx-device-modal-analysis-content--chart"
  }, loading ? (/*#__PURE__*/_react["default"].createElement(_antd.Spin, {
    spinning: true
  })) : (0, _lodash.isEmpty)(newList) ? (/*#__PURE__*/_react["default"].createElement(_vmNodata["default"], {
    style: {
      height: 300
    }
  })) : (/*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    option: timeType === 'danTime' ? getGroupDanOption(newList) : getGroupDuoOption(newList),
    notMerge: true,
    lazyUpdate: true,
    style: {
      height: '100%',
      width: '100%'
    }
  }))));
};
var _default = exports["default"] = Chart;
//# sourceMappingURL=Chart.js.map
