import CollapsableArea from "@/components/CollapsableArea"; import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"; import {useState} from "react"; import {faTrash} from "@fortawesome/free-solid-svg-icons"; import InputField from "@/components/form/InputField"; import TextInput from "@/components/form/TextInput"; import {Attribute, CharacterProps} from "@/lib/models/Character"; import {IconDefinition} from "@fortawesome/fontawesome-svg-core"; import {useTranslations} from "next-intl"; interface CharacterSectionElementProps { title: string; section: keyof CharacterProps; placeholder: string; icon: IconDefinition; selectedCharacter: CharacterProps; setSelectedCharacter: (character: CharacterProps) => void; handleAddElement: (section: keyof CharacterProps, element: Attribute) => void; handleRemoveElement: ( section: keyof CharacterProps, index: number, attrId: string, ) => void; } export default function CharacterSectionElement( { title, section, placeholder, icon, selectedCharacter, setSelectedCharacter, handleAddElement, handleRemoveElement, }: CharacterSectionElementProps) { const t = useTranslations(); const [element, setElement] = useState(''); function handleAddNewElement() { handleAddElement(section, {id: '', name: element}); setElement(''); } return (
{Array.isArray(selectedCharacter?.[section]) && selectedCharacter?.[section].map((item, index: number) => (
{ const updatedSection = [...(selectedCharacter[section] as any[])]; updatedSection[index].name = e.target.value; setSelectedCharacter({ ...selectedCharacter, [section]: updatedSection, }); }} placeholder={placeholder} />
))}
setElement(e.target.value)} placeholder={t("characterSectionElement.newItem", {item: title.toLowerCase()})} /> } addButtonCallBack={async () => handleAddNewElement()} />
) }