import {ModalForm,ProForm} from '@ant-design/pro-components';import {ProFormText} from '@ant-design/pro-components';import {ProFormSelect} from '@ant-design/pro-components';import {ProFormDateTimePicker} from '@ant-design/pro-components';
import {FormattedMessage, useIntl} from '@umijs/max';
import {postProjectGetProjectFkSelect} from "@/services/project/Project";
import {putBusinessImageUpdateBusinessImage} from "@/services/resource/BusinessImage";
import React, {useState} from 'react';
import {Button, Form, message} from 'antd';
export type FormValueType = {
      target?: string;
      template?: string;
      type?: string;
      time?: string;
      frequency?: string;
    } & Partial<API.BusinessImage>;

    export type UpdateFormProps = {
      updateModalOpen: boolean;
      handleModal: () => void;
      values: Partial<API.BusinessImage>;
      reload: any;
    };
const UpdateForm: React.FC<UpdateFormProps> = (props) => {

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

  return (
    <ModalForm<API.BusinessImage>
      title={intl.formatMessage({
        id: 'common.modal.table.update.title',
        defaultMessage: '$$$',
      })}
      open={props.updateModalOpen}
      form={form}
      autoFocusFirstInput
      modalProps={{
        destroyOnClose: true,
        onCancel: () => props.handleModal(),
      }}
      submitTimeout={2000}
      onFinish={async (values) => {
        putBusinessImageUpdateBusinessImage(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="md" name="id" label="id" disabled={true} initialValue={props.values.id}/>
<ProFormText width="md" name="name" label={<FormattedMessage id="resource.business_image.table.list.name" defaultMessage="$$$"/>} placeholder={`${intl.formatMessage({id: 'common.please_input', defaultMessage: '$$$'})}${intl.formatMessage({id: 'resource.business_image.table.list.name', defaultMessage: '$$$'})}`} required={true} initialValue={props.values.name} disabled={false}
                    rules={[
                    {
                      required: true,
                      message: (
                        <FormattedMessage
                          id="resource.business_image.table.rule.required.name"
                          defaultMessage="name is required"
                        />
                      ),
                    },
                  ]}
                />
<ProFormText width="md" name="version" label={<FormattedMessage id="resource.business_image.table.list.version" defaultMessage="$$$"/>} placeholder={`${intl.formatMessage({id: 'common.please_input', defaultMessage: '$$$'})}${intl.formatMessage({id: 'resource.business_image.table.list.version', defaultMessage: '$$$'})}`} required={true} initialValue={props.values.version} disabled={false}
                    rules={[
                    {
                      required: true,
                      message: (
                        <FormattedMessage
                          id="resource.business_image.table.rule.required.version"
                          defaultMessage="version is required"
                        />
                      ),
                    },
                  ]}
                />
<ProFormSelect width="md" name="projectFkId" label={<FormattedMessage id="resource.business_image.table.list.projectFkId" defaultMessage="$$$"/>} placeholder={`${intl.formatMessage({id: 'common.please_input', defaultMessage: '$$$'})}${intl.formatMessage({id: 'resource.business_image.table.list.projectFkId', defaultMessage: '$$$'})}`} required={true} initialValue={props.values.projectFkId} showSearch debounceTime={1000} request={async (keyWord)=>{
                              const resp = await postProjectGetProjectFkSelect({keyword: keyWord?.keyWords || ''})
                              return resp.data.list.map((v: any)=>{
                             return {
                               label: v.name,
                               value: v.id
                             }
                           })
                            }
                            }/>
<ProFormText width="md" name="path" label={<FormattedMessage id="resource.business_image.table.list.path" defaultMessage="$$$"/>} placeholder={`${intl.formatMessage({id: 'common.please_input', defaultMessage: '$$$'})}${intl.formatMessage({id: 'resource.business_image.table.list.path', defaultMessage: '$$$'})}`} required={false} initialValue={props.values.path} disabled={false}/>
<ProFormText width="md" name="startCode" label={<FormattedMessage id="resource.business_image.table.list.startCode" defaultMessage="$$$"/>} placeholder={`${intl.formatMessage({id: 'common.please_input', defaultMessage: '$$$'})}${intl.formatMessage({id: 'resource.business_image.table.list.startCode', defaultMessage: '$$$'})}`} required={false} initialValue={props.values.startCode} disabled={false}/>
<ProFormText width="md" name="configHash" label={<FormattedMessage id="resource.business_image.table.list.configHash" defaultMessage="$$$"/>} placeholder={`${intl.formatMessage({id: 'common.please_input', defaultMessage: '$$$'})}${intl.formatMessage({id: 'resource.business_image.table.list.configHash', defaultMessage: '$$$'})}`} required={false} initialValue={props.values.configHash} disabled={false}/>
<ProFormText width="md" name="remark" label={<FormattedMessage id="resource.business_image.table.list.remark" defaultMessage="$$$"/>} placeholder={`${intl.formatMessage({id: 'common.please_input', defaultMessage: '$$$'})}${intl.formatMessage({id: 'resource.business_image.table.list.remark', defaultMessage: '$$$'})}`} required={false} initialValue={props.values.remark} disabled={false}/>
<ProFormDateTimePicker width="md" name="createTime" label={<FormattedMessage id="resource.business_image.table.list.createTime" defaultMessage="$$$"/>} placeholder={`${intl.formatMessage({id: 'common.please_input', defaultMessage: '$$$'})}${intl.formatMessage({id: 'resource.business_image.table.list.createTime', defaultMessage: '$$$'})}`} required={false} initialValue={props.values.createTime} disabled={true}/>
<ProFormDateTimePicker width="md" name="updateTime" label={<FormattedMessage id="resource.business_image.table.list.updateTime" defaultMessage="$$$"/>} placeholder={`${intl.formatMessage({id: 'common.please_input', defaultMessage: '$$$'})}${intl.formatMessage({id: 'resource.business_image.table.list.updateTime', defaultMessage: '$$$'})}`} required={false} initialValue={props.values.updateTime} disabled={true}/>
</ProForm.Group>
</ModalForm>)}
export default UpdateForm;
