import "choerodon-ui/lib/spin/style";
import _Spin from "@hzero-front-ui/c7n-ui/lib/Spin";
import "choerodon-ui/lib/input/style";
import _Input from "choerodon-ui/lib/input";
import "choerodon-ui/lib/tooltip/style";
import _Tooltip from "choerodon-ui/lib/tooltip";
import "choerodon-ui/lib/button/style";
import _Button from "choerodon-ui/lib/button";
import "choerodon-ui/lib/icon/style";
import _Icon from "choerodon-ui/lib/icon";
import "choerodon-ui/lib/radio/style";
import _Radio from "choerodon-ui/lib/radio";
import "choerodon-ui/lib/select/style";
import _Select from "choerodon-ui/lib/select";
import "choerodon-ui/lib/form/style";
import _Form from "choerodon-ui/lib/form";
import "choerodon-ui/lib/modal/style";
import _Modal from "choerodon-ui/lib/modal";

var _dec, _dec2, _class;

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

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, { Component, Fragment } from 'react';
import { observer, inject } from 'mobx-react';
import { Link } from 'react-router-dom';
import { injectIntl, FormattedMessage } from 'react-intl';
import { Content, Choerodon } from '@choerodon/boot';
import classnames from 'classnames';
import _ from 'lodash';
import uuidv1 from 'uuid/v1';
import PipelineCreateStore from "../../stores/PipelineCreateStore";
import Tips from "../../../../components/Tips";
import YamlEditor from "../../../../components/yamlEditor";
import { TASK_TYPE_MANUAL, TASK_TYPE_DEPLOY, STAGE_FLOW_AUTO, MODE_TYPE_NEW, MODE_TYPE_UPDATE, VERSION_TYPE, AUDIT_MODE_ORSING, AUDIT_MODE_SING, TASK_PARALLEL, TRIGGER_TYPE_AUTO } from "../Constants";
import StatusDot from "../../../../components/status-dot";
import "./TaskCreate.less";
var Sidebar = _Modal.Sidebar;
var FormItem = _Form.Item;
var Option = _Select.Option;
var RadioGroup = _Radio.Group;
var formItemLayout = {
  labelCol: {
    xs: {
      span: 24
    },
    sm: {
      span: 100
    }
  },
  wrapperCol: {
    xs: {
      span: 24
    },
    sm: {
      span: 26
    }
  }
};
/**
 * 0 或签 | 1 会签
 * @type {{orSign: number, sign: number}}
 */

