import { Ionicons } from '@expo/vector-icons'; import { Stack, useLocalSearchParams } from 'expo-router'; import { useEffect, useState } from 'react'; import { View, Text, Pressable, Alert } from 'react-native'; import { EmptyState } from '~/components/EmptyState'; import { SongList } from '~/components/SongList'; import { SongPicker } from '~/components/SongPicker'; import { getPlaylistById, getPlaylistSongs, addSongToPlaylist, removeSongFromPlaylist, } from '~/services/playlistService'; import { usePlayerStore } from '~/stores/playerStore'; import type { Playlist, Song } from '~/types'; import { useTheme } from '~/utils/themeContext'; export default function PlaylistDetailScreen() { const { id } = useLocalSearchParams<{ id: string }>(); const { colors } = useTheme(); const playSong = usePlayerStore((s) => s.playSong); const [playlist, setPlaylist] = useState(null); const [songs, setSongs] = useState([]); const [showPicker, setShowPicker] = useState(false); const loadData = async () => { if (!id) return; const [p, s] = await Promise.all([getPlaylistById(id), getPlaylistSongs(id)]); setPlaylist(p); setSongs(s); }; useEffect(() => { loadData(); }, [id]); const handleAddSongs = async (selected: Song[]) => { if (!id) return; for (const song of selected) { await addSongToPlaylist(id, song.id); } await loadData(); }; const handleLongPress = (song: Song) => { Alert.alert('Song entfernen', `"${song.title}" aus der Playlist entfernen?`, [ { text: 'Abbrechen', style: 'cancel' }, { text: 'Entfernen', style: 'destructive', onPress: async () => { if (id) { await removeSongFromPlaylist(id, song.id); await loadData(); } }, }, ]); }; return ( ( setShowPicker(true)} style={{ padding: 8 }}> ), }} /> {playlist && ( {playlist.name} {playlist.description && ( {playlist.description} )} {songs.length} Songs )} playSong(song, songs, index)} emptyTitle="Playlist ist leer" emptyMessage="Füge Songs über den + Button hinzu." /> setShowPicker(false)} onSelect={handleAddSongs} excludeIds={songs.map((s) => s.id)} /> ); }