import React from 'react'; import { View, Text, TouchableOpacity, StyleSheet } from 'react-native'; import { MaterialIcons } from '@expo/vector-icons'; import type { ComponentProps } from 'react'; import type { SortState } from './SearchBar'; type IconName = ComponentProps['name']; interface SortChipsProps { sort: SortState; onSortChange: (s: SortState) => void; } const OPTIONS: { key: SortState['key']; label: string; icon: IconName }[] = [ { key: 'name', label: 'A-Z', icon: 'sort-by-alpha' }, { key: 'date', label: 'Date', icon: 'schedule' }, ]; export function SortChips({ sort, onSortChange }: SortChipsProps) { const select = (key: SortState['key']) => { if (sort.key === key) { onSortChange({ key, direction: sort.direction === 'asc' ? 'desc' : 'asc' }); } else { onSortChange({ key, direction: key === 'name' ? 'asc' : 'desc' }); } }; return ( {OPTIONS.map((opt) => { const active = sort.key === opt.key; return ( select(opt.key)} > {opt.label} ); })} ); } const styles = StyleSheet.create({ container: { flexDirection: 'row', alignItems: 'center', gap: 8, paddingHorizontal: 15, paddingVertical: 8, backgroundColor: '#f5f5f5', }, chip: { flexDirection: 'row', alignItems: 'center', gap: 4, paddingHorizontal: 12, paddingVertical: 6, borderRadius: 16, borderWidth: 1, borderColor: '#1976D2', backgroundColor: '#fff', }, chipActive: { backgroundColor: '#1976D2', }, chipText: { fontSize: 13, fontWeight: '600', color: '#1976D2', }, chipTextActive: { color: '#fff', }, });