'use client'
import { LegalTemplateResult } from '@/lib/sdk/types'
import { CATEGORIES } from '../_constants'
import LibraryCard from './LibraryCard'
interface TemplateLibraryProps {
allTemplates: LegalTemplateResult[]
filteredTemplates: LegalTemplateResult[]
isLoadingLibrary: boolean
activeCategory: string
onCategoryChange: (cat: string) => void
activeLanguage: 'all' | 'de' | 'en'
onLanguageChange: (lang: 'all' | 'de' | 'en') => void
librarySearch: string
onSearchChange: (q: string) => void
expandedPreviewId: string | null
onTogglePreview: (id: string) => void
onUseTemplate: (t: LegalTemplateResult) => void
}
export default function TemplateLibrary({
allTemplates,
filteredTemplates,
isLoadingLibrary,
activeCategory,
onCategoryChange,
activeLanguage,
onLanguageChange,
librarySearch,
onSearchChange,
expandedPreviewId,
onTogglePreview,
onUseTemplate,
}: TemplateLibraryProps) {
return (
Template-Bibliothek
{(['all', 'de', 'en'] as const).map((lang) => (
))}
{/* Category pills */}
{CATEGORIES.map((cat) => {
const count = cat.types === null
? allTemplates.filter(t => activeLanguage === 'all' || t.language === activeLanguage).length
: allTemplates.filter(t =>
cat.types!.includes(t.templateType || '') &&
(activeLanguage === 'all' || t.language === activeLanguage)
).length
return (
)
})}
{/* Search */}
{/* Template grid */}
{isLoadingLibrary ? (
) : filteredTemplates.length === 0 ? (
📄
Keine Vorlagen für diese Auswahl
) : (
{filteredTemplates.map((template) => (
onTogglePreview(template.id)}
onUse={() => onUseTemplate(template)}
/>
))}
)}
)
}