"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")), _amosFramework = require("amos-framework"), _amosAntd = require("amos-antd"), _rayEventpool = require("ray-eventpool"), _ActionConf = require("./../../common/ActionConf"), _TaskEnum = require("./../../common/TaskEnum"), _deviceService = require("./../../../../services/deviceService"), _ThresholdInput = _interopRequireDefault(require("./ThresholdInput")), _ThresholdName = _interopRequireDefault(require("./ThresholdName"));

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 Panel = _amosFramework.Collapse.Panel, CheckboxGroup = _amosFramework.Checkbox.Group, Option = _amosAntd.Select.Option, QuotaPropertyPanel = function(e) {
    (0, _inherits2.default)(a, e);
    var t = _createSuper(a);
    function a(e) {
        var r;
        return (0, _classCallCheck2.default)(this, a), r = t.call(this, e), (0, _defineProperty2.default)((0, 
        _assertThisInitialized2.default)(r), "onAttributeChange", (function() {})), (0, 
        _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onChangeChecked", (function(e) {
            var t = r.propertyId, a = [];
            e.map((function(e) {
                void 0 !== t && t.includes(e) && a.push(e);
            }));
            var l = r.props, o = l.updateQuotaPropertyCell, i = l.id, n = r.quotaParam;
            o(i, a), (void 0 === n[i] || 0 === n[i].length) && a.length > 0 && r.changeStatus(), 
            n[i] = a, r.quotaParam = n, r.setState({
                updateFlag: !1
            });
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onChangeCollapseSize", (function(e) {
            void 0 !== e && void 0 !== e.length && r.setState({
                collapseKey: e
            });
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onMonitorTypeChange", (function(e) {
            var t = r.props.taskParam, a = r.props, l = a.updateQuotaTaskCell, o = a.id;
            t[o].monitorPeriod = e, l(o, t[o]), r.setState({
                updateFlag: !1
            });
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onInterfaceAttributeChange", (function(e, t) {
            var a = r.state.interfaceProperty, l = r.props.updateInterfacePropertyCell;
            a[e] = t, l(e, t), r.setState({
                interfaceProperty: a
            });
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getInterfaceBaseContent", (function() {
            var e = [], t = r.props.id, a = r.state.interfaceList[t];
            return a && e.push(_react.default.createElement("div", {
                key: "interface-base",
                className: "property-config-common"
            }, _react.default.createElement("div", {
                title: "通讯方式",
                className: "property-key-style"
            }, "通讯方式", "："), _react.default.createElement("div", {
                style: {
                    width: "136px",
                    float: "left"
                }
            }, _react.default.createElement("div", {
                className: "property-normal-label",
                title: a.name
            }, a.name)))), e;
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getInterfaceAttributesEditContent", (function() {
            var e = [], t = r.props, a = t.id, l = t.equipment, o = t.enable, i = t.updateInterfacePropertyCell, n = t.capacity, s = r.state, u = s.interfaceProperty, p = s.interfaceList[a];
            return e.push(_react.default.createElement("div", {
                key: "title",
                className: "interface-property-title"
            }, "通讯参数")), p && p.attributes.map((function(t) {
                var a = "cpbl_intfc_".concat(n.id, "_").concat(p.id, "_").concat(t.id), s = u[a];
                if (void 0 === s) if (void 0 !== l && void 0 !== l.id) {
                    var c = l.cfgParamMap;
                    s = c[a] ? c[a] : s;
                } else s = t.valueStr;
                u[a] = s, i(a, s), e.push(_react.default.createElement("div", {
                    key: t.id,
                    className: "property-config-common"
                }, _react.default.createElement("div", {
                    className: "property-key-style",
                    title: t.displayName
                }, t.displayName, "："), _react.default.createElement("div", {
                    style: {
                        width: "136px",
                        float: "left"
                    }
                }, o ? _react.default.createElement(_amosFramework.Editable, {
                    value: s || t.valueStr,
                    onChange: function(e) {
                        return r.onInterfaceAttributeChange(a, e);
                    },
                    showOkCancel: !1,
                    style: {
                        width: "136px"
                    },
                    placeholder: "请输入",
                    innerValueStyle: {
                        width: "136px"
                    }
                }) : _react.default.createElement("div", {
                    className: "property-normal-label",
                    title: s || t.valueStr
                }, s || t.valueStr))));
            })), e;
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getAttributesEditContent", (function() {
            var e = [], t = [], a = r.props, l = a.updateQuotaPropertyCell, o = a.id, i = a.equipment, n = a.capacity, s = a.enable, u = a.quotaSelectedStatus, p = a.resetStatus, c = a.updateCapacityThresholdInfo, d = a.eqpThreshold, f = r.state.propertyList, m = r.quotaParam, _ = [];
            if (void 0 === m[o]) {
                if (void 0 !== i && void 0 !== i.id) {
                    var y = i.cfgParamMap.quotaSelected;
                    y && void 0 !== y[n.id] && (_ = y[n.id]);
                } else f[o] && f[o].map((function(e) {
                    _.push(e.id);
                })), l(o, _);
                0 !== _.length && (m[o] = _, r.quotaParam = m);
            } else _ = m[o];
            var h = [], v = [], C = 0;
            if (f[o] && f[o].map((function(e) {
                h.push(e.id), e.isUser && v.push(e.id);
                var a = "threshold-name-root";
                0 === C && (a = "threshold-name-first-root"), C += 1, t.push(_react.default.createElement(_ThresholdName.default, {
                    key: "title",
                    textStyle: a,
                    name: e.displayName,
                    disabled: !s,
                    value: e.id
                })), t.push(_react.default.createElement(_amosFramework.Checkbox, {
                    key: e.id,
                    disabled: !s,
                    value: e.id
                }));
                var r = !0;
                1 !== e.type && 4 !== e.type || 1 !== e.dataType && 2 !== e.dataType || (r = !1);
                var l = "".concat(n.id, "_").concat(e.id), o = d[l];
                void 0 === o && ((o = {}).upper = e.maxValue, o.lower = e.minValue), t.push(_react.default.createElement(_ThresholdInput.default, {
                    updateCapacityThresholdInfo: c,
                    unit: e.unit,
                    key: "threshold",
                    disabled: !s,
                    value: e.id,
                    upper: o.upper,
                    lower: o.lower,
                    infoKey: l,
                    isHidden: r
                }));
            })), r.propertyId = h, u) {
                var P = r.propertyId, b = [];
                _ = [], f[o] && f[o].map((function(e) {
                    _.push(e.id), void 0 !== P && P.includes(e.id) && b.push(e.id);
                })), l(o, b), m[o] = b, r.quotaParam = m, p();
            } else !1 === u && (_ = [], l(o, []), m[o] = [], r.quotaParam = m, p());
            return e.push(_react.default.createElement("div", {
                key: "group",
                className: "template-config-common"
            }, _react.default.createElement(CheckboxGroup, {
                selects: _,
                vertical: !0,
                isCheckall: s,
                onChange: r.onChangeChecked
            }, t))), e;
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getCapacityInfos", (function(e, t) {
            (0, _deviceService.fetchCapacityInterfaceAction)(t).then((function(e) {
                if (null !== e) {
                    var a = r.state.interfaceList;
                    a[t] = e, r.setState({
                        interfaceList: a
                    });
                }
            })), (0, _deviceService.fetchTemplatOrEqpQuotaPropertyAction)(e, t).then((function(e) {
                if (null !== e) {
                    var a = r.state.propertyList;
                    a[t] = e, r.setState({
                        propertyList: a
                    });
                }
            }));
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getCollapseHead", (function(e, t) {
            var a = r.props.getImgPath(t, r.state.collapseKey), l = [];
            return l.push(_react.default.createElement("div", {
                key: "head",
                className: "config-collapse-head"
            }, _react.default.createElement("label", {
                className: "config-collapse-text"
            }, e), a)), l;
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getTaskContent", (function() {
            var e = [], t = r.props, a = t.capacity, l = t.enable, o = t.taskParam, i = t.id, n = 0 === o[i].monitorPeriod ? void 0 : o[i].monitorPeriod, s = a.monitorType;
            return e.push(_react.default.createElement("div", {
                key: "type",
                className: "property-config-common"
            }, _react.default.createElement(_amosFramework.Row, null, _react.default.createElement(_amosFramework.Col, {
                span: 6,
                offset: 0,
                className: "property-key-style"
            }, "监测方式："), _react.default.createElement(_amosFramework.Col, {
                span: 16,
                offset: 0,
                style: {
                    width: "136px"
                }
            }, _react.default.createElement(_amosAntd.Select, {
                value: a.monitorType,
                style: {
                    width: 136
                },
                disabled: !0,
                placeholder: "监测方式"
            }, _TaskEnum.monitorTypeArr.map((function(e) {
                return _react.default.createElement(Option, {
                    key: e.value,
                    value: e.value
                }, e.title);
            }))))))), 1 == s && e.push(_react.default.createElement("div", {
                key: "task",
                className: "property-config-common"
            }, _react.default.createElement(_amosFramework.Row, null, _react.default.createElement(_amosFramework.Col, {
                span: 6,
                offset: 0,
                className: "property-key-style"
            }, "采集周期："), _react.default.createElement(_amosFramework.Col, {
                span: 16,
                offset: 0,
                style: {
                    width: "136px"
                }
            }, _react.default.createElement(_amosAntd.Select, {
                disabled: !l,
                value: n,
                style: {
                    width: 136
                },
                placeholder: "请选择",
                onSelect: r.onMonitorTypeChange
            }, _TaskEnum.periodArr.map((function(e) {
                return _react.default.createElement(Option, {
                    key: e.value,
                    value: e.value
                }, e.title);
            }))))))), e;
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "closeQuotaPanel", (function() {
            _rayEventpool.PubSub.publish(_ActionConf.CONFIG_PANEL_HIDE_TOPIC.trigger, {});
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "changeStatus", (function() {
            var e = r.props.capacity;
            _rayEventpool.PubSub.publish(_ActionConf.SELECT_STATUS_CHANGE_TOPIC.trigger, {
                cpbId: e.id,
                status: !0
            });
        })), r.propertyId = [], r.quotaParam = {}, r.state = {
            collapseKey: [ "1", "2", "3" ],
            propertyList: {},
            interfaceList: {},
            interfaceProperty: {},
            updateFlag: !1
        }, r;
    }
    return (0, _createClass2.default)(a, [ {
        key: "componentWillMount",
        value: function() {}
    }, {
        key: "componentDidMount",
        value: function() {
            var e = this.props, t = e.id, a = e.equipment;
            this.getCapacityInfos(a ? a.id : 0, t);
        }
    }, {
        key: "componentWillReceiveProps",
        value: function(e) {
            var t = this.props.id;
            e.id !== t && this.getCapacityInfos(e.equipment ? e.equipment.id : 0, e.id);
        }
    }, {
        key: "componentWillUnmount",
        value: function() {}
    }, {
        key: "render",
        value: function() {
            var e = this, t = this.state.collapseKey, a = this.props.capacity;
            return _react.default.createElement("div", {
                className: "quota-property-root"
            }, _react.default.createElement("div", {
                className: "quota-property-head"
            }, _react.default.createElement("div", {
                className: "common-property-text"
            }, "采集模型"), _react.default.createElement("div", {
                className: "del-button-view",
                onClick: this.closeQuotaPanel
            }, "关闭")), _react.default.createElement("div", {
                className: "quota-property-content"
            }, _react.default.createElement("div", {
                className: "quota-property-title"
            }, a.name), _react.default.createElement(_amosFramework.Collapse, {
                activeKey: t,
                onChange: function(t) {
                    return e.onChangeCollapseSize(t);
                }
            }, _react.default.createElement(Panel, {
                showArrow: !1,
                header: this.getCollapseHead("设备接口", "1"),
                key: "1"
            }, _react.default.createElement("div", {
                className: "interface-base-info"
            }, this.getInterfaceBaseContent()), _react.default.createElement("div", {
                className: "interface-property-info"
            }, this.getInterfaceAttributesEditContent())), _react.default.createElement(Panel, {
                className: "capacity-property-info",
                showArrow: !1,
                header: this.getCollapseHead("采集指标", "2"),
                key: "2"
            }, this.getAttributesEditContent()), _react.default.createElement(Panel, {
                showArrow: !1,
                header: this.getCollapseHead("监听方式", "3"),
                key: "3"
            }, _react.default.createElement("div", {
                className: "interface-property-info"
            }, this.getTaskContent())))));
        }
    } ]), a;
}(_react.Component);

QuotaPropertyPanel.displayName = "QuotaPropertyPanel", QuotaPropertyPanel.propTypes = {
    getImgPath: _propTypes.default.func,
    id: _propTypes.default.number,
    updateQuotaPropertyCell: _propTypes.default.func,
    device: _propTypes.default.object,
    equipment: _propTypes.default.object,
    capacity: _propTypes.default.object,
    updateQuotaTaskCell: _propTypes.default.func,
    enable: _propTypes.default.bool,
    taskParam: _propTypes.default.object,
    quotaSelectedStatus: _propTypes.default.bool,
    resetStatus: _propTypes.default.func,
    updateInterfacePropertyCell: _propTypes.default.func,
    updateCapacityThresholdInfo: _propTypes.default.func,
    eqpThreshold: _propTypes.default.object
};

var _default = QuotaPropertyPanel;

exports.default = _default;