import { toSelectOptions } from '@/common/converter';
import { SuperTable } from '@/components';
import ExamPaperController from '@/services/apis/ExamPaperController';
import { ExamPaperWriterType } 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 TwclExamPlanList: React.FC = () => {
    const actionRef = useRef<ActionType>();

    const { token } = theme.useToken();

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

    const columns: ProColumns<API.ExamPaperTodoPlanOutput>[] = [
        {
            title: '计划名称',
            dataIndex: 'examPlanFullName',
            // width: 480,
            search: {
                transform: (v) => ({ name: v }),
            },
            render: (v) => {
                return `${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: 'examPlanStatus',
            valueEnum: getDictValueEnum('exam_status', true),
            width: 80,
            align: 'center',
        },
        {
            title: '总数量',
            dataIndex: 'totalCount',
            width: 80,
            align: 'center',
            hideInSearch: true,
            renderText: (v) => v ? v : null,
        },
        {
            title: '未提交',
            dataIndex: 'twclUnsubmitCount',
            width: 80,
            align: 'center',
            hideInSearch: true,
            renderText: (v) => v ? <Typography.Text type="warning">{v}</Typography.Text> : null,
        },
        {
            title: '已提交',
            dataIndex: 'twclSubmittedCount',
            width: 80,
            align: 'center',
            hideInSearch: true,
            renderText: (v) => v ? <Typography.Text type="success">{v}</Typography.Text> : null,
        },
        {
            title: '操作',
            valueType: 'option',
            width: 80,
            align: 'center',
            fixed: 'right',
            render: (_, r) => {
                return (
                    <a onClick={() => history.push(`/exam-c/tr-twcl/course/${r.examPlanId}`)}>
                        去处理
                        <RightOutlined style={{ marginLeft: token.marginXXS }} />
                    </a>
                );
            },
        },
    ];

    return (
        <PageContainer title={false} >
            <SuperTable<API.ExamPaperTodoPlanOutput>
                toolbar={{
                    title: '计划列表',
                }}
                rowKey="examPlanId"
                actionRef={actionRef}
                columns={columns}
                // scroll={{ x: 'max-content' }}
                columnEmptyText=""
                request={async (params, sort) => {
                    return SuperTable.requestPageAgent({ params, sort }, async (p) => {
                        const res = await ExamPaperController.queryWriterExamPlanPageList({ ...p, writerType: ExamPaperWriterType.TWCL });
                        return res;
                    });
                }}
            />
        </PageContainer>
    );
};

export default TwclExamPlanList;
