"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _ahooks = require("ahooks");
var _moment = _interopRequireDefault(require("moment"));
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
var _vmFilter = require("../../../vm-filter");
var _vmSubTabs = require("../../../vm-sub-tabs");
var _api = require("../../api");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
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 MonitorInfo = function MonitorInfo(props) {
  var id = props.id;
  var _useSetState = (0, _ahooks.useSetState)({
      filterKey: 'PersonNum',
      startDate: (0, _moment["default"])().format('YYYY-MM-DD'),
      endDate: (0, _moment["default"])().format('YYYY-MM-DD')
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var filterKey = state.filterKey,
    startDate = state.startDate,
    endDate = state.endDate;
  var _MoniotrService$useMo = _api.MoniotrService.useMonitorType(id),
    monitorType = _MoniotrService$useMo.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,
    legend = monitorChart.legend,
    series = monitorChart.series;
  var handleDateChange = function handleDateChange(start, end) {
    setState({
      startDate: start,
      endDate: end
    });
  };
  var option = {
    color: ['#4DFFD9', '#4195FF', '#FF7979', '#FFE25D'],
    tooltip: {
      trigger: 'axis'
    },
    legend: {
      show: true,
      itemWith: 6,
      itemHeight: 6,
      top: 20,
      textStyle: {
        color: '#fff',
        fontSize: 12
      },
      data: legend || []
    },
    grid: {
      top: 58,
      left: 24,
      bottom: 12,
      right: 24,
      containLabel: true
    },
    xAxis: {
      type: 'category',
      boundaryGap: false,
      axisTick: {
        show: false
      },
      axisLabel: {
        color: '#fff'
      },
      data: xAxis || []
    },
    yAxis: [{
      name: '单位（人次）',
      type: 'value',
      nameTextStyle: {
        color: '#fff'
      },
      axisTick: {
        show: false
      },
      axisLabel: {
        color: '#fff'
      },
      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
      });
    }
  }), /*#__PURE__*/_react["default"].createElement(_vmFilter.VMRangePicker, {
    value: [(0, _moment["default"])(startDate), (0, _moment["default"])(endDate)],
    onChange: function onChange(dates) {
      return dates && handleDateChange((0, _moment["default"])(dates[0]).format('YYYY-MM-DD'), (0, _moment["default"])(dates[1]).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 = MonitorInfo;
exports["default"] = _default;
//# sourceMappingURL=MonitorInfo.js.map
