"use strict";
Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.default = void 0;
var _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 _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, n, a = {},
    o = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (r in e) Object.prototype.hasOwnProperty.call(e, r) && ((n = o ? Object.getOwnPropertyDescriptor(e, r) : null) && (n.get || n.set) ? Object.defineProperty(a, r, n) : a[r] = e[r]);
  return a.default = e, t && t.set(e, a), a
}

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 _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 n = t[r];
    n.enumerable = n.enumerable || !1, n.configurable = !0, "value" in n && (n.writable = !0), Object.defineProperty(e, n.key, n)
  }
}

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 n = _isNativeReflectConstruct();
  return function() {
    var e, t = _getPrototypeOf(r);
    return _possibleConstructorReturn(this, n ? (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
}
var Panel = _amosFramework.Collapse.Panel,
  Option = _amosAntd.Select.Option,
  DeviceCapacityInfoConfig = function() {
    _inherits(r, _react.Component);
    var t = _createSuper(r);

    function r(e) {
      var s;
      return _classCallCheck(this, r), _defineProperty(_assertThisInitialized(s = t.call(this, e)), "onInitCollapsePanel", function(e) {
        var e = e ? e.cpbl : void 0,
          t = 0,
          r = [];
        return e && e.map(function(e) {
          t += 1, r.push(t.toString())
        }), r
      }), _defineProperty(_assertThisInitialized(s), "onChangeCollapseSize", function(e) {
        void 0 !== e && void 0 !== e.length && s.setState({
          collapseKey: e
        })
      }), _defineProperty(_assertThisInitialized(s), "onTaskAttributeChange", function(e, r, n) {
        var t = s.props,
          a = t.equipmentId,
          o = t.nodeId,
          i = t.showProperty;
        e.monitorPeriod = n;
        e = {
          id: a,
          task: e
        };
        (0, _topoService.updateEquipmentConfigAction)(e).then(function(e) {
          var t = s.taskParams;
          t[r] = n, s.taskParams = t, i(o)
        })
      }), _defineProperty(_assertThisInitialized(s), "onInterfaceAttributeChange", function(r, n) {
        var e = s.props,
          t = e.equipmentId,
          a = e.nodeId,
          o = e.showProperty,
          t = {
            id: t
          };
        t[r] = n, (0, _topoService.updateEquipmentConfigAction)(t).then(function(e) {
          var t = s.interfaceProperty;
          t[r] = n, s.interfaceProperty = t, o(a)
        })
      }), _defineProperty(_assertThisInitialized(s), "getCollapseHead", function(e, t) {
        var r = s.props.getImgPath(t, s.state.collapseKey),
          t = [];
        return t.push(_react.default.createElement("div", {
          className: "config-collapse-head"
        }, _react.default.createElement("label", {
          className: "config-collapse-text"
        }, e), r)), t
      }), _defineProperty(_assertThisInitialized(s), "getCapaityContent", function() {
        var e = s.props.currentDeviceConfig,
          e = e ? e.cpbl : void 0,
          p = [],
          u = 0;
        return e && e.map(function(e) {
          u += 1;
          var t = e.cpbl,
            r = e.protocol,
            n = e.task,
            a = s.taskParams,
            o = a[t.id];
          void 0 === o && (o = 0 === n.monitorPeriod ? void 0 : n.monitorPeriod, a[t.id] = o, s.taskParams = a);
          var i = e.intfc,
            a = e.intfcProperty,
            c = n.monitorType,
            l = "";
          _TaskEnum.monitorTypeArr.map(function(e) {
            e.value === c && (l = e.title)
          });
          e = 2 === c;
          p.push(_react.default.createElement(Panel, {
            showArrow: !1,
            header: s.getCollapseHead(t.name, u.toString()),
            key: u.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: r && r.name
          }, r && r.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: l
          }, l)), e ? "" : _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: e,
            value: o,
            style: {
              width: 91
            },
            placeholder: "请选择",
            onSelect: function(e) {
              return s.onTaskAttributeChange(n, 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: i && i.name
          }, i && i.name)), _react.default.createElement("div", {
            className: "topo-capacity-single"
          }, "通信参数"), s.getIntfcPropertyContent(t.id, i.id, a))))
        }), p
      }), _defineProperty(_assertThisInitialized(s), "getIntfcPropertyContent", function(n, a, e) {
        var o = [],
          i = s.interfaceProperty;
        return e && e.map(function(e) {
          var t = "cpbl_intfc_".concat(n, "_").concat(a, "_").concat(e.id),
            r = i[t];
          void 0 === r && (r = e.value), i[t] = r, o.push(_react.default.createElement("div", {
            key: e.id,
            className: "capacity-config-common"
          }, _react.default.createElement("div", {
            className: "property-key-style",
            title: e.displayName
          }, e.displayName, "："), _react.default.createElement("div", {
            style: {
              width: "126px",
              float: "left"
            }
          }, _react.default.createElement(_amosFramework.Editable, {
            value: r,
            onChange: function(e) {
              return s.onInterfaceAttributeChange(t, e)
            },
            showOkCancel: !1,
            placeholder: "请输入"
          }))))
        }), o
      }), s.taskParams = {}, s.interfaceProperty = {}, s.state = {
        collapseKey: s.onInitCollapsePanel(e.currentDeviceConfig)
      }, s
    }
    return _createClass(r, [{
      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 t = this,
          e = this.state.collapseKey;
        return _react.default.createElement("div", {
          className: "topo-config-capacity-root"
        }, _react.default.createElement(_amosFramework.Collapse, {
          activeKey: e,
          onChange: function(e) {
            return t.onChangeCollapseSize(e)
          }
        }, this.getCapaityContent()))
      }
    }]), r
  }();
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 = DeviceCapacityInfoConfig, module.exports = exports.default;
