'use client' import React, { useMemo, useState, useRef, useEffect } from 'react' import { SearchInput, FilterDropdown, Pagination, ExpandableRow } from './LibraryTable' export interface ProtectiveMeasure { id: string reduction_type: string sub_type: string name: string description: string hazard_category: string examples: string[] norm_references: string[] } const PER_PAGE = 50 const TYPE_OPTIONS = [ { value: '', label: 'Alle Typen' }, { value: 'Design', label: 'Design' }, { value: 'Schutz', label: 'Schutz' }, { value: 'Information', label: 'Information' }, ] function typeColor(t: string): string { switch (t) { case 'Design': return 'bg-blue-100 text-blue-800' case 'Schutz': return 'bg-green-100 text-green-800' case 'Information': return 'bg-yellow-100 text-yellow-800' default: return 'bg-gray-100 text-gray-700' } } interface Props { measures: ProtectiveMeasure[] } export default function MeasuresTab({ measures }: Props) { const [search, setSearch] = useState('') const [debounced, setDebounced] = useState('') const [typeFilter, setTypeFilter] = useState('') const [page, setPage] = useState(1) const timer = useRef | null>(null) useEffect(() => { timer.current = setTimeout(() => setDebounced(search), 300) return () => { if (timer.current) clearTimeout(timer.current) } }, [search]) useEffect(() => { setPage(1) }, [debounced, typeFilter]) const filtered = useMemo(() => { const q = debounced.toLowerCase() return measures.filter((m) => { if (q && !m.name.toLowerCase().includes(q) && !m.description.toLowerCase().includes(q)) return false if (typeFilter && m.reduction_type !== typeFilter) return false return true }) }, [measures, debounced, typeFilter]) const totalPages = Math.ceil(filtered.length / PER_PAGE) const pageItems = filtered.slice((page - 1) * PER_PAGE, page * PER_PAGE) return (
{measures.length} Massnahmen{filtered.length !== measures.length && ` (${filtered.length} gefiltert)`}
{['ID', 'Name', 'Typ', 'Subtyp', 'Kategorie', 'Normen'].map((h) => ( ))} {pageItems.map((m) => ( {m.id.slice(0, 8)}, {m.name}, {m.reduction_type}, {m.sub_type || '-'}, {m.hazard_category?.replace(/_/g, ' ') || '-'}, {m.norm_references.length > 0 ? m.norm_references.slice(0, 2).join(', ') : '-'}{m.norm_references.length > 2 ? ` +${m.norm_references.length - 2}` : ''}, ]} expandedContent={
{m.description &&
Beschreibung: {m.description}
} {m.examples.length > 0 && (
Beispiele:
    {m.examples.map((ex, i) =>
  • {ex}
  • )}
)} {m.norm_references.length > 0 && (
{m.norm_references.map((nr) => ( {nr} ))}
)}
} /> ))} {pageItems.length === 0 && (
)}
{h}
Keine Massnahmen gefunden
) }