import { toSelectOptions } from '@/common/converter';
import { SuperTable } from '@/components';
import ExamSpecialStudentAuditController from '@/services/apis/ExamSpecialStudentAuditController';
import { ExamStatus } from '@/services/enums';
import { RightOutlined } from '@ant-design/icons';
import { ActionType, PageContainer, ProColumns } from '@ant-design/pro-components';
import { history, useModel } from '@umijs/max';
import { Typography, theme } from 'antd';
import { useRef } from 'react';

/** 监测特殊学生审核计划列表 */
const ExamSpecialStudentAuditPlanList: React.FC = () => {
    const actionRef = useRef<ActionType>();

    const { getDictValueEnum } = useModel('useDict');
    const { baseData } = useModel('useBaseData');
    const { token } = theme.useToken();

    const columns: ProColumns<API.ExamPlanAuditOutput>[] = [
        {
            title: '计划名称',
            dataIndex: 'fullName',
            // width: 480,
            search: {
                transform: (v) => ({ name: v }),
            },
        },
        {
            title: '监测学期',
            dataIndex: 'semesterId',
            search: {
                transform: (v) => v ? ({ semesterId: JSON.parse(v) }) : v,
            },
            valueType: 'select',
            fieldProps: {
                options: toSelectOptions(baseData?.semesters ?? [], (item) => ({ key: item.id, label: item.nickShortName, value: item.id })),
            },
            hideInTable: true,
            order: 90,
        },
        {
            title: '计划状态',
            dataIndex: 'status',
            valueEnum: getDictValueEnum('exam_status', true),
            width: 80,
            align: 'center',
        },
        {
            title: '学校数量',
            dataIndex: 'orgCount',
            width: 80,
            align: 'center',
            hideInSearch: true,
            renderText: (v) => v ? v : null,
        },
        {
            title: '总人数',
            dataIndex: 'totalCount',
            width: 80,
            align: 'center',
            hideInSearch: true,
            renderText: (v) => v ? v : null,
        },
        {
            title: '前期已认定',
            dataIndex: 'preIdentifiedCount',
            width: 88,
            align: 'center',
            hideInSearch: true,
            renderText: (v) => v ? v : null,
        },
        // {
        //     title: '待审核',
        //     dataIndex: 'auditCount',
        //     width: 80,
        //     align: 'center',
        //     hideInSearch: true,
        //     render: (_, r) => {
        //         const v = r.auditCount - r.preIdentifiedCount;
        //         if (v <= 0) {
        //             return null;
        //         }
        //         return (<Typography.Text type="warning">{v}</Typography.Text>);
        //     },
        // },
        {
            title: '待审核',
            dataIndex: 'auditCount',
            width: 80,
            align: 'center',
            hideInSearch: true,
            renderText: (v) => v ? <Typography.Text type="warning">{v}</Typography.Text> : null,
        },
        {
            title: '已通过',
            dataIndex: 'approvedCount',
            width: 80,
            align: 'center',
            hideInSearch: true,
            renderText: (v) => v ? <Typography.Text type="success">{v}</Typography.Text> : null,
        },
        {
            title: '已驳回',
            dataIndex: 'rejectedCount',
            width: 80,
            align: 'center',
            hideInSearch: true,
            renderText: (v, r) => r.rejectedCount > 0 ? <Typography.Text type="danger">{v}</Typography.Text> : null,
        },
        {
            title: '操作',
            valueType: 'option',
            width: 80,
            align: 'right',
            fixed: 'right',
            render: (_, r) => {
                return (
                    <a onClick={() => history.push(`/exam-c/sp-stu-audit/list/${r.id}`)}>
                        {r.status === ExamStatus.ACTIVE ? '去处理' : '去查看'}
                        <RightOutlined style={{ marginLeft: token.marginXXS }} />
                    </a>
                );
            },
        },
    ];

    return (
        <PageContainer title={false} >
            <SuperTable<API.ExamPlanAuditOutput>
                toolbar={{
                    title: '监测计划',
                }}
                actionRef={actionRef}
                columns={columns}
                scroll={{ x: 'max-content' }}
                columnEmptyText=""
                request={async (params, sort) => {
                    return SuperTable.requestPageAgent({ params, sort }, async (p) => {
                        const res = await ExamSpecialStudentAuditController.queryExamPlanPageList({ ...p });
                        return res;
                    });
                }}
            />
        </PageContainer>
    );
};

export default ExamSpecialStudentAuditPlanList;
