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";
import "choerodon-ui/lib/steps/style";
import _Steps from "choerodon-ui/lib/steps";

/* eslint-disable jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */
import React, { useMemo } from 'react';
import { observer } from 'mobx-react-lite';
import { useCreateHostStore } from "../../stores";
import "./index.less";
var Step = _Steps.Step;
var STATUS = {
  success: 'finish',
  failed: 'error',
  operating: 'process',
  wait: 'wait'
};
var TestConnect = observer(function (_ref) {
  var handleTestConnection = _ref.handleTestConnection;

  var _useCreateHostStore = useCreateHostStore(),
      prefixCls = _useCreateHostStore.prefixCls,
      formDs = _useCreateHostStore.formDs;

  var record = useMemo(function () {
    return formDs && formDs.current;
  }, [formDs.current]);

  var getContent = function getContent() {
    if (record) {
      var hostStatus = record.get('hostStatus') || 'wait';

      if (record.get('type') === 'distribute_test') {
        var jmeterStatus = record.get('jmeterStatus') || 'wait';
        return /*#__PURE__*/React.createElement(_Steps, {
          progressDot: true,
          size: 'small'
        }, /*#__PURE__*/React.createElement(Step // @ts-ignore
        , {
          status: STATUS[hostStatus],
          title: hostStatus === 'failed' && record.get('hostCheckError') ? /*#__PURE__*/React.createElement("span", null, "\u4E3B\u673A\u8FDE\u63A5", /*#__PURE__*/React.createElement(_Tooltip, {
            title: record.get('hostCheckError')
          }, /*#__PURE__*/React.createElement(_Icon, {
            type: "info",
            className: "".concat(prefixCls, "-test-failed-icon")
          }))) : '主机连接'
        }), /*#__PURE__*/React.createElement(Step // @ts-ignore
        , {
          status: STATUS[jmeterStatus],
          title: jmeterStatus === 'failed' && record.get('jmeterCheckError') ? /*#__PURE__*/React.createElement("span", null, "Jmeter\u68C0\u6D4B", /*#__PURE__*/React.createElement(_Tooltip, {
            title: record.get('jmeterCheckError')
          }, /*#__PURE__*/React.createElement(_Icon, {
            type: "info",
            className: "".concat(prefixCls, "-test-failed-icon")
          }))) : 'Jmeter检测'
        }));
      }

      var content;

      switch (hostStatus) {
        case 'success':
          content = [/*#__PURE__*/React.createElement(_Icon, {
            type: "finished",
            className: "".concat(prefixCls, "-test-text-icon")
          }), /*#__PURE__*/React.createElement("span", null, "\u6210\u529F")];
          break;

        case 'failed':
          content = [/*#__PURE__*/React.createElement(_Icon, {
            type: "highlight_off",
            className: "".concat(prefixCls, "-test-text-icon")
          }), /*#__PURE__*/React.createElement("span", null, "\u5931\u8D25"), record.get('hostCheckError') ? /*#__PURE__*/React.createElement(_Tooltip, {
            title: record.get('hostCheckError')
          }, /*#__PURE__*/React.createElement(_Icon, {
            type: "info",
            className: "".concat(prefixCls, "-test-failed-icon-host")
          })) : null];
          break;

        case 'operating':
          content = '正在进行连接测试';
          break;

        default:
          content = '未进行连接测试';
      }

      return /*#__PURE__*/React.createElement("span", {
        className: "".concat(prefixCls, "-test-text ").concat(prefixCls, "-test-text").concat(hostStatus ? "-".concat(hostStatus) : '')
      }, content);
    }

    return null;
  };

  return /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefixCls, "-test ").concat(prefixCls, "-test").concat(record && record.get('status') ? "-".concat(record.get('status')) : '')
  }, /*#__PURE__*/React.createElement(_Button, {
    onClick: handleTestConnection,
    className: "".concat(prefixCls, "-test-btn"),
    disabled: record && record.get('status') === 'operating'
  }, "\u6D4B\u8BD5\u8FDE\u63A5"), getContent());
});
export default TestConnect;