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 DragBar from "../../../components/drag-bar";
import Loading from "../../../components/loading";
import Sidebar from "./sidebar";
import { useEnvironmentStore } from "../stores";
import { useMainStore } from "./stores";
import "./index.less";
var Group = /*#__PURE__*/lazy(function () {
  return import("./contents/group");
});
var Detail = /*#__PURE__*/lazy(function () {
  return import("./contents/detail");
});
var EmptyPage = /*#__PURE__*/lazy(function () {
  return import("./contents/empty");
});
var MainView = observer(function () {
  var _useEnvironmentStore = useEnvironmentStore(),
      prefixCls = _useEnvironmentStore.prefixCls,
      itemType = _useEnvironmentStore.envStore.getSelectedMenu.itemType,
      _useEnvironmentStore$ = _useEnvironmentStore.itemType,
      DETAIL_ITEM = _useEnvironmentStore$.DETAIL_ITEM,
      GROUP_ITEM = _useEnvironmentStore$.GROUP_ITEM,
      treeDs = _useEnvironmentStore.treeDs;

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

  var rootRef = useRef();
  var content = useMemo(function () {
    var _cmMaps;

    var cmMaps = (_cmMaps = {}, _defineProperty(_cmMaps, GROUP_ITEM, /*#__PURE__*/React.createElement(Group, null)), _defineProperty(_cmMaps, DETAIL_ITEM, /*#__PURE__*/React.createElement(Detail, null)), _cmMaps);
    return cmMaps[itemType] ? /*#__PURE__*/React.createElement(Suspense, {
      fallback: /*#__PURE__*/React.createElement(Loading, {
        display: true
      })
    }, cmMaps[itemType]) : /*#__PURE__*/React.createElement(Loading, {
      display: true
    });
  }, [itemType]);

  function getMainView() {
    if (!treeDs.length && treeDs.status === 'ready') {
      return /*#__PURE__*/React.createElement("div", {
        className: "".concat(prefixCls, "-wrap")
      }, /*#__PURE__*/React.createElement(Suspense, {
        fallback: /*#__PURE__*/React.createElement("span", null)
      }, /*#__PURE__*/React.createElement(EmptyPage, null)), /*#__PURE__*/React.createElement("div", null, "\u8BF7\u5148\u521B\u5EFA\u5206\u7EC4\uFF01"));
    } else {
      return /*#__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));
    }
  }

  return getMainView();
});
export default MainView;