import "choerodon-ui/pro/lib/spin/style";
import _Spin from "choerodon-ui/pro/lib/spin";
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 React from 'react';
import { injectIntl } from 'react-intl';
import classnames from 'classnames';
import MouseOverWrapper from "../MouseOverWrapper";
import "./StatusIcon.less";
import ClickText from "../click-text";

function StatusIcon(props) {
  var status = props.status,
      error = props.error,
      name = props.name,
      formatMessage = props.intl.formatMessage,
      width = props.width,
      handleAtagClick = props.handleAtagClick,
      clickAble = props.clickAble,
      onClick = props.onClick,
      record = props.record,
      permissionCode = props.permissionCode,
      className = props.className;
  var statusDom = null;
  var statusClass = classnames(className, {
    'c7n-status-deleted': status === 'deleted',
    'c7n-status-unset': handleAtagClick
  });

  switch (status) {
    case 'failed':
      {
        var msg = error ? ": ".concat(error) : '';
        statusDom = /*#__PURE__*/React.createElement(_Tooltip, {
          title: "failed ".concat(msg)
        }, /*#__PURE__*/React.createElement(_Icon, {
          type: "error",
          className: "c7n-status-failed"
        }));
        break;
      }

    case 'operating':
      statusDom = /*#__PURE__*/React.createElement(_Tooltip, {
        title: formatMessage({
          id: 'ist_operating'
        })
      }, /*#__PURE__*/React.createElement(_Spin, {
        className: "c7ncd-status-progress-span" // type="loading"
        // size="small"
        // width={15}
        ,
        spinning: true
      }));
      break;

    case 'deleted':
      statusDom = /*#__PURE__*/React.createElement(_Tooltip, {
        title: formatMessage({
          id: 'deleted'
        })
      }, /*#__PURE__*/React.createElement(_Icon, {
        type: "cancel",
        className: "c7n-status-deleted"
      }));
      break;

    default:
  }

  var handleClick = function handleClick(e) {
    e.preventDefault();
    handleAtagClick(name, e);
  };

  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(MouseOverWrapper, {
    text: name,
    width: width || 0.15,
    className: "c7n-status-text"
  }, clickAble ? /*#__PURE__*/React.createElement(ClickText, {
    value: name,
    clickAble: clickAble,
    onClick: onClick,
    record: record,
    permissionCode: permissionCode
  }) : /*#__PURE__*/React.createElement("span", {
    className: statusClass
  }, name)), statusDom);
}

StatusIcon.defaultProps = {
  clickAble: false
};
export default injectIntl(StatusIcon);