"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"),
  _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 _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 a, r, o = {},
    n = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (a in e) Object.prototype.hasOwnProperty.call(e, a) && ((r = n ? Object.getOwnPropertyDescriptor(e, a) : null) && (r.get || r.set) ? Object.defineProperty(o, a, r) : o[a] = e[a]);
  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 _classCallCheck(e, t) {
  if (!(e instanceof t)) throw new TypeError("Cannot call a class as a function")
}

function _defineProperties(e, t) {
  for (var a = 0; a < t.length; a++) {
    var r = t[a];
    r.enumerable = r.enumerable || !1, r.configurable = !0, "value" in r && (r.writable = !0), Object.defineProperty(e, r.key, r)
  }
}

function _createClass(e, t, a) {
  return t && _defineProperties(e.prototype, t), a && _defineProperties(e, a), 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(a) {
  var r = _isNativeReflectConstruct();
  return function() {
    var e, t = _getPrototypeOf(a);
    return _possibleConstructorReturn(this, r ? (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, a) {
  return t in e ? Object.defineProperty(e, t, {
    value: a,
    enumerable: !0,
    configurable: !0,
    writable: !0
  }) : e[t] = a, e
}
var Panel = _amosFramework.Collapse.Panel,
  CheckboxGroup = _amosFramework.Checkbox.Group,
  Option = _amosAntd.Select.Option,
  QuotaPropertyPanel = function() {
    _inherits(a, _react.Component);
    var t = _createSuper(a);

    function a(e) {
      var P;
      return _classCallCheck(this, a), _defineProperty(_assertThisInitialized(P = t.call(this, e)), "onAttributeChange", function() {}), _defineProperty(_assertThisInitialized(P), "onChangeChecked", function(e) {
        var t = P.propertyId,
          a = [];
        e.map(function(e) {
          void 0 !== t && t.includes(e) && a.push(e)
        });
        var r = P.props,
          o = r.updateQuotaPropertyCell,
          e = r.id,
          r = P.quotaParam;
        o(e, a), (void 0 === r[e] || 0 === r[e].length) && 0 < a.length && P.changeStatus(), r[e] = a, P.quotaParam = r, P.setState({
          updateFlag: !1
        })
      }), _defineProperty(_assertThisInitialized(P), "onChangeCollapseSize", function(e) {
        void 0 !== e && void 0 !== e.length && P.setState({
          collapseKey: e
        })
      }), _defineProperty(_assertThisInitialized(P), "onMonitorTypeChange", function(e) {
        var t = P.props.taskParam,
          a = P.props,
          r = a.updateQuotaTaskCell,
          a = a.id;
        t[a].monitorPeriod = e, r(a, t[a]), P.setState({
          updateFlag: !1
        })
      }), _defineProperty(_assertThisInitialized(P), "onInterfaceAttributeChange", function(e, t) {
        var a = P.state.interfaceProperty;
        (0, P.props.updateInterfacePropertyCell)(e, a[e] = t), P.setState({
          interfaceProperty: a
        })
      }), _defineProperty(_assertThisInitialized(P), "getInterfaceBaseContent", function() {
        var e = [],
          t = P.props.id,
          t = P.state.interfaceList[t];
        return t && 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: t.name
        }, t.name)))), e
      }), _defineProperty(_assertThisInitialized(P), "getInterfaceAttributesEditContent", function() {
        var r = [],
          e = P.props,
          t = e.id,
          o = e.equipment,
          n = e.enable,
          i = e.updateInterfacePropertyCell,
          l = e.capacity,
          e = P.state,
          c = e.interfaceProperty,
          s = e.interfaceList[t];
        return r.push(_react.default.createElement("div", {
          key: "title",
          className: "interface-property-title"
        }, "通讯参数")), s && s.attributes.map(function(e) {
          var t = "cpbl_intfc_".concat(l.id, "_").concat(s.id, "_").concat(e.id),
            a = c[t];
          void 0 === a && (a = void 0 !== o && void 0 !== o.id ? o.cfgParamMap[t] || a : e.valueStr), c[t] = a, i(t, a), r.push(_react.default.createElement("div", {
            key: e.id,
            className: "property-config-common"
          }, _react.default.createElement("div", {
            className: "property-key-style",
            title: e.displayName
          }, e.displayName, "："), _react.default.createElement("div", {
            style: {
              width: "136px",
              float: "left"
            }
          }, n ? _react.default.createElement(_amosFramework.Editable, {
            value: a || e.valueStr,
            onChange: function(e) {
              return P.onInterfaceAttributeChange(t, e)
            },
            showOkCancel: !1,
            style: {
              width: "136px"
            },
            placeholder: "请输入",
            innerValueStyle: {
              width: "136px"
            }
          }) : _react.default.createElement("div", {
            className: "property-normal-label",
            title: a || e.valueStr
          }, a || e.valueStr))))
        }), r
      }), _defineProperty(_assertThisInitialized(P), "getAttributesEditContent", function() {
        var e = [],
          o = [],
          t = P.props,
          a = t.updateQuotaPropertyCell,
          r = t.id,
          n = t.equipment,
          i = t.capacity,
          l = t.enable,
          c = t.quotaSelectedStatus,
          s = t.resetStatus,
          p = t.updateCapacityThresholdInfo,
          u = t.eqpThreshold,
          d = P.state.propertyList,
          t = P.quotaParam,
          f = [];
        void 0 === t[r] ? (void 0 !== n && void 0 !== n.id ? (n = n.cfgParamMap.quotaSelected) && void 0 !== n[i.id] && (f = n[i.id]) : (d[r] && d[r].map(function(e) {
          f.push(e.id)
        }), a(r, f)), 0 !== f.length && (t[r] = f, P.quotaParam = t)) : f = t[r];
        var y, m, _ = [],
          h = [],
          v = 0;
        return d[r] && d[r].map(function(e) {
          _.push(e.id), e.isUser && h.push(e.id);
          var t = 0 === v ? "threshold-name-first-root" : "threshold-name-root";
          v += 1, o.push(_react.default.createElement(_ThresholdName.default, {
            key: "title",
            textStyle: t,
            name: e.displayName,
            disabled: !l,
            value: e.id
          })), o.push(_react.default.createElement(_amosFramework.Checkbox, {
            key: e.id,
            disabled: !l,
            value: e.id
          }));
          var a = !0;
          1 !== e.type && 4 !== e.type || 1 !== e.dataType && 2 !== e.dataType || (a = !1);
          var r = "".concat(i.id, "_").concat(e.id),
            t = u[r];
          void 0 === t && ((t = {}).upper = e.maxValue, t.lower = e.minValue), o.push(_react.default.createElement(_ThresholdInput.default, {
            updateCapacityThresholdInfo: p,
            unit: e.unit,
            key: "threshold",
            disabled: !l,
            value: e.id,
            upper: t.upper,
            lower: t.lower,
            infoKey: r,
            isHidden: a
          }))
        }), P.propertyId = _, c ? (y = P.propertyId, m = [], f = [], d[r] && d[r].map(function(e) {
          f.push(e.id), void 0 !== y && y.includes(e.id) && m.push(e.id)
        }), a(r, m), t[r] = m, P.quotaParam = t, s()) : !1 === c && (f = [], a(r, []), t[r] = [], P.quotaParam = t, s()), e.push(_react.default.createElement("div", {
          key: "group",
          className: "template-config-common"
        }, _react.default.createElement(CheckboxGroup, {
          selects: f,
          vertical: !0,
          isCheckall: l,
          onChange: P.onChangeChecked
        }, o))), e
      }), _defineProperty(_assertThisInitialized(P), "getCapacityInfos", function(e, a) {
        (0, _deviceService.fetchCapacityInterfaceAction)(a).then(function(e) {
          var t;
          null !== e && ((t = P.state.interfaceList)[a] = e, P.setState({
            interfaceList: t
          }))
        }), (0, _deviceService.fetchTemplatOrEqpQuotaPropertyAction)(e, a).then(function(e) {
          var t;
          null !== e && ((t = P.state.propertyList)[a] = e, P.setState({
            propertyList: t
          }))
        })
      }), _defineProperty(_assertThisInitialized(P), "getCollapseHead", function(e, t) {
        var a = P.props.getImgPath(t, P.state.collapseKey),
          t = [];
        return t.push(_react.default.createElement("div", {
          key: "head",
          className: "config-collapse-head"
        }, _react.default.createElement("label", {
          className: "config-collapse-text"
        }, e), a)), t
      }), _defineProperty(_assertThisInitialized(P), "getTaskContent", function() {
        var e = [],
          t = P.props,
          a = t.capacity,
          r = t.enable,
          o = t.taskParam,
          t = t.id,
          o = 0 === o[t].monitorPeriod ? void 0 : o[t].monitorPeriod,
          t = 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 == t && 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: !r,
          value: o,
          style: {
            width: 136
          },
          placeholder: "请选择",
          onSelect: P.onMonitorTypeChange
        }, _TaskEnum.periodArr.map(function(e) {
          return _react.default.createElement(Option, {
            key: e.value,
            value: e.value
          }, e.title)
        })))))), e
      }), _defineProperty(_assertThisInitialized(P), "closeQuotaPanel", function() {
        _rayEventpool.PubSub.publish(_ActionConf.CONFIG_PANEL_HIDE_TOPIC.trigger, {})
      }), _defineProperty(_assertThisInitialized(P), "changeStatus", function() {
        var e = P.props.capacity;
        _rayEventpool.PubSub.publish(_ActionConf.SELECT_STATUS_CHANGE_TOPIC.trigger, {
          cpbId: e.id,
          status: !0
        })
      }), P.propertyId = [], P.quotaParam = {}, P.state = {
        collapseKey: ["1", "2", "3"],
        propertyList: {},
        interfaceList: {},
        interfaceProperty: {},
        updateFlag: !1
      }, P
    }
    return _createClass(a, [{
      key: "componentWillMount",
      value: function() {}
    }, {
      key: "componentDidMount",
      value: function() {
        var e = this.props,
          t = e.id,
          e = e.equipment;
        this.getCapacityInfos(e ? e.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: "componentWillUnmount",
      value: function() {}
    }, {
      key: "render",
      value: function() {
        var t = this,
          e = 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: e,
          onChange: function(e) {
            return t.onChangeCollapseSize(e)
          }
        }, _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
  }();
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 = QuotaPropertyPanel, module.exports = exports.default;
