/*
 * @Author: your name
 * @Date: 2021-09-15 16:25:53
 * @LastEditTime: 2021-12-31 18:19:24
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /MedicalWisdomCheckSys/src/components/MccsDrawerForm/index.tsx
 */



import React,{useState,useEffect} from 'react'
import { Drawer } from 'antd';
import {
    DrawerForm,
  } from '@ant-design/pro-form';

const MccsDrawerForm: React.FC<MccsDrawerForm.propsType> = (props)=>{
    const {children,noFormMode,onVisibleChange,drawerProps,visible,...rest} = props;
    const [drawerVisible,setDrawerVisible] = useState(false);

    useEffect(() => {
        setDrawerVisible(visible);

        return ()=>{
            setDrawerVisible(false);
        }
    }, [visible])

    return !noFormMode?(
        <DrawerForm
             onVisibleChange={onVisibleChange}
             visible={visible}
             drawerProps={{
                ...drawerProps,
                destroyOnClose:true
             }}
             {...rest}
        >
            {children}
        </DrawerForm>
    ):(
        <Drawer 
           destroyOnClose={true}
           visible={drawerVisible}
           onClose={()=>onVisibleChange(false)}
           {...rest}
        >
            {children}
        </Drawer>
    )
}

export default MccsDrawerForm
