import ThumbUpAltIcon from "@mui/icons-material/ThumbUpAlt";
import ThumbDownIcon from "@mui/icons-material/ThumbDown";
import { Box, IconButton } from "@mui/material";
import { useContext } from "react";
import { DataTableContext } from "@/lib/app/contexts/DataTableContext";
import ConfirmForm from "./Form/ConfirmForm";
import RejectForm from "./Form/RejectForm";

const TableRowActions = ({ row }) => {
  const {
    openConfirmDialog,
    openRejectDialog,
    handleOpenConfirmDialog,
    handleOpenRejectDialog,
    handleCloseConfirmDialog,
    handleCloseRejectDialog,
    rowId,
    confirmData,
    rejectData,
  } = useContext(DataTableContext);
  return (
    <Box sx={{ display: "flex", flexWrap: "nowrap", gap: "8px" }}>
      <IconButton
        color="primary"
        onClick={() => {
          handleOpenConfirmDialog(row);
        }}
      >
        <ThumbUpAltIcon />
      </IconButton>
      {openConfirmDialog && (
        <ConfirmForm
          rowId={rowId}
          open={openConfirmDialog}
          handleClose={handleCloseConfirmDialog}
          confirmData={confirmData}
        />
      )}
      <IconButton color="primary" onClick={() => handleOpenRejectDialog(row)}>
        <ThumbDownIcon />
      </IconButton>
      {openRejectDialog && (
        <RejectForm
          rowId={rowId}
          open={openRejectDialog}
          handleClose={handleCloseRejectDialog}
          rejectData={rejectData}
        />
      )}
    </Box>
  );
};

export default TableRowActions;
