
import { useRef, useState, useEffect } from 'react';
import { connect } from '@umijs/max';
import type { ActionType, ProFormInstance } from '@ant-design/pro-components';
import {
    ProForm,
    ProFormTextArea,
} from '@ant-design/pro-components';
import { ConfigProvider, Flex, Space, Modal, message, Image, Row, Col, Switch, Form, Typography } from 'antd';
import { GetTokenizerGet, PostTokenizerModify } from '@/apis/api';
import { Imageprefix } from '@/constants';
import UploadModel from '@/components/Common/upload';


const selectfieldNames = { label: 'name', value: 'id' };


const PagesMainInformationArticleCreate: React.FC = ({ dispatch, dictModel, openModel, id }: any) => {
    const formRef = useRef<ProFormInstance>();
    const [openPreview, setOpenPreview] = useState(false);
    const [detail, setDetail] = useState<PermissionType.account | null>(null)

    useEffect(() => {
        setOpenPreview(openModel.openModal)
    }, [openModel.openModal])

    const [uploadedFilephotoName, setUploadedFilephotoName] = useState<string>('');
    const handleFileUploadedphoto = (filename: string) => {
        setUploadedFilephotoName(filename);
    };

    return (
        <>
            <ConfigProvider
                theme={{
                    token: {
                        colorPrimary: '#4FBE70',
                    }
                }}
            >
                <Modal
                    open={openPreview}
                    title='更新分词器'
                    centered
                    maskClosable={false}
                    footer={null}
                    destroyOnClose
                    width={1000}
                    onCancel={() => {
                        dispatch({ type: 'openModel/getOpenModal', payload: false })
                    }}
                >
                    <ProForm<PermissionType.account>
                        formRef={formRef}
                        request={async () => {
                            if (id) {
                                let res = await GetTokenizerGet({ id: id })
                                setDetail(res.data)
                                return res.data;
                            } else {
                                return {
                                    text: ''
                                }
                            }
                        }}
                        submitter={{
                            searchConfig: {
                                resetText: '取消',
                                submitText: '保存',
                            },
                            render: (_, dom) => { return <Flex justify='flex-end'> <Space>{dom}</Space></Flex> },
                            onReset: () => {
                                setDetail(null)
                                dispatch({ type: 'openModel/getOpenModal', payload: false })
                            }
                        }}
                        onFinish={async (values) => {
                            let res = await PostTokenizerModify(values)
                            message.success('提交成功')
                            dispatch({ type: 'openModel/getOpenModal', payload: false })
                        }}
                    >
                        <ProFormTextArea
                            name="text"
                            label="分词内容"
                            placeholder="请输入分词内容"
                            rules={[{ required: true, message: '请输入分词内容' }]}
                        />


                    </ProForm>
                </Modal>
            </ConfigProvider>
        </>
    );
};



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