import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
/**
 * @license
 * Copyright 2025 Vybestack LLC
 * SPDX-License-Identifier: Apache-2.0
 */
import { useState, useCallback } from 'react';
import { Box, Text, useInput } from 'ink';
import { RadioButtonSelect } from './shared/RadioButtonSelect.js';
import { Colors } from '../colors.js';
export const ToolsDialog = ({ tools, action, disabledTools, onSelect, onClose, }) => {
    const [selectedIndex, setSelectedIndex] = useState(0);
    // Filter tools based on action
    const availableTools = tools.filter((tool) => {
        if (action === 'disable') {
            return !disabledTools.includes(tool.name);
        }
        else {
            return disabledTools.includes(tool.name);
        }
    });
    // Create items for RadioButtonSelect
    const items = availableTools.map((tool) => ({
        label: tool.displayName,
        value: tool.name,
    }));
    const handleSelect = useCallback((value) => {
        onSelect(value);
    }, [onSelect]);
    const handleHighlight = useCallback((value) => {
        const index = items.findIndex((item) => item.value === value);
        if (index >= 0) {
            setSelectedIndex(index);
        }
    }, [items]);
    useInput((_, key) => {
        if (key.escape) {
            onClose();
        }
    });
    if (availableTools.length === 0) {
        return (_jsxs(Box, { flexDirection: "column", paddingX: 2, paddingY: 1, children: [_jsx(Text, { color: Colors.AccentYellow, children: action === 'disable'
                        ? 'All tools are already disabled.'
                        : 'No tools are currently disabled.' }), _jsx(Box, { marginTop: 1, children: _jsx(Text, { dimColor: true, children: "Press ESC to return" }) })] }));
    }
    return (_jsxs(Box, { flexDirection: "column", paddingX: 2, paddingY: 1, children: [_jsx(Box, { marginBottom: 1, children: _jsxs(Text, { bold: true, color: Colors.AccentBlue, children: ["Select a tool to ", action, ":"] }) }), _jsx(RadioButtonSelect, { items: items, onSelect: handleSelect, onHighlight: handleHighlight, isFocused: true, initialIndex: selectedIndex }), availableTools[selectedIndex] && (_jsx(Box, { marginTop: 1, children: _jsxs(Text, { dimColor: true, children: ["Tool name: ", availableTools[selectedIndex].name] }) })), _jsx(Box, { marginTop: 1, children: _jsxs(Text, { dimColor: true, children: ["Press ENTER to ", action, " \u2022 ESC to cancel"] }) })] }));
};
//# sourceMappingURL=ToolsDialog.js.map