import { Box, Text } from 'ink';
import { Select } from '@inkjs/ui';

type MenuAction = 'begin-session' | 'tools' | 'resources' | 'prompts' | 'raw' | 'session-info';

interface MainMenuProps {
  gated: boolean;
  toolCount: number;
  resourceCount: number;
  promptCount: number;
  onSelect: (action: MenuAction) => void;
}

export function MainMenu({ gated, toolCount, resourceCount, promptCount, onSelect }: MainMenuProps) {
  const items = gated
    ? [
        { label: 'Begin Session — call begin_session with tags to ungate', value: 'begin-session' as MenuAction },
        { label: 'Raw JSON-RPC — send freeform JSON-RPC messages', value: 'raw' as MenuAction },
        { label: 'Session Info — view initialize result and session state', value: 'session-info' as MenuAction },
      ]
    : [
        { label: `Tools (${toolCount}) — browse and execute MCP tools`, value: 'tools' as MenuAction },
        { label: `Resources (${resourceCount}) — browse and read MCP resources`, value: 'resources' as MenuAction },
        { label: `Prompts (${promptCount}) — browse and get MCP prompts`, value: 'prompts' as MenuAction },
        { label: 'Raw JSON-RPC — send freeform JSON-RPC messages', value: 'raw' as MenuAction },
        { label: 'Session Info — view initialize result and session state', value: 'session-info' as MenuAction },
      ];

  return (
    <Box flexDirection="column">
      <Text bold>
        {gated ? 'Session is gated — call begin_session to ungate:' : 'What would you like to explore?'}
      </Text>
      <Box marginTop={1}>
        <Select options={items} onChange={(v) => onSelect(v as MenuAction)} />
      </Box>
    </Box>
  );
}
