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 filteredOffices = useMemo(() => {
const normalized = search.toLowerCase();
return offices.filter((o) =>
o.name.toLowerCase().includes(normalized)
);
}, [offices, search]);
if (loading || isLoadingFavorites) {
return (
);
}
if (error) {
return (
{error}
Reintentar
);
}
return (
{/* HEADER */}
Espacios disponibles
{/* SEARCH */}
{/* COUNT */}
{filteredOffices.length} espacio
{filteredOffices.length !== 1 ? 's' : ''} encontrados
{/* LIST */}
item.id}
contentContainerStyle={styles.list}
renderItem={({ item }) => {
const isFav = favoriteOfficeIdsSet.has(item.id);
return (
{/* IMAGE PLACEHOLDER */}
{/*
🏢
*/}
{/* INFO */}
{item.name}
{item.location}
›
{item.capacity} personas
{/*
{item.price ?? '—'}
*/}
{isFav ? 'Favorito' : 'Disponible'}
);
}}
ListEmptyComponent={
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',
},
header: {
backgroundColor: theme.colors.surface,
padding: theme.spacing.xl,
borderBottomWidth: 1,
borderColor: theme.colors.border,
},
title: {
fontSize: theme.typography.xxxl,
fontWeight: theme.fontWeight.semibold,
color: theme.colors.text,
marginBottom: theme.spacing.md,
},
search: {
backgroundColor: theme.colors.white,
borderWidth: 1,
borderColor: theme.colors.border,
borderRadius: theme.radius.lg,
paddingHorizontal: theme.spacing.lg,
paddingVertical: theme.spacing.md,
},
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',
},
imageIcon: {
fontSize: 28,
},
info: {
flex: 1,
gap: theme.spacing.sm,
},
rowBetween: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'flex-start',
},
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',
},
price: {
color: theme.colors.primary,
fontWeight: theme.fontWeight.medium,
},
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,
},
});