"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 _react = _interopRequireWildcard(require("react"));
var _ahooks = require("ahooks");
var _moment = _interopRequireDefault(require("moment"));
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
var _useSettings2 = _interopRequireDefault(require("../../../vm-hooks/useSettings"));
var _vmFilter = require("../../../vm-filter");
var _vmSubTabs = require("../../../vm-sub-tabs");
var _api = require("../../api");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
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 MonitorInfo = function MonitorInfo(props) {
  var id = props.id;
  var _useSettings = (0, _useSettings2["default"])(),
    chartFontColor = _useSettings.chartFontColor,
    sDate = _useSettings.startDate,
    theme = _useSettings.theme;
  var _useSetState = (0, _ahooks.useSetState)({
      filterKey: '',
      startDate: sDate || (0, _moment["default"])().format('YYYY-MM-DD'),
      endDate: sDate || (0, _moment["default"])().format('YYYY-MM-DD'),
      unit: ''
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var filterKey = state.filterKey,
    startDate = state.startDate,
    endDate = state.endDate,
    unit = state.unit;
  var _MoniotrService$useMo = _api.MoniotrService.useMonitorType(id),
    monitorType = _MoniotrService$useMo.monitorType;
  (0, _react.useEffect)(function () {
    if (monitorType === null || monitorType === void 0 ? void 0 : monitorType.length) {
      setState({
        filterKey: monitorType[0].key,
        unit: monitorType[0].standardUnit
      });
    }
  }, [JSON.stringify(monitorType)]);
  var _MoniotrService$useMo2 = _api.MoniotrService.useMonitorChart(id, "".concat(startDate, " 00:00:00"), "".concat(endDate, " 23:59:59"), filterKey),
    monitorChart = _MoniotrService$useMo2.monitorChart;
  var xAxis = monitorChart.xAxis,
    xList = monitorChart.xList,
    legend = monitorChart.legend,
    legendList = monitorChart.legendList,
    series = monitorChart.series;
  var handleDateChange = function handleDateChange(start) {
    setState({
      startDate: start,
      endDate: start
    });
  };
  var option = {
    color: ['#4DFFD9', '#4195FF', '#FF7979', '#FFE25D'],
    tooltip: {
      trigger: 'axis'
    },
    legend: {
      show: true,
      itemWith: 6,
      itemHeight: 6,
      top: 20,
      textStyle: {
        color: theme === 'blue' ? '#fff' : chartFontColor,
        fontSize: 12
      },
      data: legend || legendList || []
    },
    grid: {
      top: 58,
      left: 24,
      bottom: 12,
      right: 24,
      containLabel: true
    },
    xAxis: {
      type: 'category',
      boundaryGap: false,
      axisTick: {
        show: false
      },
      axisLabel: {
        color: theme === 'blue' ? '#fff' : chartFontColor
      },
      data: xAxis || xList || []
    },
    yAxis: [{
      name: unit,
      type: 'value',
      nameTextStyle: {
        color: theme === 'blue' ? '#fff' : chartFontColor
      },
      axisTick: {
        show: false
      },
      axisLabel: {
        color: theme === 'blue' ? '#fff' : chartFontColor
      },
      axisLine: {
        show: true
      },
      splitLine: {
        lineStyle: {
          type: 'dashed',
          color: 'rgba(151,151,151,0.28)'
        }
      }
    }],
    series: series || []
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "wr-monitor-trend"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "wr-monitor-trend-head"
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTabs.SubTabsLine, {
    items: monitorType,
    activeKey: filterKey,
    onChange: function onChange(key) {
      setState({
        filterKey: key,
        unit: monitorType.find(function (ele) {
          return ele.key === key;
        }).standardUnit
      });
    }
  }), /*#__PURE__*/_react["default"].createElement(_vmFilter.VMDatePicker, {
    value: (0, _moment["default"])(startDate),
    onChange: function onChange(date) {
      date && handleDateChange(date.format('YYYY-MM-DD'));
    }
  })), /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    option: option,
    notMerge: true,
    lazyUpdate: true,
    style: {
      height: '300px',
      width: '100%'
    }
  })));
};
var _default = exports["default"] = MonitorInfo;
//# sourceMappingURL=MonitorInfo.js.map
