"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"), _processor = require("../../../../utils/processor"), _urlConsts = require("../../../../consts/urlConsts"), _AddEditDeviceCapacity = _interopRequireDefault(require("./AddEditDeviceCapacity")), _DeviceEnum = require("./../../common/DeviceEnum"), _DeviceLang = require("./../../common/DeviceLang");

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 = {}, i = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (var n in e) if ("default" !== n && Object.prototype.hasOwnProperty.call(e, n)) {
    var o = i ? Object.getOwnPropertyDescriptor(e, n) : null;
    o && (o.get || o.set) ? Object.defineProperty(a, n, o) : a[n] = e[n];
  }
  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, i = function() {};
      return {
        s: i,
        n: function() {
          return a >= e.length ? {
            done: !0
          } : {
            done: !1,
            value: e[a++]
          };
        },
        e: function(e) {
          throw e;
        },
        f: i
      };
    }
    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 n, o = !0, c = !1;
  return {
    s: function() {
      r = r.call(e);
    },
    n: function() {
      var e = r.next();
      return o = e.done, e;
    },
    e: function(e) {
      c = !0, n = e;
    },
    f: function() {
      try {
        o || null == r.return || r.return();
      } finally {
        if (c) throw n;
      }
    }
  };
}

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 i = (0, _getPrototypeOf2.default)(this).constructor;
      r = Reflect.construct(a, arguments, i);
    } 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, EditDeviceCapacity = 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), "getAllAvailableProtocols", (function(e) {
      var t = [];
      t.push({}), _processor.AmosFetch.post(_urlConsts.OltSerUrl.protocolDataList, {
        data: t
      }).then((function(e) {
        if (e.ok) return e.json();
        throw new Error("从服务端获取数据失败！");
      })).then((function(e) {
        if ("SUCCESS" === e.result && null !== e.dataList) {
          var t = e.dataList.map((function(e) {
            return _react.default.createElement(Option, {
              key: e.id,
              value: "".concat(e.id)
            }, e.name);
          }));
          a.setState({
            protocolOption: t
          });
        }
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "getAllAvailableInterfaces", (function(e) {
      var t, r = e.deviceInterfaces, i = e.listInfo, n = [], o = {}, c = _createForOfIteratorHelper(r);
      try {
        for (c.s(); !(t = c.n()).done; ) {
          var l = t.value;
          n.push(_react.default.createElement(Option, {
            key: l.intfcId,
            value: "".concat(l.intfcId, "-").concat(l.intfcDirection)
          }, "".concat(l.intfcDisplayName, "-").concat((0, _DeviceLang.stringUtil)(_DeviceEnum.interfaceDirectionEnum, parseInt(l.intfcDirection))))), 
          o[parseInt(l.intfcId)] = l.intfcDisplayName;
        }
      } catch (e) {
        c.e(e);
      } finally {
        c.f();
      }
      var u = [];
      i.interfaceInfo.map((function(e) {
        u.push("".concat(e.intfcId, "-").concat(e.intfcDirection));
      })), a.setState({
        interfaceOption: n,
        interfaceMap: o,
        selectedInterfaceList: u
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "handCancel", (function() {
      a.props.form.resetFields(), a.setState({
        visible: !1
      });
    })), a.state = {
      protocolOption: [],
      interfaceOption: [],
      selectedInterfaceList: [],
      visible: !1
    }, a;
  }
  return (0, _createClass2.default)(r, [ {
    key: "componentWillMount",
    value: function() {}
  }, {
    key: "componentDidMount",
    value: function() {
      this.getAllAvailableProtocols(), 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, t = e.form, r = e.listInfo, a = e.deviceId, i = e.protocolId, n = e.capacityId, o = e.getDeviceInfoById, c = e.deleteCurrentDeviceProperty, l = this.state, u = l.protocolOption, s = l.interfaceOption, f = l.selectedInterfaceList, p = l.interfaceMap;
      return _react.default.createElement("div", {
        className: "capacity-detail-property-button"
      }, _react.default.createElement("div", {
        className: "device-cell-delete-button",
        onClick: c
      }, _react.default.createElement("img", {
        src: require("./../../../../assets/iot/img/mk_delect.png"),
        alt: ""
      }), _react.default.createElement("label", null, "删除")), _react.default.createElement("div", {
        className: "device-capacity-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(_AddEditDeviceCapacity.default, (0, _extends2.default)({
        form: t,
        callBack: this.handCancel,
        listInfo: r,
        deviceId: a,
        protocolId: i,
        interfaceOption: s,
        protocolOption: u,
        selectedInterfaceList: f,
        capacityId: n,
        interfaceMap: p,
        getDeviceInfoById: o
      }, this.props))));
    }
  } ]), r;
}(_react.Component);

EditDeviceCapacity.displayName = "EditDeviceCapacity", EditDeviceCapacity.propTypes = {
  form: _propTypes.default.any,
  listInfo: _propTypes.default.any,
  deviceId: _propTypes.default.number,
  deviceInterfaces: _propTypes.default.array,
  protocolId: _propTypes.default.number,
  capacityId: _propTypes.default.number,
  getDeviceInfoById: _propTypes.default.func,
  deleteCurrentDeviceProperty: _propTypes.default.func
};

var _default = createForm(EditDeviceCapacity);

exports.default = _default;