import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
/**
 * @license
 * Copyright 2025 Vybestack LLC
 * SPDX-License-Identifier: Apache-2.0
 */
import { ToolConfirmationOutcome } from '@vybestack/llxprt-code-core';
import { Box, Text } from 'ink';
import { useCallback } from 'react';
import { Colors } from '../colors.js';
import { RenderInline } from '../utils/InlineMarkdownRenderer.js';
import { RadioButtonSelect, } from './shared/RadioButtonSelect.js';
import { useKeypress } from '../hooks/useKeypress.js';
import { useTerminalSize } from '../hooks/useTerminalSize.js';
import { truncateEnd } from '../utils/responsive.js';
export const ShellConfirmationDialog = ({ request }) => {
    const { commands, onConfirm } = request;
    const { rows } = useTerminalSize();
    // Calculate max number of commands to show based on terminal height
    // Reserve space for header text, radio buttons, and padding
    const maxCommandsToShow = Math.max(1, rows - 8);
    useKeypress((key) => {
        if (key.name === 'escape') {
            onConfirm(ToolConfirmationOutcome.Cancel);
        }
    }, { isActive: true });
    const handleSelect = useCallback((item) => {
        if (item === ToolConfirmationOutcome.Cancel) {
            onConfirm(item);
        }
        else {
            // For both ProceedOnce and ProceedAlways, we approve all the
            // commands that were requested.
            onConfirm(item, commands);
        }
    }, [onConfirm, commands]);
    const options = [
        {
            label: 'Yes, allow once',
            value: ToolConfirmationOutcome.ProceedOnce,
            key: 'Yes, allow once',
        },
        {
            label: 'Yes, allow always for this session',
            value: ToolConfirmationOutcome.ProceedAlways,
            key: 'Yes, allow always for this session',
        },
        {
            label: 'No (esc)',
            value: ToolConfirmationOutcome.Cancel,
            key: 'No (esc)',
        },
    ];
    return (_jsxs(Box, { flexDirection: "column", borderStyle: "round", borderColor: Colors.AccentYellow, padding: 1, width: "100%", marginLeft: 1, children: [_jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsx(Text, { bold: true, children: "Shell Command Execution" }), _jsx(Text, { children: "A custom command wants to run the following shell commands:" }), _jsxs(Box, { flexDirection: "column", borderStyle: "round", borderColor: Colors.Gray, paddingX: 1, marginTop: 1, children: [commands.slice(0, maxCommandsToShow).map((cmd) => (_jsx(Text, { color: Colors.AccentCyan, children: _jsx(RenderInline, { text: truncateEnd(cmd, 80) }) }, cmd))), commands.length > maxCommandsToShow && (_jsxs(Text, { color: Colors.Gray, children: ["...", commands.length - maxCommandsToShow, " more commands..."] }))] })] }), _jsx(Box, { marginBottom: 1, children: _jsx(Text, { children: "Do you want to proceed?" }) }), _jsx(RadioButtonSelect, { items: options, onSelect: handleSelect, isFocused: true })] }));
};
//# sourceMappingURL=ShellConfirmationDialog.js.map