/**
 * 用户列表新建弹框
 * 
 */
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 { postUserList } from '@/services/system/User';
import { proFormSmallItemStyleProps, proFormSmallModelWidth } from '../../../../../config/defaultForm';
import React from 'react';
export type FormValueType = {
  target?: string;
  template?: string;
  type?: string;
  time?: string;
  frequency?: string;
} & Partial<API.UserList>;

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

  return (
    <ModalForm<API.UserList>
      width={proFormSmallModelWidth}
      title={intl.formatMessage({
        id: 'system.user.table.list.create',
        defaultMessage: '新建用户',
      })}
      open={props.createModalOpen}
      form={form}
      autoFocusFirstInput
      modalProps={{
        destroyOnClose: true,
        onCancel: () => props.handleModal(),
        okText: intl.formatMessage({ id: 'common.yes', defaultMessage: '确认' }),
        cancelText: intl.formatMessage({ id: 'common.no', defaultMessage: '取消' }),
      }}
      submitTimeout={2000}
      onFinish={async (values) => {
        console.log(values);
        postUserList(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;
      }}
    >
      <ProForm.Group>
        <ProFormText
          width={proFormSmallItemStyleProps.width}
          name="username"
          label={
            <FormattedMessage id="system.user.table.list.userName" defaultMessage="用户名" />
          }
          placeholder={`${intl.formatMessage({
            id: 'common.please_input',
            defaultMessage: '请输入',
          })}${intl.formatMessage({
            id: 'system.user.table.list.userName',
            defaultMessage: '用户名',
          })}`}
          required={true}
          rules={[
            {
              required: true,
              message: (
                <FormattedMessage
                  id="system.user.table.rule.required.userName"
                  defaultMessage="用户名为必填项"
                />
              ),
            },
          ]}
        />
        <ProFormText
          width={proFormSmallItemStyleProps.width}
          name="password"
          label={
            <FormattedMessage id="system.user.table.list.password" defaultMessage="密码" />
          }
          placeholder={`${intl.formatMessage({
            id: 'common.please_input',
            defaultMessage: '请输入',
          })}${intl.formatMessage({
            id: 'system.user.table.list.password',
            defaultMessage: '密码',
          })}`}
          required={true}
          rules={[
            {
              required: true,
              message: (
                <FormattedMessage
                  id="system.user.table.rule.required.password"
                  defaultMessage="密码为必填项"
                />
              ),
            },
          ]}
        />
        <ProFormText
          width={proFormSmallItemStyleProps.width}
          name="note"
          label={
            <FormattedMessage id="system.user.table.list.remark" defaultMessage="备注" />
          }
          placeholder={`${intl.formatMessage({
            id: 'common.please_input',
            defaultMessage: '请输入',
          })}${intl.formatMessage({
            id: 'system.user.table.list.remark',
            defaultMessage: '备注',
          })}`}
          required={false}
        />
      </ProForm.Group>
    </ModalForm>
  );
};
export default CreateForm;
