import { Form, Input, Spin } from 'antd';
import React, { Fragment, useContext, useRef, useImperativeHandle, useEffect } from 'react';
import TaskContext from '../../modules/createJob/context';
import './styles/baseForm.less';
var classPrefix = 'cdp-dscreator-base';
var BaseForm = function BaseForm(props, ref) {
  var _useContext = useContext(TaskContext),
    mode = _useContext.mode;
  var columnList = props.columnList,
    task = props.task;
  useEffect(function () {
    // 初始化
    if ((task === null || task === void 0 ? void 0 : task.jobName) && props.onChange) {
      props.onChange({
        jobName: task === null || task === void 0 ? void 0 : task.jobName,
        jobDesc: task === null || task === void 0 ? void 0 : task.jobDesc
      });
    }
  }, []);
  var formRef = useRef();
  useImperativeHandle(ref, function () {
    return {
      formSubmit: function formSubmit() {
        var _formRef$current;
        (_formRef$current = formRef.current) === null || _formRef$current === void 0 ? void 0 : _formRef$current.submit();
      }
    };
  });
  function onChange() {
    var _formRef$current2;
    (_formRef$current2 = formRef.current) === null || _formRef$current2 === void 0 ? void 0 : _formRef$current2.submit();
  }
  function onSubmit(data) {
    if (props.onChange) props.onChange(data);
  }
  var initialValues = {
    jobName: task === null || task === void 0 ? void 0 : task.jobName,
    jobDesc: task === null || task === void 0 ? void 0 : task.jobDesc
  };
  if (mode === 'edit' && props.loading) {
    return /*#__PURE__*/React.createElement(Spin, null);
  }
  return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", null, "\u57FA\u7840\u4FE1\u606F"), /*#__PURE__*/React.createElement(Form, {
    colon: false,
    className: classPrefix,
    ref: formRef,
    onFinish: onSubmit,
    initialValues: mode === 'edit' ? initialValues : undefined,
    autoComplete: "off"
  }, /*#__PURE__*/React.createElement(Form.Item, {
    label: "\u4EFB\u52A1\u540D\u79F0",
    name: "jobName"
  }, /*#__PURE__*/React.createElement(Input
  // width={574}
  , {
    // width={574}
    placeholder: "\u8BF7\u8F93\u5165\u4EFB\u52A1\u540D\u79F0",
    onChange: onChange,
    maxLength: 50,
    showCount: true
  })), /*#__PURE__*/React.createElement(Form.Item, {
    label: "\u4EFB\u52A1\u63CF\u8FF0",
    name: "jobDesc",
    labelAlign: "right"
  }, /*#__PURE__*/React.createElement(Input.TextArea, {
    rows: 3,
    placeholder: "\u8F93\u5165\u6587\u5B57\u63CF\u8FF0\u60A8\u8981\u521B\u5EFA\u7684\u4EFB\u52A1",
    onChange: onChange,
    maxLength: 100,
    showCount: true
  }))));
};
export default /*#__PURE__*/React.forwardRef(BaseForm);