import { MyBetaModalFormProps, MyButtons, MyModalFormProps } from '@/common';
import { BetaSchemaForm, ProCard } from '@ant-design/pro-components';
import { Form, Image } from 'antd';

export default function Update(props: MyBetaModalFormProps) {
  const [form] = Form.useForm();
  return (
    <BetaSchemaForm<ApiTypes.Emergency.EmergencyEvents.Update>
      {...MyModalFormProps.props}
      title={`查看`}
      trigger={<MyButtons.View />}
      wrapperCol={{ span: 24 }}
      width="600px"
      form={form}
      key={new Date().getTime()}
      onOpenChange={(open: any) => {
        if (open && props.item) {
          form.setFieldsValue(props.item);
        }
      }}
      columns={[
        {
          title: '操作',
          key: 'node_name',
          renderFormItem: () => {
            return props?.item?.node_name;
          },
        },
        {
          key: 'content',
          title: '内容',
          renderFormItem: () => {
            return props?.item?.content;
          },
        },
        {
          title: '附件',
          renderFormItem: () => {
            return props?.item?.attachments?.length ? (
              <Image.PreviewGroup>
                {props?.item?.attachments?.map((i: any, index: number) => (
                  <Image
                    width={60}
                    height={60}
                    src={i.url}
                    key={`img_${index}`}
                  />
                ))}
              </Image.PreviewGroup>
            ) : (
              <ProCard bordered>无附件</ProCard>
            );
          },
        },
      ]}
    />
  );
}
