import { Box } from "@mui/material";
import DeleteForm from "./DeleteForm";
import RejectForm from "./RejectForm";
import ConfirmForm from "./ConfirmForm";
import RestoreForm from "./RestoreForm";
import { usePermissions } from "@/lib/hooks/usePermissions";

const RowActions = ({ row, mutate }) => {
    const { data: userPermissions } = usePermissions();
    const hasDeletePermission = userPermissions.includes("delete-road-item");
    const hasRestorePermission = userPermissions.includes("restore-road-item");
    return (
        <Box sx={{ display: "flex", gap: 1 }}>
            {row.original.status === 0 && row.original.can_supervise === 1 && (
                <ConfirmForm mutate={mutate} rowId={row.getValue("id")} />
            )}
            {row.original.status === 0 && row.original.can_supervise === 1 && (
                <RejectForm mutate={mutate} rowId={row.getValue("id")} />
            )}
            {hasRestorePermission && row.original.status !== 0 && (
                <RestoreForm mutate={mutate} rowId={row.getValue("id")} />
            )}
            {hasDeletePermission && <DeleteForm mutate={mutate} rowId={row.getValue("id")} />}
        </Box>
    );
};
export default RowActions;
