"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"), _rayEventpool = require("ray-eventpool"), _ActionConf = require("./../../common/ActionConf"), _TaskEnum = require("./../../common/TaskEnum"), _deviceService = require("./../../../../services/deviceService"), _ThresholdInput = _interopRequireDefault(require("./ThresholdInput")), _ThresholdName = _interopRequireDefault(require("./ThresholdName"));

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 = {}, o = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (var l in e) if ("default" !== l && Object.prototype.hasOwnProperty.call(e, l)) {
    var i = o ? Object.getOwnPropertyDescriptor(e, l) : null;
    i && (i.get || i.set) ? Object.defineProperty(r, l, i) : r[l] = e[l];
  }
  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 o = (0, _getPrototypeOf2.default)(this).constructor;
      a = Reflect.construct(r, arguments, o);
    } 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, CheckboxGroup = _amosFramework.Checkbox.Group, Option = _amosAntd.Select.Option, QuotaPropertyPanel = 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), "onAttributeChange", (function() {})), (0, 
    _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onChangeChecked", (function(e) {
      var t = r.propertyId, a = [];
      e.map((function(e) {
        void 0 !== t && t.includes(e) && a.push(e);
      }));
      var o = r.props, l = o.updateQuotaPropertyCell, i = o.id, n = r.quotaParam;
      l(i, a), (void 0 === n[i] || 0 === n[i].length) && a.length > 0 && r.changeStatus(), 
      n[i] = a, r.quotaParam = n, r.setState({
        updateFlag: !1
      });
    })), (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), "onMonitorTypeChange", (function(e) {
      var t = r.props.taskParam, a = r.props, o = a.updateQuotaTaskCell, l = a.id;
      t[l].monitorPeriod = e, o(l, t[l]), r.setState({
        updateFlag: !1
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onInterfaceAttributeChange", (function(e, t) {
      var a = r.state.interfaceProperty, o = r.props.updateInterfacePropertyCell;
      a[e] = t, o(e, t), r.setState({
        interfaceProperty: a
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getInterfaceBaseContent", (function() {
      var e = [], t = r.props.id, a = r.state.interfaceList[t];
      return a && e.push(_react.default.createElement("div", {
        key: "interface-base",
        className: "property-config-common"
      }, _react.default.createElement("div", {
        title: "通讯方式",
        className: "property-key-style"
      }, "通讯方式", "："), _react.default.createElement("div", {
        style: {
          width: "136px",
          float: "left"
        }
      }, _react.default.createElement("div", {
        className: "property-normal-label",
        title: a.name
      }, a.name)))), e;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getInterfaceAttributesEditContent", (function() {
      var e = [], t = r.props, a = t.id, o = t.equipment, l = t.enable, i = t.updateInterfacePropertyCell, n = t.capacity, u = r.state, s = u.interfaceProperty, p = u.interfaceList[a];
      return e.push(_react.default.createElement("div", {
        key: "title",
        className: "interface-property-title"
      }, "通讯参数")), p && p.attributes.map((function(t) {
        var a = "cpbl_intfc_".concat(n.id, "_").concat(p.id, "_").concat(t.id), u = s[a];
        if (void 0 === u) if (void 0 !== o && void 0 !== o.id) {
          var c = o.cfgParamMap;
          u = c[a] ? c[a] : u;
        } else u = t.valueStr;
        s[a] = u, i(a, u), e.push(_react.default.createElement("div", {
          key: t.id,
          className: "property-config-common"
        }, _react.default.createElement("div", {
          className: "property-key-style",
          title: t.displayName
        }, t.displayName, "："), _react.default.createElement("div", {
          style: {
            width: "136px",
            float: "left"
          }
        }, l ? _react.default.createElement(_amosFramework.Editable, {
          value: u || t.valueStr,
          onChange: function(e) {
            return r.onInterfaceAttributeChange(a, e);
          },
          showOkCancel: !1,
          style: {
            width: "136px"
          },
          placeholder: "请输入",
          innerValueStyle: {
            width: "136px"
          }
        }) : _react.default.createElement("div", {
          className: "property-normal-label",
          title: u || t.valueStr
        }, u || t.valueStr))));
      })), e;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getAttributesEditContent", (function() {
      var e = [], t = [], a = r.props, o = a.updateQuotaPropertyCell, l = a.id, i = a.equipment, n = a.capacity, u = a.enable, s = a.quotaSelectedStatus, p = a.resetStatus, c = a.updateCapacityThresholdInfo, d = a.eqpThreshold, f = r.state.propertyList, m = r.quotaParam, y = [];
      if (void 0 === m[l]) {
        if (void 0 !== i && void 0 !== i.id) {
          var _ = i.cfgParamMap.quotaSelected;
          _ && void 0 !== _[n.id] && (y = _[n.id]);
        } else f[l] && f[l].map((function(e) {
          y.push(e.id);
        })), o(l, y);
        0 !== y.length && (m[l] = y, r.quotaParam = m);
      } else y = m[l];
      var h = [], v = [], C = 0;
      if (f[l] && f[l].map((function(e) {
        h.push(e.id), e.isUser && v.push(e.id);
        var a = "threshold-name-root";
        0 === C && (a = "threshold-name-first-root"), C += 1, t.push(_react.default.createElement(_ThresholdName.default, {
          key: "title",
          textStyle: a,
          name: e.displayName,
          disabled: !u,
          value: e.id
        })), t.push(_react.default.createElement(_amosFramework.Checkbox, {
          key: e.id,
          disabled: !u,
          value: e.id
        }));
        var r = !0;
        1 !== e.type && 4 !== e.type || 1 !== e.dataType && 2 !== e.dataType || (r = !1);
        var o = "".concat(n.id, "_").concat(e.id), l = d[o];
        void 0 === l && ((l = {}).upper = e.maxValue, l.lower = e.minValue), t.push(_react.default.createElement(_ThresholdInput.default, {
          updateCapacityThresholdInfo: c,
          unit: e.unit,
          key: "threshold",
          disabled: !u,
          value: e.id,
          upper: l.upper,
          lower: l.lower,
          infoKey: o,
          isHidden: r
        }));
      })), r.propertyId = h, s) {
        var P = r.propertyId, b = [];
        y = [], f[l] && f[l].map((function(e) {
          y.push(e.id), void 0 !== P && P.includes(e.id) && b.push(e.id);
        })), o(l, b), m[l] = b, r.quotaParam = m, p();
      } else !1 === s && (y = [], o(l, []), m[l] = [], r.quotaParam = m, p());
      return e.push(_react.default.createElement("div", {
        key: "group",
        className: "template-config-common"
      }, _react.default.createElement(CheckboxGroup, {
        selects: y,
        vertical: !0,
        isCheckall: u,
        onChange: r.onChangeChecked
      }, t))), e;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getCapacityInfos", (function(e, t) {
      (0, _deviceService.fetchCapacityInterfaceAction)(t).then((function(e) {
        if (null !== e) {
          var a = r.state.interfaceList;
          a[t] = e, r.setState({
            interfaceList: a
          });
        }
      })), (0, _deviceService.fetchTemplatOrEqpQuotaPropertyAction)(e, t).then((function(e) {
        if (null !== e) {
          var a = r.state.propertyList;
          a[t] = e, r.setState({
            propertyList: a
          });
        }
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getCollapseHead", (function(e, t) {
      var a = r.props.getImgPath(t, r.state.collapseKey), o = [];
      return o.push(_react.default.createElement("div", {
        key: "head",
        className: "config-collapse-head"
      }, _react.default.createElement("label", {
        className: "config-collapse-text"
      }, e), a)), o;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getTaskContent", (function() {
      var e = [], t = r.props, a = t.capacity, o = t.enable, l = t.taskParam, i = t.id, n = 0 === l[i].monitorPeriod ? void 0 : l[i].monitorPeriod, u = a.monitorType;
      return e.push(_react.default.createElement("div", {
        key: "type",
        className: "property-config-common"
      }, _react.default.createElement(_amosFramework.Row, null, _react.default.createElement(_amosFramework.Col, {
        span: 6,
        offset: 0,
        className: "property-key-style"
      }, "监测方式："), _react.default.createElement(_amosFramework.Col, {
        span: 16,
        offset: 0,
        style: {
          width: "136px"
        }
      }, _react.default.createElement(_amosAntd.Select, {
        value: a.monitorType,
        style: {
          width: 136
        },
        disabled: !0,
        placeholder: "监测方式"
      }, _TaskEnum.monitorTypeArr.map((function(e) {
        return _react.default.createElement(Option, {
          key: e.value,
          value: e.value
        }, e.title);
      }))))))), 1 == u && e.push(_react.default.createElement("div", {
        key: "task",
        className: "property-config-common"
      }, _react.default.createElement(_amosFramework.Row, null, _react.default.createElement(_amosFramework.Col, {
        span: 6,
        offset: 0,
        className: "property-key-style"
      }, "采集周期："), _react.default.createElement(_amosFramework.Col, {
        span: 16,
        offset: 0,
        style: {
          width: "136px"
        }
      }, _react.default.createElement(_amosAntd.Select, {
        disabled: !o,
        value: n,
        style: {
          width: 136
        },
        placeholder: "请选择",
        onSelect: r.onMonitorTypeChange
      }, _TaskEnum.periodArr.map((function(e) {
        return _react.default.createElement(Option, {
          key: e.value,
          value: e.value
        }, e.title);
      }))))))), e;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "closeQuotaPanel", (function() {
      _rayEventpool.PubSub.publish(_ActionConf.CONFIG_PANEL_HIDE_TOPIC.trigger, {});
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "changeStatus", (function() {
      var e = r.props.capacity;
      _rayEventpool.PubSub.publish(_ActionConf.SELECT_STATUS_CHANGE_TOPIC.trigger, {
        cpbId: e.id,
        status: !0
      });
    })), r.propertyId = [], r.quotaParam = {}, r.state = {
      collapseKey: [ "1", "2", "3" ],
      propertyList: {},
      interfaceList: {},
      interfaceProperty: {},
      updateFlag: !1
    }, r;
  }
  return (0, _createClass2.default)(a, [ {
    key: "componentDidMount",
    value: function() {
      var e = this.props, t = e.id, a = e.equipment;
      this.getCapacityInfos(a ? a.id : 0, t);
    }
  }, {
    key: "componentWillReceiveProps",
    value: function(e) {
      var t = this.props.id;
      e.id !== t && this.getCapacityInfos(e.equipment ? e.equipment.id : 0, e.id);
    }
  }, {
    key: "render",
    value: function() {
      var e = this, t = this.state.collapseKey, a = this.props.capacity;
      return _react.default.createElement("div", {
        className: "quota-property-root"
      }, _react.default.createElement("div", {
        className: "quota-property-head"
      }, _react.default.createElement("div", {
        className: "common-property-text"
      }, "采集模型"), _react.default.createElement("div", {
        className: "del-button-view",
        onClick: this.closeQuotaPanel
      }, "关闭")), _react.default.createElement("div", {
        className: "quota-property-content"
      }, _react.default.createElement("div", {
        className: "quota-property-title"
      }, a.name), _react.default.createElement(_amosFramework.Collapse, {
        activeKey: t,
        onChange: function(t) {
          return e.onChangeCollapseSize(t);
        }
      }, _react.default.createElement(Panel, {
        showArrow: !1,
        header: this.getCollapseHead("设备接口", "1"),
        key: "1"
      }, _react.default.createElement("div", {
        className: "interface-base-info"
      }, this.getInterfaceBaseContent()), _react.default.createElement("div", {
        className: "interface-property-info"
      }, this.getInterfaceAttributesEditContent())), _react.default.createElement(Panel, {
        className: "capacity-property-info",
        showArrow: !1,
        header: this.getCollapseHead("采集指标", "2"),
        key: "2"
      }, this.getAttributesEditContent()), _react.default.createElement(Panel, {
        showArrow: !1,
        header: this.getCollapseHead("监听方式", "3"),
        key: "3"
      }, _react.default.createElement("div", {
        className: "interface-property-info"
      }, this.getTaskContent())))));
    }
  } ]), a;
}(_react.Component);

QuotaPropertyPanel.displayName = "QuotaPropertyPanel", QuotaPropertyPanel.propTypes = {
  getImgPath: _propTypes.default.func,
  id: _propTypes.default.number,
  updateQuotaPropertyCell: _propTypes.default.func,
  device: _propTypes.default.object,
  equipment: _propTypes.default.object,
  capacity: _propTypes.default.object,
  updateQuotaTaskCell: _propTypes.default.func,
  enable: _propTypes.default.bool,
  taskParam: _propTypes.default.object,
  quotaSelectedStatus: _propTypes.default.bool,
  resetStatus: _propTypes.default.func,
  updateInterfacePropertyCell: _propTypes.default.func,
  updateCapacityThresholdInfo: _propTypes.default.func,
  eqpThreshold: _propTypes.default.object
};

var _default = QuotaPropertyPanel;

exports.default = _default;