"use strict";
Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.default = void 0;
var _react = _interopRequireWildcard(require("react")),
  _propTypes = _interopRequireDefault(require("prop-types")),
  _amosAntd = require("amos-antd"),
  _amosIcon = _interopRequireDefault(require("amos-icon")),
  _urlConsts = require("../../../consts/urlConsts"),
  _processor = require("../../../utils/processor"),
  _rayEventpool = require("ray-eventpool"),
  _request = require("../../../utils/request"),
  _amosWebsocket = _interopRequireDefault(require("amos-websocket")),
  _ActionConf = require("./../common/ActionConf"),
  _ConnectTest = _interopRequireDefault(require("./ConnectTest"));
require("./onlineTest.scss");
var _PerformanceTest = _interopRequireDefault(require("./PerformanceTest"));

function _interopRequireDefault(e) {
  return e && e.__esModule ? e : {
    default: e
  }
}

function _getRequireWildcardCache() {
  if ("function" != typeof WeakMap) return null;
  var e = new WeakMap;
  return _getRequireWildcardCache = function() {
    return e
  }, e
}

function _interopRequireWildcard(e) {
  if (e && e.__esModule) return e;
  if (null === e || "object" !== _typeof(e) && "function" != typeof e) return {
    default: e
  };
  var t = _getRequireWildcardCache();
  if (t && t.has(e)) return t.get(e);
  var r, n, o = {},
    a = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (r in e) Object.prototype.hasOwnProperty.call(e, r) && ((n = a ? Object.getOwnPropertyDescriptor(e, r) : null) && (n.get || n.set) ? Object.defineProperty(o, r, n) : o[r] = e[r]);
  return o.default = e, t && t.set(e, o), o
}

function _typeof(e) {
  return (_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(e) {
    return typeof e
  } : function(e) {
    return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e
  })(e)
}

function _extends() {
  return (_extends = Object.assign || function(e) {
    for (var t = 1; t < arguments.length; t++) {
      var r, n = arguments[t];
      for (r in n) Object.prototype.hasOwnProperty.call(n, r) && (e[r] = n[r])
    }
    return e
  }).apply(this, arguments)
}

function _classCallCheck(e, t) {
  if (!(e instanceof t)) throw new TypeError("Cannot call a class as a function")
}

function _defineProperties(e, t) {
  for (var r = 0; r < t.length; r++) {
    var n = t[r];
    n.enumerable = n.enumerable || !1, n.configurable = !0, "value" in n && (n.writable = !0), Object.defineProperty(e, n.key, n)
  }
}

function _createClass(e, t, r) {
  return t && _defineProperties(e.prototype, t), r && _defineProperties(e, r), e
}

function _inherits(e, t) {
  if ("function" != typeof t && null !== t) throw new TypeError("Super expression must either be null or a function");
  e.prototype = Object.create(t && t.prototype, {
    constructor: {
      value: e,
      writable: !0,
      configurable: !0
    }
  }), t && _setPrototypeOf(e, t)
}

function _setPrototypeOf(e, t) {
  return (_setPrototypeOf = Object.setPrototypeOf || function(e, t) {
    return e.__proto__ = t, e
  })(e, t)
}

function _createSuper(r) {
  var n = _isNativeReflectConstruct();
  return function() {
    var e, t = _getPrototypeOf(r);
    return _possibleConstructorReturn(this, n ? (e = _getPrototypeOf(this).constructor, Reflect.construct(t, arguments, e)) : t.apply(this, arguments))
  }
}

function _possibleConstructorReturn(e, t) {
  return !t || "object" !== _typeof(t) && "function" != typeof t ? _assertThisInitialized(e) : t
}

function _assertThisInitialized(e) {
  if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  return e
}

function _isNativeReflectConstruct() {
  if ("undefined" == typeof Reflect || !Reflect.construct) return !1;
  if (Reflect.construct.sham) return !1;
  if ("function" == typeof Proxy) return !0;
  try {
    return Date.prototype.toString.call(Reflect.construct(Date, [], function() {})), !0
  } catch (e) {
    return !1
  }
}

function _getPrototypeOf(e) {
  return (_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function(e) {
    return e.__proto__ || Object.getPrototypeOf(e)
  })(e)
}

