import {ModalForm, ProForm, ProFormDigit, ProFormSwitch} from '@ant-design/pro-components';
import {ProFormText} from '@ant-design/pro-components';
import {ProFormSelect} from '@ant-design/pro-components';
import {FormattedMessage, useIntl} from '@umijs/max';
import React from 'react';
import {postSysOperationRecordCreateOperationRecord} from "@/services/system/OperationRecord";
import {Form, message} from 'antd';
// 表单宽度 560 单列
import { proFormSmallItemStyleProps,proFormSmallModelWidth } from '../../../../../config/defaultForm';

export type CreateFormProps = {
  createModalOpen: boolean;
  handleModal: () => void;
  values: Partial<API.OperationRecord>;
  reload: any;
};
const CreateForm: React.FC<CreateFormProps> = (props) => {

  const intl = useIntl();
  const [form] = Form.useForm<API.OperationRecord>();

  return (
    <ModalForm<API.OperationRecord>
      width={proFormSmallModelWidth}
      title={intl.formatMessage({
        id: 'system.operation.table.list.create',
        defaultMessage: '$$$',
      })}
      open={props.createModalOpen}
      form={form}
      autoFocusFirstInput
      modalProps={{
        destroyOnClose: true,
        onCancel: () => props.handleModal(),
      }}
      submitTimeout={2000}
      onFinish={async (values) => {
        postSysOperationRecordCreateOperationRecord(values).then(() => {
          message.success(intl.formatMessage({id: 'common.success', defaultMessage: '$$$'}))
          props.reload()
        }).catch(() => {
          message.error(intl.formatMessage({id: 'common.error', defaultMessage: '$$$'}))
        })
        props.handleModal();
        return true;
      }}
    >

      <ProForm.Group>
        <ProFormText width={proFormSmallItemStyleProps.width} name="ip"
                     label={<FormattedMessage id="system.operation.table.list.ip" defaultMessage="$$$"/>}
                     placeholder={`${intl.formatMessage({id: 'common.please_input', defaultMessage: '$$$'})}${intl.formatMessage({id: 'system.operation.table.list.ip', defaultMessage: '$$$'})}`}
                     required={true}
                     rules={[
                       {
                         required: true,
                         message: (
                           <FormattedMessage
                             id="system.operation.table.rule.list.ip"
                             defaultMessage="ip is required"
                           />
                         ),
                       },
                     ]}
        />
        <ProFormText width={proFormSmallItemStyleProps.width} name="path"
                     label={<FormattedMessage id="system.operation.table.list.path" defaultMessage="$$$"/>}
                     placeholder={`${intl.formatMessage({id: 'common.please_input', defaultMessage: '$$$'})}${intl.formatMessage({id: 'system.operation.table.list.path', defaultMessage: '$$$'})}`}
                     required={true}
                     rules={[
                       {
                         required: true,
                         message: (
                           <FormattedMessage
                             id="system.operation.table.rule.list.path"
                             defaultMessage="path is required"
                           />
                         ),
                       },
                     ]}
        />
        <ProFormDigit width={proFormSmallItemStyleProps.width} fieldProps={{precision: 0}} name="sort"
                      label={<FormattedMessage id="system.operation.table.list.sort" defaultMessage="$$$"/>}
                      placeholder={`${intl.formatMessage({id: 'common.please_input', defaultMessage: '$$$'})}${intl.formatMessage({id: 'system.operation.table.list.sort', defaultMessage: '$$$'})}`}
                      initialValue={1}
        />
        {/* <ProFormText width={proFormItemStyleProps.column2Width} name="remark"
                     label={<FormattedMessage id="system.operation.table.list.remark" defaultMessage="$$$"/>}
                     placeholder={`${intl.formatMessage({id: 'common.please_input', defaultMessage: '$$$'})}${intl.formatMessage({id: 'system.operation.table.list.remark', defaultMessage: '$$$'})}`}
                     required={false}/> */}
      </ProForm.Group>
      <ProForm.Group>
        <ProFormText width={proFormSmallItemStyleProps.width} name="remark"
                     label={<FormattedMessage id="system.operation.table.list.remark" defaultMessage="$$$"/>}
                     placeholder={`${intl.formatMessage({id: 'common.please_input', defaultMessage: '$$$'})}${intl.formatMessage({id: 'system.operation.table.list.remark', defaultMessage: '$$$'})}`}
                     required={false}/>
        <ProFormSwitch width={proFormSmallItemStyleProps.width} name="status" initialValue={true}
                       label={<FormattedMessage id="system.operation.table.list.status" defaultMessage="$$$"/>}
                       required={false}>

        </ProFormSwitch>
      </ProForm.Group>
    </ModalForm>)
}
export default CreateForm;
