"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")), _rayEventpool = require("ray-eventpool"), _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 l in e) if ("default" !== l && Object.prototype.hasOwnProperty.call(e, l)) {
    var i = u ? Object.getOwnPropertyDescriptor(e, l) : null;
    i && (i.get || i.set) ? Object.defineProperty(a, l, i) : a[l] = e[l];
  }
  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 QuotaCommonCell = function(e) {
  (0, _inherits2.default)(r, e);
  var t = _createSuper(r);
  function r(e) {
    var a;
    (0, _classCallCheck2.default)(this, r), a = t.call(this, e), (0, _defineProperty2.default)((0, 
    _assertThisInitialized2.default)(a), "getImgByState", (function() {
      var e = [];
      return a.usedState ? e.push(_react.default.createElement("img", {
        key: a.usedState,
        src: require("./../../../../assets/iot/deviceManage/disable.png"),
        alt: ""
      })) : e.push(_react.default.createElement("img", {
        key: a.usedState,
        src: require("./../../../../assets/iot/deviceManage/enable.png"),
        alt: ""
      })), e;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "getStyleByState", (function() {
      var e = a.usedState, t = a.props.autoSelected;
      return t ? (a.usedState = t, "quota-cell-enable-root") : e ? "quota-cell-enable-root" : "quota-cell-disable-root";
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "openConfigPanel", (function(e) {
      var t = a.props.content;
      !0 !== e && !1 !== e && (e = void 0), _rayEventpool.PubSub.publish(_ActionConf.CONFIG_PANEL_SHOW_TOPIC.trigger, {
        type: 2,
        id: t.id,
        capacity: t,
        status: e
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "changeEnableState", (function(e) {
      e.stopPropagation();
      var t = a.props, r = t.updateQuotaCellStatus, u = t.content, l = t.updateStatus, i = a.usedState;
      a.openConfigPanel(!i), a.usedState = !i, l(!0 == !i ? u.id : void 0), r(u.id, !i), 
      a.setState({
        change: a.state.change
      });
    }));
    var u = a.props, l = u.content, i = u.updateQuotaCellStatus, n = u.equipment, o = !0;
    if (void 0 !== n && void 0 !== n.id) {
      var s = n.cfgParamMap.selCpblIds;
      o = !(void 0 === s || !s.includes("".concat(l.id)));
    }
    return i(l.id, o), a.usedState = o, a.state = {
      change: !0
    }, a;
  }
  return (0, _createClass2.default)(r, [ {
    key: "componentWillReceiveProps",
    value: function(e) {
      if (e.refreshCellStatus) {
        var t = this.props, r = t.content, a = t.updateQuotaCellStatus, u = t.equipment, l = t.changeRefreshCellStatus, i = !0;
        if (void 0 !== u && void 0 !== u.id) {
          var n = u.cfgParamMap.selCpblIds;
          i = !(void 0 === n || !n.includes("".concat(r.id)));
        }
        a(r.id, i), l(), this.usedState = i;
      }
    }
  }, {
    key: "render",
    value: function() {
      var e = this.props, t = e.content, r = e.enable, a = this.getStyleByState();
      return _react.default.createElement("div", {
        className: a,
        onClick: this.openConfigPanel
      }, _react.default.createElement("div", {
        className: "quota-cell-name"
      }, t.name), _react.default.createElement("div", {
        className: "quota-cell-desc"
      }, t.descr), r ? _react.default.createElement("div", {
        className: "quota-cell-img",
        onClick: this.changeEnableState
      }, this.getImgByState()) : "");
    }
  } ]), r;
}(_react.Component);

QuotaCommonCell.displayName = "QuotaCommonCell", QuotaCommonCell.propTypes = {
  content: _propTypes.default.object,
  updateQuotaCellStatus: _propTypes.default.func,
  equipment: _propTypes.default.object,
  enable: _propTypes.default.bool,
  autoSelected: _propTypes.default.bool,
  updateStatus: _propTypes.default.func,
  refreshCellStatus: _propTypes.default.bool,
  changeRefreshCellStatus: _propTypes.default.func
};

var _default = QuotaCommonCell;

exports.default = _default;