"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"), _amosFramework = require("amos-framework"), _DeviceEnum = require("./../../common/DeviceEnum"), _DeviceLang = require("./../../common/DeviceLang"), _AddEditCapacityInterface = _interopRequireDefault(require("./AddEditCapacityInterface"));

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 c = n ? Object.getOwnPropertyDescriptor(e, i) : null;
    c && (c.get || c.set) ? Object.defineProperty(a, i, c) : a[i] = e[i];
  }
  return a.default = e, r && r.set(e, a), a;
}

function _createForOfIteratorHelper(e, t) {
  var r = "undefined" != typeof Symbol && e[Symbol.iterator] || e["@@iterator"];
  if (!r) {
    if (Array.isArray(e) || (r = _unsupportedIterableToArray(e)) || t && e && "number" == typeof e.length) {
      r && (e = r);
      var a = 0, n = function() {};
      return {
        s: n,
        n: function() {
          return a >= e.length ? {
            done: !0
          } : {
            done: !1,
            value: e[a++]
          };
        },
        e: function(e) {
          throw e;
        },
        f: n
      };
    }
    throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  }
  var i, c = !0, o = !1;
  return {
    s: function() {
      r = r.call(e);
    },
    n: function() {
      var e = r.next();
      return c = e.done, e;
    },
    e: function(e) {
      o = !0, i = e;
    },
    f: function() {
      try {
        c || null == r.return || r.return();
      } finally {
        if (o) throw i;
      }
    }
  };
}

function _unsupportedIterableToArray(e, t) {
  if (e) {
    if ("string" == typeof e) return _arrayLikeToArray(e, t);
    var r = Object.prototype.toString.call(e).slice(8, -1);
    return "Object" === r && e.constructor && (r = e.constructor.name), "Map" === r || "Set" === r ? Array.from(e) : "Arguments" === r || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r) ? _arrayLikeToArray(e, t) : void 0;
  }
}

function _arrayLikeToArray(e, t) {
  (null == t || t > e.length) && (t = e.length);
  for (var r = 0, a = new Array(t); r < t; r++) a[r] = e[r];
  return 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("./../device-detail.scss");

var createForm = _amosAntd.Form.create(), Option = _amosFramework.Select.Option, EditCapacityInterface = function(e) {
  (0, _inherits2.default)(r, e);
  var t = _createSuper(r);
  function r(e) {
    var a;
    return (0, _classCallCheck2.default)(this, r), a = t.call(this, e), (0, _defineProperty2.default)((0, 
    _assertThisInitialized2.default)(a), "onClick", (function() {
      a.setState({
        visible: !0
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "getAllAvailableInterfaces", (function(e) {
      var t, r = [], n = {}, i = _createForOfIteratorHelper(e.deviceInterfaces);
      try {
        for (i.s(); !(t = i.n()).done; ) {
          var c = t.value, o = "".concat(c.intfcDisplayName, "-").concat((0, _DeviceLang.stringUtil)(_DeviceEnum.interfaceDirectionEnum, parseInt(c.intfcDirection)));
          r.push(_react.default.createElement(Option, {
            key: c.intfcId,
            value: "".concat(c.intfcId, "-").concat(c.intfcDirection)
          }, "".concat(c.intfcDisplayName, "-").concat((0, _DeviceLang.stringUtil)(_DeviceEnum.interfaceDirectionEnum, parseInt(c.intfcDirection))))), 
          n["".concat(c.intfcId, "-").concat(c.intfcDirection)] = {
            interfaceMultiName: o,
            interfaceID: c.intfcId,
            devIntfcID: c.devIntfcID
          };
        }
      } catch (e) {
        i.e(e);
      } finally {
        i.f();
      }
      a.setState({
        interfaceOption: r,
        interfaceMap: n
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "handCancel", (function() {
      a.props.form.resetFields(), a.setState({
        visible: !1
      });
    })), a.state = {
      visible: !1,
      interfaceOption: [],
      interfaceMap: {}
    }, a;
  }
  return (0, _createClass2.default)(r, [ {
    key: "componentWillMount",
    value: function() {}
  }, {
    key: "componentDidMount",
    value: function() {
      this.getAllAvailableInterfaces(this.props);
    }
  }, {
    key: "componentWillReceiveProps",
    value: function(e) {
      void 0 !== e.deviceInterfaces && e.deviceInterfaces !== this.props.deviceInterfaces && this.getAllAvailableInterfaces(e);
    }
  }, {
    key: "render",
    value: function() {
      var e = this.props.form, t = this.state, r = t.interfaceOption, a = t.interfaceMap;
      return _react.default.createElement("div", {
        className: "interface-detail-property-button"
      }, _react.default.createElement("div", {
        className: "capacity-interface-button",
        onClick: this.onClick
      }, _react.default.createElement("img", {
        src: require("./../../../../assets/iot/img/list_edit.png"),
        alt: ""
      }), _react.default.createElement("label", null)), _react.default.createElement(_amosAntd.Modal, {
        maskClosable: !1,
        title: "编辑设备接口",
        closable: !0,
        visible: this.state.visible,
        onCancel: this.handCancel,
        width: 500,
        footer: null
      }, _react.default.createElement(_AddEditCapacityInterface.default, (0, _extends2.default)({
        form: e,
        callBack: this.handCancel,
        interfaceOption: r,
        interfaceMap: a
      }, this.props))));
    }
  } ]), r;
}(_react.Component);

EditCapacityInterface.displayName = "EditCapacityInterface", EditCapacityInterface.propTypes = {
  form: _propTypes.default.any,
  deviceInterfaces: _propTypes.default.array
};

var _default = createForm(EditCapacityInterface);

exports.default = _default;