'use client'; import React, {useState} from 'react'; import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'; import {faArrowLeft} from '@fortawesome/free-solid-svg-icons'; interface RelatedItem { name: string; type: string; description: string; history: string; } interface Item { id: number | null; name: string; description: string; history: string; location: string; ownedBy: string; functionality: string; image: string; relatedItems: RelatedItem[]; } const initialItemState: Item = { id: null, name: '', description: '', history: '', location: '', ownedBy: '', functionality: '', image: '', relatedItems: [], }; export default function Items() { const [items, setItems] = useState([ { id: 1, name: 'Sword of Destiny', description: 'A powerful sword', history: 'Forged in the ancient times...', location: 'Castle', ownedBy: 'John Doe', functionality: 'Cuts through anything', image: 'https://via.placeholder.com/150', relatedItems: [] }, { id: 2, name: 'Shield of Valor', description: 'An unbreakable shield', history: 'Used by the legendary hero...', location: 'Fortress', ownedBy: 'Jane Doe', functionality: 'Deflects any attack', image: 'https://via.placeholder.com/150', relatedItems: [] } ]); const [selectedItem, setSelectedItem] = useState(null); const [searchQuery, setSearchQuery] = useState(''); const [newItem, setNewItem] = useState(initialItemState); const [newRelatedItem, setNewRelatedItem] = useState({ name: '', type: '', description: '', history: '' }); const filteredItems = items.filter( (item) => item.name.toLowerCase().includes(searchQuery.toLowerCase()) ); const handleItemClick = (item: Item) => { setSelectedItem(item); }; const handleAddItem = () => { setSelectedItem(newItem); }; const handleSaveItem = () => { if (selectedItem) { if (selectedItem.id === null) { setItems([...items, {...selectedItem, id: items.length + 1}]); } else { setItems(items.map((item) => (item.id === selectedItem.id ? selectedItem : item))); } setSelectedItem(null); setNewItem(initialItemState); } }; const handleItemChange = (key: keyof Item, value: string) => { if (selectedItem) { setSelectedItem({...selectedItem, [key]: value}); } }; const handleElementChange = (section: keyof Item, index: number, key: keyof RelatedItem, value: string) => { if (selectedItem) { const updatedSection = [...(selectedItem[section] as RelatedItem[])]; updatedSection[index][key] = value; setSelectedItem({...selectedItem, [section]: updatedSection}); } }; const handleAddElement = (section: keyof Item, value: RelatedItem) => { if (selectedItem) { const updatedSection = [...(selectedItem[section] as RelatedItem[]), value]; setSelectedItem({...selectedItem, [section]: updatedSection}); } }; const handleRemoveElement = (section: keyof Item, index: number) => { if (selectedItem) { const updatedSection = (selectedItem[section] as RelatedItem[]).filter((_, i) => i !== index); setSelectedItem({...selectedItem, [section]: updatedSection}); } }; return (
{selectedItem ? (

{selectedItem.name}

handleItemChange('name', e.target.value)} className="w-full px-4 py-2.5 rounded-xl bg-secondary/50 text-text-primary border border-secondary/50 outline-none hover:bg-secondary hover:border-secondary focus:border-primary focus:ring-4 focus:ring-primary/20 transition-all duration-200" />
handleItemChange('image', e.target.value)} className="w-full px-4 py-2.5 rounded-xl bg-secondary/50 text-text-primary border border-secondary/50 outline-none hover:bg-secondary hover:border-secondary focus:border-primary focus:ring-4 focus:ring-primary/20 transition-all duration-200" />

Related Items

{selectedItem.relatedItems.map((relatedItem, index) => (
{relatedItem.name}
))}
) : (
setSearchQuery(e.target.value)} className="w-full px-4 py-2.5 rounded-xl bg-secondary/50 text-text-primary border border-secondary/50 outline-none hover:bg-secondary hover:border-secondary focus:border-primary focus:ring-4 focus:ring-primary/20 transition-all duration-200" placeholder="Search Items" />

Items

{filteredItems.map((item) => (
handleItemClick(item)} className="cursor-pointer bg-tertiary/90 backdrop-blur-sm p-4 rounded-xl shadow-lg hover:shadow-xl hover:scale-105 transition-all duration-200 border border-secondary/50"> {item.name}

{item.name}

{item.description}

))}
)}
); }