import { SuperTable } from '@/components';
import BaseSchoolClassController from '@/services/apis/BaseSchoolClassController';
import { ActionType, PageContainer, ProColumns } from '@ant-design/pro-components';
import { useModel } from '@umijs/max';
import { useRef } from 'react';

/** 学校班级 */
const SchoolClassList: React.FC = () => {
    const actionRef = useRef<ActionType>();

    const { getDictValueEnum } = useModel('useDict');

    const columns: ProColumns<API.SchoolClassOutput>[] = [
        {
            title: '全称',
            dataIndex: 'fullName',
            width: 144,
            align: 'center',
            hideInSearch: true,
        },
        {
            title: '名称',
            dataIndex: 'name',
            width: 96,
            align: 'center',
        },
        {
            title: '简称',
            dataIndex: 'shortName',
            width: 96,
            align: 'center',
            hideInSearch: true,
        },
        {
            title: '班级号',
            dataIndex: 'classNumber',
            width: 80,
            align: 'center',
        },
        {
            title: '学段',
            dataIndex: 'educationStage',
            valueEnum: getDictValueEnum('education_stage'),
            width: 96,
            align: 'center',
            hideInSearch: true,
        },
        {
            title: '级（入学年份）',
            dataIndex: 'gradeBeginYear',
            width: 112,
            align: 'center',
            renderText: (v) => `${v}级`,
        },
        {
            title: '届（毕业年份）',
            dataIndex: 'gradeEndYear',
            width: 112,
            align: 'center',
            renderText: (v) => `${v}届`,
            hideInSearch: true,
        },
        {
            title: '备注',
            dataIndex: 'remark',
            hideInSearch: true,
        },
    ];

    return (
        <PageContainer title={false} childrenContentStyle={{ paddingTop: 0 }}>
            <SuperTable<API.SchoolClassOutput>
                headerTitle="班级列表"
                actionRef={actionRef}
                columns={columns}
                request={async (params, sort) => {
                    return SuperTable.requestPageAgent({ params, sort }, async (p) => {
                        const res = await BaseSchoolClassController.queryPageList({ ...p });
                        return res;
                    });
                }}
            />
        </PageContainer>
    );
};

export default SchoolClassList;
