import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { ChevronRight, AlertCircle, BookOpen, FileText, ShieldAlert, } from 'lucide-react';
import { formatDuration } from './utils';
import { ToolErrorDisplay } from './ToolErrorDisplay';
export function SkillRenderer({ contentJson, toolDurationMs, isExpanded, onToggle, compact, }) {
    const result = contentJson.result || {};
    const timeStr = formatDuration(toolDurationMs);
    const hasToolError = typeof result === 'object' && 'ok' in result && result.ok === false;
    const errorMessage = hasToolError && 'error' in result && typeof result.error === 'string'
        ? result.error
        : null;
    const name = result.name;
    const description = result.description;
    const content = result.content;
    const scope = result.scope;
    const availableFiles = result.availableFiles;
    const securityNotices = result.securityNotices;
    const isSubFile = description?.startsWith('Sub-file:');
    const fileCount = availableFiles?.length ?? 0;
    const noticeCount = securityNotices?.length ?? 0;
    const canExpand = !!content || hasToolError;
    return (_jsxs("div", { className: "text-xs", children: [_jsxs("button", { type: "button", onClick: () => canExpand && onToggle(), className: `flex items-center gap-2 transition-colors w-full min-w-0 ${hasToolError
                    ? 'text-red-700 dark:text-red-300 hover:text-red-600 dark:hover:text-red-200'
                    : canExpand
                        ? 'text-violet-700 dark:text-violet-300 hover:text-violet-600 dark:hover:text-violet-200'
                        : 'text-violet-700 dark:text-violet-300'}`, children: [canExpand ? (_jsx(ChevronRight, { className: `h-3 w-3 flex-shrink-0 transition-transform ${isExpanded ? 'rotate-90' : ''}` })) : (_jsx("div", { className: "w-3 flex-shrink-0" })), hasToolError && (_jsx(AlertCircle, { className: "h-3 w-3 flex-shrink-0 text-red-600 dark:text-red-400" })), isSubFile ? (_jsx(FileText, { className: "h-3 w-3 flex-shrink-0" })) : (_jsx(BookOpen, { className: "h-3 w-3 flex-shrink-0" })), _jsxs("span", { className: "font-medium flex-shrink-0", children: ["skill", hasToolError ? ' error' : ''] }), name && !compact && (_jsxs(_Fragment, { children: [_jsx("span", { className: "text-muted-foreground/70 flex-shrink-0", children: "\u00B7" }), _jsx("span", { className: "text-foreground/70 truncate", children: isSubFile ? description?.replace('Sub-file: ', '') : name })] })), scope && !compact && !isSubFile && (_jsxs("span", { className: "text-muted-foreground/80 flex-shrink-0", children: ["\u00B7 ", scope] })), fileCount > 0 && !compact && (_jsxs("span", { className: "text-muted-foreground/80 flex-shrink-0", children: ["\u00B7 ", fileCount, " file", fileCount !== 1 ? 's' : ''] })), noticeCount > 0 && !compact && (_jsxs("span", { className: "text-amber-600 dark:text-amber-400 flex-shrink-0 flex items-center gap-0.5", children: ["\u00B7 ", _jsx(ShieldAlert, { className: "h-3 w-3 inline" }), " ", noticeCount] })), timeStr && !compact && (_jsxs("span", { className: "text-muted-foreground/80 flex-shrink-0", children: ["\u00B7 ", timeStr] }))] }), isExpanded && hasToolError && errorMessage && (_jsx(ToolErrorDisplay, { error: errorMessage })), isExpanded && !hasToolError && (_jsxs("div", { className: "mt-2 ml-5 space-y-2", children: [noticeCount > 0 && securityNotices && (_jsxs("div", { className: "bg-amber-50 dark:bg-amber-950/30 border border-amber-200 dark:border-amber-800 rounded-lg p-2.5 space-y-1", children: [_jsxs("div", { className: "flex items-center gap-1.5 text-amber-700 dark:text-amber-300 font-medium text-[11px]", children: [_jsx(ShieldAlert, { className: "h-3 w-3" }), "Security Notice", noticeCount > 1 ? 's' : ''] }), securityNotices.map((notice, i) => (_jsxs("div", { className: "text-amber-600 dark:text-amber-400 text-[11px] leading-snug", children: [_jsx("span", { className: "font-mono bg-amber-100 dark:bg-amber-900/40 rounded px-1 py-0.5", children: notice.type }), ' ', notice.description] }, `${notice.type}-${notice.line ?? i}`)))] })), description && !isSubFile && (_jsx("p", { className: "text-muted-foreground italic", children: description })), content && (_jsx("div", { className: "bg-card/60 border border-border rounded-lg overflow-hidden max-h-96 overflow-y-auto max-w-full", children: _jsx("div", { className: "p-3 whitespace-pre-wrap font-mono text-xs leading-relaxed", children: content }) })), fileCount > 0 && availableFiles && (_jsxs("details", { className: "group", children: [_jsxs("summary", { className: "text-muted-foreground cursor-pointer hover:text-foreground/80 text-[11px] select-none", children: [fileCount, " available sub-file", fileCount !== 1 ? 's' : ''] }), _jsx("div", { className: "mt-1.5 bg-card/40 border border-border rounded-lg p-2 space-y-0.5 max-h-48 overflow-y-auto", children: availableFiles.map((f) => (_jsxs("div", { className: "flex items-center justify-between gap-2 font-mono text-[11px]", children: [_jsx("span", { className: "text-foreground/80 truncate", children: f.relativePath }), _jsx("span", { className: "text-muted-foreground/60 flex-shrink-0 tabular-nums", children: formatFileSize(f.size) })] }, f.relativePath))) })] }))] }))] }));
}
function formatFileSize(bytes) {
    if (bytes < 1024)
        return `${bytes}B`;
    const kb = bytes / 1024;
    if (kb < 1024)
        return `${kb.toFixed(1)}KB`;
    return `${(kb / 1024).toFixed(1)}MB`;
}
//# sourceMappingURL=SkillRenderer.js.map