"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"), _typeof = require("@babel/runtime/helpers/typeof");

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 _getRequireWildcardCache(e) {
  if ("function" != typeof WeakMap) return null;
  var t = new WeakMap, r = new WeakMap;
  return (_getRequireWildcardCache = function(e) {
    return e ? r : t;
  })(e);
}

function _interopRequireWildcard(e, t) {
  if (!t && e && e.__esModule) return e;
  if (null === e || "object" !== _typeof(e) && "function" != typeof e) return {
    default: e
  };
  var r = _getRequireWildcardCache(t);
  if (r && r.has(e)) return r.get(e);
  var a = {}, i = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (var s in e) if ("default" !== s && Object.prototype.hasOwnProperty.call(e, s)) {
    var o = i ? Object.getOwnPropertyDescriptor(e, s) : null;
    o && (o.get || o.set) ? Object.defineProperty(a, s, o) : a[s] = e[s];
  }
  return a.default = e, r && r.set(e, a), 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("./../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, o = a.selected, l = [];
      switch (e) {
       case "1":
        l.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":
        l.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":
        l.push(_react.default.createElement(_PrivateProtocolDetail.default, {
          key: 3,
          scriptLangOptions: r,
          selected: o,
          setSelected: a.setSelected
        }));
        break;

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

       default:
        l.push(_react.default.createElement(_publicProtocol.default, {
          key: 1,
          setSelected: a.setSelected,
          updateAddView: a.updateAddView,
          criterias: i,
          visibility: "0"
        }));
      }
      return l;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "requestMethod", (function(e, t, r, i) {
      var s = {
        name: "visibility",
        type: "EQUAL",
        value: e
      }, o = [];
      if (t.length > 0) {
        for (var l = 0; l < t.length; l++) {
          var u = t[l];
          "EQUAL" !== u.type && o.push(u);
        }
        t = o;
      }
      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 = [], o = [], l = 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: l,
          visibility: "0"
        })), a.setState({
          tabContent: s
        })) : "2" === u && (o.push(_react.default.createElement(_privateProtocol.default, {
          key: 2,
          setSelected: a.setSelected,
          dataList: t.dataList,
          requestMethod: a.requestMethod,
          updateAddView: a.updateAddView,
          criterias: l,
          visibility: "1"
        })), a.setState({
          privateTabContent: o
        }));
      }));
    })), (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;