import { useEffect, useState } from 'react'; import { View, Text, FlatList, Pressable, StyleSheet, ActivityIndicator, Platform, } from 'react-native'; import { useRouter } from 'expo-router'; import { useStoresStore } from '@/store/stores'; import { api } from '@/lib/api'; import type { Store } from '@shop/types'; /** * Stores list screen * Displays all stores and allows creating/editing stores */ export default function StoresScreen() { const router = useRouter(); const { stores, setStores, setIsLoading } = useStoresStore(); const [isLoading, setIsLoadingLocal] = useState(true); useEffect(() => { loadStores(); }, []); const loadStores = async () => { try { setIsLoadingLocal(true); const storesData = await api.get('/api/stores'); setStores(storesData); } catch (err) { console.error('Failed to load stores:', err); } finally { setIsLoadingLocal(false); } }; const handleCreateStore = () => { router.push('/(app)/stores/new'); }; const handleEditStore = (storeId: string) => { router.push(`/(app)/stores/${storeId}/edit`); }; const handleManageAisles = (storeId: string) => { router.push(`/(app)/stores/${storeId}/aisles`); }; if (isLoading) { return ( ); } return ( {/* Header */} router.back()}> ← Back Stores + Add {/* Stores list */} item.id} renderItem={({ item: store }) => ( {store.name} {store.location && 📍 {store.location}} {store.aisles?.length || 0} aisles handleManageAisles(store.id)}> Aisles handleEditStore(store.id)}> Edit )} ListEmptyComponent={ No stores yet Create a store to get started } contentContainerStyle={stores.length === 0 ? styles.emptyContent : undefined} /> {/* FAB to add store */} + ); } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#fff', }, centerContainer: { flex: 1, justifyContent: 'center', alignItems: 'center', }, header: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', paddingHorizontal: 16, paddingVertical: 12, marginTop: Platform.OS === 'ios' ? 44 : 0, borderBottomWidth: 1, borderBottomColor: '#e0e0e0', }, title: { fontSize: 18, fontWeight: '600', color: '#000', }, backButton: { fontSize: 16, color: '#007AFF', }, addButton: { fontSize: 16, color: '#007AFF', fontWeight: '600', }, storeCard: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', paddingVertical: 12, paddingHorizontal: 16, marginVertical: 4, marginHorizontal: 8, backgroundColor: '#f9f9f9', borderRadius: 8, borderLeftWidth: 4, borderLeftColor: '#007AFF', }, storeInfo: { flex: 1, }, storeName: { fontSize: 16, fontWeight: '600', color: '#000', marginBottom: 4, }, storeLocation: { fontSize: 13, color: '#666', marginBottom: 2, }, aisleCount: { fontSize: 12, color: '#999', }, storeActions: { flexDirection: 'row', gap: 8, }, actionButton: { paddingVertical: 6, paddingHorizontal: 12, backgroundColor: '#007AFF', borderRadius: 4, }, actionButtonText: { fontSize: 12, color: '#fff', fontWeight: '600', }, emptyContainer: { alignItems: 'center', justifyContent: 'center', paddingVertical: 48, }, emptyText: { fontSize: 18, fontWeight: '600', color: '#000', marginBottom: 8, }, emptySubtext: { fontSize: 14, color: '#999', }, emptyContent: { flexGrow: 1, justifyContent: 'center', }, fab: { position: 'absolute', bottom: 24, right: 24, width: 56, height: 56, borderRadius: 28, backgroundColor: '#007AFF', justifyContent: 'center', alignItems: 'center', shadowColor: '#000', shadowOffset: { width: 0, height: 2 }, shadowOpacity: 0.25, shadowRadius: 3.84, elevation: 5, }, fabText: { fontSize: 32, color: '#fff', fontWeight: '300', }, });