import { Ionicons } from '@expo/vector-icons';
import { useState } from 'react';
import { Pressable, View, Text, Modal } from 'react-native';
import type { SortField, SortDirection } from '~/types';
import { useTheme } from '~/utils/themeContext';
const SORT_OPTIONS: { field: SortField; label: string }[] = [
{ field: 'title', label: 'Titel' },
{ field: 'artist', label: 'Künstler' },
{ field: 'album', label: 'Album' },
{ field: 'addedAt', label: 'Hinzugefügt' },
{ field: 'playCount', label: 'Wiedergaben' },
];
interface SortMenuProps {
currentField: SortField;
currentDirection: SortDirection;
onSort: (field: SortField, direction: SortDirection) => void;
}
export function SortMenu({ currentField, currentDirection, onSort }: SortMenuProps) {
const { colors } = useTheme();
const [visible, setVisible] = useState(false);
return (
<>
setVisible(true)} style={{ padding: 8 }}>
setVisible(false)}
style={{ flex: 1, backgroundColor: 'rgba(0,0,0,0.4)', justifyContent: 'flex-end' }}
>
Sortieren
{SORT_OPTIONS.map((opt) => {
const isActive = opt.field === currentField;
return (
{
if (isActive) {
onSort(opt.field, currentDirection === 'asc' ? 'desc' : 'asc');
} else {
onSort(opt.field, 'asc');
}
setVisible(false);
}}
style={{
flexDirection: 'row',
alignItems: 'center',
paddingVertical: 14,
borderBottomWidth: 0.5,
borderBottomColor: colors.border,
}}
>
{opt.label}
{isActive && (
)}
);
})}
>
);
}