function _defineProperty(e, t, r) {
  return t in e ? Object.defineProperty(e, t, {
    value: r,
    enumerable: !0,
    configurable: !0,
    writable: !0
  }) : e[t] = r, e
}
var TabPane = _amosAntd.Tabs.TabPane,
  OnlineTest = function() {
    _inherits(r, _react.Component);
    var t = _createSuper(r);

    function r(e) {
      var o;
      _classCallCheck(this, r), _defineProperty(_assertThisInitialized(o = t.call(this, e)), "getProInfo", function() {
        var e = o.props.quotaSelected;
        if ("{}" !== JSON.stringify(e)) {
          var t, r = [];
          for (t in e) 0 < e[t].length && r.push(e[t]);
          var n = "".concat(_urlConsts.OltSerUrl.quotaSelecteds, "/").concat(r);
          _processor.AmosFetch.get(n).then(function(e) {
            if (e.ok) return e.json();
            throw new Error("从服务端获取数据失败！")
          }).then(function(e) {
            "SUCCESS" === e.result && o.setState({
              quotaSelecteList: e.dataList
            })
          })
        } else o.setState({
          quotaSelecteList: []
        })
      }), _defineProperty(_assertThisInitialized(o), "callback", function(e) {
        console.log(e)
      }), _defineProperty(_assertThisInitialized(o), "closeQuotaPanel", function() {
        _rayEventpool.PubSub.publish(_ActionConf.CONFIG_PANEL_HIDE_TOPIC.trigger, {})
      }), _defineProperty(_assertThisInitialized(o), "handleData", function(e) {
        console.log("我应该链接测试数据："), console.log(e), e.connectData ? o.getConnectNeeddata(e) : e.metricData && o.getMetricNeeddata(e)
      }), _defineProperty(_assertThisInitialized(o), "getConnectNeeddata", function(e) {
        var t = e.connectData.id,
          r = o.state.connectData;
        r[t] = e.connectData.result, o.setState({
          connectData: r,
          connectPercent: e.connectData.percent
        })
      }), _defineProperty(_assertThisInitialized(o), "getMetricNeeddata", function(e) {
        var t = o.state.quotaSelecteList;
        t.map(function(t) {
          e.metricData.attributes.map(function(e) {
            e.id === t.id && (t.value = e.value)
          })
        }), o.setState({
          quotaSelecteList: t,
          metricPercent: e.metricData.percent
        })
      }), _defineProperty(_assertThisInitialized(o), "send", function() {}), o.state = {
        quotaSelecteList: [],
        collapsed: !1,
        connectData: {},
        connectPercent: 0,
        metricPercent: 0
      };
      e = (0, _request.getToken)();
      return o.websocketUrl = "".concat(_urlConsts.onlineTestWsURL, "test-equipment.ws?token=").concat(e), o
    }
    return _createClass(r, [{
      key: "componentDidMount",
      value: function() {
        this.getProInfo()
      }
    }, {
      key: "componentWillReceiveProps",
      value: function(e) {
        var t = this.props.quotaSelected;
        e.quotaSelected !== t && this.getProInfo()
      }
    }, {
      key: "render",
      value: function() {
        var t = this,
          e = [];
        return e.push(_react.default.createElement(_amosAntd.Button, {
          type: "primary",
          style: {
            marginRight: "10px",
            marginTop: "7px"
          },
          size: "small",
          onClick: this.closeQuotaPanel
        }, "关闭")), _react.default.createElement("div", {
          className: "online-test-custom"
        }, _react.default.createElement("div", {
          className: "dispatch-mask",
          ref: function(e) {
            return t.dispatchMask = e
          }
        }, _react.default.createElement(_amosWebsocket.default, {
          ref: function(e) {
            return t.aws = e
          },
          url: this.websocketUrl,
          onMessage: this.handleData,
          onOpen: this.send,
          reconnect: !0,
          debug: !0
        })), _react.default.createElement("div", null, _react.default.createElement(_amosAntd.Tabs, {
          defaultActiveKey: "1",
          onChange: this.callback,
          tabBarExtraContent: e
        }, _react.default.createElement(TabPane, {
          tab: "连接测试",
          key: "1"
        }, _react.default.createElement(_ConnectTest.default, _extends({
          connectData: this.state.connectData,
          percent: this.state.connectPercent
        }, this.props))), _react.default.createElement(TabPane, {
          tab: "性能测试",
          key: "2"
        }, _react.default.createElement(_PerformanceTest.default, _extends({
          quotaSelecteList: this.state.quotaSelecteList,
          percent: this.state.metricPercent
        }, this.props))))))
      }
    }]), r
  }();
OnlineTest.displayName = "OnlineTest", OnlineTest.propTypes = {
  visible: _propTypes.default.any,
  quotaSelected: _propTypes.default.any,
  onlinTestSwich: _propTypes.default.func,
  quotaSelecteList: _propTypes.default.any
};
var _default = OnlineTest;
exports.default = OnlineTest, module.exports = exports.default;
