import { Ionicons } from '@expo/vector-icons'; import { useState, useEffect } from 'react'; import { FlatList, Pressable, View, Text, Modal } from 'react-native'; import type { Song } from '~/types'; import { useTheme } from '~/utils/themeContext'; import { getAllSongs } from '~/services/libraryService'; import { Artwork } from './Artwork'; interface SongPickerProps { visible: boolean; onClose: () => void; onSelect: (songs: Song[]) => void; excludeIds?: string[]; } export function SongPicker({ visible, onClose, onSelect, excludeIds = [] }: SongPickerProps) { const { colors } = useTheme(); const [songs, setSongs] = useState([]); const [selected, setSelected] = useState>(new Set()); useEffect(() => { if (visible) { getAllSongs().then((all) => { setSongs(all.filter((s) => !excludeIds.includes(s.id))); }); setSelected(new Set()); } }, [visible]); const toggleSelection = (id: string) => { setSelected((prev) => { const next = new Set(prev); if (next.has(id)) next.delete(id); else next.add(id); return next; }); }; const handleDone = () => { const selectedSongs = songs.filter((s) => selected.has(s.id)); onSelect(selectedSongs); onClose(); }; return ( Abbrechen Songs auswählen Fertig ({selected.size}) item.id} renderItem={({ item }) => { const isSelected = selected.has(item.id); return ( toggleSelection(item.id)} style={{ flexDirection: 'row', alignItems: 'center', paddingVertical: 10, paddingHorizontal: 16, }} > {item.title} {item.artist || 'Unbekannt'} ); }} /> ); }