import type { CreateCrudOptionsRet } from '@fast-crud/fast-crud';
import { dict } from '@fast-crud/fast-crud';
import { queryAttendance, queryClassAll, queryClassRoomList } from './api';
function curd(): CreateCrudOptionsRet {
  return {
    crudOptions: {
      container: {
        is: 'fs-layout-card'
      },
      request: {
        pageRequest: async ({ page, query }) => {
          const { total, data } = await queryAttendance(page.offset + 1, page.limit, query);
          return { records: data, total, currentPage: page.offset, pageSize: page.limit };
        }
      },
      toolbar: {
        show: true
      },
      actionbar: {
        show: false
      },
      rowHandle: {
        show: false,
        buttons: {
          remove: {
            show: false
          },
          add: {
            show: false
          },
          edit: {
            show: false
          },
          view: {
            show: false
          }
        }
      },
      columns: {
        id: {
          title: '排课ID',
          type: 'text',
          search: {
            show: true
          },
          column: {
            show: true
          }
        },
        checkinDate: {
          title: '签到日期',
          type: 'text',
          search: {
            show: false
          },
          column: {
            show: false
          }
        },
        morning: {
          title: '上午',
          type: 'dict-select',
          dict: dict({
            data: [
              // a  表示正常出勤,   b  表示迟到、早退, c  表示旷课, d  表示请假, e表示无效
              { value: 'a', label: '正常' },
              { value: 'b', label: '迟到/早退' },
              { value: 'c', label: '旷课' },
              { value: 'd', label: '请假' },
              { value: 'e', label: '无效' }
            ]
          }),
          search: {
            show: false
          },
          column: {
            resizable: true,
            align: 'center',
            fixed: 'left'
          }
        },
        afternoon: {
          title: '下午',
          type: 'dict-select',
          dict: dict({
            data: [
              // a  表示正常出勤,   b  表示迟到、早退, c  表示旷课, d  表示请假, e表示无效
              { value: 'a', label: '正常' },
              { value: 'b', label: '迟到/早退' },
              { value: 'c', label: '旷课' },
              { value: 'd', label: '请假' },
              { value: 'e', label: '无效' }
            ]
          }),
          search: {
            show: false
          },
          column: {
            resizable: true,
            align: 'center',
            fixed: 'left'
          }
        },
        month: {
          title: '月份',
          type: 'text',
          search: {
            show: true
          },
          column: {
            resizable: true,
            width: 20,
            align: 'center',
            fixed: 'left'
          }
        },
        studentId: {
          title: '学生ID',
          type: 'text',
          search: {
            show: true
          },
          column: {
            resizable: true,
            align: 'center',
            fixed: 'left'
          }
        },
        type: {
          title: '类型',
          type: 'text',
          search: {
            show: false
          },
          column: {
            resizable: true,
            align: 'center',
            fixed: 'left'
          }
        },
        className: {
          title: '班级',
          search: {
            show: true
          },
          column: {
            resizable: true,
            align: 'center',
            fixed: 'left'
          },
          type: 'dict-select',
          dict: dict({
            async getData() {
              const result = await queryClassAll();
              return result.data?.map(r => {
                return {
                  label: r.name,
                  value: r.id
                };
              }) as any[];
            }
          })
        },
        startTime: {
          title: '开始时间',
          type: 'easDateTime',
          search: {
            show: true
          },
          column: {
            resizable: true,
            align: 'center',
            fixed: 'left'
          }
        },
        endTime: {
          title: '结束时间',
          type: 'easDateTime',
          search: {
            show: true
          },
          column: {
            resizable: true,
            align: 'center',
            fixed: 'left'
          }
        },
        categoryName: {
          title: '类别名称',
          type: 'text',
          search: {
            show: false
          },
          column: {
            resizable: true,
            align: 'center',
            fixed: 'left'
          }
        },
        subjectsName: {
          title: '科目名称',
          type: 'text',
          search: {
            show: false
          },
          column: {
            resizable: true,
            align: 'center',
            fixed: 'left'
          }
        },
        studentName: {
          title: '姓名',
          type: 'text',
          search: {
            show: true
          },
          column: {
            resizable: true,
            align: 'center',
            fixed: 'left'
          }
        },
        teacherName: {
          title: '教师姓名',
          type: 'text',
          search: {
            show: false
          },
          column: {
            resizable: true,
            align: 'center',
            fixed: 'left'
          }
        },
        roomName: {
          search: {
            show: true
          },
          title: '教室',
          type: 'dict-select',
          dict: dict({
            async getData() {
              const result = await queryClassRoomList(1, 100, {});
              return result.data?.map(r => {
                return {
                  label: r.name,
                  value: r.id
                };
              }) as any[];
            }
          })
        }
      }
    }
  };
}
export default curd;
