"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 _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")), _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")), _rayEventpool = require("ray-eventpool"), _QuotaCommonCell = _interopRequireDefault(require("./commoncell/QuotaCommonCell")), _deviceService = require("./../../../services/deviceService"), _ActionConf = require("./../common/ActionConf");

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

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

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 DeviceQuotaInfo = function(e) {
  (0, _inherits2.default)(r, e);
  var t = _createSuper(r);
  function r(e) {
    var a;
    return (0, _classCallCheck2.default)(this, r), a = t.call(this, e), (0, _defineProperty2.default)((0, 
    _assertThisInitialized2.default)(a), "getTemplatQuotas", (function(e, t) {
      (0, _deviceService.fetchTemplatOrEqpQuotaAction)(e, t).then((function(e) {
        a.setState({
          quotaList: e
        });
        var t = a.props.updateQuotaTaskCell;
        e && e.map((function(e) {
          var r = {
            monitorType: e.monitorType,
            monitorPeriod: e.monitorPeriod
          };
          t(e.id, r);
        })), a.props.getQuotaInfo(e);
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "getQuotaList", (function() {
      var e = a.state.quotaList, t = a.autoSelectedCpbId;
      a.props.refreshCellStatus && (t = void 0, a.autoSelectedCpbId = t);
      var r = [];
      return e.map((function(e) {
        var u;
        t && t === e.id && (u = !0), r.push(_react.default.createElement(_QuotaCommonCell.default, (0, 
        _extends2.default)({
          key: e.id,
          updateStatus: a.updateStatus,
          autoSelected: u,
          content: e
        }, a.props)));
      })), r;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "updateStatus", (function(e) {
      a.autoSelectedCpbId = e, a.setState({
        refreshFlag: !0
      });
    })), a.autoSelectedCpbId = void 0, a.state = {
      quotaList: [],
      refreshFlag: !0
    }, a;
  }
  return (0, _createClass2.default)(r, [ {
    key: "componentDidMount",
    value: function() {
      var e = this, t = this.props, r = t.device, a = t.equipment, u = t.updateQuotaCellStatus;
      this.getTemplatQuotas(r.id, a ? a.id : 0), this.pubsub_change = _rayEventpool.PubSub.subscribe(_ActionConf.SELECT_STATUS_CHANGE_TOPIC.selectStatusChange, (function(t, r) {
        var a = r.cpbId, o = r.status;
        void 0 !== a && u(a, o), e.autoSelectedCpbId = a, e.setState({
          refreshFlag: !0
        });
      }));
    }
  }, {
    key: "componentWillUnmount",
    value: function() {
      _rayEventpool.PubSub.unsubscribe(this.pubsub_change);
    }
  }, {
    key: "render",
    value: function() {
      return _react.default.createElement("div", {
        className: "add-device-left-quota"
      }, _react.default.createElement("div", {
        className: "template-quota-info-title"
      }, "数据采集"), _react.default.createElement("div", {
        className: "template-quota-info-body"
      }, this.getQuotaList()));
    }
  } ]), r;
}(_react.Component);

DeviceQuotaInfo.displayName = "DeviceQuotaInfo", DeviceQuotaInfo.propTypes = {
  device: _propTypes.default.object,
  equipment: _propTypes.default.object,
  getQuotaInfo: _propTypes.default.func,
  updateQuotaCellStatus: _propTypes.default.func,
  enable: _propTypes.default.bool,
  refreshCellStatus: _propTypes.default.bool,
  updateQuotaTaskCell: _propTypes.default.func
}, DeviceQuotaInfo.defaultProps = {
  enable: !0
};

var _default = DeviceQuotaInfo;

exports.default = _default;