function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

import React, { useRef, lazy, Suspense, useMemo } from 'react';
import { observer } from 'mobx-react-lite';
import map from 'lodash/map';
import Sidebar from "./sidebar";
import DragBar from "../../../components/drag-bar";
import Loading from "../../../components/loading";
import EmptyPage from "../../../components/empty-page";
import DeleteModal from "./components/delete-modal";
import { useResourceStore } from "../stores";
import { useMainStore } from "./stores";
import "./index.less"; // 实例视图

var EnvContent = /*#__PURE__*/lazy(function () {
  return import("./contents/environment");
});
var AppContent = /*#__PURE__*/lazy(function () {
  return import("./contents/application");
});
var IstContent = /*#__PURE__*/lazy(function () {
  return import("./contents/instance");
}); // 资源视图

var ResourceEnvContent = /*#__PURE__*/lazy(function () {
  return import("./contents/resource-env");
});
var NetworkContent = /*#__PURE__*/lazy(function () {
  return import("./contents/network");
});
var IngressContent = /*#__PURE__*/lazy(function () {
  return import("./contents/ingress");
});
var CertContent = /*#__PURE__*/lazy(function () {
  return import("./contents/certificate");
});
var ConfigMapContent = /*#__PURE__*/lazy(function () {
  return import("./contents/configMap");
});
var SecretContent = /*#__PURE__*/lazy(function () {
  return import("./contents/secret");
});
var CustomContent = /*#__PURE__*/lazy(function () {
  return import("./contents/custom");
});
var IstListContent = /*#__PURE__*/lazy(function () {
  return import("./contents/instance-list");
});
var CustomDetail = /*#__PURE__*/lazy(function () {
  return import("./contents/custom-detail");
});
var IngressDetail = /*#__PURE__*/lazy(function () {
  return import("./contents/ingress-detail");
});
var CertDetail = /*#__PURE__*/lazy(function () {
  return import("./contents/certificate-detail");
});
var ConfigMapDetail = /*#__PURE__*/lazy(function () {
  return import("./contents/config-detail");
});
var SecretDetail = /*#__PURE__*/lazy(function () {
  return import("./contents/secret-detail");
});
var ServiceDetail = /*#__PURE__*/lazy(function () {
  return import("./contents/service-detail");
});
var PVCContent = /*#__PURE__*/lazy(function () {
  return import("./contents/pvc");
});
var EmptyShown = /*#__PURE__*/lazy(function () {
  return import("./contents/empty");
});
var MainView = observer(function () {
  var _useResourceStore = useResourceStore(),
      prefixCls = _useResourceStore.prefixCls,
      resourceStore = _useResourceStore.resourceStore,
      IST_VIEW_TYPE = _useResourceStore.viewTypeMappings.IST_VIEW_TYPE,
      _useResourceStore$ite = _useResourceStore.itemTypes,
      ENV_ITEM = _useResourceStore$ite.ENV_ITEM,
      APP_ITEM = _useResourceStore$ite.APP_ITEM,
      IST_ITEM = _useResourceStore$ite.IST_ITEM,
      SERVICES_ITEM = _useResourceStore$ite.SERVICES_ITEM,
      INGRESS_ITEM = _useResourceStore$ite.INGRESS_ITEM,
      CERT_ITEM = _useResourceStore$ite.CERT_ITEM,
      MAP_ITEM = _useResourceStore$ite.MAP_ITEM,
      CIPHER_ITEM = _useResourceStore$ite.CIPHER_ITEM,
      CUSTOM_ITEM = _useResourceStore$ite.CUSTOM_ITEM,
      SERVICES_GROUP = _useResourceStore$ite.SERVICES_GROUP,
      INGRESS_GROUP = _useResourceStore$ite.INGRESS_GROUP,
      CERT_GROUP = _useResourceStore$ite.CERT_GROUP,
      MAP_GROUP = _useResourceStore$ite.MAP_GROUP,
      CIPHER_GROUP = _useResourceStore$ite.CIPHER_GROUP,
      CUSTOM_GROUP = _useResourceStore$ite.CUSTOM_GROUP,
      IST_GROUP = _useResourceStore$ite.IST_GROUP,
      PVC_ITEM = _useResourceStore$ite.PVC_ITEM,
      PVC_GROUP = _useResourceStore$ite.PVC_GROUP,
      treeDs = _useResourceStore.treeDs,
      formatMessage = _useResourceStore.intl.formatMessage;

  var _useMainStore = useMainStore(),
      mainStore = _useMainStore.mainStore;

  var rootRef = useRef(null);
  var parentId = resourceStore.getSelectedMenu.parentId;
  var getDeleteArr = mainStore.getDeleteArr;
  var deleteModals = useMemo(function () {
    return map(getDeleteArr, function (_ref) {
      var name = _ref.name,
          display = _ref.display,
          deleteId = _ref.deleteId,
          type = _ref.type,
          refresh = _ref.refresh,
          envId = _ref.envId;
      return /*#__PURE__*/React.createElement(DeleteModal, {
        key: deleteId,
        envId: envId || parentId.split('**')[0],
        store: mainStore,
        title: "".concat(formatMessage({
          id: "".concat(type, ".delete")
        }), "\u201C").concat(name, "\u201D"),
        visible: display,
        objectId: deleteId,
        objectType: type,
        refresh: refresh
      });
    });
  }, [getDeleteArr]);
  var content = useMemo(function () {
    var _cmMaps;

    var getViewType = resourceStore.getViewType,
        itemType = resourceStore.getSelectedMenu.itemType;
    if (!itemType) return /*#__PURE__*/React.createElement(Loading, {
      display: true
    });
    var cmMaps = (_cmMaps = {}, _defineProperty(_cmMaps, ENV_ITEM, getViewType === IST_VIEW_TYPE ? /*#__PURE__*/React.createElement(EnvContent, null) : /*#__PURE__*/React.createElement(ResourceEnvContent, null)), _defineProperty(_cmMaps, APP_ITEM, /*#__PURE__*/React.createElement(AppContent, null)), _defineProperty(_cmMaps, IST_ITEM, /*#__PURE__*/React.createElement(IstContent, null)), _defineProperty(_cmMaps, SERVICES_GROUP, /*#__PURE__*/React.createElement(NetworkContent, null)), _defineProperty(_cmMaps, INGRESS_GROUP, /*#__PURE__*/React.createElement(IngressContent, null)), _defineProperty(_cmMaps, CERT_GROUP, /*#__PURE__*/React.createElement(CertContent, null)), _defineProperty(_cmMaps, MAP_GROUP, /*#__PURE__*/React.createElement(ConfigMapContent, null)), _defineProperty(_cmMaps, CIPHER_GROUP, /*#__PURE__*/React.createElement(SecretContent, null)), _defineProperty(_cmMaps, CUSTOM_GROUP, /*#__PURE__*/React.createElement(CustomContent, null)), _defineProperty(_cmMaps, IST_GROUP, /*#__PURE__*/React.createElement(IstListContent, null)), _defineProperty(_cmMaps, CUSTOM_ITEM, /*#__PURE__*/React.createElement(CustomDetail, null)), _defineProperty(_cmMaps, INGRESS_ITEM, /*#__PURE__*/React.createElement(IngressDetail, null)), _defineProperty(_cmMaps, CERT_ITEM, /*#__PURE__*/React.createElement(CertDetail, null)), _defineProperty(_cmMaps, MAP_ITEM, /*#__PURE__*/React.createElement(ConfigMapDetail, null)), _defineProperty(_cmMaps, CIPHER_ITEM, /*#__PURE__*/React.createElement(SecretDetail, null)), _defineProperty(_cmMaps, SERVICES_ITEM, /*#__PURE__*/React.createElement(ServiceDetail, null)), _defineProperty(_cmMaps, PVC_GROUP, /*#__PURE__*/React.createElement(PVCContent, null)), _cmMaps);
    return cmMaps[itemType] ? /*#__PURE__*/React.createElement(Suspense, {
      fallback: /*#__PURE__*/React.createElement(Loading, {
        display: true
      })
    }, cmMaps[itemType]) : /*#__PURE__*/React.createElement(EmptyPage, {
      title: "\u6CA1\u6709\u8BE5\u7C7B\u578B\u8D44\u6E90",
      describe: "\u8BF7\u7A0D\u540E\u91CD\u8BD5"
    });
  }, [resourceStore.getViewType, resourceStore.getSelectedMenu.itemType]);
  return !treeDs.length && treeDs.status === 'ready' && !resourceStore.getSearchValue ? /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefixCls, "-wrap")
  }, /*#__PURE__*/React.createElement(Suspense, {
    fallback: /*#__PURE__*/React.createElement("span", null)
  }, /*#__PURE__*/React.createElement(EmptyShown, null))) : /*#__PURE__*/React.createElement("div", {
    ref: rootRef,
    className: "".concat(prefixCls, "-wrap")
  }, /*#__PURE__*/React.createElement(DragBar, {
    parentRef: rootRef,
    store: mainStore
  }), /*#__PURE__*/React.createElement(Sidebar, null), /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefixCls, "-main ").concat(prefixCls, "-animate")
  }, content), deleteModals);
});
export default MainView;