'use client'; import React, {useState} from 'react'; import {SpellListItem, SpellTagProps} from "@/lib/models/Spell"; import InputField from "@/components/form/InputField"; import TextInput from "@/components/form/TextInput"; import SpellTagChip from "@/components/book/settings/spells/SpellTagChip"; import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"; import {faChevronRight, faCog, faHatWizard, faPlus} from "@fortawesome/free-solid-svg-icons"; import {useTranslations} from "next-intl"; interface SpellListProps { spells: SpellListItem[]; tags: SpellTagProps[]; handleSpellClick: (spell: SpellListItem) => void; handleAddSpell: () => void; handleManageTags: () => void; } export default function SpellList( { spells, tags, handleSpellClick, handleAddSpell, handleManageTags, }: SpellListProps) { const t = useTranslations(); const [searchQuery, setSearchQuery] = useState(''); const [filterTag, setFilterTag] = useState('all'); function getFilteredSpells(): SpellListItem[] { return spells.filter((spell: SpellListItem) => { const matchesSearch = spell.name.toLowerCase().includes(searchQuery.toLowerCase()); const matchesTag = filterTag === 'all' || spell.tags.some((tag: SpellTagProps) => tag.id === filterTag); return matchesSearch && matchesTag; }); } const filteredSpells = getFilteredSpells(); return (
setSearchQuery(e.target.value)} placeholder={t("spellList.search")} /> } actionIcon={faPlus} actionLabel={t("spellList.add")} addButtonCallBack={async () => handleAddSpell()} />
{filteredSpells.length === 0 ? (

{t("spellList.noSpells")}

{t("spellList.noSpellsDescription")}

) : (
{filteredSpells.map((spell: SpellListItem) => (
handleSpellClick(spell)} className="group flex items-center p-4 bg-secondary/30 rounded-xl border-l-4 border-primary border border-secondary/50 cursor-pointer hover:bg-secondary hover:shadow-md hover:scale-102 transition-all duration-200 hover:border-primary/50" >
{spell.name}
{spell.description}
{spell.tags.length > 0 && (
{spell.tags.slice(0, 3).map((tag: SpellTagProps) => ( ))} {spell.tags.length > 3 && ( +{spell.tags.length - 3} )}
)}
))}
)}
); }