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

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

// 抽屉表单配置
export const drawerFormSchema: any | FormSchemaGetter = () => [
  {
    component: 'DatePicker',
    componentProps: {
      placeholder: '请选择参与时间',
      type: 'datetime',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
    },
    fieldName: 'participationTime',
    label: '参与时间',
    rules: 'required',
  },
  {
    component: 'Input',
    componentProps: {
      placeholder: '请输入参与记录',
      type: 'textarea',
      rows: 4,
    },
    fieldName: 'participationRecord',
    label: '参与记录',
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'images',
    label: '图片',
    componentProps: {
      maxlength: 30,
    },
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
  },
  {
    component: 'Upload',
    fieldName: 'imagesPaths',
    label: '图片',
    rules: 'required',
    componentProps: (row: any) => {
      return {
        ...getMultipleImageUploadConfig(5),
        multiple: true,
        onSuccess: (res: any, uploadFile: any, uploadFiles: any) => {
          if (res.code === 200) {
            const paths: string[] = [];
            uploadFiles.forEach((item: any) => {
              if (item.response?.code === 200) {
                paths.push(item.response.data.fileName);
              }
            });
            row.images = paths.join(',');

            return res.data;
          }
        },
      };
    },
    renderComponentContent: () => {
      return {
        default: () => '点击上传',
      };
    },
  },
];
