import React from 'react';
import Snackbar from '@material-ui/core/Snackbar';
import {Image} from "react-bootstrap";
import MuiAlert, {AlertProps} from '@material-ui/lab/Alert';

function Alert(props: AlertProps) {
    return <MuiAlert elevation={6} variant="filled" {...props} />;
}

export function SimpleSnackbar(props:Readonly<{message:string;duration:number;onClose:Function }>) {


    const [open, setOpen] = React.useState(true);

    const handleClose = (event: React.SyntheticEvent | React.MouseEvent, reason?: string) => {
        if (reason === 'clickaway') {
            return;
        }

        setOpen(false);

        props.onClose()
    };

    return (
            <Snackbar
                open={open}
                autoHideDuration={props.duration}
                onClose={handleClose}
                action={
                    <React.Fragment>
                        <Image className="closeIcon20" src="close.svg" onClick={handleClose}/>
                    </React.Fragment>
                }
            >
                <Alert  severity="success" onClick={handleClose}>
                    {props.message}
                </Alert>
            </Snackbar>
    );
}
