import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { File, Folder, FolderOpen } from 'lucide-react';
import { formatDuration, isToolError, getErrorMessage } from './utils';
import { ToolHeader, ToolHeaderSeparator, ToolHeaderDetail, ToolHeaderMeta, ToolContentBox, } from './shared';
import { ToolErrorDisplay } from './ToolErrorDisplay';
export function ListRenderer({ contentJson, toolDurationMs, isExpanded, onToggle, }) {
    const result = contentJson.result || {};
    const args = (contentJson.args || {});
    const hasError = isToolError(result);
    const errorMessage = getErrorMessage(result);
    const errorStack = result && typeof result === 'object' && 'stack' in result
        ? String(result.stack)
        : undefined;
    const entries = result.entries || [];
    const timeStr = formatDuration(toolDurationMs);
    const path = typeof args.path === 'string' ? args.path : '.';
    return (_jsxs("div", { className: "text-xs", children: [_jsxs(ToolHeader, { toolName: "ls", isExpanded: isExpanded, onToggle: onToggle, isError: hasError, colorVariant: "cyan", canExpand: true, children: [path && path !== '.' && (_jsxs(_Fragment, { children: [_jsx(ToolHeaderSeparator, {}), _jsx("span", { className: "text-foreground/70 truncate min-w-0", title: path, children: path.length > 30 ? `…${path.slice(-30)}` : path })] })), _jsx(ToolHeaderSeparator, {}), _jsxs(ToolHeaderDetail, { children: [entries.length, " ", entries.length === 1 ? 'entry' : 'entries'] }), _jsx(ToolHeaderSeparator, {}), _jsx(ToolHeaderMeta, { children: timeStr })] }), isExpanded && hasError && errorMessage && (_jsx(ToolErrorDisplay, { error: errorMessage, stack: errorStack, showStack: true })), isExpanded && !hasError && (_jsxs("div", { className: "mt-2 ml-5 flex flex-col gap-2 max-w-full", children: [_jsx(ToolContentBox, { title: "path", icon: _jsx(FolderOpen, { className: "h-3 w-3" }), copyText: path, maxHeight: "", children: _jsx("div", { className: "px-3 py-2 font-mono text-xs bg-muted/10 break-all", children: path }) }), entries.length > 0 && (_jsx(ToolContentBox, { title: "entries", copyText: entries
                            .map((e) => {
                            const entry = e;
                            return entry.name || '';
                        })
                            .join('\n'), maxHeight: "max-h-80", children: _jsx("div", { className: "divide-y divide-border/50", children: entries.map((entry, i) => {
                                const e = entry;
                                const isDir = e.type === 'dir' || e.isDirectory;
                                return (_jsxs("div", { className: "flex items-center gap-1.5 px-3 py-1 font-mono text-foreground/80 hover:bg-muted/20", children: [isDir ? (_jsx(Folder, { className: "h-3 w-3 text-blue-500 flex-shrink-0" })) : (_jsx(File, { className: "h-3 w-3 text-muted-foreground flex-shrink-0" })), _jsx("span", { className: "truncate", children: e.name })] }, `${e.name}-${i}`));
                            }) }) })), entries.length === 0 && (_jsx(ToolContentBox, { title: "entries", maxHeight: "", children: _jsx("div", { className: "px-3 py-2 text-muted-foreground/60 italic", children: "Directory is empty" }) }))] }))] }));
}
//# sourceMappingURL=ListRenderer.js.map