|
| 1 | +/** |
| 2 | + * Confirmation screen component for submitting the ask_user form |
| 3 | + * Shown as the final "question" after all questions are answered |
| 4 | + */ |
| 5 | + |
| 6 | +import React from 'react' |
| 7 | +import { TextAttributes } from '@opentui/core' |
| 8 | +import { useTheme } from '../../../hooks/use-theme' |
| 9 | +import { Button } from '../../button' |
| 10 | +import { BORDER_CHARS } from '../../../utils/ui-constants' |
| 11 | + |
| 12 | +export interface AnswerSummary { |
| 13 | + question: string |
| 14 | + header?: string |
| 15 | + answer: string |
| 16 | +} |
| 17 | + |
| 18 | +export interface ConfirmScreenProps { |
| 19 | + onSubmit: () => void |
| 20 | + onBack: () => void |
| 21 | + submitFocused: boolean |
| 22 | + backFocused: boolean |
| 23 | + onSubmitMouseOver: () => void |
| 24 | + onBackMouseOver: () => void |
| 25 | + answers: AnswerSummary[] |
| 26 | +} |
| 27 | + |
| 28 | +export const ConfirmScreen: React.FC<ConfirmScreenProps> = ({ |
| 29 | + onSubmit, |
| 30 | + onBack, |
| 31 | + submitFocused, |
| 32 | + backFocused, |
| 33 | + onSubmitMouseOver, |
| 34 | + onBackMouseOver, |
| 35 | + answers, |
| 36 | +}) => { |
| 37 | + const theme = useTheme() |
| 38 | + |
| 39 | + return ( |
| 40 | + <box style={{ flexDirection: 'column', gap: 1 }}> |
| 41 | + <text |
| 42 | + style={{ |
| 43 | + fg: theme.foreground, |
| 44 | + attributes: TextAttributes.BOLD, |
| 45 | + }} |
| 46 | + > |
| 47 | + Your answers: |
| 48 | + </text> |
| 49 | + |
| 50 | + {/* Answer summary */} |
| 51 | + <box style={{ flexDirection: 'column', gap: 0, marginTop: 0, paddingLeft: 1 }}> |
| 52 | + {answers.map((item, idx) => ( |
| 53 | + <box key={idx} style={{ flexDirection: 'row', gap: 1 }}> |
| 54 | + <text style={{ fg: theme.muted }}>{idx + 1}.</text> |
| 55 | + <text style={{ fg: theme.primary }}>{item.answer}</text> |
| 56 | + </box> |
| 57 | + ))} |
| 58 | + </box> |
| 59 | + |
| 60 | + <box style={{ flexDirection: 'row', gap: 2, marginTop: 1 }}> |
| 61 | + <Button |
| 62 | + onClick={onBack} |
| 63 | + onMouseOver={onBackMouseOver} |
| 64 | + style={{ |
| 65 | + borderStyle: 'single', |
| 66 | + borderColor: backFocused ? theme.secondary : theme.muted, |
| 67 | + customBorderChars: BORDER_CHARS, |
| 68 | + paddingLeft: 2, |
| 69 | + paddingRight: 2, |
| 70 | + backgroundColor: backFocused ? theme.surface : undefined, |
| 71 | + }} |
| 72 | + > |
| 73 | + <text |
| 74 | + style={{ |
| 75 | + fg: backFocused ? theme.foreground : theme.muted, |
| 76 | + attributes: backFocused ? TextAttributes.BOLD : undefined, |
| 77 | + }} |
| 78 | + > |
| 79 | + ← Back |
| 80 | + </text> |
| 81 | + </Button> |
| 82 | + |
| 83 | + <Button |
| 84 | + onClick={onSubmit} |
| 85 | + onMouseOver={onSubmitMouseOver} |
| 86 | + style={{ |
| 87 | + borderStyle: 'single', |
| 88 | + borderColor: submitFocused ? theme.primary : theme.secondary, |
| 89 | + customBorderChars: BORDER_CHARS, |
| 90 | + paddingLeft: 2, |
| 91 | + paddingRight: 2, |
| 92 | + backgroundColor: submitFocused ? theme.surface : undefined, |
| 93 | + }} |
| 94 | + > |
| 95 | + <text |
| 96 | + style={{ |
| 97 | + fg: submitFocused ? theme.primary : theme.foreground, |
| 98 | + attributes: submitFocused ? TextAttributes.BOLD : undefined, |
| 99 | + }} |
| 100 | + > |
| 101 | + Submit ↵ |
| 102 | + </text> |
| 103 | + </Button> |
| 104 | + </box> |
| 105 | + </box> |
| 106 | + ) |
| 107 | +} |
0 commit comments