import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
/**
 * @license
 * Copyright 2025 Vybestack LLC
 * SPDX-License-Identifier: Apache-2.0
 */
import { Box, Text } from 'ink';
import { Colors } from '../colors.js';
import { PrepareLabel } from './PrepareLabel.js';
import { isSlashCommand } from '../utils/commandUtils.js';
export const MAX_SUGGESTIONS_TO_SHOW = 8;
/**
 * @plan:PLAN-20251013-AUTOCOMPLETE.P08
 * @requirement:REQ-002
 * @requirement:REQ-003
 * Feature flag enabled for hint display integration
 */
const SHOW_ARGUMENT_HINTS = true;
/**
 * @plan:PLAN-20251013-AUTOCOMPLETE.P08
 * @requirement:REQ-002
 * @requirement:REQ-003
 * @requirement:REQ-004
 * @pseudocode UIHintRendering.md lines 4-7
 * Full implementation of hint line rendering
 * - Line 4: Modify SuggestionsDisplay to accept activeHint prop
 * - Line 5-6: Render hint in dedicated line above suggestion list
 * - Line 7: Ensure consistent height to avoid layout shift
 */
export function SuggestionsDisplay({ suggestions, activeIndex, isLoading, width, scrollOffset, userInput, activeHint, }) {
    if (isLoading) {
        return (_jsx(Box, { paddingX: 1, width: width, children: _jsx(Text, { color: Colors.Gray, children: "Loading suggestions..." }) }));
    }
    if (suggestions.length === 0) {
        return null;
    }
    // Calculate the visible slice based on scrollOffset
    const startIndex = scrollOffset;
    const endIndex = Math.min(scrollOffset + MAX_SUGGESTIONS_TO_SHOW, suggestions.length);
    const visibleSuggestions = suggestions.slice(startIndex, endIndex);
    const isSlashCommandMode = isSlashCommand(userInput);
    let commandNameWidth = 0;
    if (isSlashCommandMode) {
        const maxLabelLength = visibleSuggestions.length
            ? Math.max(...visibleSuggestions.map((s) => s.label.length))
            : 0;
        const maxAllowedWidth = Math.floor(width * 0.35);
        commandNameWidth = Math.max(15, Math.min(maxLabelLength + 2, maxAllowedWidth));
    }
    // Calculate how many lines we need to reserve
    const hasScrollUp = scrollOffset > 0;
    const hasScrollDown = endIndex < suggestions.length;
    const hasCounter = suggestions.length > MAX_SUGGESTIONS_TO_SHOW;
    return (_jsxs(Box, { flexDirection: "column", paddingX: 1, width: width, children: [SHOW_ARGUMENT_HINTS && activeHint ? (_jsx(Box, { marginBottom: 1, children: _jsx(Text, { color: Colors.Gray, wrap: "wrap", children: activeHint }) })) : null, hasScrollUp && _jsx(Text, { color: Colors.Foreground, children: "\u25B2" }), visibleSuggestions.map((suggestion, index) => {
                const originalIndex = startIndex + index;
                const isActive = originalIndex === activeIndex;
                const textColor = isActive ? '#00ff00' : Colors.Foreground;
                const labelElement = (_jsx(PrepareLabel, { label: suggestion.label, matchedIndex: suggestion.matchedIndex, userInput: userInput, textColor: textColor }));
                return (_jsx(Box, { width: width, children: _jsx(Box, { flexDirection: "row", children: isSlashCommandMode ? (_jsxs(_Fragment, { children: [_jsx(Box, { width: commandNameWidth, flexShrink: 0, children: labelElement }), suggestion.description ? (_jsx(Box, { flexGrow: 1, marginLeft: 1, children: _jsx(Text, { color: textColor, wrap: "wrap", children: suggestion.description }) })) : null] })) : (_jsxs(_Fragment, { children: [labelElement, suggestion.description ? (_jsx(Box, { flexGrow: 1, marginLeft: 1, children: _jsx(Text, { color: textColor, wrap: "wrap", children: suggestion.description }) })) : null] })) }) }, `${suggestion.value}-${originalIndex}`));
            }), hasScrollDown && _jsx(Text, { color: Colors.Gray, children: "\u25BC" }), hasCounter && (_jsxs(Text, { color: Colors.Gray, children: ["(", activeIndex + 1, "/", suggestions.length, ")"] }))] }));
}
//# sourceMappingURL=SuggestionsDisplay.js.map