"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 _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"), _urlConsts = require("../../../consts/urlConsts"), _processor = require("../../../utils/processor"), _amosIcon = _interopRequireDefault(require("amos-icon"));

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 l in e) if ("default" !== l && Object.prototype.hasOwnProperty.call(e, l)) {
    var o = n ? Object.getOwnPropertyDescriptor(e, l) : null;
    o && (o.get || o.set) ? Object.defineProperty(a, l, o) : a[l] = e[l];
  }
  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;
  }
}

require("./onlineTest.scss");

var ConnectTest = 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), "getViewForList", (function() {
      var e = a.props.intfcList, t = a.state.connectData, r = [];
      return e.map((function(e) {
        if (t[e.id] && "ok" === t[e.id]) r.push(_react.default.createElement(_amosAntd.Row, null, _react.default.createElement("span", {
          style: {
            fontSize: "14px"
          }
        }, e.name), _react.default.createElement(_amosIcon.default, {
          icon: "ok",
          size: "lg",
          style: {
            color: "red",
            float: "right",
            marginTop: "5px"
          }
        }), _react.default.createElement("div", {
          className: "divider-css"
        }))); else if (t[e.id] && "ok" !== t[e.id]) {
          var n = "flag".concat(e.id);
          r.push(_react.default.createElement(_amosAntd.Row, {
            onClick: function() {
              a.anErrorInfo(n);
            }
          }, _react.default.createElement("span", {
            style: {
              fontSize: "14px",
              color: "red"
            }
          }, e.name), _react.default.createElement(_amosIcon.default, {
            icon: "close",
            size: "lg",
            style: {
              color: "red",
              float: "right",
              marginTop: "5px"
            }
          }), _react.default.createElement("div", {
            className: "divider-red"
          }), a.state[n] ? _react.default.createElement("div", null, _react.default.createElement("span", {
            style: {
              color: "red"
            }
          }, t[e.id]), _react.default.createElement("div", {
            className: "divider-css"
          })) : null));
        } else r.push(_react.default.createElement(_amosAntd.Row, null, _react.default.createElement("span", {
          style: {
            fontSize: "14px"
          }
        }, e.name), _react.default.createElement("div", {
          className: "divider-css"
        })));
      })), r;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "anErrorInfo", (function(e) {
      a.setState((0, _defineProperty2.default)({}, e, !a.state[e]));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "TodoTest", (function() {
      a.setState({
        percent: 0
      });
      a.props.saveEquipmnet({
        binaryImg: null,
        imgName: "default.png"
      }, "connect");
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "ExportData", (function() {
      var e = "".concat(_urlConsts.OltSerUrl.exportData);
      _processor.AmosFetch.get(e).then((function(e) {
        if (e.ok) return e;
        throw new Error("从服务端获取数据失败！");
      })).then((function(e) {
        "SUCCESS" === e.result && console.log(e);
      }));
    }));
    var n = a.props.percent, l = a.props.connectData, o = a.props.exprotButton;
    return a.state = {
      connectData: l,
      flag: !1,
      percent: n,
      exprotButton: o
    }, a;
  }
  return (0, _createClass2.default)(r, [ {
    key: "componentWillReceiveProps",
    value: function(e) {
      this.setState({
        percent: e.percent
      }), 100 === e.percent ? this.setState({
        exprotButton: "inline"
      }) : this.setState({
        exprotButton: "none"
      });
    }
  }, {
    key: "render",
    value: function() {
      var e = "".concat(_urlConsts.OltSerUrl.exportData);
      return _react.default.createElement("div", null, _react.default.createElement("div", {
        className: "online-test-top"
      }, _react.default.createElement(_amosAntd.Row, null, _react.default.createElement(_amosAntd.Progress, {
        type: "circle",
        percent: this.state.percent,
        width: 175
      })), _react.default.createElement(_amosAntd.Row, {
        style: {
          marginTop: "20px"
        }
      }, _react.default.createElement(_amosAntd.Button, {
        type: "primary",
        onClick: this.TodoTest
      }, "测试"), " ", _react.default.createElement("a", {
        href: e
      }, _react.default.createElement(_amosAntd.Button, {
        type: "primary",
        style: {
          display: this.state.exprotButton
        }
      }, "导出测试报告")))), _react.default.createElement("div", {
        className: "online-test-bottom"
      }, _react.default.createElement("div", {
        className: "bottom-one"
      }, _react.default.createElement(_amosAntd.Row, null, _react.default.createElement("span", {
        style: {
          fontSize: "20px",
          fontWeight: "bold"
        }
      }, "接口连接")), _react.default.createElement("div", {
        className: "divider-css"
      }), _react.default.createElement(_amosAntd.Row, null, _react.default.createElement("span", {
        style: {
          fontSize: "14px",
          fontWeight: "bold"
        }
      }, "固定接口连接测试")), _react.default.createElement("div", {
        className: "divider-css"
      }), this.getViewForList())));
    }
  } ]), r;
}(_react.Component);

ConnectTest.displayName = "ConnectTest", ConnectTest.propTypes = {
  intfcList: _propTypes.default.any,
  saveEquipmnet: _propTypes.default.func,
  visible: _propTypes.default.any,
  percent: _propTypes.default.any,
  connectData: _propTypes.default.any
};

var _default = ConnectTest;

exports.default = _default;