import { useState } from 'react' import { Plus, Pencil, Trash2, ScanLine, Folder, BookOpen, Headphones } from 'lucide-react' import { PageHeader } from '@/components/ui/PageHeader' import { Button } from '@/components/ui/Button' import { EmptyState } from '@/components/ui/States' import { ConfirmDialog } from '@/components/ui/ConfirmDialog' import { Spinner } from '@/components/ui/Spinner' import { LibraryModal } from '@/components/admin/LibraryModal' import { getLibraries, deleteLibrary, scanLibrary } from '@/api/libraries' import { apiErrorMessage } from '@/api/client' import { toast } from '@/store/toastStore' import { useLibraryStore } from '@/store/libraryStore' import type { Library } from '@/types/abs' export default function AdminLibraries() { const libraries = useLibraryStore((s) => s.libraries) const setLibraries = useLibraryStore((s) => s.setLibraries) const [modal, setModal] = useState<{ open: boolean; library: Library | null }>({ open: false, library: null }) const [toDelete, setToDelete] = useState(null) const [scanning, setScanning] = useState>(new Set()) async function reload() { try { setLibraries(await getLibraries()) } catch { /* keep current */ } } async function startScan(lib: Library, force: boolean) { setScanning((s) => new Set(s).add(lib.id)) try { await scanLibrary(lib.id, force) toast.success(`Scan gestartet: ${lib.name}`) } catch (err) { toast.error(apiErrorMessage(err, 'Scan konnte nicht gestartet werden.')) } finally { // Live progress requires the ABS socket; clear the indicator after a moment. setTimeout(() => { setScanning((s) => { const next = new Set(s) next.delete(lib.id) return next }) }, 4000) } } async function confirmDelete() { if (!toDelete) return try { await deleteLibrary(toDelete.id) toast.success('Bibliothek gelöscht.') await reload() } catch (err) { toast.error(apiErrorMessage(err, 'Löschen fehlgeschlagen.')) } finally { setToDelete(null) } } return ( <> setModal({ open: true, library: null })}> Bibliothek } /> {libraries.length === 0 ? ( ) : (
{libraries.map((lib) => (
{lib.mediaType === 'podcast' ? : }

{lib.name}

{lib.mediaType === 'podcast' ? 'Podcasts' : 'Hörbücher'}
{lib.folders.map((f) => ( {f.fullPath} ))}
))}
)} setModal({ open: false, library: null })} onSaved={reload} /> {toDelete?.name} und alle zugehörigen Items + Fortschritte werden entfernt. Diese Aktion kann nicht rückgängig gemacht werden. } onConfirm={confirmDelete} onCancel={() => setToDelete(null)} /> ) }