"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"),
  _processor = require("../../../../utils/processor"),
  _urlConsts = require("../../../../consts/urlConsts"),
  _amosFramework = require("amos-framework"),
  _DeviceCapacityCell = _interopRequireDefault(require("./DeviceCapacityCell")),
  _AddDeviceCapacity = _interopRequireDefault(require("./../deviceAddEdit/AddDeviceCapacity"));

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, i, o = {},
    n = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (r in e) Object.prototype.hasOwnProperty.call(e, r) && ((i = n ? Object.getOwnPropertyDescriptor(e, r) : null) && (i.get || i.set) ? Object.defineProperty(o, r, i) : 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, i = arguments[t];
      for (r in i) Object.prototype.hasOwnProperty.call(i, r) && (e[r] = i[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 i = t[r];
    i.enumerable = i.enumerable || !1, i.configurable = !0, "value" in i && (i.writable = !0), Object.defineProperty(e, i.key, i)
  }
}

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 i = _isNativeReflectConstruct();
  return function() {
    var e, t = _getPrototypeOf(r);
    return _possibleConstructorReturn(this, i ? (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
}
require("./../device-detail.scss");
var DeviceCapacity = function() {
  _inherits(r, _react.Component);
  var t = _createSuper(r);

  function r(e) {
    var f;
    return _classCallCheck(this, r), _defineProperty(_assertThisInitialized(f = t.call(this, e)), "updateNewInfo", function() {
      f.fetchDeviceCapacity(f.props)
    }), _defineProperty(_assertThisInitialized(f), "fetchDeviceCapacity", function(e) {
      var c = e.device,
        a = e.getDeviceInfoById,
        s = e.deviceInterfaces,
        p = c.capabilities,
        u = [];
      if (p && 0 < p.length)
        for (var t = 0; t < p.length; t++) ! function(o) {
          var n = p[o],
            e = "".concat(_urlConsts.OltSerUrl.fetchCapacityListInfoById, "/").concat(n.id);
          _processor.AmosFetch.get(e).then(function(e) {
            if (e.ok) return e.json();
            throw new Error("从服务端获取数据失败！")
          }).then(function(e) {
            var t, r, i;
            "SUCCESS" !== e.result || (i = e.dataList) && (t = i.interface, r = i.property, e = i.protocolName, i = n.protocolId, _extends(n, {
              interfaceInfo: t,
              protocolName: e,
              propertyInfo: r
            }), u.push(_react.default.createElement(_DeviceCapacityCell.default, {
              protocolId: i,
              capacityId: n.id,
              deviceId: c.id,
              getDeviceInfoById: a,
              key: o,
              listInfo: n,
              deleteCapacityProperty: f.deleteCapacityProperty,
              addCapacityProperty: f.addCapacityProperty,
              deviceInterfaces: s,
              updateNewInfo: f.updateNewInfo,
              visibility: c.visibility
            }))), o === p.length - 1 && f.setState({
              capaCityList: u
            })
          })
        }(t);
      else f.setState({
        capaCityList: []
      })
    }), _defineProperty(_assertThisInitialized(f), "deleteCapacityProperty", function(e) {
      var t = f.delCapacity;
      _amosAntd.Modal.confirm({
        title: "删除",
        content: "是否删除所选属性？",
        okText: "确定",
        cancelText: "取消",
        onOk: function() {
          t(e)
        },
        onCancel: function() {}
      })
    }), _defineProperty(_assertThisInitialized(f), "addCapacityProperty", function() {
      var e = f.props.device.id;
      f.props.getDeviceInfoById(e)
    }), _defineProperty(_assertThisInitialized(f), "delCapacity", function(e) {
      var t = f.props.device.id,
        e = "".concat(_urlConsts.OltSerUrl.deleteDeviceCapacity, "/").concat(e);
      _processor.AmosFetch.del(e).then(function(e) {
        if (e.ok) return e.text();
        throw new Error("从服务端获取数据失败！")
      }).then(function(e) {
        _amosFramework.message.success("删除成功！"), f.props.getDeviceInfoById(t)
      })
    }), f.state = {
      capaCityList: []
    }, f
  }
  return _createClass(r, [{
    key: "componentDidMount",
    value: function() {}
  }, {
    key: "componentWillReceiveProps",
    value: function(e) {
      void 0 === e.device || e.deviceInterfaces === this.props.deviceInterfaces && e.device === this.props.device || this.fetchDeviceCapacity(e)
    }
  }, {
    key: "render",
    value: function() {
      var e = this.state.capaCityList,
        t = this.props,
        r = t.device,
        i = t.getDeviceInfoById,
        t = t.deviceInterfaces;
      return _react.default.createElement("div", {
        className: "device-capacity"
      }, _react.default.createElement("div", {
        className: "device-detail-capacity"
      }, _react.default.createElement("label", null, "数据采集"), 1 === r.visibility ? _react.default.createElement(_AddDeviceCapacity.default, {
        deviceInterfaces: t,
        deviceId: r.id,
        visibility: r.visibility,
        getDeviceInfoById: i
      }) : null), _react.default.createElement("div", {
        className: "device-detail-capacity-content"
      }, e))
    }
  }]), r
}();
DeviceCapacity.displayName = "DeviceCapacity", DeviceCapacity.propTypes = {
  device: _propTypes.default.object,
  getDeviceInfoById: _propTypes.default.func,
  deviceInterfaces: _propTypes.default.array
};
var _default = DeviceCapacity;
exports.default = DeviceCapacity, module.exports = exports.default;
