function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

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, { Fragment, useMemo } from 'react';
import { observer } from 'mobx-react-lite';
import { useClusterMainStore } from "../../../stores";
import { useNodeContentStore } from "../stores";
import { useClusterStore } from "../../../../stores";
import Loading from "../../../../../../components/loading";
import EmptyPage from "../../../../../../components/empty-page";
import setTreeMenuSelect from "../../../../../../utils/setTreeMenuSelect";
import "./index.less";
export default observer(function (props) {
  var _useClusterStore = useClusterStore(),
      clusterStore = _useClusterStore.clusterStore,
      treeDs = _useClusterStore.treeDs;

  var _useClusterMainStore = useClusterMainStore(),
      intlPrefix = _useClusterMainStore.intlPrefix,
      prefixCls = _useClusterMainStore.prefixCls,
      mainStore = _useClusterMainStore.mainStore;

  var _useNodeContentStore = useNodeContentStore(),
      getGrafanaUrl = _useNodeContentStore.contentStore.getGrafanaUrl,
      formatMessage = _useNodeContentStore.formatMessage,
      COMPONENT_TAB = _useNodeContentStore.COMPONENT_TAB;

  var _clusterStore$getSele = clusterStore.getSelectedMenu,
      name = _clusterStore$getSele.name,
      parentId = _clusterStore$getSele.parentId,
      key = _clusterStore$getSele.key,
      setSelectedMenu = clusterStore.setSelectedMenu;

  function refresh() {}

  function LinkToComponent() {
    var clusterRecord = treeDs.find(function (record) {
      return record.get('id') === parentId;
    });
    var currentRecord = treeDs.find(function (record) {
      return record.get('key') === key;
    });

    if (clusterRecord) {
      mainStore.setClusterDefaultTab(COMPONENT_TAB);
    }

    currentRecord.isSelected = false;
    setSelectedMenu(_objectSpread({}, clusterRecord.toData()));
    setTreeMenuSelect(treeDs, clusterStore);
  }

  function getContent() {
    if (getGrafanaUrl) {
      var clusterRecord = treeDs.find(function (record) {
        return record.get('id') === Number(parentId);
      });
      var code = clusterRecord && clusterRecord.get('code');
      return /*#__PURE__*/React.createElement("iframe", {
        height: 700,
        width: "100%",
        src: "".concat(getGrafanaUrl, "?kiosk=tv&var-node=").concat(name),
        title: "grafanaNode",
        frameBorder: 0,
        sandbox: true
      });
    } else {
      return /*#__PURE__*/React.createElement(EmptyPage, {
        title: formatMessage({
          id: "".concat(intlPrefix, ".monitor.install")
        }),
        describe: formatMessage({
          id: "".concat(intlPrefix, ".monitor.empty.des")
        }),
        btnText: formatMessage({
          id: "".concat(intlPrefix, ".monitor.link")
        }),
        onClick: LinkToComponent,
        access: true
      });
    }
  }

  return /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefixCls, "-node-monitor-wrap")
  }, getContent());
});