import React, { Fragment } from 'react';
import "./index.less";
var UPDATE_FAILED = 'failed.upgrade';
var DEPLOY_FAILED = 'failed.deploy';
export default function DetailsModal(_ref) {
  var intlPrefix = _ref.intlPrefix,
      record = _ref.record,
      prefixCls = _ref.prefixCls,
      formatMessage = _ref.formatMessage;

  function getStatusCode() {
    var status;

    if (record) {
      status = record.get('status');

      if (!status) {
        return '';
      } else if (status === 'failed') {
        var appServiceVersionId = record.get('appServiceVersionId');
        var commandVersionId = record.get('commandVersionId');

        if (appServiceVersionId) {
          return UPDATE_FAILED;
        } else if (appServiceVersionId !== commandVersionId) {
          return DEPLOY_FAILED;
        }
      } else {
        return status;
      }
    }

    return '';
  }

  function getStatus() {
    var statusCode = getStatusCode();
    var commandVersion = record.get('commandVersion');

    if (statusCode === UPDATE_FAILED) {
      return formatMessage({
        id: "".concat(intlPrefix, ".instance.status.failed.upgrade.describe")
      }, {
        version: commandVersion
      });
    } else if (statusCode === DEPLOY_FAILED) {
      return formatMessage({
        id: "".concat(intlPrefix, ".instance.status.failed.deploy.describe")
      }, {
        version: commandVersion
      });
    } else {
      return statusCode && /*#__PURE__*/React.createElement("span", {
        className: "".concat(prefixCls, "-modals-value ").concat(prefixCls, "-modals-cell")
      }, formatMessage({
        id: "".concat(intlPrefix, ".instance.status.").concat(statusCode)
      }));
    }
  }

  function getVersion() {
    var statusCode = getStatusCode();
    if (!statusCode) return '';
    var versionName = record.get('versionName');
    return versionName || '-';
  }

  return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefixCls, "-modals-row")
  }, /*#__PURE__*/React.createElement("span", {
    className: "".concat(prefixCls, "-modals-key ").concat(prefixCls, "-modals-cell")
  }, formatMessage({
    id: "".concat(intlPrefix, ".instance.status")
  })), getStatus()), /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefixCls, "-modals-row")
  }, /*#__PURE__*/React.createElement("span", {
    className: "".concat(prefixCls, "-modals-key ").concat(prefixCls, "-modals-cell")
  }, formatMessage({
    id: 'version'
  })), /*#__PURE__*/React.createElement("span", {
    className: "".concat(prefixCls, "-modals-value ").concat(prefixCls, "-modals-cell")
  }, getVersion())));
}