import "choerodon-ui/pro/lib/button/style";
import _Button from "choerodon-ui/pro/lib/button";
import "choerodon-ui/pro/lib/icon/style";
import _Icon from "choerodon-ui/pro/lib/icon";
import "choerodon-ui/pro/lib/modal/style";
import _Modal from "choerodon-ui/pro/lib/modal";

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

import React, { createRef } from 'react';
import { observer } from 'mobx-react-lite';
import { usePipelineStageEditStore } from "../../stores";
import AddTask from "../../../AddTask";
import AddCDTask from "../../../AddCDTask";
import jobType from "../../../../../../stores/jobsTypeMappings";

var EditItem = function EditItem(props) {
  var index = props.index,
      sequence = props.sequence,
      jobDetail = props.jobDetail,
      PipelineCreateFormDataSet = props.PipelineCreateFormDataSet,
      AppServiceOptionsDs = props.AppServiceOptionsDs,
      appServiceName = props.appServiceName,
      image = props.image,
      openVariableModal = props.openVariableModal,
      stageType = props.stageType,
      witchColumnJobIndex = props.witchColumnJobIndex,
      columnIndex = props.columnIndex,
      innerRef = props.innerRef,
      dragProvided = props.dragProvided,
      snapshotinner = props.snapshotinner;
  var name = jobDetail.name,
      type = jobDetail.type;

  var _usePipelineStageEdit = usePipelineStageEditStore(),
      editBlockStore = _usePipelineStageEdit.editBlockStore;

  var editJob = editBlockStore.editJob,
      removeStepTask = editBlockStore.removeStepTask,
      getStepData = editBlockStore.getStepData;

  function handleEditOk(data) {
    editJob(sequence, index, data);
  }

  function openEditJobModal() {
    _Modal.open({
      key: _Modal.key(),
      title: /*#__PURE__*/React.createElement("div", {
        style: {
          display: 'flex',
          alignItems: 'center'
        }
      }, /*#__PURE__*/React.createElement("span", {
        className: "c7n-piplineManage-edit-title-text"
      }, "\u7F16\u8F91".concat(name, "\u4EFB\u52A1")), stageType === 'CI' && /*#__PURE__*/React.createElement("div", {
        className: "c7n-piplineManage-edit-title-text-btn",
        onClick: function onClick() {
          return openVariableModal();
        },
        role: "none"
      }, /*#__PURE__*/React.createElement(_Icon, {
        type: "find_in_page-o",
        className: "c7n-piplineManage-edit-title-btn"
      }), /*#__PURE__*/React.createElement("span", null, "\u67E5\u770B\u6D41\u6C34\u7EBF\u53D8\u91CF"))),
      style: {
        width: '740px'
      },
      children: stageType === 'CI' ? /*#__PURE__*/React.createElement(AddTask, {
        jobDetail: jobDetail,
        appServiceId: appServiceName,
        appServiceName: appServiceName,
        handleOk: handleEditOk,
        PipelineCreateFormDataSet: PipelineCreateFormDataSet,
        AppServiceOptionsDs: AppServiceOptionsDs,
        image: image,
        columnIndex: columnIndex,
        witchColumnJobIndex: witchColumnJobIndex,
        sequence: sequence,
        index: index
      }) : /*#__PURE__*/React.createElement(AddCDTask, {
        random: Math.random(),
        jobDetail: jobDetail,
        appServiceId: appServiceName,
        appServiceName: appServiceName,
        pipelineStageMainSource: getStepData,
        PipelineCreateFormDataSet: PipelineCreateFormDataSet,
        handleOk: handleEditOk,
        columnIndex: columnIndex,
        witchColumnJobIndex: witchColumnJobIndex,
        sequence: sequence,
        index: index
      }),
      drawer: true,
      okText: '添加'
    });
  }

  function openDeleteJobModal() {
    _Modal.open({
      key: _Modal.key(),
      title: "\u5220\u9664".concat(name, "\u4EFB\u52A1"),
      children: '确认删除此任务吗？',
      okText: '确认',
      onOk: function onOk() {
        return removeStepTask(sequence, index);
      }
    });
  }

  var getItemStyle = function getItemStyle(isDragging, draggableStyle) {
    return _objectSpread(_objectSpread({
      // some basic styles to make the items look a bit nicer
      userSelect: 'none'
    }, draggableStyle), {}, {
      cursor: 'all-scroll'
    });
  };

  return /*#__PURE__*/React.createElement("div", Object.assign({
    className: "c7n-piplineManage-edit-column-item",
    ref: innerRef
  }, dragProvided.draggableProps, dragProvided.dragHandleProps, {
    style: getItemStyle(snapshotinner.isDragging, dragProvided.draggableProps.style)
  }), /*#__PURE__*/React.createElement("div", {
    className: "c7n-piplineManage-edit-column-item-header"
  }, "\u3010", Object.prototype.hasOwnProperty.bind(jobType, type) && jobType[type], "\u3011", name), /*#__PURE__*/React.createElement("div", {
    className: "c7n-piplineManage-edit-column-item-btnGroup"
  }, /*#__PURE__*/React.createElement(_Button, {
    className: "c7n-piplineManage-edit-column-item-btnGroup-btn",
    shape: "circle",
    size: "small",
    icon: "mode_edit",
    onClick: openEditJobModal
  }), /*#__PURE__*/React.createElement(_Button, {
    className: "c7n-piplineManage-edit-column-item-btnGroup-btn",
    shape: "circle",
    size: "small",
    icon: "delete_forever",
    onClick: openDeleteJobModal
  })));
};

export default observer(EditItem);