import { putProjectUpdateProject } from '@/services/project/Project';
import {
  ModalForm,
  ProForm,
  ProFormText,
} from '@ant-design/pro-components';
import { FormattedMessage, useIntl } from '@umijs/max';
import { Form, message } from 'antd';
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.Project>;

export type UpdateFormProps = {
  updateModalOpen: boolean;
  handleModal: () => void;
  values: Partial<API.Project>;
  reload: any;
};



const UpdatePasswordForm: React.FC<UpdateFormProps> = (props) => {
  const intl = useIntl();
  const [form] = Form.useForm<API.Project>();

  return (
    <ModalForm<API.Project>
      width={proFormSmallModelWidth}
      title={intl.formatMessage({
        id: 'account.account_center.table.list.UpdatePasswordForm',
        defaultMessage: '$$$',
      })}
      open={props.updateModalOpen}
      form={form}
      autoFocusFirstInput
      modalProps={{
        destroyOnClose: true,
        onCancel: () => props.handleModal(),
      }}
      submitTimeout={2000}
      onFinish={async (values) => {
        putProjectUpdateProject(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="name"
          label={<FormattedMessage id="account.account_center.table.list.originalPassword" defaultMessage="$$$" />}
          placeholder={`${intl.formatMessage({
            id: 'common.please_input',
            defaultMessage: '$$$',
          })}${intl.formatMessage({
            id: 'account.account_center.table.list.originalPassword',
            defaultMessage: '$$$',
          })}`}
          required={true}
          initialValue={props.values.name}
          disabled={false}
          rules={[
            {
              required: true,
              message: (
                <FormattedMessage
                  id="account.account_center.table.rule.required.originalPassword"
                  defaultMessage="name is required"
                />
              ),
            },
          ]}
        />
        <ProFormText
          width={proFormSmallItemStyleProps.width}
          name="name"
          label={<FormattedMessage id="account.account_center.table.list.newPassword" defaultMessage="$$$" />}
          placeholder={`${intl.formatMessage({
            id: 'common.please_input',
            defaultMessage: '$$$',
          })}${intl.formatMessage({
            id: 'account.account_center.table.list.newPassword',
            defaultMessage: '$$$',
          })}`}
          required={true}
          initialValue={props.values.name}
          disabled={false}
          rules={[
            {
              required: true,
              message: (
                <FormattedMessage
                  id="account.account_center.table.rule.required.newPassword"
                  defaultMessage="name is required"
                />
              ),
            },
          ]}
        />
        <ProFormText
          width={proFormSmallItemStyleProps.width}
          name="name"
          label={<FormattedMessage id="account.account_center.table.list.confirmPassword" defaultMessage="$$$" />}
          placeholder={`${intl.formatMessage({
            id: 'common.please_input',
            defaultMessage: '$$$',
          })}${intl.formatMessage({
            id: 'account.account_center.table.list.confirmPassword',
            defaultMessage: '$$$',
          })}`}
          required={true}
          initialValue={props.values.name}
          disabled={false}
          rules={[
            {
              required: true,
              message: (
                <FormattedMessage
                  id="account.account_center.table.rule.required.confirmPassword"
                  defaultMessage="name is required"
                />
              ),
            },
          ]}
        />
      </ProForm.Group>
    </ModalForm>
  );
};
export default UpdatePasswordForm;
