"use strict";
Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.default = void 0;
var _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 _interopRequireDefault(e) {
  return e && e.__esModule ? e : {
    default: e
  }
}

function _getRequireWildcardCache() {
  if ("function" != typeof WeakMap) return null;
  var e = new WeakMap;
  return _getRequireWildcardCache = function() {
    return e
  }, e
}

function _interopRequireWildcard(e) {
  if (e && e.__esModule) return e;
  if (null === e || "object" !== _typeof(e) && "function" != typeof e) return {
    default: e
  };
  var t = _getRequireWildcardCache();
  if (t && t.has(e)) return t.get(e);
  var r, a, i = {},
    o = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (r in e) Object.prototype.hasOwnProperty.call(e, r) && ((a = o ? Object.getOwnPropertyDescriptor(e, r) : null) && (a.get || a.set) ? Object.defineProperty(i, r, a) : i[r] = e[r]);
  return i.default = e, t && t.set(e, i), i
}

function _typeof(e) {
  return (_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(e) {
    return typeof e
  } : function(e) {
    return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e
  })(e)
}

function _classCallCheck(e, t) {
  if (!(e instanceof t)) throw new TypeError("Cannot call a class as a function")
}

function _defineProperties(e, t) {
  for (var r = 0; r < t.length; r++) {
    var a = t[r];
    a.enumerable = a.enumerable || !1, a.configurable = !0, "value" in a && (a.writable = !0), Object.defineProperty(e, a.key, a)
  }
}

function _createClass(e, t, r) {
  return t && _defineProperties(e.prototype, t), r && _defineProperties(e, r), e
}

function _inherits(e, t) {
  if ("function" != typeof t && null !== t) throw new TypeError("Super expression must either be null or a function");
  e.prototype = Object.create(t && t.prototype, {
    constructor: {
      value: e,
      writable: !0,
      configurable: !0
    }
  }), t && _setPrototypeOf(e, t)
}

function _setPrototypeOf(e, t) {
  return (_setPrototypeOf = Object.setPrototypeOf || function(e, t) {
    return e.__proto__ = t, e
  })(e, t)
}

function _createSuper(r) {
  var a = _isNativeReflectConstruct();
  return function() {
    var e, t = _getPrototypeOf(r);
    return _possibleConstructorReturn(this, a ? (e = _getPrototypeOf(this).constructor, Reflect.construct(t, arguments, e)) : t.apply(this, arguments))
  }
}

function _possibleConstructorReturn(e, t) {
  return !t || "object" !== _typeof(t) && "function" != typeof t ? _assertThisInitialized(e) : t
}

function _assertThisInitialized(e) {
  if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  return e
}

function _isNativeReflectConstruct() {
  if ("undefined" == typeof Reflect || !Reflect.construct) return !1;
  if (Reflect.construct.sham) return !1;
  if ("function" == typeof Proxy) return !0;
  try {
    return Date.prototype.toString.call(Reflect.construct(Date, [], function() {})), !0
  } catch (e) {
    return !1
  }
}

function _getPrototypeOf(e) {
  return (_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function(e) {
    return e.__proto__ || Object.getPrototypeOf(e)
  })(e)
}

