// @ts-ignore: 忽略
import type { FormSchemaGetter } from '#/adapter/form';

import { ElButton } from 'element-plus';

// @ts-ignore: 忽略
import { getMultipleUploadConfig } from '#/components/upload';

export const drawerFormSchema: FormSchemaGetter = () => [
  {
    component: 'Upload',
    fieldName: 'attachmentFiles',
    label: '上传文件',
    componentProps: (row: any) => {
      return {
        ...getMultipleUploadConfig(5),
        multiple: true,
        onSuccess: (res: any, uploadFile: any, uploadFiles: any) => {
          if (res.code === 200) {
            const paths: string[] = [];
            const names: string[] = [];
            uploadFiles.forEach((item: any) => {
              if (item.response?.code === 200) {
                paths.push(item.response.data.fileName);
                names.push(item.name);
              }
            });
            row.attachment = paths.join(',');
            row.attachmentName = names.join(',');

            return res.data;
          }
        },
      };
    },
    renderComponentContent: () => {
      return {
        default: () => {
          const title = '点击上传';
          const style = 'margin-top: 8px;';
          return <ElButton style={style}>{title}</ElButton>;
        },
      };
    },
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'attachment',
    label: '文件名称',
    componentProps: {
      maxlength: 30,
    },
    // rules: 'required',

    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
  },
  {
    component: 'Input',
    fieldName: 'attachmentName',
    label: '文件名称',
    componentProps: {
      maxlength: 30,
    },
    // rules: 'required',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
  },
  {
    component: 'Input',
    fieldName: 'remark',
    label: '备注',
    componentProps: {
      type: 'textarea',
      rows: 3,
      maxlength: 200,
    },
  },
];
