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

const EditForm = ({ 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);
                    }}
                >
                    <BorderColorIcon />
                </IconButton>
            </Tooltip>
            <Dialog
                maxWidth="md"
                fullWidth
                open={openEditDialog}
                PaperProps={{
                    sx: {
                        boxShadow: "rgba(60, 64, 67, 0.3) 0px 1px 16px 0px, rgba(60, 64, 67, 0.15) 0px 1px 10px 0px",
                    },
                }}
            >
                <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 && (
                    <EditController
                        openEditDialog={openEditDialog}
                        setOpenEditDialog={setOpenEditDialog}
                        rowId={rowId}
                        row={row}
                        mutate={mutate}
                    />
                )}
            </Dialog>
        </>
    );
};
export default EditForm;
