"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")), _amosAntd = require("amos-antd"), _amosFramework = require("amos-framework"), _processor = require("../../../../utils/processor"), _urlConsts = require("../../../../consts/urlConsts"), _AddEditDeviceCapacity = _interopRequireDefault(require("./AddEditDeviceCapacity")), _DeviceEnum = require("./../../common/DeviceEnum"), _DeviceLang = require("./../../common/DeviceLang");

function _createForOfIteratorHelper(e, t) {
    var r = "undefined" != typeof Symbol && e[Symbol.iterator] || e["@@iterator"];
    if (!r) {
        if (Array.isArray(e) || (r = _unsupportedIterableToArray(e)) || t && e && "number" == typeof e.length) {
            r && (e = r);
            var a = 0, i = function() {};
            return {
                s: i,
                n: function() {
                    return a >= e.length ? {
                        done: !0
                    } : {
                        done: !1,
                        value: e[a++]
                    };
                },
                e: function(e) {
                    throw e;
                },
                f: i
            };
        }
        throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
    }
    var n, o = !0, l = !1;
    return {
        s: function() {
            r = r.call(e);
        },
        n: function() {
            var e = r.next();
            return o = e.done, e;
        },
        e: function(e) {
            l = !0, n = e;
        },
        f: function() {
            try {
                o || null == r.return || r.return();
            } finally {
                if (l) throw n;
            }
        }
    };
}

function _unsupportedIterableToArray(e, t) {
    if (e) {
        if ("string" == typeof e) return _arrayLikeToArray(e, t);
        var r = Object.prototype.toString.call(e).slice(8, -1);
        return "Object" === r && e.constructor && (r = e.constructor.name), "Map" === r || "Set" === r ? Array.from(e) : "Arguments" === r || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r) ? _arrayLikeToArray(e, t) : void 0;
    }
}

function _arrayLikeToArray(e, t) {
    (null == t || t > e.length) && (t = e.length);
    for (var r = 0, a = new Array(t); r < t; r++) a[r] = e[r];
    return a;
}

function _createSuper(e) {
    var t = _isNativeReflectConstruct();
    return function() {
        var r, a = (0, _getPrototypeOf2.default)(e);
        if (t) {
            var i = (0, _getPrototypeOf2.default)(this).constructor;
            r = Reflect.construct(a, arguments, i);
        } 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;
    }
}

require("./../device-detail.scss");

var createForm = _amosAntd.Form.create(), Option = _amosFramework.Select.Option, AddDeviceCapacity = function(e) {
    (0, _inherits2.default)(r, e);
    var t = _createSuper(r);
    function r(e) {
        var a;
        return (0, _classCallCheck2.default)(this, r), a = t.call(this, e), (0, _defineProperty2.default)((0, 
        _assertThisInitialized2.default)(a), "onClick", (function() {
            a.setState({
                visible: !0
            });
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "getAllAvailableProtocols", (function(e) {
            var t = [];
            t.push({}), _processor.AmosFetch.post(_urlConsts.OltSerUrl.protocolDataList, {
                data: t
            }).then((function(e) {
                if (e.ok) return e.json();
                throw new Error("从服务端获取数据失败！");
            })).then((function(e) {
                if ("SUCCESS" === e.result && null !== e.dataList) {
                    var t = e.dataList.map((function(e) {
                        return _react.default.createElement(Option, {
                            key: e.id,
                            value: "".concat(e.id)
                        }, e.name);
                    }));
                    a.setState({
                        protocolOption: t
                    });
                }
            }));
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "getAllAvailableInterfaces", (function(e) {
            var t, r = [], i = {}, n = _createForOfIteratorHelper(e.deviceInterfaces);
            try {
                for (n.s(); !(t = n.n()).done; ) {
                    var o = t.value;
                    r.push(_react.default.createElement(Option, {
                        key: o.intfcId,
                        value: "".concat(o.intfcId, "-").concat(o.intfcDirection)
                    }, "".concat(o.intfcDisplayName, "-").concat((0, _DeviceLang.stringUtil)(_DeviceEnum.interfaceDirectionEnum, parseInt(o.intfcDirection))))), 
                    i[parseInt(o.intfcId)] = o.intfcDisplayName;
                }
            } catch (e) {
                n.e(e);
            } finally {
                n.f();
            }
            a.setState({
                interfaceOption: r,
                interfaceMap: i
            });
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "handCancel", (function() {
            a.props.form.resetFields(), a.setState({
                visible: !1
            });
        })), a.state = {
            visible: !1,
            protocolOption: [],
            interfaceOption: [],
            interfaceMap: {}
        }, a;
    }
    return (0, _createClass2.default)(r, [ {
        key: "componentWillMount",
        value: function() {}
    }, {
        key: "componentDidMount",
        value: function() {
            this.getAllAvailableProtocols(), this.getAllAvailableInterfaces(this.props);
        }
    }, {
        key: "componentWillReceiveProps",
        value: function(e) {
            void 0 !== e.deviceInterfaces && this.getAllAvailableInterfaces(e);
        }
    }, {
        key: "render",
        value: function() {
            var e = this.props, t = e.form, r = e.repuestType, a = e.visibility, i = this.state, n = i.protocolOption, o = i.interfaceOption, l = i.interfaceMap;
            return _react.default.createElement("div", {
                className: "capacity-detail-property-button"
            }, 1 === a || void 0 === a ? _react.default.createElement("div", null, _react.default.createElement("div", {
                className: "add-img",
                onClick: this.onClick
            }, r && "addProperty" === r ? _react.default.createElement("img", {
                src: require("./../../../../assets/iot/deviceManage/add.png"),
                alt: ""
            }) : _react.default.createElement("div", {
                className: "detail-add-img"
            }, _react.default.createElement("img", {
                src: require("./../../../../assets/iot/img/list_add.png"),
                alt: ""
            }), _react.default.createElement("label", null, "新增"))), _react.default.createElement(_amosAntd.Modal, {
                maskClosable: !1,
                title: "增加数据采集",
                closable: !0,
                visible: this.state.visible,
                onCancel: this.handCancel,
                width: 500,
                footer: null
            }, _react.default.createElement(_AddEditDeviceCapacity.default, (0, _extends2.default)({
                form: t,
                callBack: this.handCancel,
                autoCardCalculate: this.autoCardCalculate,
                protocolOption: n,
                interfaceOption: o,
                interfaceMap: l
            }, this.props)))) : null);
        }
    } ]), r;
}(_react.Component);

AddDeviceCapacity.displayName = "AddDeviceCapacity", AddDeviceCapacity.propTypes = {
    form: _propTypes.default.any,
    repuestType: _propTypes.default.string,
    autoCardCalculate: _propTypes.default.func,
    deviceInterfaces: _propTypes.default.array,
    deviceId: _propTypes.default.number,
    getDeviceInfoById: _propTypes.default.func,
    visibility: _propTypes.default.bool
};

var _default = createForm(AddDeviceCapacity);

exports.default = _default;