import { useState } from "react";
import {
DropdownMenu,
DropdownMenuTrigger,
DropdownMenuContent,
DropdownMenuItem,
} from "@/src/components/ui/dropdown-menu";
import { Button } from "@/src/components/ui/button";
import { ChevronDown, Trash } from "lucide-react";
import { Plus } from "lucide-react";
import {
type TableAction,
type CustomDialogTableAction,
} from "@/src/features/table/types";
import { TableActionDialog } from "@/src/features/table/components/TableActionDialog";
import { type BatchExportTableName } from "@langfuse/shared";
type TableActionMenuProps = {
projectId: string;
actions: TableAction[];
tableName: BatchExportTableName;
onCustomAction?: (actionType: CustomDialogTableAction["id"]) => void;
};
const getDefaultIcon = (type: TableAction["type"]) => {
if (type === "create") {
return ;
}
return ;
};
export function TableActionMenu({
projectId,
actions,
tableName,
onCustomAction,
}: TableActionMenuProps) {
const [selectedAction, setSelectedAction] = useState(
null,
);
const [isDialogOpen, setDialogOpen] = useState(false);
const handleActionSelect = (action: TableAction) => {
if ("customDialog" in action && action.customDialog) {
onCustomAction?.(action.id);
return;
}
setSelectedAction(action);
setDialogOpen(true);
};
const handleClose = () => {
setSelectedAction(null);
setDialogOpen(false);
};
return (
<>
{actions.map((action) => (
handleActionSelect(action)}
>
{action.icon || getDefaultIcon(action.type)}
{action.label}
))}
{selectedAction && (
)}
>
);
}