"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _vtxModal = _interopRequireDefault(require("@vtx/components/lib/vtx-modal"));
var _button = _interopRequireDefault(require("antd/lib/button"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _react = _interopRequireWildcard(require("react"));
var _MyModal = _interopRequireDefault(require("../_component/MyModal"));
var _DeviceDetail = _interopRequireDefault(require("../_component/DeviceDetail"));
var _DetailModal = require("./DetailModal");
var _lodash = require("lodash");
var _antd = require("antd");
var _ahooks = require("ahooks");
var _service = require("./service");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } /* eslint-disable react/prop-types */
var DeviceModal = function DeviceModal(_ref) {
  var visible = _ref.visible,
    id = _ref.id,
    onCancel = _ref.onCancel,
    _ref$theme = _ref.theme,
    theme = _ref$theme === void 0 ? 'light' : _ref$theme,
    gwList = _ref.gwList;
  var _useState = (0, _react.useState)(''),
    _useState2 = _slicedToArray(_useState, 2),
    activeKey = _useState2[0],
    setActiveKey = _useState2[1];
  var info = gwList.find(function (item) {
    return item.lineNo === activeKey;
  }) || {};
  var _useRequest = (0, _ahooks.useRequest)(function () {
      if (info.facilityId) {
        return (0, _service.fetchQueryDataResult)({
          facilityId: info.facilityId
        });
      }
      return {};
    }, {
      refreshDeps: [info.facilityId],
      ready: !!info.facilityId
    }),
    _useRequest$data = _useRequest.data,
    data = _useRequest$data === void 0 ? {} : _useRequest$data;
  (0, _react.useEffect)(function () {
    if (!(0, _lodash.isEmpty)(gwList)) {
      setActiveKey(gwList[0].lineNo);
    }
  }, [gwList]);
  var _data$result = data.result,
    result = _data$result === void 0 ? {} : _data$result;
  var upstreamItems = result.upstreamItems,
    downstreamItems = result.downstreamItems,
    _result$config = result.config,
    config = _result$config === void 0 ? {} : _result$config;
  return /*#__PURE__*/_react["default"].createElement(_MyModal["default"], {
    title: /*#__PURE__*/_react["default"].createElement(_vtxModal["default"].Title, {
      text: "\u96E8\u6C61\u6DF7\u63A5",
      subtitle: "\u8BE6\u60C5"
    }),
    width: 1366,
    footer: theme === 'light' ? /*#__PURE__*/_react["default"].createElement(_button["default"], {
      onClick: onCancel
    }, "\u5173\u95ED") : null,
    visible: visible,
    onCancel: onCancel,
    theme: theme,
    isAntd: true
  }, /*#__PURE__*/_react["default"].createElement(_DeviceDetail["default"], {
    id: id
  }), /*#__PURE__*/_react["default"].createElement(_antd.Tabs, {
    size: "small",
    activeKey: activeKey,
    onChange: function onChange(key) {
      return setActiveKey(key);
    }
  }, gwList.map(function (item) {
    return /*#__PURE__*/_react["default"].createElement(_antd.Tabs.TabPane, {
      key: item.lineNo,
      tab: item.lineNo
    });
  })), /*#__PURE__*/_react["default"].createElement(_DetailModal.Analysis, {
    info: data,
    theme: theme
  }), (0, _lodash.isEmpty)(upstreamItems) ? null : upstreamItems.map(function (item) {
    return /*#__PURE__*/_react["default"].createElement(_DetailModal.StreamInfo, {
      info: item,
      isUp: true,
      key: item.deviceFacilityId,
      config: config,
      theme: theme
    });
  }), (0, _lodash.isEmpty)(downstreamItems) ? null : downstreamItems.map(function (item) {
    return /*#__PURE__*/_react["default"].createElement(_DetailModal.StreamInfo, {
      info: item,
      isUp: false,
      key: item.deviceFacilityId,
      config: config,
      theme: theme
    });
  }));
};
DeviceModal.propTypes = {
  visible: _propTypes["default"].bool,
  gwList: _propTypes["default"].array,
  onCancel: _propTypes["default"].func,
  id: _propTypes["default"].string,
  theme: _propTypes["default"].string
};
var _default = exports["default"] = DeviceModal;
//# sourceMappingURL=DeviceModal.js.map
