"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"), _typeof = require("@babel/runtime/helpers/typeof");

Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.default = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")), _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")), _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")), _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized")), _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")), _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")), _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")), _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")), _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 _getRequireWildcardCache(e) {
  if ("function" != typeof WeakMap) return null;
  var t = new WeakMap, r = new WeakMap;
  return (_getRequireWildcardCache = function(e) {
    return e ? r : t;
  })(e);
}

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

function _createSuper(e) {
  var t = _isNativeReflectConstruct();
  return function() {
    var r, a = (0, _getPrototypeOf2.default)(e);
    if (t) {
      var n = (0, _getPrototypeOf2.default)(this).constructor;
      r = Reflect.construct(a, arguments, n);
    } else r = a.apply(this, arguments);
    return (0, _possibleConstructorReturn2.default)(this, r);
  };
}

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

var TabPane = _amosAntd.Tabs.TabPane, OnlineTest = function(e) {
  (0, _inherits2.default)(r, e);
  var t = _createSuper(r);
  function r(e) {
    var a;
    (0, _classCallCheck2.default)(this, r), a = t.call(this, e), (0, _defineProperty2.default)((0, 
    _assertThisInitialized2.default)(a), "getProInfo", (function() {
      var e = a.props.quotaSelected;
      if ("{}" !== JSON.stringify(e)) {
        var t = [];
        for (var r in e) e[r].length > 0 && t.push(e[r]);
        var n = "".concat(_urlConsts.OltSerUrl.quotaSelecteds, "/").concat(t);
        _processor.AmosFetch.get(n).then((function(e) {
          if (e.ok) return e.json();
          throw new Error("从服务端获取数据失败！");
        })).then((function(e) {
          "SUCCESS" === e.result && a.setState({
            quotaSelecteList: e.dataList
          });
        }));
      } else a.setState({
        quotaSelecteList: []
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "callback", (function(e) {
      console.log(e);
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "closeQuotaPanel", (function() {
      _rayEventpool.PubSub.publish(_ActionConf.CONFIG_PANEL_HIDE_TOPIC.trigger, {});
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "handleData", (function(e) {
      console.log("我应该链接测试数据："), console.log(e), e.connectData ? a.getConnectNeeddata(e) : e.metricData && a.getMetricNeeddata(e);
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "getConnectNeeddata", (function(e) {
      var t = e.connectData.id, r = a.state.connectData;
      r[t] = e.connectData.result, a.setState({
        connectData: r,
        connectPercent: e.connectData.percent
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "getMetricNeeddata", (function(e) {
      var t = a.state.quotaSelecteList;
      t.map((function(t) {
        e.metricData.attributes.map((function(e) {
          e.id === t.id && (t.value = e.value);
        }));
      })), a.setState({
        quotaSelecteList: t,
        metricPercent: e.metricData.percent
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "send", (function() {})), 
    a.state = {
      quotaSelecteList: [],
      collapsed: !1,
      connectData: {},
      connectPercent: 0,
      metricPercent: 0
    };
    var n = (0, _request.getToken)();
    return a.websocketUrl = "".concat(_urlConsts.onlineTestWsURL, "test-equipment.ws?token=").concat(n), 
    a;
  }
  return (0, _createClass2.default)(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 e = this, t = [];
      return t.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(t) {
          return e.dispatchMask = t;
        }
      }, _react.default.createElement(_amosWebsocket.default, {
        ref: function(t) {
          return e.aws = t;
        },
        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: t
      }, _react.default.createElement(TabPane, {
        tab: "连接测试",
        key: "1"
      }, _react.default.createElement(_ConnectTest.default, (0, _extends2.default)({
        connectData: this.state.connectData,
        percent: this.state.connectPercent
      }, this.props))), _react.default.createElement(TabPane, {
        tab: "性能测试",
        key: "2"
      }, _react.default.createElement(_PerformanceTest.default, (0, _extends2.default)({
        quotaSelecteList: this.state.quotaSelecteList,
        percent: this.state.metricPercent
      }, this.props))))));
    }
  } ]), r;
}(_react.Component);

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 = _default;