'use client'; import { Autocomplete, TextField, Box, Typography, Chip, Button, Dialog } from '@mui/material'; import AddIcon from '@mui/icons-material/Add'; import { useTranslation } from 'react-i18next'; import { useState } from 'react'; export default function QuestionSelector({ templates, selectedTemplate, onTemplateChange, answeredQuestions = [], unansweredQuestions = [], onOpenCreateQuestion, onOpenCreateTemplate }) { const { t } = useTranslation(); const [showNoQuestionsMessage, setShowNoQuestionsMessage] = useState(false); // 构建未完成标注的问题选项(用于下拉框) const dropdownOptions = unansweredQuestions.map(q => ({ ...q, isUnanswered: true })); const getAnswerTypeLabel = answerType => { switch (answerType) { case 'text': return t('images.answerTypeText', { defaultValue: '文字' }); case 'label': return t('images.answerTypeLabel', { defaultValue: '标签' }); case 'custom_format': return t('images.answerTypeCustomFormat', { defaultValue: '自定义格式' }); default: return answerType; } }; // 判断是否有待标注问题 const hasUnansweredQuestions = unansweredQuestions.length > 0; const hasAnsweredQuestions = answeredQuestions.length > 0; const hasAnyQuestions = hasUnansweredQuestions || hasAnsweredQuestions; return ( {/* 已标注问题区域 - 优化显示为一行,添加最大高度 */} {answeredQuestions.length > 0 && ( {t('images.answeredQuestions', { defaultValue: '已标注问题' })} ({answeredQuestions.length}) {answeredQuestions.map(question => ( ))} )} {/* 问题选择下拉框 */} {t('images.selectNewQuestion', { defaultValue: '选择新问题' })} {!hasUnansweredQuestions ? ( // 没有待标注问题的提示 {hasAnsweredQuestions ? ( {t('images.allQuestionsAnnotated', { defaultValue: '当前图片所有问题已标注完成' })} ) : ( {t('images.noQuestionsAssociated', { defaultValue: '当前图片未关联任何问题' })} )} ) : ( // 有待标注问题时显示下拉框 { if (newValue) { onTemplateChange(newValue); } }} getOptionLabel={option => option.question || ''} renderOption={(props, option) => ( {option.question} )} renderInput={params => ( )} isOptionEqualToValue={(option, value) => option.id === value.id} /> )} {selectedTemplate && selectedTemplate.description && ( {selectedTemplate.description} )} ); }