"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")), _amosAntd = require("amos-antd"), _processor = require("../../utils/processor"), _urlConsts = _interopRequireDefault(require("../../consts/urlConsts")), _publicProtocol = _interopRequireDefault(require("./publicProtocol")), _privateProtocol = _interopRequireDefault(require("./privateProtocol")), _PrivateProtocolDetail = _interopRequireDefault(require("./privateProtocol/PrivateProtocolDetail")), _addProtocol = _interopRequireDefault(require("./addProtocol")), _searchBar = _interopRequireDefault(require("./common/searchBar"));

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("./../common/style/commonTabs.scss"), require("./../common/style/commonStyle.scss");

var TabPane = _amosAntd.Tabs.TabPane, DeviceProtocol = 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), "onTabClick", (function(e) {
            "1" === e ? a.requestMethod("0", a.state.criterias, void 0, e) : "2" === e && a.requestMethod("1", a.state.criterias, void 0, e);
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "setSelected", (function(e) {
            a.selected = e;
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "showTabPane", (function(e) {
            var t = a.state, r = t.scriptLangOptions, i = t.criterias, s = t.dataList, l = a.selected, o = [];
            switch (e) {
              case "1":
                o.push(_react.default.createElement(_publicProtocol.default, {
                    key: 1,
                    setSelected: a.setSelected,
                    dataList: s,
                    requestMethod: a.requestMethod,
                    updateAddView: a.updateAddView,
                    criterias: i,
                    visibility: "0"
                }));
                break;

              case "2":
                o.push(_react.default.createElement(_privateProtocol.default, {
                    key: 2,
                    setSelected: a.setSelected,
                    dataList: s,
                    requestMethod: a.requestMethod,
                    updateAddView: a.updateAddView,
                    criterias: i,
                    visibility: "1"
                }));
                break;

              case "3":
                o.push(_react.default.createElement(_PrivateProtocolDetail.default, {
                    key: 3,
                    scriptLangOptions: r,
                    selected: l,
                    setSelected: a.setSelected
                }));
                break;

              case "4":
                o.push(_react.default.createElement(_addProtocol.default, {
                    key: 4,
                    updateAddView: a.updateAddView
                }));
                break;

              default:
                o.push(_react.default.createElement(_publicProtocol.default, {
                    key: 1,
                    setSelected: a.setSelected,
                    updateAddView: a.updateAddView,
                    criterias: i,
                    visibility: "0"
                }));
            }
            return o;
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "requestMethod", (function(e, t, r, i) {
            var s = {
                name: "visibility",
                type: "EQUAL",
                value: e
            }, l = [];
            if (t.length > 0) {
                for (var o = 0; o < t.length; o++) {
                    var u = t[o];
                    "EQUAL" !== u.type && l.push(u);
                }
                t = l;
            }
            t.push(s), _processor.AmosFetch.post(_urlConsts.default.protocolDataList, {
                data: t
            }).then((function(e) {
                if (e.ok) return e.json();
                throw new Error("从服务端获取数据失败！");
            })).then((function(t) {
                "SUCCESS" === t.result ? null !== t.dataList && a.setState({
                    dataList: t.dataList
                }) : a.setState({
                    dataList: []
                });
                var s = [], l = [], o = a.state.criterias;
                r && a.setState({
                    flag: r
                }), i && a.setState({
                    flag: i,
                    criterias: [],
                    visibility: e,
                    activeKey: i
                });
                var u = a.state.activeKey;
                "1" === u ? (s.push(_react.default.createElement(_publicProtocol.default, {
                    key: 1,
                    setSelected: a.setSelected,
                    dataList: t.dataList,
                    requestMethod: a.requestMethod,
                    updateAddView: a.updateAddView,
                    criterias: o,
                    visibility: "0"
                })), a.setState({
                    tabContent: s
                })) : "2" === u && (l.push(_react.default.createElement(_privateProtocol.default, {
                    key: 2,
                    setSelected: a.setSelected,
                    dataList: t.dataList,
                    requestMethod: a.requestMethod,
                    updateAddView: a.updateAddView,
                    criterias: o,
                    visibility: "1"
                })), a.setState({
                    privateTabContent: l
                }));
            }));
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "updateAddView", (function(e) {
            if ("2" === e) a.requestMethod(a.state.visibility, a.state.criterias, e); else {
                var t = a.state.activeKey;
                "1" === t ? a.setState({
                    flag: e,
                    tabContent: a.showTabPane(e)
                }) : "2" === t && a.setState({
                    flag: e,
                    privateTabContent: a.showTabPane(e)
                });
            }
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "handleCriterias", (function(e) {
            var t = a.state.visibility;
            a.setState({
                criterias: e
            }), a.requestMethod(t, e);
        }));
        var i = "1", s = a.props.location;
        return s.query.activeKey && (i = s.query.activeKey), a.state = {
            criterias: [],
            scriptLangOptions: [],
            flag: i,
            visibility: "0",
            dataList: [],
            tabContent: [],
            privateTabContent: [],
            activeKey: i
        }, a;
    }
    return (0, _createClass2.default)(r, [ {
        key: "componentWillMount",
        value: function() {
            var e = this;
            _processor.AmosFetch.get(_urlConsts.default.scriptLangType).then((function(e) {
                if (e.ok) return e.json();
                throw new Error("从服务端获取数据失败！");
            })).then((function(t) {
                if ("SUCCESS" === t.result) {
                    var r = [];
                    !t || t.dataList.map((function(e) {
                        r.push({
                            value: e.id,
                            label: e.name,
                            selected: !1,
                            style: "all-filter-btn"
                        });
                    })), e.setState({
                        scriptLangOptions: r
                    });
                }
            })), this.requestMethod("1" === this.state.activeKey ? "0" : "1", []);
        }
    }, {
        key: "render",
        value: function() {
            var e = this.state, t = e.scriptLangOptions, r = e.activeKey, a = e.privateTabContent, i = e.tabContent;
            return _react.default.createElement("div", {
                className: "tabs-outside"
            }, _react.default.createElement(_amosAntd.Tabs, {
                activeKey: r,
                onTabClick: this.onTabClick,
                tabBarExtraContent: _react.default.createElement(_searchBar.default, {
                    handleCriterias: this.handleCriterias,
                    scriptLangOptions: t
                })
            }, _react.default.createElement(TabPane, {
                tab: _react.default.createElement("div", null, "公共"),
                key: "1"
            }, i), _react.default.createElement(TabPane, {
                tab: _react.default.createElement("div", null, "我的"),
                key: "2"
            }, a)));
        }
    } ]), r;
}(_react.Component);

DeviceProtocol.displayName = "DeviceProtocol", DeviceProtocol.propTypes = {};

var _default = DeviceProtocol;

exports.default = _default;