import {ModalForm,ProForm} from '@ant-design/pro-components';import {ProFormText} from '@ant-design/pro-components';import {ProFormSwitch} 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 {postDeviceGroupGetDeviceGroupFkSelect} from "@/services/device/DeviceGroup";
import {putDeviceGroupUpdateDeviceGroup} from "@/services/device/DeviceGroup";
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.DeviceGroup>;

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

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

  return (
    <ModalForm<API.DeviceGroup>
      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) => {
        putDeviceGroupUpdateDeviceGroup(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}/>
  {/*<ProFormSelect width="md" name="parentFkId" label={<FormattedMessage id="device.device_group.table.list.parentFkId" defaultMessage="$$$"/>} placeholder={`${intl.formatMessage({id: 'common.please_input', defaultMessage: '$$$'})}${intl.formatMessage({id: 'device.device_group.table.list.parentFkId', defaultMessage: '$$$'})}`} required={false} initialValue={props.values.parentFkId}*/}
  {/*               disabled={true} />*/}
<ProFormText width="md" name="name" label={<FormattedMessage id="device.device_group.table.list.name" defaultMessage="$$$"/>} placeholder={`${intl.formatMessage({id: 'common.please_input', defaultMessage: '$$$'})}${intl.formatMessage({id: 'device.device_group.table.list.name', defaultMessage: '$$$'})}`} required={true} initialValue={props.values.name} disabled={false}
                    rules={[
                    {
                      required: true,
                      message: (
                        <FormattedMessage
                          id="device.device_group.table.rule.required.name"
                          defaultMessage="name is required"
                        />
                      ),
                    },
                  ]}
                />
<ProFormText width="md" name="code" label={<FormattedMessage id="device.device_group.table.list.code" defaultMessage="$$$"/>} placeholder={`${intl.formatMessage({id: 'common.please_input', defaultMessage: '$$$'})}${intl.formatMessage({id: 'device.device_group.table.list.code', defaultMessage: '$$$'})}`} required={true} initialValue={props.values.code} disabled={false}
                    rules={[
                    {
                      required: true,
                      message: (
                        <FormattedMessage
                          id="device.device_group.table.rule.required.code"
                          defaultMessage="code is required"
                        />
                      ),
                    },
                  ]}
                />
<ProFormText width="md" name="address" label={<FormattedMessage id="device.device_group.table.list.address" defaultMessage="$$$"/>} placeholder={`${intl.formatMessage({id: 'common.please_input', defaultMessage: '$$$'})}${intl.formatMessage({id: 'device.device_group.table.list.address', defaultMessage: '$$$'})}`} required={false} initialValue={props.values.address} disabled={false}/>
<ProFormText width="md" name="telephone" label={<FormattedMessage id="device.device_group.table.list.telephone" defaultMessage="$$$"/>} placeholder={`${intl.formatMessage({id: 'common.please_input', defaultMessage: '$$$'})}${intl.formatMessage({id: 'device.device_group.table.list.telephone', defaultMessage: '$$$'})}`} required={false} initialValue={props.values.telephone} disabled={false}/>
<ProFormText width="md" name="lon" label={<FormattedMessage id="device.device_group.table.list.lon" defaultMessage="$$$"/>} placeholder={`${intl.formatMessage({id: 'common.please_input', defaultMessage: '$$$'})}${intl.formatMessage({id: 'device.device_group.table.list.lon', defaultMessage: '$$$'})}`} required={false} initialValue={props.values.lon} disabled={false}/>
<ProFormText width="md" name="lat" label={<FormattedMessage id="device.device_group.table.list.lat" defaultMessage="$$$"/>} placeholder={`${intl.formatMessage({id: 'common.please_input', defaultMessage: '$$$'})}${intl.formatMessage({id: 'device.device_group.table.list.lat', defaultMessage: '$$$'})}`} required={false} initialValue={props.values.lat} disabled={false}/>
<ProFormText width="md" name="managerName" label={<FormattedMessage id="device.device_group.table.list.managerName" defaultMessage="$$$"/>} placeholder={`${intl.formatMessage({id: 'common.please_input', defaultMessage: '$$$'})}${intl.formatMessage({id: 'device.device_group.table.list.managerName', defaultMessage: '$$$'})}`} required={false} initialValue={props.values.managerName} disabled={false}/>
<ProFormText width="md" name="managerPhone" label={<FormattedMessage id="device.device_group.table.list.managerPhone" defaultMessage="$$$"/>} placeholder={`${intl.formatMessage({id: 'common.please_input', defaultMessage: '$$$'})}${intl.formatMessage({id: 'device.device_group.table.list.managerPhone', defaultMessage: '$$$'})}`} required={false} initialValue={props.values.managerPhone} disabled={false}/>
<ProFormSwitch width="md" name="isEnable" label={<FormattedMessage id="device.device_group.table.list.isEnable" defaultMessage="$$$"/>} initialValue={props.values.isEnable} disabled={false}/>

<ProFormText width="md" name="remark" label={<FormattedMessage id="device.device_group.table.list.remark" defaultMessage="$$$"/>} placeholder={`${intl.formatMessage({id: 'common.please_input', defaultMessage: '$$$'})}${intl.formatMessage({id: 'device.device_group.table.list.remark', defaultMessage: '$$$'})}`} required={false} initialValue={props.values.remark} disabled={false}/>
<ProFormDateTimePicker width="md" name="createTime" label={<FormattedMessage id="device.device_group.table.list.createTime" defaultMessage="$$$"/>} placeholder={`${intl.formatMessage({id: 'common.please_input', defaultMessage: '$$$'})}${intl.formatMessage({id: 'device.device_group.table.list.createTime', defaultMessage: '$$$'})}`} required={false} initialValue={props.values.createTime} disabled={true}/>
<ProFormDateTimePicker width="md" name="updateTime" label={<FormattedMessage id="device.device_group.table.list.updateTime" defaultMessage="$$$"/>} placeholder={`${intl.formatMessage({id: 'common.please_input', defaultMessage: '$$$'})}${intl.formatMessage({id: 'device.device_group.table.list.updateTime', defaultMessage: '$$$'})}`} required={false} initialValue={props.values.updateTime} disabled={true}/>
</ProForm.Group>
</ModalForm>)}
export default UpdateForm;