var auditMode = {
  sign: 1,
  orSign: 0
};
var TaskCreate = (_dec = _Form.create({}), _dec2 = inject('AppState'), _dec(_class = injectIntl(_class = _dec2(_class = observer(_class = /*#__PURE__*/function (_Component) {
  _inherits(TaskCreate, _Component);

  var _super = _createSuper(TaskCreate);

  function TaskCreate() {
    var _this;

    _classCallCheck(this, TaskCreate);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _super.call.apply(_super, [this].concat(args));
    _this.state = {
      submitting: false,
      taskType: TASK_TYPE_DEPLOY,
      mode: MODE_TYPE_NEW,
      envId: null,
      appId: null,
      isHead: false,
      configValue: null,
      configError: false,
      value: '',
      configData: null,
      showEditValue: false,
      editLoading: false,
      initIstId: undefined,
      initIstName: undefined
    };
    _this.checkIstName = _.debounce(function (rule, value, callback) {
      var _this$props = _this.props,
          formatMessage = _this$props.intl.formatMessage,
          isModifiedField = _this$props.form.isModifiedField,
          id = _this$props.AppState.currentMenuType.id;
      var p = /^[a-z]([-a-z0-9]*[a-z0-9])?$/;

      if (!value || !isModifiedField('instanceName')) {
        callback();
        return;
      }

      var envId = _this.state.envId;

      if (p.test(value)) {
        PipelineCreateStore.checkInstanceName(id, value, envId).then(function (data) {
          if (data && data.failed || !data) {
            callback(formatMessage({
              id: 'checkNameExist'
            }));
          } else {
            callback();
          }
        })["catch"](function (error) {
          callback(formatMessage({
            id: 'checkNameFail'
          }));
        });
      } else {
        callback(formatMessage({
          id: 'formatError'
        }));
      }
    }, 600);

    _this.handleSubmit = function (e) {
      e.preventDefault();
      var _this$props2 = _this.props,
          validateFields = _this$props2.form.validateFields,
          onClose = _this$props2.onClose,
          stageId = _this$props2.stageId,
          taskId = _this$props2.id;
      validateFields(function (err, _ref) {
        var type = _ref.type,
            name = _ref.name,
            appServiceId = _ref.appServiceId,
            triggerVersion = _ref.triggerVersion,
            envId = _ref.envId,
            instanceName = _ref.instanceName,
            valueId = _ref.valueId,
            instanceId = _ref.instanceId,
            users = _ref.users,
            isCountersigned = _ref.isCountersigned;

        if (!err) {
          var isHead = _this.state.isHead;
          var pipelineAppServiceDeployVO = null;

          if (type === TASK_TYPE_DEPLOY) {
            var istName = instanceName;

            if (instanceId) {
              istName = _.find(PipelineCreateStore.getInstance, ['id', instanceId]).code;
            }

            pipelineAppServiceDeployVO = {
              appServiceId: appServiceId,
              triggerVersion: triggerVersion,
              envId: envId,
              instanceId: instanceId,
              instanceName: istName || null,
              valueId: valueId
            };
          }

          var taskUserRels = type === TASK_TYPE_MANUAL ? _.map(users, function (item) {
            return item;
          }) : null;
          var data = {
            type: type,
            name: name,
            pipelineAppServiceDeployVO: pipelineAppServiceDeployVO,
            taskUserRels: taskUserRels,
            isCountersigned: auditMode[isCountersigned || 'orSign'],
            isHead: isHead
          };

          if (!taskId) {
            var index = (PipelineCreateStore.getTaskIndex[stageId] || 0) + 1;
            PipelineCreateStore.setTaskIndex(stageId, index);
            PipelineCreateStore.setTaskList(stageId, _objectSpread(_objectSpread({}, data), {}, {
              index: index
            }));
          } else {
            PipelineCreateStore.updateTaskList(stageId, taskId, _objectSpread(_objectSpread({}, data), {}, {
              index: taskId
            }));
          }

          if (!PipelineCreateStore.getCanSubmit) {
            PipelineCreateStore.checkCanSubmit();
          }

          onClose();
        }
      });
    };

    _this.changeTaskType = function (value) {
      if (value === TASK_TYPE_DEPLOY) {
        _this.loadingOptionsData();
      }

      _this.props.form.setFields({
        type: {
          value: value,
          errors: null
        }
      });

      _this.setState({
        taskType: value
      });
    };

    _this.handleChangeMode = function (e) {
      var appId = _this.state.appId;
      var mode = e.target.value;
      var app = appId ? _.find(PipelineCreateStore.getAppData, ['id', appId]) : null;
      var initIstName = app ? "".concat(app.code, "-").concat(uuidv1().substring(0, 5)) : uuidv1().substring(0, 30);

      _this.setState({
        mode: mode,
        initIstName: initIstName
      });
    };

    _this.handleChangeEnv = function (id) {
      var appId = _this.state.appId;

      _this.setState({
        envId: id
      }, function () {
        return _this.changeAppOrEnv();
      });

      appId && _this.loadInstanceData(id, appId);
      appId && _this.loadConfigValue(id, appId);
    };

    _this.handleChangeApp = function (id) {
      var envId = _this.state.envId;

      _this.setState({
        appId: id
      }, function () {
        return _this.changeAppOrEnv();
      });

      envId && _this.loadInstanceData(envId, id);
      envId && _this.loadConfigValue(envId, id);
    };

    _this.changeAppOrEnv = function () {
      var _this$props3 = _this.props,
          stageId = _this$props3.stageId,
          taskId = _this$props3.id,
          _this$props3$form = _this$props3.form,
          setFieldsValue = _this$props3$form.setFieldsValue,
          getFieldsValue = _this$props3$form.getFieldsValue;
      var _this$state = _this.state,
          selectApp = _this$state.appId,
          selectEnv = _this$state.envId;
      var getTaskList = PipelineCreateStore.getTaskList;

      var _ref2 = _.find(getTaskList[stageId], ['index', taskId]) || {},
          pipelineAppServiceDeployVO = _ref2.pipelineAppServiceDeployVO;

      var _ref3 = pipelineAppServiceDeployVO || {},
          appServiceId = _ref3.appServiceId,
          envId = _ref3.envId,
          instanceId = _ref3.instanceId,
          valueId = _ref3.valueId;

      var _ref4 = _.find(PipelineCreateStore.getAppData, ['id', selectApp]) || {},
          code = _ref4.code;

      var initIstName = code ? "".concat(code, "-").concat(uuidv1().substring(0, 5)) : uuidv1().substring(0, 30);

      if (selectApp === appServiceId && selectEnv === envId) {
        if (instanceId) {
          _this.setState({
            initIstId: instanceId,
            mode: MODE_TYPE_UPDATE
          });
        } else {
          setFieldsValue({
            instanceName: initIstName
          });

          _this.setState({
            mode: MODE_TYPE_NEW
          });
        }

        setFieldsValue({
          valueId: valueId
        });

        _this.handleChangeConfig(valueId);
      } else {
        _this.setState({
          value: '',
          initIstId: undefined,
          mode: MODE_TYPE_NEW,
          initIstName: initIstName
        });

        if (getFieldsValue(['instanceName'])) {
          setFieldsValue({
            instanceName: initIstName
          });
        }

        _this.clearConfigFiled();
      }
    };

    _this.handleChangeConfig = /*#__PURE__*/function () {
      var _ref5 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(value) {
        var id, configValue;
        return regeneratorRuntime.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                id = _this.props.AppState.currentMenuType.id;
                _context.next = 3;
                return PipelineCreateStore.loadValue(id, value);

              case 3:
                configValue = _context.sent;

                if (configValue && configValue.value) {
                  _this.setState({
                    value: configValue.value,
                    configData: configValue
                  });
                } else {
                  _this.setState({
                    value: '',
                    configData: null
                  });
                }

              case 5:
              case "end":
                return _context.stop();
            }
          }
        }, _callee);
      }));

      return function (_x) {
        return _ref5.apply(this, arguments);
      };
    }();

    _this.handleChangeValue = function (value) {
      _this.setState({
        configValue: value
      });
    };

    _this.handleEnableNext = function (flag) {
      _this.setState({
        configError: flag
      });
    };

    _this.renderYamlEditor = function () {
      var value = _this.state.value;
      var formatMessage = _this.props.intl.formatMessage;
      return value && /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
        className: "c7n-pipeline-config-value"
      }, /*#__PURE__*/React.createElement(_Icon, {
        className: "c7n-config-tip-icon",
        type: "error"
      }), /*#__PURE__*/React.createElement("span", {
        className: "c7n-config-tip-text"
      }, formatMessage({
        id: 'pipeline.config.value.tips'
      })), /*#__PURE__*/React.createElement(_Button, {
        icon: "mode_edit",
        type: "primary",
        onClick: _this.openEditValue
      }, /*#__PURE__*/React.createElement(FormattedMessage, {
        id: "pipeline.config.value.edit"
      }))), /*#__PURE__*/React.createElement(YamlEditor, {
        readOnly: true,
        value: value
      }));
    };

    _this.openEditValue = function () {
      _this.setState({
        showEditValue: true
      });
    };

    _this.closeEditValue = function () {
      _this.setState({
        showEditValue: false,
        configValue: null,
        configError: false
      });
    };

    _this.handleEditValue = function () {
      var _this$state2 = _this.state,
          configValue = _this$state2.configValue,
          configData = _this$state2.configData;
      var id = _this.props.AppState.currentMenuType.id;

      _this.setState({
        editLoading: true
      });

      configData.value = configValue;
      PipelineCreateStore.editConfigValue(id, configData).then(function (data) {
        _this.setState({
          editLoading: false
        });

        if (data && data.failed) {
          Choerodon.prompt(data.message);
        } else {
          _this.handleChangeConfig(configData.id);

          _this.closeEditValue();
        }
      })["catch"](function (err) {
        _this.setState({
          editLoading: false
        });

        Choerodon.handleResponseError(err);
      });
    };

    _this.loadMoreWrap = function (e) {
      e.stopPropagation();
      var projectId = _this.props.AppState.currentMenuType.id;
      var getPageInfo = PipelineCreateStore.getPageInfo;

      var _ref6 = getPageInfo || {},
          pageNum = _ref6.pageNum;

      PipelineCreateStore.loadUser(projectId, pageNum + 1);
    };

    _this.handleSearch = _.debounce(function (value) {
      var projectId = _this.props.AppState.currentMenuType.id;
      PipelineCreateStore.loadUser(projectId, 1, value);
    }, 700);

    _this.handleUserChange = function (value) {
      var setFieldsValue = _this.props.form.setFieldsValue;

      if (_.includes(value, 'pipeline-create-user-select-more-key')) {
        var realValue = _.remove(value, function (item) {
          return item === 'pipeline-create-user-select-more-key';
        });

        setFieldsValue({
          users: realValue
        });
      }
    };

    return _this;
  }

  _createClass(TaskCreate, [{
    key: "componentDidMount",
    value: function componentDidMount() {
      var _this2 = this;

      var _this$props4 = this.props,
          stageId = _this$props4.stageId,
          taskId = _this$props4.id,
          isHead = _this$props4.isHead,
          formatMessage = _this$props4.intl.formatMessage,
          setFields = _this$props4.form.setFields;
      var getTaskList = PipelineCreateStore.getTaskList,
          getStageList = PipelineCreateStore.getStageList,
          getUser = PipelineCreateStore.getUser;

      var _ref7 = _.find(getTaskList[stageId], ['index', taskId]) || {},
          pipelineAppServiceDeployVO = _ref7.pipelineAppServiceDeployVO,
          type = _ref7.type,
          taskUserRels = _ref7.taskUserRels;

      var _ref8 = pipelineAppServiceDeployVO || {},
          appServiceId = _ref8.appServiceId,
          envId = _ref8.envId,
          instanceId = _ref8.instanceId,
          valueId = _ref8.valueId,
          instanceName = _ref8.instanceName;

      this.setState({
        initIstName: instanceName
      });

      if (instanceId) {
        this.setState({
          // initValue 可以接受undefined表示无初始值，但是不能为null
          initIstId: instanceId
        });
      }

      if (!(type === TASK_TYPE_MANUAL)) {
        this.loadingOptionsData();
      }

      if (appServiceId && envId) {
        this.setState({
          envId: envId,
          appId: appServiceId
        });
        this.loadInstanceData(envId, appServiceId);
        this.loadConfigValue(envId, appServiceId);
      }

      valueId && this.handleChangeConfig(valueId);
      /**
       * 第一个阶段的第一个任务
       * 针对自动触发时，首个阶段的首个任务必须是部署任务
       */

      var isHeadStage = (_.head(getStageList) || {}).tempId === stageId;
      var isHeadTask = _.isEmpty(getTaskList) || (_.head(getTaskList[stageId]) || {}).index === taskId;

      if (isHeadStage && isHeadTask) {
        this.setState({
          isHead: true
        });
      }

      var isErrorType = PipelineCreateStore.getTrigger === TRIGGER_TYPE_AUTO && (taskId || taskId === 0) && isHead && type === TASK_TYPE_MANUAL;

      if (isErrorType) {
        setFields({
          type: {
            value: TASK_TYPE_MANUAL,
            errors: [new Error(formatMessage({
              id: 'pipeline.task.type.error'
            }))]
          }
        });
      } // 使用这个trick，是因为当模态框还没有渲染出来，表单项就已经注册，之后就无法删除


      setTimeout(function () {
        _this2.setState({
          taskType: type || TASK_TYPE_DEPLOY,
          mode: instanceId ? MODE_TYPE_UPDATE : MODE_TYPE_NEW
        });
      });
    }
  }, {
    key: "componentWillUnmount",
    value: function componentWillUnmount() {
      PipelineCreateStore.setAppDate([]);
      PipelineCreateStore.setEnvData([]);
      PipelineCreateStore.setInstances([]);
      PipelineCreateStore.setConfigList('');
    }
  }, {
    key: "clearConfigFiled",
    value:
    /**
     * 清空部属配置选择器的已选项
     */
    function clearConfigFiled() {
      this.props.form.setFieldsValue({
        valueId: ''
      });
    }
  }, {
    key: "loadingOptionsData",
    value: function loadingOptionsData() {
      var id = this.props.AppState.currentMenuType.id;
      PipelineCreateStore.loadEnvData(id);
      PipelineCreateStore.loadAppData(id);
    }
  }, {
    key: "loadInstanceData",
    value: function loadInstanceData(envId, appId) {
      var id = this.props.AppState.currentMenuType.id;
      PipelineCreateStore.loadInstances(id, envId, appId);
    }
    /**
     * 加载部署配置信息
     * @param envId
     * @param appId
     */

  }, {
    key: "loadConfigValue",
    value: function loadConfigValue(envId, appId) {
      var id = this.props.AppState.currentMenuType.id;
      PipelineCreateStore.loadConfig(id, envId, appId);
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props5 = this.props,
          visible = _this$props5.visible,
          onClose = _this$props5.onClose,
          _this$props5$form = _this$props5.form,
          getFieldDecorator = _this$props5$form.getFieldDecorator,
          getFieldValue = _this$props5$form.getFieldValue,
          formatMessage = _this$props5.intl.formatMessage,
          stageId = _this$props5.stageId,
          stageName = _this$props5.stageName,
          taskId = _this$props5.id,
          _this$props5$AppState = _this$props5.AppState.currentMenuType,
          projectId = _this$props5$AppState.id,
          menuType = _this$props5$AppState.type,
          projectName = _this$props5$AppState.name,
          organizationId = _this$props5$AppState.organizationId;
      var getEnvData = PipelineCreateStore.getEnvData,
          getAppData = PipelineCreateStore.getAppData,
          getLoading = PipelineCreateStore.getLoading,
          getInstance = PipelineCreateStore.getInstance,
          getTaskList = PipelineCreateStore.getTaskList,
          getConfigList = PipelineCreateStore.getConfigList,
          getUser = PipelineCreateStore.getUser,
          getTaskSettings = PipelineCreateStore.getTaskSettings,
          getTrigger = PipelineCreateStore.getTrigger,
          getPageInfo = PipelineCreateStore.getPageInfo;
      var _this$state3 = this.state,
          submitting = _this$state3.submitting,
          taskType = _this$state3.taskType,
          mode = _this$state3.mode,
          isHead = _this$state3.isHead,
          appId = _this$state3.appId,
          selectEnvId = _this$state3.envId,
          showEditValue = _this$state3.showEditValue,
          editLoading = _this$state3.editLoading,
          value = _this$state3.value,
          configData = _this$state3.configData,
          configError = _this$state3.configError,
          initIstId = _this$state3.initIstId,
          initIstName = _this$state3.initIstName;

      var _ref9 = _.find(getTaskList[stageId], ['index', taskId]) || {},
          pipelineAppServiceDeployVO = _ref9.pipelineAppServiceDeployVO,
          type = _ref9.type,
          taskName = _ref9.name,
          isCountersigned = _ref9.isCountersigned,
          taskUserRels = _ref9.taskUserRels;

      var _ref10 = pipelineAppServiceDeployVO || {},
          instanceId = _ref10.instanceId,
          appServiceId = _ref10.appServiceId,
          triggerVersion = _ref10.triggerVersion,
          envId = _ref10.envId,
          valueId = _ref10.valueId;
      /** ********* 生成选择器的选项 ********* */


      var appOptions = _.map(getAppData, function (_ref11) {
        var id = _ref11.id,
            name = _ref11.name;
        return /*#__PURE__*/React.createElement(Option, {
          key: id,
          value: id
        }, name);
      });

      var envOptions = _.map(getEnvData, function (_ref12) {
        var id = _ref12.id,
            connect = _ref12.connect,
            permission = _ref12.permission,
            name = _ref12.name,
            synchro = _ref12.synchro,
            active = _ref12.active;
        return /*#__PURE__*/React.createElement(Option, {
          key: id,
          value: id,
          disabled: !connect || !synchro || !permission,
          title: name
        }, /*#__PURE__*/React.createElement(StatusDot, {
          connect: connect,
          synchronize: synchro,
          active: active,
          size: "small"
        }), /*#__PURE__*/React.createElement("span", {
          className: "c7ncd-pipeline-create-env"
        }, name));
      });

      var instanceOptions = _.map(getInstance, function (_ref13) {
        var id = _ref13.id,
            code = _ref13.code;
        return /*#__PURE__*/React.createElement(Option, {
          value: id,
          key: id
        }, code);
      });

      var userOptions = _.map(getUser, function (_ref14) {
        var id = _ref14.id,
            realName = _ref14.realName,
            loginName = _ref14.loginName;
        return /*#__PURE__*/React.createElement(Option, {
          key: id,
          value: String(id)
        }, /*#__PURE__*/React.createElement(_Tooltip, {
          title: loginName
        }, realName || loginName));
      });

      if (getPageInfo && getPageInfo.hasNextPage) {
        userOptions.push( /*#__PURE__*/React.createElement(Option, {
          key: "pipeline-create-user-select-more-key",
          className: "c7n-load-more-wrap"
        }, /*#__PURE__*/React.createElement("div", {
          className: "c7n-option-popover",
          onClick: this.loadMoreWrap
        }, /*#__PURE__*/React.createElement("span", {
          className: "c7n-option-span"
        }, formatMessage({
          id: 'loadMore'
        })))));
      }

      var configOptions = _.map(getConfigList, function (_ref15) {
        var id = _ref15.id,
            name = _ref15.name;
        return /*#__PURE__*/React.createElement(Option, {
          key: id,
          value: id
        }, name);
      });
      /** ********** end ************** */


      var initUsers = _.map(taskUserRels, function (item) {
        return String(item);
      });

      var initSign;

      if (typeof isCountersigned === 'number') {
        initSign = isCountersigned ? AUDIT_MODE_SING : AUDIT_MODE_ORSING;
      }
      /**
       * 不可以选择人工卡点情况：
       * 1. 阶段任务为并行执行
       * 2. 流水线触发方式为自动触发时，第一个阶段的第一个任务
       * @type {*|boolean}
       */


      var disableChooseManual = getTaskSettings[stageId] && getTaskSettings[stageId] === String(TASK_PARALLEL) || getTrigger === STAGE_FLOW_AUTO && isHead;
      var isEdit = taskId || taskId === 0;
      var deployFields = taskType === TASK_TYPE_DEPLOY ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        className: "c7n-select_512"
      }, formItemLayout), getFieldDecorator('appServiceId', {
        rules: [{
          required: true,
          message: formatMessage({
            id: 'required'
          })
        }],
        initialValue: appOptions.length ? appServiceId : undefined
      })( /*#__PURE__*/React.createElement(_Select, {
        label: formatMessage({
          id: 'appService'
        }),
        optionFilterProp: "children",
        onChange: this.handleChangeApp,
        loading: getLoading.app,
        filter: true,
        filterOption: function filterOption(input, option) {
          return option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0;
        }
      }, appOptions))), /*#__PURE__*/React.createElement("div", {
        className: "c7ncd-sidebar-select pipeline-type-tips"
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        className: "c7ncd-select_has-tips"
      }, formItemLayout), getFieldDecorator('triggerVersion', {
        initialValue: triggerVersion ? triggerVersion.slice() : undefined
      })( /*#__PURE__*/React.createElement(_Select, {
        mode: "tags",
        label: formatMessage({
          id: 'pipeline.task.version'
        }),
        allowClear: true
      }, _.map(VERSION_TYPE, function (item) {
        return /*#__PURE__*/React.createElement(Option, {
          key: item,
          value: item
        }, item);
      })))), /*#__PURE__*/React.createElement(Tips, {
        type: "form",
        data: "pipeline.task.version.tips"
      })), /*#__PURE__*/React.createElement(FormItem, Object.assign({
        className: "c7n-select_512"
      }, formItemLayout), getFieldDecorator('envId', {
        rules: [{
          required: true,
          message: formatMessage({
            id: 'required'
          })
        }],
        initialValue: envOptions.length ? envId : undefined
      })( /*#__PURE__*/React.createElement(_Select, {
        label: formatMessage({
          id: 'envName'
        }),
        optionFilterProp: "children",
        onChange: this.handleChangeEnv,
        loading: getLoading.env,
        filter: true,
        filterOption: function filterOption(input, option) {
          return option.props.children[1].toLowerCase().indexOf(input.toLowerCase()) >= 0;
        }
      }, envOptions))), /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
        className: "c7n-pipeline-config"
      }, /*#__PURE__*/React.createElement(Tips, {
        type: "title",
        data: "pipeline.deploy.mode"
      })), /*#__PURE__*/React.createElement(RadioGroup, {
        onChange: this.handleChangeMode,
        value: mode,
        className: "c7n-pipeline-radio"
      }, /*#__PURE__*/React.createElement(_Radio, {
        disabled: instanceId && selectEnvId === envId && appId === appServiceId,
        value: MODE_TYPE_NEW
      }, /*#__PURE__*/React.createElement(FormattedMessage, {
        id: "pipeline.task.instance.create"
      })), /*#__PURE__*/React.createElement(_Radio, {
        disabled: !(getInstance && getInstance.length),
        value: MODE_TYPE_UPDATE
      }, /*#__PURE__*/React.createElement(FormattedMessage, {
        id: "pipeline.task.instance.update"
      }), /*#__PURE__*/React.createElement(_Icon, {
        className: "c7n-pipeline-replace-tip-icon",
        type: "error"
      }), /*#__PURE__*/React.createElement("span", {
        className: "c7n-pipeline-replace-tip-text"
      }, formatMessage({
        id: 'pipeline.task.instance.tips'
      }))))), mode === MODE_TYPE_NEW && /*#__PURE__*/React.createElement(FormItem, Object.assign({
        className: "c7n-select_512"
      }, formItemLayout), getFieldDecorator('instanceName', {
        rules: [{
          required: true,
          message: formatMessage({
            id: 'required'
          })
        }, {
          validator: this.checkIstName
        }],
        initialValue: initIstName
      })( /*#__PURE__*/React.createElement(_Input, {
        disabled: mode !== MODE_TYPE_NEW,
        maxLength: 30,
        label: formatMessage({
          id: 'pipeline.task.instance'
        })
      }))), mode === MODE_TYPE_UPDATE && /*#__PURE__*/React.createElement(FormItem, Object.assign({
        className: "c7n-select_512"
      }, formItemLayout), getFieldDecorator('instanceId', {
        rules: [{
          required: true,
          message: formatMessage({
            id: 'required'
          })
        }],
        initialValue: instanceOptions.length ? initIstId : undefined
      })( /*#__PURE__*/React.createElement(_Select, {
        filter: true,
        optionFilterProp: "children",
        label: formatMessage({
          id: 'pipeline.task.instance.replace'
        }),
        filterOption: function filterOption(input, option) {
          return option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0;
        }
      }, instanceOptions))), /*#__PURE__*/React.createElement("div", {
        className: "c7n-pipeline-config"
      }, /*#__PURE__*/React.createElement(Tips, {
        type: "title",
        data: "pipeline.task.config.title"
      })), /*#__PURE__*/React.createElement(FormItem, Object.assign({
        className: "c7n-select_512"
      }, formItemLayout), getFieldDecorator('valueId', {
        rules: [{
          required: true,
          message: formatMessage({
            id: 'required'
          })
        }],
        initialValue: configOptions.length ? valueId : undefined
      })( /*#__PURE__*/React.createElement(_Select, {
        disabled: !(getFieldValue('appServiceId') && getFieldValue('envId')),
        label: formatMessage({
          id: 'pipeline.task.config'
        }),
        optionFilterProp: "children",
        onChange: this.handleChangeConfig,
        loading: getLoading.config,
        filter: true,
        filterOption: function filterOption(input, option) {
          return option.props.children.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0;
        },
        dropdownClassName: "c7n-pipeline-config-select"
      }, configOptions)))) : null;
      var manualFields = taskType === TASK_TYPE_MANUAL ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        className: "c7n-select_512"
      }, formItemLayout), getFieldDecorator('users', {
        rules: [{
          required: true,
          message: formatMessage({
            id: 'required'
          })
        }],
        initialValue: userOptions.length ? initUsers : undefined
      })( /*#__PURE__*/React.createElement(_Select, {
        filter: true,
        filterOption: false,
        loading: getLoading.user,
        allowClear: true,
        mode: "multiple",
        optionFilterProp: "children",
        className: "c7n-select_512",
        label: /*#__PURE__*/React.createElement(FormattedMessage, {
          id: "pipeline.task.auditor"
        }),
        onSearch: this.handleSearch,
        onChange: this.handleUserChange
      }, userOptions))), getFieldValue('users') && getFieldValue('users').length > 1 && /*#__PURE__*/React.createElement("div", {
        className: "c7ncd-sidebar-select pipeline-type-tips"
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        className: "c7ncd-select_has-tips"
      }, formItemLayout), getFieldDecorator('isCountersigned', {
        rules: [{
          required: true,
          message: formatMessage({
            id: 'required'
          })
        }],
        initialValue: initSign
      })( /*#__PURE__*/React.createElement(_Select, {
        className: "c7n-select_512",
        label: /*#__PURE__*/React.createElement(FormattedMessage, {
          id: "pipeline.task.auditMode"
        }),
        getPopupContainer: function getPopupContainer(triggerNode) {
          return triggerNode.parentNode;
        }
      }, /*#__PURE__*/React.createElement(Option, {
        value: AUDIT_MODE_SING,
        title: formatMessage({
          id: 'pipeline.audit.sign'
        })
      }, formatMessage({
        id: 'pipeline.audit.sign'
      })), /*#__PURE__*/React.createElement(Option, {
        value: AUDIT_MODE_ORSING,
        title: formatMessage({
          id: 'pipeline.audit.orSign'
        })
      }, formatMessage({
        id: 'pipeline.audit.orSign'
      }))))), /*#__PURE__*/React.createElement(Tips, {
        type: "form",
        data: "pipeline.task.auditMode.tips"
      }))) : null;
      return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Sidebar, {
        destroyOnClose: true,
        title: /*#__PURE__*/React.createElement(FormattedMessage, {
          id: "pipeline.task.".concat(isEdit ? 'edit' : 'create', ".head")
        }),
        visible: visible,
        width: 740,
        onOk: this.handleSubmit,
        onCancel: onClose,
        okText: formatMessage({
          id: isEdit ? 'save' : 'add'
        })
      }, /*#__PURE__*/React.createElement(Content, {
        className: "sidebar-content c7n-pipeline-task-create"
      }, /*#__PURE__*/React.createElement(_Form, {
        layout: "vertical"
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        className: "c7n-select_512"
      }, formItemLayout), getFieldDecorator('type', {
        initialValue: type || TASK_TYPE_DEPLOY
      })( /*#__PURE__*/React.createElement(_Select, {
        label: formatMessage({
          id: 'pipeline.task.type'
        }),
        getPopupContainer: function getPopupContainer(triggerNode) {
          return triggerNode.parentNode;
        },
        onChange: this.changeTaskType
      }, /*#__PURE__*/React.createElement(Option, {
        value: TASK_TYPE_DEPLOY,
        title: formatMessage({
          id: 'pipeline.mode.auto'
        })
      }, formatMessage({
        id: 'pipeline.mode.auto'
      })), /*#__PURE__*/React.createElement(Option // 并行任务不可以选择人工卡点
      , {
        disabled: disableChooseManual,
        value: TASK_TYPE_MANUAL,
        title: formatMessage({
          id: 'pipeline.mode.manual'
        })
      }, /*#__PURE__*/React.createElement(_Tooltip, {
        title: disableChooseManual ? /*#__PURE__*/React.createElement("div", {
          className: "c7n-pipeline-task-parallel-disabled"
        }, /*#__PURE__*/React.createElement(FormattedMessage, {
          id: "pipeline.task.parallel.disabled-1"
        }), /*#__PURE__*/React.createElement(FormattedMessage, {
          id: "pipeline.task.parallel.disabled-2"
        })) : '',
        placement: "right"
      }, /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement(FormattedMessage, {
        id: "pipeline.mode.manual"
      }))))))), /*#__PURE__*/React.createElement(FormItem, Object.assign({
        className: "c7n-select_512"
      }, formItemLayout), getFieldDecorator('name', {
        rules: [{
          required: true,
          message: formatMessage({
            id: 'required'
          }),
          whitespace: true
        }],
        initialValue: taskName
      })( /*#__PURE__*/React.createElement(_Input, {
        maxLength: 30,
        type: "text",
        label: /*#__PURE__*/React.createElement(FormattedMessage, {
          id: "pipeline.task.name"
        })
      }))), deployFields, manualFields), taskType === TASK_TYPE_DEPLOY && (getLoading.value ? /*#__PURE__*/React.createElement(_Spin, null) : this.renderYamlEditor()))), showEditValue && /*#__PURE__*/React.createElement(_Modal, {
        confirmLoading: editLoading,
        visible: showEditValue,
        title: "".concat(formatMessage({
          id: 'pipeline.config.edit.title'
        }, {
          name: configData.name
        })),
        className: "c7n-config-value-modal",
        closable: false,
        onOk: this.handleEditValue,
        onCancel: this.closeEditValue,
        disableOk: configError,
        okText: formatMessage({
          id: 'edit'
        })
      }, /*#__PURE__*/React.createElement("div", {
        className: "c7n-config-value-modal-content"
      }, /*#__PURE__*/React.createElement(YamlEditor, {
        readOnly: false,
        value: value,
        originValue: value,
        onValueChange: this.handleChangeValue,
        handleEnableNext: this.handleEnableNext
      }))));
    }
  }]);

  return TaskCreate;
}(Component)) || _class) || _class) || _class) || _class);
export { TaskCreate as default };