"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")),
  _publicInterface = _interopRequireDefault(require("./publicInterface")),
  _privateInterface = _interopRequireDefault(require("./privateInterface")),
  _addInterface = _interopRequireDefault(require("./addInterface")),
  _PrivateInterfaceDetail = _interopRequireDefault(require("./privateInterface/PrivateInterfaceDetail")),
  _searchBar = _interopRequireDefault(require("./common/searchBar"));
require("./../common/style/commonTabs.scss"), require("./../common/style/commonStyle.scss");
var _PropTypes = _interopRequireDefault(require("amos-react-router/lib/PropTypes"));

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 = {},
    n = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (r in e) Object.prototype.hasOwnProperty.call(e, r) && ((a = n ? 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
}
var TabPane = _amosAntd.Tabs.TabPane,
  DeviceInterface = 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), "requestMethod", function(o, e, s, u) {
        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.interfaceDataList, {
          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: []
          }), s && c.setState({
            carInfo: s
          }), u && c.setState({
            flag: u,
            criterias: [],
            visibility: o,
            activeKey: u
          });
          var t = c.state,
            r = t.communityDatas,
            a = t.criterias,
            i = [],
            n = [],
            t = c.state.activeKey;
          "1" === t ? (i.push(_react.default.createElement(_publicInterface.default, {
            key: 1,
            updateAddView: c.updateAddView,
            dataList: e.dataList,
            requestMethod: c.requestMethod,
            criterias: a,
            visibility: "0"
          })), c.setState({
            tabContent: i
          })) : "2" === t && (n.push(_react.default.createElement(_privateInterface.default, {
            key: 2,
            communityDatas: r,
            updateAddView: c.updateAddView,
            dataList: e.dataList,
            requestMethod: c.requestMethod,
            criterias: a,
            visibility: "1"
          })), c.setState({
            privateTabContent: n
          }))
        })
      }), _defineProperty(_assertThisInitialized(c), "updateAddView", function(e, t) {
        var r;
        "2" === e ? c.requestMethod(c.state.visibility, c.state.criterias, t) : "1" === (r = c.state.activeKey) ? c.setState({
          flag: e,
          carInfo: t,
          tabContent: c.showTabPane(e, t)
        }) : "2" === r && c.setState({
          flag: e,
          carInfo: t,
          privateTabContent: c.showTabPane(e, t)
        })
      }), _defineProperty(_assertThisInitialized(c), "showTabPane", function(e, t) {
        var r = c.state,
          a = r.communityDatas,
          i = r.criterias,
          r = [];
        switch (e) {
          case "1":
            r.push(_react.default.createElement(_publicInterface.default, {
              key: 1,
              updateAddView: c.updateAddView,
              dataList: c.state.dataList,
              requestMethod: c.requestMethod,
              criterias: i,
              visibility: "0"
            }));
            break;
          case "2":
            r.push(_react.default.createElement(_privateInterface.default, {
              key: 2,
              communityDatas: a,
              updateAddView: c.updateAddView,
              dataList: c.state.dataList,
              requestMethod: c.requestMethod,
              criterias: i,
              visibility: "1"
            }));
            break;
          case "3":
            r.push(_react.default.createElement(_PrivateInterfaceDetail.default, {
              key: 3,
              communityDatas: a,
              carInfo: t
            }));
            break;
          case "4":
            r.push(_react.default.createElement(_addInterface.default, {
              key: 4,
              communityDatas: a,
              updateAddView: c.updateAddView
            }));
            break;
          default:
            r.push(_react.default.createElement(_publicInterface.default, {
              key: 1,
              updateAddView: c.updateAddView,
              criterias: i,
              visibility: "0"
            }))
        }
        return r
      }), _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 = {
        visibility: "0",
        criterias: [],
        flag: t,
        dataList: [],
        communityDatas: [],
        communityOptions: [],
        tabContent: [],
        privateTabContent: [],
        activeKey: t
      }, c
    }
    return _createClass(a, [{
      key: "componentWillMount",
      value: function() {
        var r = this;
        _processor.AmosFetch.get(_urlConsts.default.communityProtocol).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({
            communityOptions: t,
            communityDatas: e.dataList
          }))
        }), this.requestMethod("1" === this.state.activeKey ? "0" : "1", [])
      }
    }, {
      key: "render",
      value: function() {
        var e = this.state,
          t = e.communityOptions,
          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,
            communityOptions: 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
  }();
DeviceInterface.displayName = "DeviceInterface", DeviceInterface.propTypes = {};
var _default = DeviceInterface;
exports.default = DeviceInterface, module.exports = exports.default;
