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

const DeleteContent = ({ rowId, mutate, setOpenDeleteDialog }) => {
    const [submitting, setSubmitting] = useState(false);
    const requestServer = useRequest({ notificationSuccess: true });
    const handleClick = () => {
        setSubmitting(true);
        requestServer(`${DELETE_SAFETY_AND_PRIVACY}/${rowId}`, "delete", {
            hasSidebarUpdate: true,
        })
            .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;
