import { App, Form, Input, Modal } from "antd"
import React from "react"
import { editCorpApi } from "../../API/corpUserAssign"
import { useAjax } from "@/Hook/useAjax"

interface Props {
    initialValues: any
    visible?: boolean
    onClose?: () => void
    onChange?: () => void
}
/**
 * 修改企业
 * @param param0 
 * @returns 
 */
const ModifyCorp: React.FC<Props> = ({ initialValues = {}, visible, onChange, onClose }) => {

    /*********************************/
    const { message } = App.useApp();
    const [form] = Form.useForm();
    const editCorp = useAjax((params) => editCorpApi(params))
    /*********************************/

    const handleOk = () => {
        form.validateFields().then(valid => {
            editCorp.run({ ...valid, corpId: initialValues.corpId }).then(res => {
                if (res) {
                    message.success('修改成功')
                    onChange?.()
                    form.resetFields()
                }
            })
        })
    }

    return <Modal
        title="修改企业"
        open={visible}
        onCancel={onClose}
        onOk={handleOk}
        confirmLoading={editCorp.loading}
    >
        <Form
            form={form}
            name="modifyCorp"
            labelAlign='left'
            labelCol={{ span: 4 }}
            initialValues={initialValues}
            colon={false}
        >
            <Form.Item name="originCorpId" label="企业ID" rules={[{ required: true, message: '请输入企业ID!' }]}>
                <Input placeholder='请输入企业ID' />
            </Form.Item>
            <Form.Item name="corpName" label="企业简称" rules={[{ required: true, message: '请输入企业简称!' }]}>
                <Input placeholder='请输入企业简称' />
            </Form.Item>
            <Form.Item name="corpFullName" label="企业全称" rules={[{ required: true, message: '请输入企业全称!' }]}>
                <Input placeholder='请输入企业全称' />
            </Form.Item>
        </Form>
    </Modal>
}


export default React.memo(ModifyCorp)