import type { CreateCrudOptionsProps, CreateCrudOptionsRet } from '@fast-crud/fast-crud';
import { dict } from '@fast-crud/fast-crud';
import importStudent from '@/public/学员导入.xlsx';
import { addRequest, delRequest, editRequest, pageRequest } from './api';
function curd({ context }: CreateCrudOptionsProps): CreateCrudOptionsRet {
  return {
    crudOptions: {
      container: {
        is: 'fs-layout-card'
      },
      request: {
        pageRequest: async ({ page, query }) => {
          const { total, data } = await pageRequest(page.offset + 1, page.limit, query);
          return { records: data, total, currentPage: page.offset, pageSize: page.limit };
        },
        addRequest: ({ form }) => {
          return addRequest(form);
        },
        editRequest: ({ form }) => {
          editRequest(form);
        },
        delRequest: ({ row }) => {
          return delRequest(row.id);
        }
      },
      toolbar: {
        show: true
      },
      actionbar: {
        show: true,
        buttons: {
          add: {
            text: '新增学员',
            title: '使用表单新增学员',
            circle: false,
            tooltip: {
              slots: {
                default() {
                  return '使用表单新增学员';
                }
              }
            }
          },
          importAdd: {
            text: 'Excel文件导入',
            title: '上传Excel文件批量导入学员',
            icon: '',
            iconRight: '',
            circle: false,
            style: {},
            disabled: false,
            tooltip: {
              slots: {
                default() {
                  return '上传Excel文件，支持xlsx 格式';
                }
              }
            },
            show: true,
            click: () => {
              context?.openModal();
            },
            order: 1
          },
          exportAdd: {
            text: '下载导入模板',
            circle: false,
            disabled: false,
            tooltip: {
              slots: {
                default() {
                  return '下载导入学员的 Excel 模板';
                }
              }
            },
            show: true,
            click: () => {
              window.location.href = importStudent;
            },
            order: 1
          }
        }
      },
      columns: {
        studentName: {
          title: '姓名',
          type: 'text',
          search: { show: true },
          column: {
            resizable: true,
            width: 60,
            align: 'center',
            fixed: 'left'
          }
        },
        phone: {
          title: '手机',
          type: 'text',
          search: { show: true },
          column: {
            resizable: true,
            width: 120,
            align: 'center',
            fixed: 'left'
          }
        },
        studentIdnumber: {
          title: '身份证号',
          type: 'text',
          search: { show: true },
          column: {
            resizable: true,
            width: 180,
            align: 'center',
            fixed: 'left'
          }
        },
        university: {
          title: '学校',
          type: 'text',
          search: { show: true },
          column: {
            resizable: true,
            width: 120,
            align: 'center',
            fixed: 'left'
          }
        },
        address: {
          title: '住址',
          type: 'text',
          search: { show: true },
          column: {
            resizable: true,
            width: 180,
            align: 'center',
            fixed: 'left'
          }
        },
        email: {
          title: '邮箱',
          type: 'text',
          search: { show: true },
          column: {
            resizable: true,
            width: 180,
            align: 'center',
            fixed: 'left'
          }
        },
        birthdate: {
          title: '生日',
          type: 'easDate',
          search: { show: true },
          column: {
            resizable: true,
            align: 'center',
            width: 120
          }
        },
        studentNumber: {
          title: '学生档案号',
          type: 'text',
          search: { show: true },
          column: {
            resizable: true,
            align: 'center',
            width: 200
          },
          form: {
            show: false
          }
        },
        enrollmentDate: {
          title: '入学时间',
          type: 'easDate',
          search: { show: true },
          column: {
            resizable: true,
            width: 100
          }
        },
        graduationDate: {
          title: '毕业时间',
          type: 'easDate',
          search: { show: true },
          column: {
            resizable: true,
            width: 100
          }
        },
        gender: {
          title: '性别',
          type: 'dict-select',
          dict: dict({
            data: [
              { value: 'M', label: '男' },
              { value: 'F', label: '女' }
            ]
          }),
          column: {
            resizable: true,
            width: 40
          }
        }
      }
    }
  };
}
export default curd;
