/** @format */
import * as React from 'react';
import {Modal} from 'antd';
import Button from '../button';

import {ModalProps} from 'antd/es/modal';
import styles from './index.module.scss';
export interface ModalFormProps extends ModalProps {
    error?: null | string;
    footer?: React.ReactNode;
    loading?: boolean;
}
const ModalForm: React.FC<ModalFormProps> = props => {
    const {error = null, footer, loading = false, onCancel, onOk, children, ...rest} = props;
    return (
        <Modal
            onCancel={onCancel}
            maskClosable={false}
            destroyOnClose
            footer={
                footer !== undefined ? (
                    footer
                ) : (
                    <div className={styles.modalFooter}>
                        <span className={styles.errorMsg}>{!!error ? `错误信息:  ${error}` : ''}</span>
                        <div>
                            <Button onClick={onCancel}>取消</Button>
                            <Button loading={loading} onClick={onOk} type='primary'>
                                提交
                            </Button>
                        </div>
                    </div>
                )
            }
            {...rest}
        >
            {children}
        </Modal>
    );
};
ModalForm.displayName = 'modalFormWrapper';
export default ModalForm;
