import { Close, LocalShipping } from "@mui/icons-material";
import { Dialog, DialogTitle, IconButton, Tooltip } from "@mui/material";
import { useState } from "react";
import AllocationForm from "./Form";

const Allocation = ({ row, mutate }) => {
    const [openAllocationDialog, setOpenAllocationDialog] = useState(false);

    return (
        <>
            <Tooltip title="لیست خودرو های درخواستی" arrow placement="right">
                <IconButton
                    color="primary"
                    sx={{ textTransform: "unset", alignSelf: "center" }}
                    onClick={() => {
                        setOpenAllocationDialog(true);
                    }}
                >
                    <LocalShipping />
                </IconButton>
            </Tooltip>
            <Dialog open={openAllocationDialog} fullWidth maxWidth="sm">
                <IconButton
                    aria-label="close"
                    onClick={() => setOpenAllocationDialog(false)}
                    sx={(theme) => ({
                        position: "absolute",
                        right: 8,
                        top: 8,
                        zIndex: 50,
                        color: theme.palette.grey[500],
                    })}
                >
                    <Close />
                </IconButton>
                <DialogTitle>لیست خودرو های درخواستی</DialogTitle>
                {openAllocationDialog && (
                    <AllocationForm
                        requested_machines={row.original.requested_machines}
                        rowId={row.original.id}
                        mutate={mutate}
                        setOpenAllocationDialog={setOpenAllocationDialog}
                    />
                )}
            </Dialog>
        </>
    );
};
export default Allocation;
