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

/** 监测计划 */
const OrgExamPlanList: React.FC = () => {
    const actionRef = useRef<ActionType>();

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

    const columns: ProColumns<API.ExamPlanOutput>[] = [
        {
            title: '监测全称',
            dataIndex: 'fullName',
            renderText: (v, r) => <a onClick={() => history.push(`/exam-s/plan/detail/${r.id}`)}>{v}</a>,
            hideInDescriptions: true,
        },
        {
            title: '监测名称',
            dataIndex: 'name',
            hideInSearch: true,
            hideInTable: true,
        },
        {
            title: '监测简称',
            dataIndex: 'shortName',
            hideInSearch: true,
            hideInTable: true,
        },
        {
            title: '监测状态',
            dataIndex: 'status',
            valueEnum: getDictValueEnum('exam_status', true),
            width: 80,
            align: 'center',
            hideInDescriptions: true,
        },
        {
            title: '监测学期',
            dataIndex: ['semester', 'nickShortName'],
            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 })),
            },
            width: 80,
            align: 'center',
        },
        {
            title: '监测学段',
            dataIndex: 'educationStage',
            valueEnum: getDictValueEnum('education_stage'),
            width: 80,
            align: 'center',
        },
        {
            title: '开始时间',
            dataIndex: 'beginTime',
            hideInSearch: true,
            hideInTable: true,
        },
        {
            title: '结束时间',
            dataIndex: 'endTime',
            hideInSearch: true,
            hideInTable: true,
        },


        {
            title: '备注说明',
            dataIndex: 'remark',
            hideInSearch: true,
            className: 'minw-120',
        },
    ];

    return (
        <PageContainer title={false}>
            <SuperTable<API.ExamPlanOutput>
                headerTitle="评估监测计划列表"
                actionRef={actionRef}
                columns={columns}
                scroll={{ x: 'max-content' }}
                request={async (params, sort) => {
                    return SuperTable.requestPageAgent({ params, sort }, async (p) => {
                        const res = await ExamOrgController.queryExamPlanPageList(p);
                        return res;
                    });
                }}
            />
        </PageContainer>
    );
};

export default OrgExamPlanList;
