import { IconButton, Popover, Tooltip } from "@mui/material";
import { useState } from "react";
// import DeleteIcon from "@mui/icons-material/Delete";
import TuneIcon from "@mui/icons-material/Tune";
import EditIcon from "@mui/icons-material/Edit";
import { Grid } from "../../../../components/grid/Grid";
import { useDispatch } from "react-redux";
import { DRAWER } from "../../../../lib/redux/slices/appSlice";
import { ProvinceJahadEditShare } from "../province-jahad-edit-share/ProvinceJahadEditShare";

export const ProvinceJahadSharesOperations = ({ item, updateTable }) => {
  const [anchorEl, setAnchorEl] = useState(null);
  const dispatch = useDispatch();
  const handleClick = (event) => {
    setAnchorEl(event.currentTarget);
  };

  const handleClose = () => {
    setAnchorEl(null);
  };

  const open = Boolean(anchorEl);
  const id = open ? "popover" : undefined;

  return (
    <Grid container>
      <IconButton
        aria-describedby={id}
        variant="contained"
        color="primary"
        onClick={handleClick}
      >
        <TuneIcon />
      </IconButton>
      <Popover
        anchorOrigin={{
          vertical: "bottom",
          horizontal: "right",
        }}
        transformOrigin={{
          vertical: "top",
          horizontal: "left",
        }}
        id={id}
        open={open}
        anchorEl={anchorEl}
        onClose={handleClose}
      >
        <div
          style={{ padding: "20px", display: "flex", flexDirection: "column" }}
        >
          <Tooltip title={"ویرایش"} placement="left-start">
            <IconButton
              aria-label="delete"
              color="primary"
              onClick={() => {
                handleClose();
                dispatch(
                  DRAWER({
                    title: "ویرایش اطلاعات  ",
                    right: !(window.innerWidth <= 600),
                    bottom: window.innerWidth <= 600,
                    content: (
                      <ProvinceJahadEditShare
                        item={item}
                        updateTable={updateTable}
                      />
                    ),
                  })
                );
              }}
            >
              <EditIcon />
            </IconButton>
          </Tooltip>

          {/* <Tooltip title={"حذف "} placement="left-start">
              <IconButton aria-label="delete" color="error">
                <DeleteIcon />
              </IconButton>
            </Tooltip> */}
        </div>
      </Popover>
    </Grid>
  );
};
