
import { useRef, useState, useEffect } from 'react';
import { connect } from '@umijs/max';
import type { ActionType, ProFormInstance } from '@ant-design/pro-components';
import {
    ProFormText,
    ProFormSelect,
    ProForm
} from '@ant-design/pro-components';
import { ConfigProvider, Flex, Space, Modal, message } from 'antd';
import { PostCustomerUpdate, GetCustomerDetail } from '@/apis/api';

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

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

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

    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<CompanyType.Department>
                        formRef={formRef}
                        request={async () => {
                            if (id) {
                                let res = await GetCustomerDetail({ id: id.id })
                                return res.data;
                            }
                        }}
                        submitter={{
                            searchConfig: {
                                resetText: '取消',
                                submitText: '保存',
                            },
                            render: (_, dom) => { return <Flex justify='flex-end'> <Space>{dom}</Space></Flex> },
                            onReset: () => {
                                setDetail(null)
                                setOpenPreview(false)
                            }
                        }}
                        onFinish={async (values) => {
                            console.log(values)
                            values.id = id.id;
                            let res = await PostCustomerUpdate(values)
                            message.success('提交成功')
                            dispatch({ type: 'openModel/getOpenModal', payload: false })
                        }}
                    >
                        
                        <ProFormText
                            name="mobile"
                            label="手机号"
                            placeholder="请输入手机号"
                        />
                        <ProFormText
                            name="email"
                            label="邮箱"
                            placeholder="请输入邮箱"
                        />
                      

                    </ProForm>

                </Modal>
            </ConfigProvider>

        </>



    );
};



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