import React, { useEffect } from 'react';

import Button from '@mui/material/Button';
import Dialog from '@mui/material/Dialog';
import DialogActions from '@mui/material/DialogActions';
import DialogContent from '@mui/material/DialogContent';
import DialogContentText from '@mui/material/DialogContentText';
import DialogTitle from '@mui/material/DialogTitle';
import Slide from '@mui/material/Slide';

const Transition = React.forwardRef(function Transition(props, ref) {
  return <Slide direction="up" ref={ref} {...props} />;
});

export default function AlertDialogSlide({confirm, setConfirm}) {  

    useEffect(function () {        
        if( confirm ) {
            setConfirm({
                ...confirm,
                //open: !confirm.open && false,
                //title: !confirm.title && "중요",
                ///yes: !confirm.yes && "예",
                //no: !confirm.no && "아니요",
            });
        }        
    // eslint-disable-next-line react-hooks/exhaustive-deps
    }, []);


    const handleClose = () => {
        setConfirm({...confirm, open: false});
    };

    return (
        <React.Fragment>
            {confirm &&
                <Dialog
                    open={ confirm.open }
                    TransitionComponent={Transition}
                    keepMounted
                    onClose={handleClose}
                    aria-describedby="alert-dialog-slide-description"
                >
                    <DialogTitle>{confirm.title ? confirm.title : "알림"}</DialogTitle>
                    <DialogContent>
                    <DialogContentText id="alert-dialog-slide-description">{confirm.body}</DialogContentText>
                    </DialogContent>
                    <DialogActions>
                        <Button onClick={() => {handleClose(); confirm.yesCallback && confirm.yesCallback(confirm.yesCallbackParams);}}>{confirm.yes ? confirm.yes : "예"}</Button>
                        <Button onClick={() => {handleClose(); confirm.noCallback && confirm.noCallback(confirm.noCallbackParams);}}>{confirm.no ? confirm.no : "아니요"}</Button>
                    </DialogActions>
                </Dialog>
            }
      
    </React.Fragment>
  );
}