import { BorderColor, Close } from "@mui/icons-material";
import { Dialog, IconButton, Tooltip } from "@mui/material";
import EditController from "./EditController";
import { useState } from "react";

const Edit = ({ row, mutate }) => {
    const [openEditDialog, setOpenEditDialog] = useState(false);

    return (
        <>
            <Tooltip title="ویرایش" arrow placement="right">
                <IconButton
                    color="primary"
                    sx={{ textTransform: "unset", alignSelf: "center" }}
                    onClick={() => {
                        setOpenEditDialog(true);
                    }}
                >
                    <BorderColor />
                </IconButton>
            </Tooltip>
            <Dialog open={openEditDialog} fullWidth maxWidth="sm">
                <IconButton
                    aria-label="close"
                    onClick={() => setOpenEditDialog(false)}
                    sx={(theme) => ({
                        position: "absolute",
                        right: 8,
                        top: 8,
                        zIndex: 50,
                        color: theme.palette.grey[500],
                    })}
                >
                    <Close />
                </IconButton>
                {openEditDialog && (
                    <EditController
                        openEditDialog={openEditDialog}
                        setOpenEditDialog={setOpenEditDialog}
                        row={row}
                        mutate={mutate}
                    />
                )}
            </Dialog>
        </>
    );
};
export default Edit;
