import "choerodon-ui/pro/lib/table/style";
import _Table from "@hzero-front-ui/c7n-ui/lib/TablePro";

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); }); }; }

import React, { Fragment, useEffect } from 'react';
import { injectIntl, FormattedMessage } from 'react-intl';
import { observer } from 'mobx-react-lite';
import map from 'lodash/map';
import isEmpty from 'lodash/isEmpty';
import UserInfo from "../../../../components/userInfo";
import { useProcessStore } from "./stores";
var Column = _Table.Column;
export default injectIntl(observer(function (props) {
  var _useProcessStore = useProcessStore(),
      pipelineDs = _useProcessStore.pipelineDs,
      deployStore = _useProcessStore.deployStore,
      refresh = _useProcessStore.refresh,
      intlPrefix = _useProcessStore.intlPrefix,
      prefixCls = _useProcessStore.prefixCls,
      modal = _useProcessStore.modal,
      projectId = _useProcessStore.AppState.currentMenuType.projectId;

  useEffect(function () {
    if (pipelineDs.selected && pipelineDs.selected.length) {
      modal.update({
        okProps: {
          disabled: false
        }
      });
    } else {
      modal.update({
        okProps: {
          disabled: true
        }
      });
    }
  }, [pipelineDs.selected]);
  modal.handleOk( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
    var pipelineIds;
    return regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            pipelineIds = map(pipelineDs.selected, function (record) {
              return record.get('id');
            });

            if (!isEmpty(pipelineIds)) {
              _context.next = 3;
              break;
            }

            return _context.abrupt("return", true);

          case 3:
            _context.prev = 3;
            _context.next = 6;
            return deployStore.startPipeline(projectId, pipelineIds);

          case 6:
            _context.t0 = _context.sent;

            if (!(_context.t0 !== false)) {
              _context.next = 11;
              break;
            }

            refresh();
            _context.next = 12;
            break;

          case 11:
            return _context.abrupt("return", false);

          case 12:
            _context.next = 17;
            break;

          case 14:
            _context.prev = 14;
            _context.t1 = _context["catch"](3);
            return _context.abrupt("return", false);

          case 17:
          case "end":
            return _context.stop();
        }
      }
    }, _callee, null, [[3, 14]]);
  })));

  function renderCreator(_ref2) {
    var value = _ref2.value,
        record = _ref2.record;
    return /*#__PURE__*/React.createElement(UserInfo, {
      name: record.get('createUserRealName') || '',
      id: value,
      avatar: record.get('createUserUrl')
    });
  }

  return /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefixCls, "-process-wrap")
  }, /*#__PURE__*/React.createElement(_Table, {
    dataSet: pipelineDs
  }, /*#__PURE__*/React.createElement(Column, {
    name: "name"
  }), /*#__PURE__*/React.createElement(Column, {
    name: "createUserName",
    renderer: renderCreator
  })));
}));