import { useState, useMemo } from 'react'
import Icon from './Icon'
import { BarToggle, BarButton, BAR_H } from './BarControls'
/* SymbolPicker — Modal-Overlay: zeigt Library-Items (symbol/object) als
Grid. Klick auf Item → onPick(id). Schliesst via onClose. */
function ItemPreview({ item }) {
// Thumbnail wenn vorhanden, sonst type-spezifisches Icon
if (item.previewDataUri) {
return (
)
}
const iconName = item.type === 'symbol' ? 'navigation' : 'forest'
return (
)
}
function ItemCard({ item, onPick }) {
return (
)
}
export default function SymbolPicker({ items, onPick, onClose, embedded = false }) {
const [search, setSearch] = useState('')
const [typeFilter, setTypeFilter] = useState('all')
// Nur symbol/object — material wird hier nicht gepicked
const placable = useMemo(() =>
(items || []).filter(it =>
it.type === 'symbol' || it.type === 'object'),
[items])
const filtered = useMemo(() => {
const q = search.trim().toLowerCase()
return placable.filter(it => {
if (typeFilter !== 'all' && it.type !== typeFilter) return false
if (!q) return true
if ((it.name || '').toLowerCase().includes(q)) return true
if ((it.tags || []).some(t => t.toLowerCase().includes(q))) return true
return false
})
}, [placable, search, typeFilter])
const innerStyle = embedded ? {
width: '100%', height: '100%',
background: 'var(--bg-dialog)',
display: 'flex', flexDirection: 'column',
overflow: 'hidden',
color: 'var(--text-primary)',
fontFamily: 'var(--font)', fontSize: 11,
} : {
width: '90%', maxWidth: 640, maxHeight: '80vh',
background: 'var(--bg-dialog)',
border: '1px solid var(--border)',
borderRadius: 12,
display: 'flex', flexDirection: 'column',
overflow: 'hidden',
color: 'var(--text-primary)',
fontFamily: 'var(--font)', fontSize: 11,
boxShadow: '0 8px 32px rgba(0,0,0,0.4)',
}
const content = (
{/* Header */}
Symbol / Objekt einfuegen
{/* Toolbar */}
setSearch(ev.target.value)}
placeholder="Suchen (Name oder Tag)…"
autoFocus
style={{ flex: 1, height: BAR_H, padding: '0 12px',
fontSize: 11 }} />
setTypeFilter('all')} />
setTypeFilter('symbol')} />
setTypeFilter('object')} />
{/* Grid */}
{filtered.length === 0 ? (
{placable.length === 0
? 'Keine Symbole/Objekte in der Library.'
: 'Nichts gefunden.'}
) : (
{filtered.map(it => (
))}
)}
{/* Footer */}
Klick auf Item → im Viewport Punkt waehlen zum Platzieren.
{filtered.length > 0 && (
· {filtered.length} / {placable.length}
)}
)
if (embedded) return content
return (
e.stopPropagation()}>{content}
)
}