/*
 * @Author: your name
 * @Date: 2021-09-08 17:09:34
 * @LastEditTime: 2022-01-07 17:09:20
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: /MedicalWisdomCheckSys/src/components/MccsModal/index.tsx
 */




import React,{useRef,createContext} from 'react'
import {
    ModalForm,
  } from '@ant-design/pro-form';
  import type { ProFormInstance } from '@ant-design/pro-form';
  



// 卡片组件，使用参考antD pro ModalForm

type MccsModalProps = {
    title: string,
    visible: boolean,
    onVisibleChange?: (bool: boolean) => void,
    [propName: string]: any;
}

// const MccsModalContext = React.createContext({});


const MccsModalContext: React.Context<MccsModal.MccsModalContextT> = createContext({});



const MccsModal: React.FC<MccsModalProps> = (props) => {
  const { title,visible=false,children,onVisibleChange,...restProps } = props;
  const formRef = useRef<ProFormInstance>();
  // const [ifVisible, setIfVisible] = useState(false)
  return (
    <ModalForm
      title={title}
      visible={visible}
      formRef={formRef}
      onVisibleChange={onVisibleChange}
      modalProps={{
        destroyOnClose:true,
      }}
      {...restProps}
    >
      <MccsModalContext.Provider value={{formRef}}>
         {children}
      </MccsModalContext.Provider> 
   </ModalForm>
  );
};


export {MccsModal,MccsModalContext} 


