import { DELETE_REQUEST_MISSION } from "@/core/utils/routes";
import useRequest from "@/lib/hooks/useRequest";
import { Button, DialogActions, DialogContent, Stack, Typography } from "@mui/material";
import { useState } from "react";

const DeleteContent = ({ rowId, mutate, setOpenDeleteDialog }) => {
    const [submitting, setSubmitting] = useState(false);
    const requestServer = useRequest({ notificationSuccess: true });
    const handleClick = () => {
        setSubmitting(true);
        requestServer(`${DELETE_REQUEST_MISSION}/${rowId}`, "delete")
            .then(() => {
                mutate();
                setOpenDeleteDialog(false);
                setSubmitting(false);
            })
            .catch(() => {
                setSubmitting(false);
            });
    };
    return (
        <>
            <DialogContent>
                <Stack alignItems="center" spacing={2}>
                    <Typography mt={2}>آیا از حذف ماموریت اطمینان دارید؟</Typography>
                </Stack>
            </DialogContent>
            <DialogActions sx={{ justifyContent: "center", paddingBottom: 2, width: "100%" }}>
                <Button onClick={() => setOpenDeleteDialog(false)} variant="outlined" color="secondary">
                    خیر !
                </Button>
                <Button onClick={handleClick} variant="contained" color="error" disabled={submitting}>
                    {submitting ? "درحال حذف..." : "بله اطمینان دارم"}
                </Button>
            </DialogActions>
        </>
    );
};
export default DeleteContent;
