/**
 * 服务器状态新建弹框
 * 
 */
import { postBusinessImageCreateBusinessImage } from '@/services/resource/BusinessImage';
import { ModalForm, ProForm, ProFormText, ProFormTextArea } from '@ant-design/pro-components';
import { FormattedMessage, useIntl } from '@umijs/max';
import { Button, Form, message } from 'antd';
import { proFormItemStyleProps, proFormModelWidth } from '../../../../../config/defaultForm';
import React from 'react';
export type FormValueType = {
  target?: string;
  template?: string;
  type?: string;
  time?: string;
  frequency?: string;
} & Partial<API.BusinessImage>;

export type CreateFormProps = {
  createModalOpen: boolean;
  handleModal: () => void;
  values: Partial<API.BusinessImage>;
  reload: any;
};
const CreateForm: React.FC<CreateFormProps> = (props) => {
  const intl = useIntl();
  const [form] = Form.useForm<API.BusinessImage>();

  return (
    <ModalForm<API.BusinessImage>
      width={proFormModelWidth}
      title={intl.formatMessage({
        id: 'resource.server_status.table.list.add',
        defaultMessage: '$$$',
      })}
      open={props.createModalOpen}
      form={form}
      autoFocusFirstInput
      modalProps={{
        destroyOnClose: true,
        onCancel: () => props.handleModal(),
      }}
      submitTimeout={2000}
      onFinish={async (values) => {
        postBusinessImageCreateBusinessImage(values)
          .then(() => {
            message.success(intl.formatMessage({ id: 'common.success', defaultMessage: '$$$' }));
            props.reload();
          })
          .catch(() => {
            message.error(intl.formatMessage({ id: 'common.failure', defaultMessage: '$$$' }));
          });
        props.handleModal();
        return true;
      }}
    >
      <span style={{
        display: 'inline-block',
        fontWeight: 600,
        marginBottom: 12
      }}>
        <FormattedMessage id="resource.server_status.table.list.parameter" defaultMessage="$$$" />
      </span>
      <ProForm.Group>
        <ProFormText
          width={proFormItemStyleProps.column2Width}
          name="name"
          label={
            <FormattedMessage id="resource.server_status.table.list.name" defaultMessage="$$$" />
          }
          placeholder={`${intl.formatMessage({
            id: 'common.please_input',
            defaultMessage: '$$$',
          })}${intl.formatMessage({
            id: 'resource.server_status.table.list.name',
            defaultMessage: '$$$',
          })}`}
          required={false}
          rules={[
            {
              required: true,
              message: (
                <FormattedMessage
                  id="resource.server_status.table.list.name"
                  defaultMessage="name is required"
                />
              ),
            },
          ]}
        />
        <ProFormText
          width={proFormItemStyleProps.column2Width}
          name="userName"
          label={
            <FormattedMessage
              id="resource.server_status.table.list.userName"
              defaultMessage="$$$"
            />
          }
          placeholder={`${intl.formatMessage({
            id: 'common.please_input',
            defaultMessage: '$$$',
          })}${intl.formatMessage({
            id: 'resource.server_status.table.list.userName',
            defaultMessage: '$$$',
          })}`}
          required={false}
          rules={[
            {
              required: true,
              message: (
                <FormattedMessage
                  id="resource.server_status.table.list.userName"
                  defaultMessage="version is required"
                />
              ),
            },
          ]}
        />
        <ProFormText
          width={proFormItemStyleProps.column2Width}
          name="ip"
          label={
            <FormattedMessage id="resource.server_status.table.list.ip" defaultMessage="$$$" />
          }
          placeholder={`${intl.formatMessage({
            id: 'common.please_input',
            defaultMessage: '$$$',
          })}${intl.formatMessage({
            id: 'resource.server_status.table.list.ip',
            defaultMessage: '$$$',
          })}`}
          required={false}
        />
        <ProFormText
          width={proFormItemStyleProps.column2Width}
          name="password"
          label={
            <FormattedMessage
              id="resource.server_status.table.list.password"
              defaultMessage="$$$"
            />
          }
          placeholder={`${intl.formatMessage({
            id: 'common.please_input',
            defaultMessage: '$$$',
          })}${intl.formatMessage({
            id: 'resource.server_status.table.list.password',
            defaultMessage: '$$$',
          })}`}
          required={false}
        />
        <ProFormText
          width={proFormItemStyleProps.column2Width}
          name="defaultPort"
          label={
            <FormattedMessage
              id="resource.server_status.table.list.defaultPort"
              defaultMessage="$$$"
            />
          }
          placeholder={`${intl.formatMessage({
            id: 'common.please_input',
            defaultMessage: '$$$',
          })}${intl.formatMessage({
            id: 'resource.server_status.table.list.defaultPort',
            defaultMessage: '$$$',
          })}`}
          required={false}
        />
        <ProFormTextArea
          width={proFormItemStyleProps.width}
          name="publicKeyString"
          label={
            <FormattedMessage id="resource.server_status.table.list.publicKeyString" defaultMessage="$$$" />
          }
          placeholder={`${intl.formatMessage({
            id: 'common.please_input',
            defaultMessage: '$$$',
          })}${intl.formatMessage({
            id: 'resource.server_status.table.list.publicKeyString',
            defaultMessage: '$$$',
          })}`}
          required={false}
        />
        <Button type="primary" ghost><FormattedMessage id="resource.server_status.table.list.connectivityTesting" defaultMessage="$$$" /></Button>
      </ProForm.Group>
    </ModalForm>
  );
};
export default CreateForm;
