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

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

export default TableRowActions;
