"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"), _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

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 _createSuper(e) {
    var t = _isNativeReflectConstruct();
    return function() {
        var a, r = (0, _getPrototypeOf2.default)(e);
        if (t) {
            var l = (0, _getPrototypeOf2.default)(this).constructor;
            a = Reflect.construct(r, arguments, l);
        } 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 QuotaCommonCell = function(e) {
    (0, _inherits2.default)(a, e);
    var t = _createSuper(a);
    function a(e) {
        var r;
        (0, _classCallCheck2.default)(this, a), r = t.call(this, e), (0, _defineProperty2.default)((0, 
        _assertThisInitialized2.default)(r), "getImgByState", (function() {
            var e = [];
            return r.usedState ? e.push(_react.default.createElement("img", {
                key: r.usedState,
                src: require("./../../../../assets/iot/deviceManage/disable.png"),
                alt: ""
            })) : e.push(_react.default.createElement("img", {
                key: r.usedState,
                src: require("./../../../../assets/iot/deviceManage/enable.png"),
                alt: ""
            })), e;
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getStyleByState", (function() {
            var e = r.usedState, t = r.props.autoSelected;
            return t ? (r.usedState = t, "quota-cell-enable-root") : e ? "quota-cell-enable-root" : "quota-cell-disable-root";
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "openConfigPanel", (function(e) {
            var t = r.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)(r), "changeEnableState", (function(e) {
            e.stopPropagation();
            var t = r.props, a = t.updateQuotaCellStatus, l = t.content, u = t.updateStatus, o = r.usedState;
            r.openConfigPanel(!o), r.usedState = !o, u(!0 == !o ? l.id : void 0), a(l.id, !o), 
            r.setState({
                change: r.state.change
            });
        }));
        var l = r.props, u = l.content, o = l.updateQuotaCellStatus, i = l.equipment, n = !0;
        if (void 0 !== i && void 0 !== i.id) {
            var s = i.cfgParamMap.selCpblIds;
            n = !(void 0 === s || !s.includes("".concat(u.id)));
        }
        return o(u.id, n), r.usedState = n, r.state = {
            change: !0
        }, r;
    }
    return (0, _createClass2.default)(a, [ {
        key: "componentWillMount",
        value: function() {}
    }, {
        key: "componentDidMount",
        value: function() {}
    }, {
        key: "componentWillReceiveProps",
        value: function(e) {
            if (e.refreshCellStatus) {
                var t = this.props, a = t.content, r = t.updateQuotaCellStatus, l = t.equipment, u = t.changeRefreshCellStatus, o = !0;
                if (void 0 !== l && void 0 !== l.id) {
                    var i = l.cfgParamMap.selCpblIds;
                    o = !(void 0 === i || !i.includes("".concat(a.id)));
                }
                r(a.id, o), u(), this.usedState = o;
            }
        }
    }, {
        key: "componentWillUnmount",
        value: function() {}
    }, {
        key: "render",
        value: function() {
            var e = this.props, t = e.content, a = e.enable, r = this.getStyleByState();
            return _react.default.createElement("div", {
                className: r,
                onClick: this.openConfigPanel
            }, _react.default.createElement("div", {
                className: "quota-cell-name"
            }, t.name), _react.default.createElement("div", {
                className: "quota-cell-desc"
            }, t.descr), a ? _react.default.createElement("div", {
                className: "quota-cell-img",
                onClick: this.changeEnableState
            }, this.getImgByState()) : "");
        }
    } ]), a;
}(_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;