import { memo } from 'react' import type { ReactNode } from 'react' import { QuestionAnswerLine } from '../basic/icons-inline' export interface UserQuestionAnswerLabels { answer?: string answers?: string } export interface UserQuestionAnswerProps { answers: Record showHeader?: boolean labels?: UserQuestionAnswerLabels className?: string questionAnswerIcon?: ReactNode } const DEFAULT_LABELS: Required = { answer: 'Answer', answers: 'Answers', } const iconClass = 'w-4 h-4 shrink-0 text-text-tertiary' export const UserQuestionAnswer = memo(function UserQuestionAnswer({ answers, showHeader = true, labels: labelsProp, className = '', questionAnswerIcon, }: UserQuestionAnswerProps) { const labels = { ...DEFAULT_LABELS, ...labelsProp } const entries = Object.entries(answers) const defaultIcon = questionAnswerIcon ?? if (entries.length === 0) return null return (
{showHeader && (
{defaultIcon} {entries.length === 1 ? labels.answer : labels.answers}
)}
{entries.map(([question, answer], idx) => (
{question} {answer}
))}
) }) UserQuestionAnswer.displayName = 'UserQuestionAnswer'