import { useState } from 'react'; import { View, Text, FlatList, ActivityIndicator, StyleSheet, SafeAreaView, Image, RefreshControl, TouchableOpacity, Modal } from 'react-native'; import { useLocalSearchParams, useRouter } from 'expo-router'; import { Ionicons } from '@expo/vector-icons'; import { useOutlet, useArticlesByOutlet } from '@/hooks/useApi'; import ArticleCard from '@/components/ArticleCard'; import BottomTabBar from '@/components/BottomTabBar'; import SearchModal from '@/components/SearchModal'; import LanguageModal from '@/components/LanguageModal'; import { useLanguage } from '@/contexts/LanguageContext'; export default function OutletScreen() { const { id } = useLocalSearchParams<{ id: string }>(); const router = useRouter(); const [refreshing, setRefreshing] = useState(false); const [activeFilter, setActiveFilter] = useState<'people' | 'topics' | 'companies'>('people'); const [showProfileModal, setShowProfileModal] = useState(false); const [showSearch, setShowSearch] = useState(false); const [showLanguage, setShowLanguage] = useState(false); const [viewMode, setViewMode] = useState<'card' | 'list'>('card'); const { language, setLanguage } = useLanguage(); const { data: outlet, isLoading: outletLoading, error: outletError, refetch: refetchOutlet } = useOutlet(id || '', language); const { data: articlesResponse, isLoading: articlesLoading, refetch: refetchArticles } = useArticlesByOutlet(id || '', language); const onRefresh = async () => { setRefreshing(true); await Promise.all([refetchOutlet(), refetchArticles()]); setRefreshing(false); }; const getInitials = (name: string) => { return name .split(' ') .map(word => word[0]) .join('') .toUpperCase() .slice(0, 2); }; if (outletLoading) { return ( Loading... ); } if (outletError || !outlet) { return ( Outlet not found router.back()} > Go Back ); } const outletData = outlet as any; // Extract articles array from paginated response const articlesData = (articlesResponse as any)?.articles || []; return ( {/* Header */} {outletData.avatar ? ( ) : ( {getInitials(outletData.name)} )} {outletData.name} setShowSearch(true)}> setShowLanguage(true)}> {/* Content Area */} {showSearch ? ( setShowSearch(false)} /> ) : ( <> {/* Articles List */} item.newsId)} keyExtractor={(item: any) => item.newsId} renderItem={({ item, index }: any) => ( { router.push(`/article/${newsId}`); }} isAd={item.isAd || false} tags={item.tags || []} index={index} /> )} refreshControl={ } contentContainerStyle={styles.listContent} showsVerticalScrollIndicator={false} ListEmptyComponent={ articlesLoading ? ( Loading articles... ) : ( No articles available yet. ) } /> )} {/* Footer Navigation */} router.back()}> router.push('/')}> {/* Profile Modal */} setShowProfileModal(false)} > setShowProfileModal(false)} > {outletData.avatar ? ( ) : ( {getInitials(outletData.name)} )} {outletData.name} setShowProfileModal(false)}> {outletData.description || outletData.focusSubject} {/* Language Modal */} setShowLanguage(false)} currentLanguage={language} onSelectLanguage={setLanguage} /> ); } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#f5f5f5', }, header: { backgroundColor: '#fff', borderBottomWidth: 1, borderBottomColor: '#e0e0e0', paddingVertical: 12, paddingHorizontal: 16, flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', }, contentContainer: { flex: 1, overflow: 'hidden', }, headerLeft: { flexDirection: 'row', alignItems: 'center', flex: 1, gap: 12, }, outletAvatar: { width: 40, height: 40, borderRadius: 20, }, outletInfo: { flexDirection: 'column', alignItems: 'flex-start', gap: 3, flex: 1, }, miniLogo: { height: 10, width: 90, resizeMode: 'contain', marginLeft: 0, }, outletName: { fontSize: 16, fontWeight: '600', color: '#000', maxWidth: 150, }, categoryBadge: { backgroundColor: '#f0f0f0', paddingHorizontal: 8, paddingVertical: 4, borderRadius: 12, }, categoryText: { fontSize: 11, color: '#666', fontWeight: '500', }, headerRight: { flexDirection: 'row', alignItems: 'center', gap: 8, }, profileContainer: { flexDirection: 'row', alignItems: 'center', gap: 12, flex: 1, }, avatar: { width: 40, height: 40, borderRadius: 20, }, avatarFallback: { width: 40, height: 40, borderRadius: 20, backgroundColor: '#e0e0e0', justifyContent: 'center', alignItems: 'center', }, avatarText: { fontSize: 14, fontWeight: '600', color: '#333', }, profileInfo: { flex: 1, }, sapiensLogo: { height: 10, marginBottom: 2, }, nameRow: { flexDirection: 'row', alignItems: 'center', gap: 6, }, name: { fontSize: 16, fontWeight: 'bold', color: '#000', }, infoIcon: { fontSize: 16, color: '#007AFF', }, iconButton: { padding: 8, }, articleWrapper: { paddingHorizontal: 16, paddingTop: 16, }, listContent: { paddingBottom: 16, }, loadingContainer: { flex: 1, justifyContent: 'center', alignItems: 'center', padding: 20, }, errorContainer: { flex: 1, justifyContent: 'center', alignItems: 'center', padding: 20, }, emptyContainer: { padding: 32, alignItems: 'center', }, text: { fontSize: 14, color: '#666', marginTop: 10, }, errorText: { fontSize: 16, color: 'red', fontWeight: 'bold', marginBottom: 16, }, emptyText: { fontSize: 14, color: '#666', textAlign: 'center', }, modalOverlay: { flex: 1, backgroundColor: 'rgba(0, 0, 0, 0.5)', justifyContent: 'center', alignItems: 'center', }, modalContent: { backgroundColor: '#fff', borderRadius: 12, padding: 20, width: '85%', maxWidth: 400, }, modalHeader: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'flex-start', marginBottom: 16, }, modalProfileContainer: { flexDirection: 'row', alignItems: 'center', gap: 12, flex: 1, }, modalAvatar: { width: 48, height: 48, borderRadius: 24, }, modalName: { fontSize: 18, fontWeight: 'bold', color: '#000', flex: 1, }, closeButton: { fontSize: 24, color: '#666', fontWeight: '300', }, modalDescription: { fontSize: 14, color: '#666', lineHeight: 20, }, footer: { backgroundColor: '#fff', borderTopWidth: 1, borderTopColor: '#e0e0e0', paddingVertical: 12, paddingHorizontal: 16, flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', }, navButton: { padding: 8, }, footerLogo: { height: 16, }, });