'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useState } from 'react';
import { MoreHorizontal, Loader2 } from 'lucide-react';
import { Button } from '../../ui/button.js';
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from '../../ui/dropdown-menu.js';
import { FEATURE_ROW_ACTIONS_CONFIG } from './feature-row-actions-config.js';
const ACTION_HANDLERS = {
    start: 'onStart',
    stop: 'onStop',
    retry: 'onRetry',
    review: 'onReview',
    archive: 'onArchive',
    unarchive: 'onUnarchive',
    delete: 'onDelete',
};
export function FeatureRowActions(props) {
    const { featureId, nodeState, isLoading } = props;
    const [open, setOpen] = useState(false);
    const actions = FEATURE_ROW_ACTIONS_CONFIG[nodeState];
    if (actions.length === 0) {
        return null;
    }
    function handleActionClick(key) {
        setOpen(false);
        const handlerName = ACTION_HANDLERS[key];
        const handler = props[handlerName];
        if (typeof handler === 'function') {
            handler(featureId);
        }
    }
    return (_jsxs(DropdownMenu, { open: open, onOpenChange: setOpen, children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsx(Button, { variant: "ghost", size: "icon", className: "h-7 w-7", disabled: isLoading, "aria-label": "Actions", children: isLoading ? (_jsx(Loader2, { className: "h-4 w-4 animate-spin" })) : (_jsx(MoreHorizontal, { className: "h-4 w-4" })) }) }), _jsx(DropdownMenuContent, { align: "end", children: actions.map((action) => {
                    const Icon = action.icon;
                    return (_jsxs(DropdownMenuItem, { onClick: () => handleActionClick(action.key), className: action.key === 'delete' ? 'text-destructive focus:text-destructive' : '', children: [_jsx(Icon, { className: "mr-2 h-4 w-4" }), action.label] }, action.key));
                }) })] }));
}
