import { Link } from 'expo-router'; import { useMemo, useState } from 'react'; import { ActivityIndicator, FlatList, Pressable, StyleSheet, Text, TextInput, View, } from 'react-native'; import { useOffices } from '@/features/offices/hooks/useOffices'; import { useFavoriteOffices } from '@/features/offices/hooks/useFavoriteOffices'; import { Feather, MaterialIcons } from '@expo/vector-icons'; import theme from '@/theme'; export default function OfficesScreen() { const { offices, loading, error, reload } = useOffices(); const { favoriteOfficeIdsSet, isLoadingFavorites } = useFavoriteOffices(); const [search, setSearch] = useState(''); const [showOnlyFavorites, setShowOnlyFavorites] = useState(false); const filteredOffices = useMemo(() => { const normalized = search.toLowerCase(); return offices.filter((office) => { const matchesSearch = office.name.toLowerCase().includes(normalized); const matchesFavorite = !showOnlyFavorites || favoriteOfficeIdsSet.has(office.id); return matchesSearch && matchesFavorite; }); }, [favoriteOfficeIdsSet, offices, search, showOnlyFavorites]); if (loading || isLoadingFavorites) { return ( ); } if (error) { return ( {error} Reintentar ); } return ( {/* cabecera superior de la pantalla */} Espacios {/* herramientas de filtrado */} setShowOnlyFavorites((current) => !current)} > Solo favoritos {/* contador de resultados */} {filteredOffices.length} espacio {filteredOffices.length !== 1 ? "s" : ""} encontrados {/* lista */} item.id} contentContainerStyle={styles.list} renderItem={({ item }) => { const isFav = favoriteOfficeIdsSet.has(item.id); return ( {item.name} {item.location} › {item.capacity} personas {isFav ? "Favorito" : "Disponible"} ); }} ListEmptyComponent={ {showOnlyFavorites ? "No tienes espacios favoritos con estos filtros" : "No se encontraron espacios"} } /> ); } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: theme.colors.background, }, content: { flex: 1, width: "100%", maxWidth: theme.layout.contentWidth, alignSelf: "center", }, center: { flex: 1, justifyContent: "center", alignItems: "center", padding: theme.spacing.xl, gap: theme.spacing.md, backgroundColor: theme.colors.background, }, // cabecera superior de la pantalla topBar: { backgroundColor: theme.colors.surface, borderBottomWidth: 1, borderBottomColor: theme.colors.border, paddingHorizontal: theme.spacing.xl, paddingTop: theme.spacing.xxxl, paddingBottom: theme.spacing.lg, }, // titulo principal de la cabecera topBarTitle: { fontSize: theme.typography.xxl, fontWeight: theme.fontWeight.semibold, color: theme.colors.text, textAlign: "left", maxWidth: theme.layout.contentWidth, width: "100%", alignSelf: "center", }, errorText: { color: theme.colors.error, textAlign: "center", }, // bloque de busqueda y filtros toolsCard: { backgroundColor: theme.colors.surface, padding: theme.spacing.xl, gap: theme.spacing.md, borderBottomWidth: 1, borderBottomColor: theme.colors.border, }, search: { backgroundColor: theme.colors.white, borderWidth: 1, borderColor: theme.colors.border, borderRadius: theme.radius.lg, paddingHorizontal: theme.spacing.lg, paddingVertical: theme.spacing.md, color: theme.colors.text, }, favoriteFilterButton: { borderWidth: 1, borderColor: theme.colors.primary, borderRadius: theme.radius.lg, paddingHorizontal: theme.spacing.lg, paddingVertical: theme.spacing.md, flexDirection: "row", alignItems: "center", justifyContent: "center", gap: theme.spacing.sm, }, favoriteFilterButtonActive: { backgroundColor: theme.colors.primary, }, favoriteFilterText: { color: theme.colors.primary, fontWeight: theme.fontWeight.medium, }, favoriteFilterTextActive: { color: theme.colors.white, }, resultText: { fontSize: theme.typography.sm, color: theme.colors.textSecondary, paddingHorizontal: theme.spacing.xl, paddingTop: theme.spacing.md, }, list: { padding: theme.spacing.xl, gap: theme.spacing.lg, }, card: { backgroundColor: theme.colors.surface, borderRadius: theme.radius.lg, padding: theme.spacing.lg, borderWidth: 1, borderColor: theme.colors.border, ...theme.shadows.card, }, cardContent: { flexDirection: "row", gap: theme.spacing.lg, }, imageBox: { width: 80, height: 80, borderRadius: theme.radius.lg, backgroundColor: theme.colors.primarySoft, alignItems: "center", justifyContent: "center", }, info: { flex: 1, gap: theme.spacing.sm, }, rowBetween: { flexDirection: "row", justifyContent: "space-between", alignItems: "flex-start", }, infoMain: { flex: 1, }, cardTitle: { fontSize: theme.typography.lg, fontWeight: theme.fontWeight.semibold, color: theme.colors.text, }, cardSubtitle: { fontSize: theme.typography.sm, color: theme.colors.textSecondary, }, chevron: { fontSize: 18, color: theme.colors.muted, }, capacity: { fontSize: theme.typography.sm, color: theme.colors.textSecondary, }, footer: { flexDirection: "row", justifyContent: "space-between", alignItems: "center", }, badge: { backgroundColor: theme.colors.divider, paddingHorizontal: theme.spacing.md, paddingVertical: theme.spacing.xs, borderRadius: theme.radius.sm, }, badgeActive: { backgroundColor: theme.colors.successBg, }, badgeText: { fontSize: theme.typography.sm, color: theme.colors.textSecondary, }, badgeTextActive: { color: theme.colors.successText, }, emptyBox: { alignItems: "center", padding: theme.spacing.xxxl, }, emptyText: { color: theme.colors.textSecondary, }, primaryButton: { marginTop: theme.spacing.md, backgroundColor: theme.colors.primary, padding: theme.spacing.md, borderRadius: theme.radius.md, }, primaryButtonText: { color: theme.colors.white, fontWeight: theme.fontWeight.semibold, }, });