import "choerodon-ui/lib/spin/style";
import _Spin from "@hzero-front-ui/c7n-ui/lib/Spin";
import "choerodon-ui/lib/tabs/style";
import _Tabs from "choerodon-ui/lib/tabs";
import React, { Fragment, lazy, Suspense, useEffect, useMemo, useState } from 'react';
import { observer } from 'mobx-react-lite';
import { axios } from '@choerodon/boot';
import { useClusterContentStore } from "./stores";
import Modals from "./modals";
import PageTitle from "../../../../../components/page-title";
import StatusDot from "../../../../../components/status-dot";
import Tips from "../../../../../components/new-tips";
import "./index.less";
var TabPane = _Tabs.TabPane;
var NodeList = /*#__PURE__*/lazy(function () {
  return import("./node-list");
});
var PermissionList = /*#__PURE__*/lazy(function () {
  return import("./permission-list");
});
var Monitor = /*#__PURE__*/lazy(function () {
  return import("./monitor");
});
var ComponentManage = /*#__PURE__*/lazy(function () {
  return import("./component-manage");
});
var Polaris = /*#__PURE__*/lazy(function () {
  return import("./polaris");
});
var EnvManage = /*#__PURE__*/lazy(function () {
  return import("./env-manage");
});
export default observer(function (props) {
  var _useClusterContentSto = useClusterContentStore(),
      intlPrefix = _useClusterContentSto.intlPrefix,
      formatMessage = _useClusterContentSto.intl.formatMessage,
      _useClusterContentSto2 = _useClusterContentSto.tabs,
      NODE_TAB = _useClusterContentSto2.NODE_TAB,
      ENV_TAB = _useClusterContentSto2.ENV_TAB,
      POLARIS_TAB = _useClusterContentSto2.POLARIS_TAB,
      ASSIGN_TAB = _useClusterContentSto2.ASSIGN_TAB,
      COMPONENT_TAB = _useClusterContentSto2.COMPONENT_TAB,
      MONITOR_TAB = _useClusterContentSto2.MONITOR_TAB,
      contentStore = _useClusterContentSto.contentStore,
      ClusterDetailDs = _useClusterContentSto.ClusterDetailDs;

  var handleChange = function handleChange(key) {
    contentStore.setTabKey(key);
  };

  function title() {
    var record = ClusterDetailDs.current;

    if (record) {
      var name = record.get('name');

      var getStatus = function getStatus() {
        var tempStatus = record.get('status');

        switch (tempStatus) {
          case 'running':
            return ['running', 'connect'];

          case 'failed':
            return ['failed', 'failed'];

          case 'operating':
            return ['operating', 'operating'];

          default:
            break;
        }

        return ['disconnect'];
      };

      return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(StatusDot, {
        getStatus: getStatus
      }), /*#__PURE__*/React.createElement("span", {
        className: "c7ncd-page-title-text"
      }, name));
    }

    return null;
  }

  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Modals, null), /*#__PURE__*/React.createElement(PageTitle, {
    content: title()
  }), /*#__PURE__*/React.createElement(_Tabs, {
    animated: false,
    activeKey: contentStore.getTabKey,
    onChange: handleChange,
    className: "c7ncd-cluster-tab-content"
  }, /*#__PURE__*/React.createElement(TabPane, {
    key: NODE_TAB,
    tab: formatMessage({
      id: "".concat(intlPrefix, ".node.list")
    })
  }, /*#__PURE__*/React.createElement(Suspense, {
    fallback: /*#__PURE__*/React.createElement(_Spin, null)
  }, /*#__PURE__*/React.createElement("div", {
    className: "c7ncd-cluster-node-list"
  }, /*#__PURE__*/React.createElement(NodeList, null)))), /*#__PURE__*/React.createElement(TabPane, {
    key: POLARIS_TAB,
    tab: formatMessage({
      id: "".concat(intlPrefix, ".polaris")
    })
  }, /*#__PURE__*/React.createElement(Suspense, {
    fallback: /*#__PURE__*/React.createElement(_Spin, null)
  }, /*#__PURE__*/React.createElement(Polaris, null))), /*#__PURE__*/React.createElement(TabPane, {
    key: ASSIGN_TAB,
    tab: /*#__PURE__*/React.createElement(Tips, {
      helpText: formatMessage({
        id: "".concat(intlPrefix, ".permission.tab.tips")
      }),
      title: formatMessage({
        id: "".concat(intlPrefix, ".permission.assign")
      })
    })
  }, /*#__PURE__*/React.createElement(Suspense, {
    fallback: /*#__PURE__*/React.createElement(_Spin, null)
  }, /*#__PURE__*/React.createElement(PermissionList, null))), /*#__PURE__*/React.createElement(TabPane, {
    key: COMPONENT_TAB,
    tab: formatMessage({
      id: "".concat(intlPrefix, ".component")
    })
  }, /*#__PURE__*/React.createElement(Suspense, {
    fallback: /*#__PURE__*/React.createElement(_Spin, null)
  }, /*#__PURE__*/React.createElement(ComponentManage, null))), /*#__PURE__*/React.createElement(TabPane, {
    key: MONITOR_TAB,
    tab: formatMessage({
      id: "".concat(intlPrefix, ".monitor")
    })
  }, /*#__PURE__*/React.createElement(Suspense, {
    fallback: /*#__PURE__*/React.createElement(_Spin, null)
  }, /*#__PURE__*/React.createElement(Monitor, null)))));
});