import {Dialog, DialogTitle, IconButton,  Tooltip} from "@mui/material";
import {useTranslations} from "next-intl";
import {useState , useEffect} from "react";
import ConfirmContent from "./ConfirmContent";
import CallMadeIcon from '@mui/icons-material/CallMade';
const Confirm = ({rowId, mutate}) => {
    const t = useTranslations();
    const [openConfirmDialog, setOpenConfirmDialog] = useState(false);
    const [dialogSize, setDialogSize] = useState('sm');

    useEffect(() => {
        if (!openConfirmDialog) {
            setDialogSize('sm');
        }
    }, [openConfirmDialog]);

    const handleSizeChangeClick = (size) => {
        setDialogSize(size);
    };

    return (
        <>
            <Tooltip title={t("ConfirmDialog.confirm")}>
                <IconButton
                    color="primary"
                    onClick={() => {
                        setOpenConfirmDialog(true);
                    }}
                >
                    <CallMadeIcon/>
                </IconButton>
            </Tooltip>
            <Dialog fullWidth open={openConfirmDialog}
                    PaperProps={{sx: {transition: 'all .3s', boxShadow: 'rgba(60, 64, 67, 0.3) 0px 1px 16px 0px, rgba(60, 64, 67, 0.15) 0px 1px 10px 0px'}}}  maxWidth={dialogSize}>
                <DialogTitle>{t("TransportationAssistance.confirm")}</DialogTitle>
                <ConfirmContent mutate={mutate} rowId={rowId} setOpenConfirmDialog={setOpenConfirmDialog}  handleSizeChangeClick={handleSizeChangeClick}/>
            </Dialog>
        </>
    )

}
export default Confirm;