import { Box, Text } from 'ink';

interface ResultViewProps {
  title: string;
  data: unknown;
}

function formatJson(data: unknown): string {
  try {
    return JSON.stringify(data, null, 2);
  } catch {
    return String(data);
  }
}

export function ResultView({ title, data }: ResultViewProps) {
  const formatted = formatJson(data);

  return (
    <Box flexDirection="column">
      <Text bold color="cyan">{title}</Text>
      <Box marginTop={1}>
        <Text>{formatted}</Text>
      </Box>
    </Box>
  );
}
