import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
import { Box, Text } from 'ink';
import { getAllFilesInDirectory } from './utils.js';
export function TreeItem({ item, isHighlighted, isSelected, selectedFiles, colors, }) {
    const { node, depth, isExpanded, hasChildren } = item;
    const indent = '  '.repeat(depth);
    // Add trailing slash for directories
    const displayName = node.isDirectory ? `${node.name}/` : node.name;
    if (node.isDirectory) {
        // Check if directory has any/all files selected
        const filesInDir = getAllFilesInDirectory(node);
        const selectedCount = filesInDir.filter(f => selectedFiles.has(f)).length;
        const hasSelection = selectedCount > 0;
        const allSelected = filesInDir.length > 0 && selectedCount === filesInDir.length;
        // Selection icon replaces expand icon when there's a selection
        let prefix;
        if (allSelected) {
            prefix = '✓ ';
        }
        else if (hasSelection) {
            prefix = '◐ ';
        }
        else if (hasChildren) {
            prefix = isExpanded ? 'v ' : '> ';
        }
        else {
            prefix = '  ';
        }
        return (_jsxs(Box, { children: [_jsxs(Text, { color: hasSelection ? colors.success : colors.text, children: [indent, prefix] }), _jsx(Text, { color: isHighlighted
                        ? colors.primary
                        : hasSelection
                            ? colors.success
                            : colors.text, bold: isHighlighted || hasSelection, inverse: isHighlighted, children: displayName })] }));
    }
    // File - show green checkmark if selected
    return (_jsxs(Box, { children: [_jsxs(Text, { color: isSelected ? colors.success : colors.text, children: [indent, isSelected ? '✓ ' : '  '] }), _jsx(Text, { color: isHighlighted
                    ? colors.primary
                    : isSelected
                        ? colors.success
                        : colors.text, bold: isHighlighted || isSelected, inverse: isHighlighted, children: displayName })] }));
}
//# sourceMappingURL=tree-item.js.map