/**
 * StructuredOutput - React component for rendering structured data
 *
 * Uses the RenderManager to automatically select the best renderer
 * for the given data type. Falls back to plain text for unknown types.
 */
import React, { useMemo } from 'react';
import { Box, Text } from 'ink';
import { getRenderManager } from '../../renderers/index.js';
import { useTheme } from '../context/theme-context.js';
// ============================================================================
// Component
// ============================================================================
export function StructuredOutput({ data, title, plain, maxWidth, }) {
    const { colors } = useTheme();
    const manager = getRenderManager();
    // Build render context
    const context = useMemo(() => {
        const ctx = {};
        if (plain)
            ctx.mode = 'plain';
        if (maxWidth)
            ctx.width = maxWidth;
        return ctx;
    }, [plain, maxWidth]);
    // Render the data
    const rendered = useMemo(() => {
        if (typeof data === 'string') {
            return data;
        }
        return manager.render(data, context);
    }, [data, context, manager]);
    // Check if we have a specialized renderer for this data
    const _hasSpecialRenderer = useMemo(() => {
        return manager.canRender(data);
    }, [data, manager]);
    return (React.createElement(Box, { flexDirection: "column" },
        title && (React.createElement(Box, { marginBottom: 1 },
            React.createElement(Text, { bold: true, color: colors.primary }, title))),
        React.createElement(Box, { flexDirection: "column" }, rendered.split('\n').map((line, index) => (React.createElement(Text, { key: index }, line))))));
}
// ============================================================================
// Hook for programmatic rendering
// ============================================================================
/**
 * Hook to access the RenderManager for programmatic rendering
 */
export function useRenderManager() {
    const manager = getRenderManager();
    const globalContext = manager.getContext();
    return {
        /** Render data to string */
        render: (data, context) => manager.render(data, context),
        /** Check if data can be rendered by a specialized renderer */
        canRender: (data) => manager.canRender(data),
        /** Get the current global render context */
        context: globalContext,
        /** Get all registered renderers */
        renderers: manager.getRenderers(),
    };
}
// ============================================================================
// Specialized Components
// ============================================================================
/**
 * TestResults - Render test execution results
 */
export function TestResults({ results, plain, }) {
    const data = {
        type: 'test-results',
        ...results,
    };
    return React.createElement(StructuredOutput, { data: data, plain: plain });
}
/**
 * Weather - Render weather information
 */
export function Weather({ location, current, forecast, units = 'metric', plain, }) {
    const data = {
        type: 'weather',
        location,
        current: {
            ...current,
            condition: current.condition,
        },
        forecast: forecast?.map((f) => ({
            ...f,
            condition: f.condition,
        })),
        units,
    };
    return React.createElement(StructuredOutput, { data: data, plain: plain });
}
/**
 * CodeStructure - Render code file analysis
 */
export function CodeStructure({ filePath, language, classes, functions, imports, exports, variables, plain, }) {
    const data = {
        type: 'code-structure',
        filePath,
        language,
        classes: classes || [],
        functions: (functions || []).map((f) => ({
            ...f,
            returnType: undefined,
            line: undefined,
            exported: false,
        })),
        imports: (imports || []).map((i) => ({
            ...i,
            isDefault: false,
            line: undefined,
        })),
        exports: (exports || []).map((e) => ({
            ...e,
            kind: e.kind,
            line: undefined,
        })),
        variables: (variables || []).map((v) => ({
            ...v,
            kind: v.kind,
            type: undefined,
            line: undefined,
            exported: false,
        })),
    };
    return React.createElement(StructuredOutput, { data: data, plain: plain });
}
export default StructuredOutput;
//# sourceMappingURL=StructuredOutput.js.map