"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 _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 _createSuper(e) {
    var t = _isNativeReflectConstruct();
    return function() {
        var r, u = (0, _getPrototypeOf2.default)(e);
        if (t) {
            var a = (0, _getPrototypeOf2.default)(this).constructor;
            r = Reflect.construct(u, arguments, a);
        } else r = u.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 u;
        return (0, _classCallCheck2.default)(this, r), u = t.call(this, e), (0, _defineProperty2.default)((0, 
        _assertThisInitialized2.default)(u), "getTemplatQuotas", (function(e, t) {
            (0, _deviceService.fetchTemplatOrEqpQuotaAction)(e, t).then((function(e) {
                u.setState({
                    quotaList: e
                });
                var t = u.props.updateQuotaTaskCell;
                e && e.map((function(e) {
                    var r = {
                        monitorType: e.monitorType,
                        monitorPeriod: e.monitorPeriod
                    };
                    t(e.id, r);
                })), u.props.getQuotaInfo(e);
            }));
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(u), "getQuotaList", (function() {
            var e = u.state.quotaList, t = u.autoSelectedCpbId;
            u.props.refreshCellStatus && (t = void 0, u.autoSelectedCpbId = t);
            var r = [];
            return e.map((function(e) {
                var a;
                t && t === e.id && (a = !0), r.push(_react.default.createElement(_QuotaCommonCell.default, (0, 
                _extends2.default)({
                    key: e.id,
                    updateStatus: u.updateStatus,
                    autoSelected: a,
                    content: e
                }, u.props)));
            })), r;
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(u), "updateStatus", (function(e) {
            u.autoSelectedCpbId = e, u.setState({
                refreshFlag: !0
            });
        })), u.autoSelectedCpbId = void 0, u.state = {
            quotaList: [],
            refreshFlag: !0
        }, u;
    }
    return (0, _createClass2.default)(r, [ {
        key: "componentWillMount",
        value: function() {}
    }, {
        key: "componentDidMount",
        value: function() {
            var e = this, t = this.props, r = t.device, u = t.equipment, a = t.updateQuotaCellStatus;
            this.getTemplatQuotas(r.id, u ? u.id : 0), this.pubsub_change = _rayEventpool.PubSub.subscribe(_ActionConf.SELECT_STATUS_CHANGE_TOPIC.selectStatusChange, (function(t, r) {
                var u = r.cpbId, o = r.status;
                void 0 !== u && a(u, o), e.autoSelectedCpbId = u, e.setState({
                    refreshFlag: !0
                });
            }));
        }
    }, {
        key: "componentWillReceiveProps",
        value: function(e) {}
    }, {
        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;