import "choerodon-ui/lib/icon/style";
import _Icon from "choerodon-ui/lib/icon";
import "choerodon-ui/lib/tooltip/style";
import _Tooltip from "choerodon-ui/lib/tooltip";
import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import { injectIntl } from 'react-intl';
import "./index.less";
/**
 * 分为六种内容：部署中、处理中、部署失败、正常版本、版本升级失败和版本升级
 * - 部署中和版本升级，根据 appVersion 空和非空
 * - 部署失败和版本升级失败，根据 appVersion 空和非空
 * - appVersionId 和 commandVersionId 相同时，均为正常显示
 */

function UploadIcon(props) {
  var ICON_UPLOADING = /*#__PURE__*/React.createElement("div", {
    className: "c7n-instance-upload"
  }, /*#__PURE__*/React.createElement("svg", {
    width: "16",
    height: "14"
  }, /*#__PURE__*/React.createElement("path", {
    className: "c7n-instance-upload-arrow",
    d: " M 5  11 L 11 11 L 11 6.5 L 15 6.5 L 8  1 L 1  6.5 L 5  6.5 Z "
  }), /*#__PURE__*/React.createElement("line", {
    className: "c7n-instance-upload-line1",
    x1: "3",
    y1: "10",
    x2: "13",
    y2: "10"
  }), /*#__PURE__*/React.createElement("line", {
    className: "c7n-instance-upload-line2",
    x1: "3",
    y1: "12.5",
    x2: "13",
    y2: "12.5"
  })));
  var formatMessage = props.intl.formatMessage,
      dataSource = props.dataSource;
  var appVersion = dataSource.appVersion,
      appVersionId = dataSource.appVersionId,
      commandVersionId = dataSource.commandVersionId,
      commandType = dataSource.commandType,
      commandVersion = dataSource.commandVersion,
      status = dataSource.status;
  var CONTENT_DOM = {
    deploying: function deploying(av, cv) {
      return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("span", {
        className: "c7n-instance-upload-text"
      }, av || formatMessage({
        id: 'ist.deploy.upload'
      })), cv ? /*#__PURE__*/React.createElement(_Tooltip, {
        title: formatMessage({
          id: "ist.version.".concat(av ? 'upload' : 'deploy')
        }, {
          text: cv
        })
      }, ICON_UPLOADING) : null);
    },
    operating: function operating(av, cv) {
      return /*#__PURE__*/React.createElement("span", {
        className: "c7n-instance-upload-text"
      }, formatMessage({
        id: 'ist.deploy.delete'
      }));
    },
    failed: function failed(av, cv) {
      return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("span", {
        className: "c7n-instance-upload-text"
      }, av || formatMessage({
        id: 'ist.deploy.failed'
      })), cv ? /*#__PURE__*/React.createElement(_Tooltip, {
        title: formatMessage({
          id: "ist.version.".concat(av ? '' : 'deploy.', "failed")
        }, {
          text: cv
        })
      }, /*#__PURE__*/React.createElement(_Icon, {
        type: "error",
        className: "c7n-instance-upload-failed"
      })) : null);
    },
    normal: function normal(av, cv) {
      return /*#__PURE__*/React.createElement("span", {
        className: "c7n-instance-upload-text"
      }, cv || av);
    }
  };
  var type = 'normal';

  if (!appVersionId) {
    switch (status) {
      case 'operating':
        type = 'deploying';

        if (commandType === 'delete') {
          type = 'operating';
        }

        break;

      case 'failed':
        type = 'failed';
        break;

      default:
        type = 'normal';
    }
  } else if (commandVersionId === appVersionId) {
    type = 'normal';
  } else if (commandType === 'update') {
    if (status === 'operating') {
      type = 'deploying';
    } else {
      type = 'failed';
    }
  }

  return CONTENT_DOM[type](appVersion, commandVersion);
}

UploadIcon.defaultProps = {
  dataSource: {}
};
UploadIcon.propTypes = {
  dataSource: PropTypes.object.isRequired
};
export default injectIntl(UploadIcon);