import React, { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Stack, Text, TextInput, Button, Group, ActionIcon } from '@mantine/core'; interface WordsToRedactInputProps { wordsToRedact: string[]; onWordsChange: (words: string[]) => void; disabled?: boolean; } export default function WordsToRedactInput({ wordsToRedact, onWordsChange, disabled }: WordsToRedactInputProps) { const { t } = useTranslation(); const [currentWord, setCurrentWord] = useState(''); const addWord = () => { if (currentWord.trim() && !wordsToRedact.includes(currentWord.trim())) { onWordsChange([...wordsToRedact, currentWord.trim()]); setCurrentWord(''); } }; const removeWord = (index: number) => { onWordsChange(wordsToRedact.filter((_, i) => i !== index)); }; const handleKeyPress = (e: React.KeyboardEvent) => { if (e.key === 'Enter') { e.preventDefault(); addWord(); } }; return ( {t('redact.auto.wordsToRedact.title', 'Words to Redact')} {/* Current words */} {wordsToRedact.map((word, index) => ( {word} removeWord(index)} disabled={disabled} > × ))} {/* Add new word input */} setCurrentWord(e.target.value)} onKeyDown={handleKeyPress} disabled={disabled} size="sm" /> {/* Examples */} {wordsToRedact.length === 0 && ( {t('redact.auto.wordsToRedact.examples', 'Examples: Confidential, Top-Secret')} )} ); }