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

var _class;

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }

function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

/* eslint-disable */
import React, { PureComponent, Fragment } from 'react';
import { withRouter, Link } from 'react-router-dom';
import _ from 'lodash';
import { FormattedMessage, injectIntl } from 'react-intl';
import { TabCode } from '@choerodon/master';
import { STATUS_ICON } from "../Constants";
import StatusIcon from "../../../../../../components/StatusIcon";
import "./index.less";
var Panel = _Collapse.Panel;
var INSTANCE_DELETE_STATUS = 'deleted';

var DetailCard = injectIntl(_class = withRouter(_class = /*#__PURE__*/function (_PureComponent) {
  _inherits(DetailCard, _PureComponent);

  var _super = _createSuper(DetailCard);

  function DetailCard() {
    _classCallCheck(this, DetailCard);

    return _super.apply(this, arguments);
  }

  _createClass(DetailCard, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          isParallel = _this$props.isParallel,
          tasks = _this$props.tasks,
          formatMessage = _this$props.intl.formatMessage,
          _this$props$location = _this$props.location,
          search = _this$props$location.search,
          recordRouteState = _this$props$location.state,
          rId = _this$props.match.params.rId;
      var executeType = ['serial', 'parallel'];
      var mode = ['orSign', 'sign'];

      var task = _.map(tasks, function (_ref) {
        var id = _ref.id,
            name = _ref.name,
            status = _ref.status,
            taskType = _ref.taskType,
            isCountersigned = _ref.isCountersigned,
            userDTOList = _ref.userDTOList,
            appServiceName = _ref.appServiceName,
            envName = _ref.envName,
            version = _ref.version,
            instanceStatus = _ref.instanceStatus,
            envId = _ref.envId,
            appServiceId = _ref.appServiceId,
            instanceId = _ref.instanceId,
            instanceName = _ref.instanceName,
            envPermission = _ref.envPermission;
        var panelHead = /*#__PURE__*/React.createElement("div", {
          className: "c7ncd-pipeline-panel-title"
        }, /*#__PURE__*/React.createElement(_Tooltip, {
          title: name,
          placement: "top"
        }, /*#__PURE__*/React.createElement("span", {
          className: "c7ncd-pipeline-panel-name"
        }, "\u3010", formatMessage({
          id: "pipeline.mode.".concat(taskType)
        }), "\u3011", /*#__PURE__*/React.createElement("span", {
          className: "c7ncd-stage-name-light"
        }, name))), /*#__PURE__*/React.createElement(_Icon, {
          type: STATUS_ICON[status],
          className: "task-status_".concat(status)
        }));
        var auditUsers = [];
        var allAuditUsers = [];

        _.forEach(userDTOList, function (_ref2) {
          var audit = _ref2.audit,
              realName = _ref2.realName,
              loginName = _ref2.loginName;

          if (audit) {
            auditUsers.push(realName || loginName);
          } else {
            allAuditUsers.push(realName || loginName);
          }
        });

        var instanceNode = null;

        if (instanceName) {
          if (instanceStatus && instanceStatus === INSTANCE_DELETE_STATUS || !envPermission) {
            instanceNode = /*#__PURE__*/React.createElement(StatusIcon, {
              name: instanceName,
              status: instanceStatus,
              width: "110px"
            });
          } else {
            instanceNode = /*#__PURE__*/React.createElement(Link, {
              to: {
                pathname: '/devops/resource',
                search: "".concat(search, "&activeKey=").concat(TabCode.get('/devops/resource').tabCodes[0]),
                state: _objectSpread(_objectSpread({}, recordRouteState), {}, {
                  instanceId: instanceId,
                  recordId: rId,
                  appServiceId: appServiceId,
                  envId: envId
                })
              }
            }, /*#__PURE__*/React.createElement(StatusIcon, {
              name: instanceName,
              status: instanceStatus,
              width: "110px"
            }));
          }
        } else {
          instanceNode = formatMessage({
            id: 'null'
          });
        }

        var expandRow = {
          manual: function manual() {
            return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
              className: "c7ncd-pipeline-task"
            }, /*#__PURE__*/React.createElement("span", {
              className: "c7ncd-pipeline-task-label"
            }, formatMessage({
              id: 'pipeline.detail.mode'
            })), formatMessage({
              id: "pipeline.audit.".concat(mode[isCountersigned])
            })), /*#__PURE__*/React.createElement("div", {
              className: "c7ncd-pipeline-task"
            }, /*#__PURE__*/React.createElement("span", {
              className: "c7ncd-pipeline-task-label"
            }, formatMessage({
              id: 'pipeline.detail.users.all'
            })), allAuditUsers.length ? allAuditUsers.join('，') : formatMessage({
              id: 'null'
            })), /*#__PURE__*/React.createElement("div", {
              className: "c7ncd-pipeline-task"
            }, /*#__PURE__*/React.createElement("span", {
              className: "c7ncd-pipeline-task-label"
            }, formatMessage({
              id: 'pipeline.detail.users.audit'
            })), auditUsers.length ? auditUsers.join('，') : formatMessage({
              id: 'null'
            })), /*#__PURE__*/React.createElement("div", {
              className: "c7ncd-pipeline-task"
            }, /*#__PURE__*/React.createElement("span", {
              className: "c7ncd-pipeline-task-label"
            }, formatMessage({
              id: 'pipeline.detail.result'
            })), formatMessage({
              id: "pipeline.result.".concat(status)
            })));
          },
          auto: function auto() {
            return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
              className: "c7ncd-pipeline-task"
            }, /*#__PURE__*/React.createElement("span", {
              className: "c7ncd-pipeline-task-label"
            }, formatMessage({
              id: 'appService'
            }), "\uFF1A"), appServiceName), /*#__PURE__*/React.createElement("div", {
              className: "c7ncd-pipeline-task"
            }, /*#__PURE__*/React.createElement("span", {
              className: "c7ncd-pipeline-task-label"
            }, formatMessage({
              id: 'version'
            }), "\uFF1A"), version || formatMessage({
              id: 'null'
            })), /*#__PURE__*/React.createElement("div", {
              className: "c7ncd-pipeline-task"
            }, /*#__PURE__*/React.createElement("span", {
              className: "c7ncd-pipeline-task-label"
            }, formatMessage({
              id: 'environment'
            }), "\uFF1A"), envName), /*#__PURE__*/React.createElement("div", {
              className: "c7ncd-pipeline-task"
            }, /*#__PURE__*/React.createElement("span", {
              className: "c7ncd-pipeline-task-label c7ncd-pipeline-middle"
            }, formatMessage({
              id: 'pipeline.detail.instance'
            })), instanceNode));
          }
        };
        return /*#__PURE__*/React.createElement(Panel, {
          key: id,
          className: "c7ncd-pipeline-panel",
          header: panelHead
        }, expandRow[taskType] ? expandRow[taskType]() : null);
      });

      return /*#__PURE__*/React.createElement("div", {
        className: "c7ncd-pipeline-card"
      }, /*#__PURE__*/React.createElement("div", {
        className: "c7ncd-task-top"
      }, formatMessage({
        id: 'pipeline.task.settings'
      }), ' ', "-", ' ', /*#__PURE__*/React.createElement(FormattedMessage, {
        id: "pipeline.task.".concat(executeType[isParallel])
      })), /*#__PURE__*/React.createElement("h4", {
        className: "c7ncd-task-header"
      }, formatMessage({
        id: 'pipeline.task.list'
      })), task.length ? /*#__PURE__*/React.createElement(_Collapse, {
        className: "c7ncd-pipeline-collapse",
        bordered: false
      }, task) : /*#__PURE__*/React.createElement("div", {
        className: "c7ncd-pipeline-task-empty"
      }, /*#__PURE__*/React.createElement(FormattedMessage, {
        id: "pipeline.task.empty"
      })));
    }
  }]);

  return DetailCard;
}(PureComponent)) || _class) || _class;

export { DetailCard as default };