"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")), _amosFramework = require("amos-framework"), _amosAntd = require("amos-antd"), _TaskEnum = require("./../../../createEquipment/common/TaskEnum"), _topoService = require("./../../../../services/topoService");

function _getRequireWildcardCache(e) {
  if ("function" != typeof WeakMap) return null;
  var t = new WeakMap, a = new WeakMap;
  return (_getRequireWildcardCache = function(e) {
    return e ? a : 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 a = _getRequireWildcardCache(t);
  if (a && a.has(e)) return a.get(e);
  var r = {}, 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(r, i, o) : r[i] = e[i];
  }
  return r.default = e, a && a.set(e, r), r;
}

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

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 Panel = _amosFramework.Collapse.Panel, Option = _amosAntd.Select.Option, DeviceCapacityInfoConfig = function(e) {
  (0, _inherits2.default)(a, e);
  var t = _createSuper(a);
  function a(e) {
    var r;
    return (0, _classCallCheck2.default)(this, a), r = t.call(this, e), (0, _defineProperty2.default)((0, 
    _assertThisInitialized2.default)(r), "onInitCollapsePanel", (function(e) {
      var t = e ? e.cpbl : void 0, a = 0, r = [];
      return t && t.map((function(e) {
        a += 1, r.push(a.toString());
      })), r;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onChangeCollapseSize", (function(e) {
      void 0 !== e && void 0 !== e.length && r.setState({
        collapseKey: e
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onTaskAttributeChange", (function(e, t, a) {
      var n = r.props, i = n.equipmentId, o = n.nodeId, l = n.showProperty;
      e.monitorPeriod = a;
      var c = {
        id: i,
        task: e
      };
      (0, _topoService.updateEquipmentConfigAction)(c).then((function(e) {
        var n = r.taskParams;
        n[t] = a, r.taskParams = n, l(o);
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onInterfaceAttributeChange", (function(e, t) {
      var a = r.props, n = a.equipmentId, i = a.nodeId, o = a.showProperty, l = {
        id: n
      };
      l[e] = t, (0, _topoService.updateEquipmentConfigAction)(l).then((function(a) {
        var n = r.interfaceProperty;
        n[e] = t, r.interfaceProperty = n, o(i);
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getCollapseHead", (function(e, t) {
      var a = r.props.getImgPath(t, r.state.collapseKey), n = [];
      return n.push(_react.default.createElement("div", {
        className: "config-collapse-head"
      }, _react.default.createElement("label", {
        className: "config-collapse-text"
      }, e), a)), n;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getCapaityContent", (function() {
      var e = r.props.currentDeviceConfig, t = e ? e.cpbl : void 0, a = [], n = 0;
      return t && t.map((function(e) {
        n += 1;
        var t = e.cpbl, i = e.protocol, o = e.task, l = r.taskParams, c = l[t.id];
        void 0 === c && (c = 0 === o.monitorPeriod ? void 0 : o.monitorPeriod, l[t.id] = c, 
        r.taskParams = l);
        var u = e.intfc, s = e.intfcProperty, p = o.monitorType, f = "";
        _TaskEnum.monitorTypeArr.map((function(e) {
          e.value === p && (f = e.title);
        }));
        var d = !1;
        2 === p && (d = !0), a.push(_react.default.createElement(Panel, {
          showArrow: !1,
          header: r.getCollapseHead(t.name, n.toString()),
          key: n.toString()
        }, _react.default.createElement("div", {
          className: "device-capacity-info"
        }, _react.default.createElement("div", {
          className: "topo-capacity-common"
        }, _react.default.createElement("div", {
          className: "property-label-name"
        }, "通信协议："), _react.default.createElement("div", {
          className: "property-normal-label",
          title: i && i.name
        }, i && i.name)), _react.default.createElement("div", {
          className: "topo-capacity-common"
        }, _react.default.createElement("div", {
          className: "property-label-name"
        }, "监测方式："), _react.default.createElement("div", {
          className: "property-normal-label",
          title: f
        }, f)), d ? "" : _react.default.createElement("div", {
          className: "topo-capacity-common"
        }, _react.default.createElement("div", {
          className: "property-label-name"
        }, "采集周期："), _react.default.createElement("div", {
          className: "property-normal-select"
        }, _react.default.createElement(_amosAntd.Select, {
          disabled: d,
          value: c,
          style: {
            width: 91
          },
          placeholder: "请选择",
          onSelect: function(e) {
            return r.onTaskAttributeChange(o, t.id, e);
          }
        }, _TaskEnum.periodArr.map((function(e) {
          return _react.default.createElement(Option, {
            key: e.value,
            value: e.value
          }, e.title);
        }))))), _react.default.createElement("div", {
          className: "topo-capacity-common"
        }, _react.default.createElement("div", {
          className: "property-label-name"
        }, "通信方式："), _react.default.createElement("div", {
          className: "property-normal-label",
          title: u && u.name
        }, u && u.name)), _react.default.createElement("div", {
          className: "topo-capacity-single"
        }, "通信参数"), r.getIntfcPropertyContent(t.id, u.id, s))));
      })), a;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getIntfcPropertyContent", (function(e, t, a) {
      var n = [], i = r.interfaceProperty;
      return a && a.map((function(a) {
        var o = "cpbl_intfc_".concat(e, "_").concat(t, "_").concat(a.id), l = i[o];
        void 0 === l && (l = a.value), i[o] = l, n.push(_react.default.createElement("div", {
          key: a.id,
          className: "capacity-config-common"
        }, _react.default.createElement("div", {
          className: "property-key-style",
          title: a.displayName
        }, a.displayName, "："), _react.default.createElement("div", {
          style: {
            width: "126px",
            float: "left"
          }
        }, _react.default.createElement(_amosFramework.Editable, {
          value: l,
          onChange: function(e) {
            return r.onInterfaceAttributeChange(o, e);
          },
          showOkCancel: !1,
          placeholder: "请输入"
        }))));
      })), n;
    })), r.taskParams = {}, r.interfaceProperty = {}, r.state = {
      collapseKey: r.onInitCollapsePanel(e.currentDeviceConfig)
    }, r;
  }
  return (0, _createClass2.default)(a, [ {
    key: "componentWillMount",
    value: function() {}
  }, {
    key: "componentDidMount",
    value: function() {}
  }, {
    key: "componentWillReceiveProps",
    value: function(e) {
      e.currentDeviceConfig !== this.props.currentDeviceConfig && this.onInitCollapsePanel(e.currentDeviceConfig);
    }
  }, {
    key: "componentWillUnmount",
    value: function() {}
  }, {
    key: "render",
    value: function() {
      var e = this, t = this.state.collapseKey;
      return _react.default.createElement("div", {
        className: "topo-config-capacity-root"
      }, _react.default.createElement(_amosFramework.Collapse, {
        activeKey: t,
        onChange: function(t) {
          return e.onChangeCollapseSize(t);
        }
      }, this.getCapaityContent()));
    }
  } ]), a;
}(_react.Component);

DeviceCapacityInfoConfig.displayName = "DeviceCapacityInfoConfig", DeviceCapacityInfoConfig.propTypes = {
  getImgPath: _propTypes.default.func,
  currentDeviceConfig: _propTypes.default.object,
  subviewId: _propTypes.default.string,
  nodeId: _propTypes.default.string,
  equipmentId: _propTypes.default.number,
  config: _propTypes.default.object,
  showProperty: _propTypes.default.func
};

var _default = DeviceCapacityInfoConfig;

exports.default = _default;