function _defineProperty(e, t, r) {
  return t in e ? Object.defineProperty(e, t, {
    value: r,
    enumerable: !0,
    configurable: !0,
    writable: !0
  }) : e[t] = r, e
}
require("./../common/style/commonTabs.scss"), require("./../common/style/commonStyle.scss");
var TabPane = _amosAntd.Tabs.TabPane,
  DeviceProtocol = function() {
    _inherits(a, _react.Component);
    var r = _createSuper(a);

    function a(e) {
      var c;
      _classCallCheck(this, a), _defineProperty(_assertThisInitialized(c = r.call(this, e)), "onTabClick", function(e) {
        "1" === e ? c.requestMethod("0", c.state.criterias, void 0, e) : "2" === e && c.requestMethod("1", c.state.criterias, void 0, e)
      }), _defineProperty(_assertThisInitialized(c), "setSelected", function(e) {
        c.selected = e
      }), _defineProperty(_assertThisInitialized(c), "showTabPane", function(e) {
        var t = c.state,
          r = t.scriptLangOptions,
          a = t.criterias,
          i = t.dataList,
          o = c.selected,
          t = [];
        switch (e) {
          case "1":
            t.push(_react.default.createElement(_publicProtocol.default, {
              key: 1,
              setSelected: c.setSelected,
              dataList: i,
              requestMethod: c.requestMethod,
              updateAddView: c.updateAddView,
              criterias: a,
              visibility: "0"
            }));
            break;
          case "2":
            t.push(_react.default.createElement(_privateProtocol.default, {
              key: 2,
              setSelected: c.setSelected,
              dataList: i,
              requestMethod: c.requestMethod,
              updateAddView: c.updateAddView,
              criterias: a,
              visibility: "1"
            }));
            break;
          case "3":
            t.push(_react.default.createElement(_PrivateProtocolDetail.default, {
              key: 3,
              scriptLangOptions: r,
              selected: o,
              setSelected: c.setSelected
            }));
            break;
          case "4":
            t.push(_react.default.createElement(_addProtocol.default, {
              key: 4,
              updateAddView: c.updateAddView
            }));
            break;
          default:
            t.push(_react.default.createElement(_publicProtocol.default, {
              key: 1,
              setSelected: c.setSelected,
              updateAddView: c.updateAddView,
              criterias: a,
              visibility: "0"
            }))
        }
        return t
      }), _defineProperty(_assertThisInitialized(c), "requestMethod", function(o, e, n, s) {
        var t = {
            name: "visibility",
            type: "EQUAL",
            value: o
          },
          r = [];
        if (0 < e.length) {
          for (var a = 0; a < e.length; a++) {
            var i = e[a];
            "EQUAL" !== i.type && r.push(i)
          }
          e = r
        }
        e.push(t), _processor.AmosFetch.post(_urlConsts.default.protocolDataList, {
          data: e
        }).then(function(e) {
          if (e.ok) return e.json();
          throw new Error("从服务端获取数据失败！")
        }).then(function(e) {
          "SUCCESS" === e.result ? null !== e.dataList && c.setState({
            dataList: e.dataList
          }) : c.setState({
            dataList: []
          });
          var t = [],
            r = [],
            a = c.state.criterias;
          n && c.setState({
            flag: n
          }), s && c.setState({
            flag: s,
            criterias: [],
            visibility: o,
            activeKey: s
          });
          var i = c.state.activeKey;
          "1" === i ? (t.push(_react.default.createElement(_publicProtocol.default, {
            key: 1,
            setSelected: c.setSelected,
            dataList: e.dataList,
            requestMethod: c.requestMethod,
            updateAddView: c.updateAddView,
            criterias: a,
            visibility: "0"
          })), c.setState({
            tabContent: t
          })) : "2" === i && (r.push(_react.default.createElement(_privateProtocol.default, {
            key: 2,
            setSelected: c.setSelected,
            dataList: e.dataList,
            requestMethod: c.requestMethod,
            updateAddView: c.updateAddView,
            criterias: a,
            visibility: "1"
          })), c.setState({
            privateTabContent: r
          }))
        })
      }), _defineProperty(_assertThisInitialized(c), "updateAddView", function(e) {
        var t;
        "2" === e ? c.requestMethod(c.state.visibility, c.state.criterias, e) : "1" === (t = c.state.activeKey) ? c.setState({
          flag: e,
          tabContent: c.showTabPane(e)
        }) : "2" === t && c.setState({
          flag: e,
          privateTabContent: c.showTabPane(e)
        })
      }), _defineProperty(_assertThisInitialized(c), "handleCriterias", function(e) {
        var t = c.state.visibility;
        c.setState({
          criterias: e
        }), c.requestMethod(t, e)
      });
      var t = "1",
        e = c.props.location;
      return e.query.activeKey && (t = e.query.activeKey), c.state = {
        criterias: [],
        scriptLangOptions: [],
        flag: t,
        visibility: "0",
        dataList: [],
        tabContent: [],
        privateTabContent: [],
        activeKey: t
      }, c
    }
    return _createClass(a, [{
      key: "componentWillMount",
      value: function() {
        var r = this;
        _processor.AmosFetch.get(_urlConsts.default.scriptLangType).then(function(e) {
          if (e.ok) return e.json();
          throw new Error("从服务端获取数据失败！")
        }).then(function(e) {
          var t;
          "SUCCESS" === e.result && (t = [], e && e.dataList.map(function(e) {
            t.push({
              value: e.id,
              label: e.name,
              selected: !1,
              style: "all-filter-btn"
            })
          }), r.setState({
            scriptLangOptions: t
          }))
        }), 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,
          e = 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"
        }, e), _react.default.createElement(TabPane, {
          tab: _react.default.createElement("div", null, "我的"),
          key: "2"
        }, a)))
      }
    }]), a
  }();
DeviceProtocol.displayName = "DeviceProtocol", DeviceProtocol.propTypes = {};
var _default = DeviceProtocol;
exports.default = DeviceProtocol, module.exports = exports.default;
