import "choerodon-ui/lib/spin/style";
import _Spin from "@hzero-front-ui/c7n-ui/lib/Spin";
import "choerodon-ui/pro/lib/button/style";
import _Button from "choerodon-ui/pro/lib/button";
import "choerodon-ui/pro/lib/tooltip/style";
import _Tooltip from "choerodon-ui/pro/lib/tooltip";
import "choerodon-ui/pro/lib/icon/style";
import _Icon from "choerodon-ui/pro/lib/icon";

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

import React, { Fragment, Suspense, useEffect, useMemo } from 'react';
import map from 'lodash/map';
import { observer } from 'mobx-react-lite';
import omit from 'lodash/omit';
import { useClusterMainStore } from "../../../../stores";
import { useClusterContentStore } from "../../stores";
import "./index.less";
export default observer(function (_ref) {
  var refresh = _ref.refresh;

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

  var _useClusterContentSto = useClusterContentStore(),
      formatMessage = _useClusterContentSto.formatMessage,
      contentStore = _useClusterContentSto.contentStore,
      projectId = _useClusterContentSto.projectId,
      clusterId = _useClusterContentSto.clusterId;

  var getPrometheusStatus = contentStore.getPrometheusStatus,
      getPrometheusLoading = contentStore.getPrometheusLoading;
  var progressData = useMemo(function () {
    return omit(getPrometheusStatus, ['error']);
  }, [getPrometheusStatus]);
  var progressError = useMemo(function () {
    return getPrometheusStatus.error;
  }, [getPrometheusStatus]);
  useEffect(function () {
    contentStore.loadPrometheusStatus(projectId, clusterId);
  }, []);

  function handleRetry() {
    return _handleRetry.apply(this, arguments);
  }

  function _handleRetry() {
    _handleRetry = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
      return regeneratorRuntime.wrap(function _callee$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              _context.next = 2;
              return contentStore.retryPrometheus(projectId, clusterId);

            case 2:
              if (!_context.sent) {
                _context.next = 4;
                break;
              }

              refresh();

            case 4:
            case "end":
              return _context.stop();
          }
        }
      }, _callee);
    }));
    return _handleRetry.apply(this, arguments);
  }

  return /*#__PURE__*/React.createElement(_Spin, {
    spinning: getPrometheusLoading
  }, map(progressData, function (value, key) {
    return /*#__PURE__*/React.createElement("div", {
      className: "".concat(prefixCls, "-install-step"),
      key: key
    }, /*#__PURE__*/React.createElement("div", {
      className: "".concat(prefixCls, "-install-step-content")
    }, /*#__PURE__*/React.createElement("span", {
      className: "".concat(prefixCls, "-install-step-status ").concat(prefixCls, "-install-step-status-").concat(value)
    }), /*#__PURE__*/React.createElement("span", {
      className: "".concat(prefixCls, "-install-step-text")
    }, formatMessage({
      id: "".concat(intlPrefix, ".install.step.").concat(key)
    })), value === 'failed' && /*#__PURE__*/React.createElement(Fragment, null, progressError && /*#__PURE__*/React.createElement(_Tooltip, {
      title: progressError
    }, /*#__PURE__*/React.createElement(_Icon, {
      type: "error",
      className: "".concat(prefixCls, "-install-step-icon-failed")
    })), /*#__PURE__*/React.createElement(_Button, {
      funcType: "raised",
      color: "primary",
      size: "small",
      onClick: handleRetry,
      className: "".concat(prefixCls, "-install-step-btn")
    }, formatMessage({
      id: "".concat(intlPrefix, ".install.step.retry")
    })))), key !== 'installPrometheus' && /*#__PURE__*/React.createElement("div", {
      className: "".concat(prefixCls, "-install-step-line ").concat(prefixCls, "-install-step-").concat(value)
    }));
  }));
});