/** * Role Selection Step - Allows the user to choose which role they want * to take for the selected action. */ import React from 'react'; import { Box, Text } from 'ink'; import { colors } from '../../../theme.js'; import type { XOTemplate } from '@xo-cash/types'; import type { FocusArea } from '../types.js'; interface RoleSelectStepProps { /** The loaded template definition. */ template: XOTemplate; /** The selected action identifier. */ actionIdentifier: string; /** Role identifiers available for this action. */ availableRoles: string[]; /** The currently focused role index. */ selectedRoleIndex: number; /** Whether the content area or button bar is focused. */ focusArea: FocusArea; } /** * Displays the available roles for the selected action and * lets the user navigate between them with arrow keys. */ export function RoleSelectStep({ template, actionIdentifier, availableRoles, selectedRoleIndex, focusArea, }: RoleSelectStepProps): React.ReactElement { const action = template.actions?.[actionIdentifier]; return ( Select your role for this action: {/* Action info */} {action && ( {action.description || 'No description available'} )} {/* Role list */} {availableRoles.length === 0 ? ( No roles available ) : ( availableRoles.map((roleId, index) => { const isCursor = selectedRoleIndex === index && focusArea === 'content'; const roleDef = template.roles?.[roleId]; const actionRole = action?.roles?.[roleId]; const requirements = actionRole?.requirements; return ( {isCursor ? '▸ ' : ' '} {roleDef?.name || roleId} {/* Show role description indented below the name */} {roleDef?.description && ( {' '} {roleDef.description} )} {/* Show a brief summary of requirements */} {requirements && ( {requirements.variables && requirements.variables.length > 0 && ( {requirements.variables.length} variable {requirements.variables.length !== 1 ? 's' : ''} {' '} )} {requirements.slots && requirements.slots.min > 0 && ( {requirements.slots.min} input slot {requirements.slots.min !== 1 ? 's' : ''} )} )} ); }) )} ↑↓: Navigate • Next: Confirm selection ); }