import "choerodon-ui/pro/lib/form/style";
import _Form from "@hzero-front-ui/c7n-ui/lib/FormPro";
import "choerodon-ui/pro/lib/text-field/style";
import _TextField from "choerodon-ui/pro/lib/text-field";
import "choerodon-ui/pro/lib/tooltip/style";
import _Tooltip from "choerodon-ui/pro/lib/tooltip";
import "choerodon-ui/pro/lib/select/style";
import _Select from "choerodon-ui/pro/lib/select";
import React, { useEffect } from 'react';
import { observer } from 'mobx-react-lite';
import Tips from "../../../../../../../../components/new-tips";
var Option = _Select.Option;
export default observer(function (_ref) {
  var _addStepDs$current2;

  var addStepDs = _ref.addStepDs,
      curType = _ref.curType,
      optType = _ref.optType,
      appServiceType = _ref.appServiceType,
      appServiceId = _ref.appServiceId,
      projectId = _ref.projectId,
      firstIf = _ref.firstIf,
      nextStageType = _ref.nextStageType;
  useEffect(function () {
    var _addStepDs$current;

    var type = addStepDs === null || addStepDs === void 0 ? void 0 : (_addStepDs$current = addStepDs.current) === null || _addStepDs$current === void 0 ? void 0 : _addStepDs$current.get('type');
    addStepDs.current.set('parallel', type === 'CI' ? 1 : 0);
  }, [addStepDs === null || addStepDs === void 0 ? void 0 : (_addStepDs$current2 = addStepDs.current) === null || _addStepDs$current2 === void 0 ? void 0 : _addStepDs$current2.get('type')]);

  var renderer = function renderer(_ref2) {
    var text = _ref2.text;
    return text;
  };

  var optionRenderer = function optionRenderer(_ref3) {
    var text = _ref3.text;

    if (text.includes('CI') && curType && curType === 'CD' && !firstIf) {
      return /*#__PURE__*/React.createElement(_Tooltip, {
        title: "CD\u9636\u6BB5\u540E\uFF0C\u65E0\u6CD5\u6DFB\u52A0CI\u9636\u6BB5"
      }, renderer({
        text: text
      }));
    }

    if (text.includes('CD')) {
      if (appServiceId && appServiceType === 'test') {
        return /*#__PURE__*/React.createElement(_Tooltip, {
          title: "\u6D4B\u8BD5\u7C7B\u578B\u5E94\u7528\u670D\u52A1\u4E0D\u80FD\u6DFB\u52A0CD\u9636\u6BB5"
        }, renderer({
          text: text
        }));
      }

      if (nextStageType === 'CI') {
        return /*#__PURE__*/React.createElement(_Tooltip, {
          title: "CI\u9636\u6BB5\u524D\uFF0C\u65E0\u6CD5\u6DFB\u52A0CD\u9636\u6BB5"
        }, renderer({
          text: text
        }));
      }
    }

    return renderer({
      text: text
    });
  }; // eslint-disable-next-line consistent-return


  function hanldeTypeDisabled(record) {
    var isCi = record.get('value') === 'CI'; // opts得value

    var isCd = record.get('value') === 'CD';
    var hasCurTypeCd = curType && curType === 'CD';
    var hasCurTypeCi = curType && curType === 'CI';

    if (firstIf) {
      if (hasCurTypeCi && isCd) {
        return true;
      }

      if (hasCurTypeCd && isCi) {
        return false;
      }
    }

    if (hasCurTypeCi) {
      if (nextStageType === 'CD') {
        return false;
      }

      if (nextStageType === 'CI' && isCd) {
        return true;
      }

      if (appServiceType === 'test' && isCd) {
        return true;
      }

      return false;
    }

    if (hasCurTypeCd) {
      if (isCi) return true;

      if (isCd && appServiceType === 'test') {
        return false;
      }
    }
  }

  return /*#__PURE__*/React.createElement(_Form, {
    className: "addStageForm",
    dataSet: addStepDs
  }, /*#__PURE__*/React.createElement(_Select, {
    name: "type",
    addonAfter: /*#__PURE__*/React.createElement(Tips, {
      helpText: "CI\u9636\u6BB5\u4E2D\u652F\u6301\u6DFB\u52A0\u6784\u5EFA\u3001\u53D1\u5E03Chart\u3001\u4EE3\u7801\u68C0\u67E5\u4EE5\u53CA\u81EA\u5B9A\u4E49\u7C7B\u578B\u7684CI\u4EFB\u52A1\uFF1BCD\u9636\u6BB5\u4E2D\u652F\u6301\u6DFB\u52A0\u90E8\u7F72\u3001\u4E3B\u673A\u90E8\u7F72\u4EE5\u53CA\u4EBA\u5DE5\u5361\u70B9\u7684CD\u4EFB\u52A1\u3002\u4E14\u6D41\u6C34\u7EBF\u4E2D\u4EFB\u4F55CD\u9636\u6BB5\u540E\uFF0C\u4E0D\u80FD\u518D\u6DFB\u52A0CI\u9636\u6BB5"
    }),
    onOption: function onOption(_ref4) {
      var record = _ref4.record;
      return optType !== 'edit' ? {
        disabled: hanldeTypeDisabled(record)
      } : {};
    },
    optionRenderer: optionRenderer,
    renderer: renderer,
    disabled: optType === 'edit'
  }), /*#__PURE__*/React.createElement(_TextField, {
    name: "step"
  }), /*#__PURE__*/React.createElement(_Select, {
    name: "parallel",
    addonAfter: /*#__PURE__*/React.createElement(Tips, {
      helpText: "\u76EE\u524DCI\u9636\u6BB5\u4E2D\u7684\u4EFB\u52A1\u53EA\u652F\u6301\u5E76\u884C\uFF0CCD\u4E2D\u7684\u9636\u6BB5\u4EC5\u652F\u6301\u4E32\u884C"
    })
  }, /*#__PURE__*/React.createElement(Option, {
    value: 0
  }, "\u4EFB\u52A1\u4E32\u884C"), /*#__PURE__*/React.createElement(Option, {
    value: 1
  }, "\u4EFB\u52A1\u5E76\u884C")));
});