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

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 _extends() {
  return (_extends = Object.assign || function(e) {
    for (var t = 1; t < arguments.length; t++) {
      var o, r = arguments[t];
      for (o in r) Object.prototype.hasOwnProperty.call(r, o) && (e[o] = r[o])
    }
    return e
  }).apply(this, arguments)
}

function _classCallCheck(e, t) {
  if (!(e instanceof t)) throw new TypeError("Cannot call a class as a function")
}

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

function _createClass(e, t, o) {
  return t && _defineProperties(e.prototype, t), o && _defineProperties(e, o), 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(o) {
  var r = _isNativeReflectConstruct();
  return function() {
    var e, t = _getPrototypeOf(o);
    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, o) {
  return t in e ? Object.defineProperty(e, t, {
    value: o,
    enumerable: !0,
    configurable: !0,
    writable: !0
  }) : e[t] = o, e
}
var DeviceQuotaInfo = function() {
  _inherits(o, _react.Component);
  var t = _createSuper(o);

  function o(e) {
    var n;
    return _classCallCheck(this, o), _defineProperty(_assertThisInitialized(n = t.call(this, e)), "getTemplatQuotas", function(e, t) {
      (0, _deviceService.fetchTemplatOrEqpQuotaAction)(e, t).then(function(e) {
        n.setState({
          quotaList: e
        });
        var o = n.props.updateQuotaTaskCell;
        e && e.map(function(e) {
          var t = {
            monitorType: e.monitorType,
            monitorPeriod: e.monitorPeriod
          };
          o(e.id, t)
        }), n.props.getQuotaInfo(e)
      })
    }), _defineProperty(_assertThisInitialized(n), "getQuotaList", function() {
      var e = n.state.quotaList,
        o = n.autoSelectedCpbId;
      n.props.refreshCellStatus && (o = void 0, n.autoSelectedCpbId = o);
      var r = [];
      return e.map(function(e) {
        var t;
        o && o === e.id && (t = !0), r.push(_react.default.createElement(_QuotaCommonCell.default, _extends({
          key: e.id,
          updateStatus: n.updateStatus,
          autoSelected: t,
          content: e
        }, n.props)))
      }), r
    }), _defineProperty(_assertThisInitialized(n), "updateStatus", function(e) {
      n.autoSelectedCpbId = e, n.setState({
        refreshFlag: !0
      })
    }), n.autoSelectedCpbId = void 0, n.state = {
      quotaList: [],
      refreshFlag: !0
    }, n
  }
  return _createClass(o, [{
    key: "componentWillMount",
    value: function() {}
  }, {
    key: "componentDidMount",
    value: function() {
      var r = this,
        e = this.props,
        t = e.device,
        o = e.equipment,
        n = e.updateQuotaCellStatus;
      this.getTemplatQuotas(t.id, o ? o.id : 0), this.pubsub_change = _rayEventpool.PubSub.subscribe(_ActionConf.SELECT_STATUS_CHANGE_TOPIC.selectStatusChange, function(e, t) {
        var o = t.cpbId,
          t = t.status;
        void 0 !== o && n(o, t), r.autoSelectedCpbId = o, r.setState({
          refreshFlag: !0
        })
      })
    }
  }, {
    key: "componentWillReceiveProps",
    value: function() {}
  }, {
    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()))
    }
  }]), o
}();
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 = DeviceQuotaInfo, module.exports = exports.default;
