import { useRef, useState, useEffect } from 'react';
import { connect } from '@umijs/max';
import type { ActionType, ProFormInstance } from '@ant-design/pro-components';
import {
    ProFormText,
    ProFormSegmented,
    ProFormSelect,
    ProForm,
    ProFormDatePicker,
    ProFormCascader,
    ProFormDigit
} from '@ant-design/pro-components';
import { ConfigProvider, Flex, Space, Modal, message, Image, Row, Col, Switch, Form, Typography } from 'antd';
import { PostJobapplicantAdddesirebase, PostJobapplicantDeldesirebase, PostJobapplicantUpdatedesirebase, PostJobapplicantDesirebasedetail } from '@/apis/api';

const selectfieldNames = { label: 'name', value: 'id' };
const PagesMainJobseekerListResumeIntentionBasic: React.FC = ({ dispatch, dictModel, openModel, id }: any) => {
    const formRef = useRef<ProFormInstance>();
    const [detail, setDetail] = useState<ResumeType.intentionBasic | null>(null)

    useEffect(() => {
        dispatch({ type: 'dictModel/getList', payload: { code: 2019, type: 'setJobTypeList' } })
        dispatch({ type: 'dictModel/getList', payload: { code: 2020, type: 'setTalentTypeList' } })
        dispatch({ type: 'dictModel/getList', payload: { code: 2021, type: 'setWorkExperienceList' } })
        dispatch({ type: 'dictModel/getList', payload: { code: 2005, type: 'setScaleList' } })
        dispatch({ type: 'dictModel/getList', payload: { code: 2013, type: 'setAvailableDateList' } })
        dispatch({ type: 'dictModel/getList', payload: { code: 2014, type: 'setTitleList' } })
        dispatch({ type: 'dictModel/getList', payload: { code: 2015, type: 'setSkillCertificationeList' } })
        dispatch({ type: 'dictModel/getList', payload: { code: 2016, type: 'setAccommodationRequirementList' } })
        dispatch({ type: 'dictModel/getList', payload: { code: 2017, type: 'setHolidayRestList' } })
    }, [])

    return (
        <>
            <ConfigProvider
                theme={{
                    token: {
                        colorPrimary: '#4FBE70',
                    }
                }}
            >
                <ProForm<ResumeType.intentionBasic>
                    formRef={formRef}
                    request={async () => {
                        if (id) {
                            let res = await PostJobapplicantDesirebasedetail({ customer_id: id.customer_id })
                            setDetail(res.data)
                            return res.data;
                        }
                    }}
                    submitter={{
                        searchConfig: {
                            resetText: '取消',
                            submitText: '保存',
                        },
                        render: (_, dom) => { return <Flex justify='flex-end'> <Space>{dom}</Space></Flex> },
                        onReset: () => {

                        }
                    }}
                    onFinish={async (values) => {
                        console.log(values)
                        if (detail) {
                            values.id = detail.id;
                            values.customer_id = detail.customer_id;
                            let res = await PostJobapplicantUpdatedesirebase(values)
                            message.success('提交成功')
                        } else {
                            values.customer_id = id.customer_id;
                            let res = await PostJobapplicantAdddesirebase(values)
                            message.success('提交成功')
                        }
                    }}
                >
                    <Row gutter={[16, 16]}>
                        <Col span={24}>
                            <ProFormText
                                label="其他职位"
                                name="other_positions"
                                placeholder="请输入其他职位"
                            />
                        </Col>
                        <Col span={8}>
                            <ProFormSelect
                                name="job_type"
                                label="求职类型"
                                fieldProps={{
                                    fieldNames: selectfieldNames,
                                    placeholder: '请选择求职类型'
                                }}
                                options={dictModel.jobTypeList}
                                rules={[{ required: true, message: '请选择求职类型' }]}
                            />
                        </Col>
                        <Col span={8}> 
                            <ProFormSelect
                                name="talent_type"
                                label="人才类型"
                                fieldProps={{
                                    fieldNames: selectfieldNames,
                                    placeholder: '请选择人才类型'
                                }}
                                options={dictModel.talentTypeList}
                                rules={[{ required: true, message: '请选择人才类型' }]}

                            />
                        </Col>
                        <Col span={8}>
                            <ProFormSelect
                                name="work_experience"
                                label="工作经验"
                                fieldProps={{
                                    fieldNames: selectfieldNames,
                                    placeholder: '请选择工作经验'
                                }}
                                options={dictModel.workExperienceList}
                                rules={[{ required: true, message: '请选择工作经验' }]}

                            />
                        </Col>
                        <Col span={8}>
                            <ProFormSelect
                                name="salary_range"
                                label="月薪要求范围"
                                fieldProps={{
                                    fieldNames: selectfieldNames,
                                    placeholder: '请选择月薪要求范围'
                                }}
                                options={dictModel.scaleList}
                                rules={[{ required: true, message: '请选择月薪要求范围' }]}

                            />
                        </Col>
                        <Col span={8}>
                            <ProFormSelect
                                name="available_date"
                                label="可到职日期"
                                fieldProps={{
                                    fieldNames: selectfieldNames,
                                    placeholder: '请选择可到职日期'
                                }}
                                options={dictModel.availableDateList}
                                rules={[{ required: true, message: '请选择可到职日期' }]}

                            />
                        </Col>
                        <Col span={8}>
                            <ProFormSelect
                                name="title_requirement"
                                label="职称要求"
                                fieldProps={{
                                    fieldNames: selectfieldNames,
                                    placeholder: '请选择职称要求'
                                }}
                                options={dictModel.titleList}
                            />
                        </Col>
                        <Col span={8}>
                            <ProFormSelect
                                name="skill_certification"
                                label="技能认证"
                                fieldProps={{
                                    fieldNames: selectfieldNames,
                                    placeholder: '请选择技能认证'
                                }}
                                options={dictModel.skillCertificationeList}
                            />
                        </Col>
                        <Col span={8}>
                            <ProFormSelect
                                name="accommodation_requirement"
                                label="食宿要求"
                                fieldProps={{
                                    fieldNames: selectfieldNames,
                                    placeholder: '请选择食宿要求'
                                }}
                                options={dictModel.accommodationRequirementList}
                            />
                        </Col>
                        <Col span={8}>
                            <ProFormSelect
                                name="holiday_rest"
                                label="节假日休息情况"
                                fieldProps={{
                                    fieldNames: selectfieldNames,
                                    placeholder: '请选择节假日休息情况'
                                }}
                                options={dictModel.holidayRestList}
                            />
                        </Col>
                    </Row>
                </ProForm>
            </ConfigProvider>
        </>
    );
};



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