import { SuperTable } from '@/components';
import ExamPlanController from '@/services/apis/ExamPlanController';
import ExamSpecialStudentAuditController from '@/services/apis/ExamSpecialStudentAuditController';
import { DataReportStatus } from '@/services/enums';
import { RightOutlined } from '@ant-design/icons';
import { ActionType, PageContainer, ProColumns } from '@ant-design/pro-components';
import { history, useModel, useParams } from '@umijs/max';
import { useRequest } from 'ahooks';
import { Typography, theme } from 'antd';
import { useRef } from 'react';

/** 特殊学生审核监测计划列表 */
const ExamSpecialStudentAuditList: React.FC = () => {
    const reqParams = useParams() as unknown as { examPlanId: number };

    const actionRef = useRef<ActionType>();

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

    const { data, loading } = useRequest(() => {
        return ExamPlanController.getById({ id: reqParams.examPlanId });
    });

    const columns: ProColumns<API.ExamPlanOrgAuditOutput>[] = [
        {
            title: '学校名称',
            dataIndex: 'sysOrgFullName',
            hideInDescriptions: true,
            order: 99,
            search: {
                transform: (v) => ({ sysOrgName: v }),
            },
        },
        {
            title: '上报状态',
            dataIndex: 'dataReportStatus',
            valueEnum: getDictValueEnum('data_report_status', true),
            width: 80,
            align: 'center',
            hideInSearch: true,
            // render: (v, r) => {
            //     const drs = dataReportStatusDict[r.dataReportStatus];
            //     return (
            //         <>
            //             <Space size="small">
            //                 <StatusIcon
            //                     filled
            //                     status={drs?.antStatus as any ?? 'warning'}
            //                 />
            //                 {drs?.name ?? '未上报'}
            //             </Space>
            //         </>
            //     );
            // },
        },
        {
            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: 'center',
            fixed: 'right',
            render: (_, r) => {
                if (r.dataReportStatus === DataReportStatus.UNREPORT) {
                    return null;
                }
                return (
                    <a onClick={() => history.push(`/exam-c/sp-stu-audit/org/${r.sysOrgId}/${r.examPlanId}`)}>
                        {r.auditCount > 0 && r.dataReportStatus === DataReportStatus.REPORTED ? '去审核' : '去查看'}
                        <RightOutlined style={{ marginLeft: token.marginXXS }} />
                    </a>
                );
            },
        },
    ];

    return (
        <PageContainer
            title={`${data?.fullName ?? ''} - 特殊学生审核学校名单`}
            onBack={() => history.back()}
            loading={loading}
        >
            <SuperTable<API.ExamPlanOrgAuditOutput>
                toolbar={{
                    title: '学校列表',
                    // actions: [
                    //     <Button key="view" type="primary">特殊学生汇总名单</Button>,
                    //     <Button key="confirm">确定审核结果</Button>,
                    // ],
                }}
                actionRef={actionRef}
                columns={columns}
                scroll={{ x: 'max-content' }}
                rowKey="rowNumber"
                columnEmptyText=""
                request={async (params, sort) => {
                    return SuperTable.requestPageAgent({ params, sort }, async (p) => {
                        const res = await ExamSpecialStudentAuditController.queryOrgAuditPageList({
                            ...p,
                            examPlanId: reqParams.examPlanId,
                        });
                        return res;
                    });
                }}
            />
        </PageContainer>
    );
};

export default ExamSpecialStudentAuditList;
