import { SwapHoriz } from "@mui/icons-material";
import CloseIcon from "@mui/icons-material/Close";
import { Dialog, IconButton, Tooltip } from "@mui/material";
import { useState } from "react";
import EditFormContent from "./Form";

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

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