import {Button, DialogActions, DialogContent, DialogTitle, Typography} from "@mui/material";
import {DELETE_ROLE} from "@/core/data/apiRoutes";
import {useState} from "react";
import useRequest from "@/lib/app/hooks/useRequest";
import useNotification from "@/lib/app/hooks/useNotification";
import {useTranslations} from "next-intl";

const DeleteContent = ({rowId, mutate, setOpenConfirmDialog}) => {
    const t = useTranslations();
    const [isSubmitting, setIsSubmitting] = useState(false)
    const requestServer = useRequest({auth: true})
    const {update_notification} = useNotification()
    const handleSubmit = () => {
        setIsSubmitting(true)
        requestServer(`${DELETE_ROLE}/${rowId}`, 'delete').then((response) => {
            mutate()
            update_notification()
        }).catch(() => {
        }).finally(() => {
            setIsSubmitting(false)
        });
    }
    return (
        <>
            <DialogTitle>{t("DeleteDialog.delete")}</DialogTitle>
            <DialogContent>
                <Typography>{t("DeleteDialog.typography")}</Typography>
            </DialogContent>
            <DialogActions>
                <Button onClick={() => setOpenConfirmDialog(false)} variant="outlined" color="secondary"
                        disabled={isSubmitting} autoFocus>
                    {t("DeleteDialog.button-cancel")}
                </Button>
                <Button onClick={handleSubmit} variant="contained" color="primary"
                        disabled={isSubmitting}>
                    {t("DeleteDialog.button-delete")}
                </Button>
            </DialogActions>
        </>
    )
}
export default DeleteContent