import { useRef, useState, useEffect } from 'react';
import { connect } from '@umijs/max';
import type { ActionType} from '@ant-design/pro-components';
import {
    ProTable
} from '@ant-design/pro-components';
import { Button,  ConfigProvider, Image } from 'antd';
import { GetTokenizerGet, PostTokenizerModify } from '@/apis/api';
import { Imageprefix } from '@/constants';

const PagesMainInformationArticleTable: React.FC = ({ dispatch,getId, openModel }: any) => {
    const actionRef = useRef<ActionType>();
    const [list, setList] = useState<object[]>([])
    const setId = (id: number) => {
        getId(id)
    }

    useEffect(() => {
        if (!openModel.openModal) {
            actionRef.current.reload();
        }
    }, [openModel.openModal])
    return (
        <>
            <ConfigProvider
                theme={{
                    token: {
                        colorPrimary: '#4FBE70',
                        colorLink: '#4FBE70',
                    }
                }}
            >

                <ProTable
                    actionRef={actionRef}
                    dataSource={list}
                    search={false}
                    columns={[
                        {
                            title: '分词内容',
                            dataIndex: 'text'
                        },
                        {
                            title: '操作',
                            key: 'option',
                            valueType: 'option',
                            fixed: 'right',
                            render: (_, record, action) => [
                                <Button key='1' type='link' onClick={() => {
                                    dispatch({ type: 'openModel/getOpenModal', payload: true })
                                }}>更新分词器</Button>
                            ],
                        },
                    ]}
                    rowKey="id"
                    request={async (params = {} as Record<string, any>) =>
                        GetTokenizerGet().then(res => {
                            setList([{text: res.data.text}])
                        })
                    }
                    headerTitle="分词器"
                />
            </ConfigProvider>

        </>



    );
};


export default connect(({ dictModel , openModel}: any) => ({
    dictModel,
    openModel
}))(PagesMainInformationArticleTable);