import React, { useState } from 'react'; import { View, Text, StyleSheet, SafeAreaView, ScrollView, TouchableOpacity, TextInput, Modal, Alert, StatusBar, Platform, RefreshControl, } from 'react-native'; import { useNavigation } from '@react-navigation/native'; import { KurdistanColors } from '../../theme/colors'; import { usePezkuwi } from '../../contexts/PezkuwiContext'; import { logger } from '../../utils/logger'; type CategoryType = 'All' | 'Finance' | 'Governance' | 'Social' | 'Education' | 'Health' | 'Entertainment' | 'Tools' | 'Gaming'; interface MiniApp { id: string; name: string; icon: string; developer: string; category: Exclude; description: string; status: 'live' | 'coming_soon'; } const FEATURED_APPS: MiniApp[] = [ { id: 'bereketli', name: 'Bereketli', icon: '🥘', developer: 'Pezkuwi', category: 'Social', description: 'Neighborhood economy - food packages, meals, merchants', status: 'live', }, { id: 'dapp-browser', name: 'DApp Browser', icon: '🌐', developer: 'Pezkuwi', category: 'Tools', description: 'Browse Web3 dApps with wallet integration', status: 'live', }, { id: 'governance', name: 'Governance', icon: '🗳️', developer: 'Pezkuwi', category: 'Governance', description: 'Vote on referenda and proposals', status: 'live', }, { id: 'pezkuwi-b2b-ai', name: 'PezkuwiB2B AI', icon: '🤖', developer: 'Dijital Kurdistan Tech Inst', category: 'Finance', description: 'B2B marketplace specialized AI', status: 'coming_soon', }, { id: 'kurd-health', name: 'KurdHealth', icon: '🏥', developer: 'Health Ministry', category: 'Health', description: 'Digital health records & telemedicine', status: 'coming_soon', }, { id: 'kurd-games', name: 'KurdGames', icon: '🎮', developer: 'Dijital Kurdistan Tech Inst', category: 'Gaming', description: 'Play-to-earn Kurdish games', status: 'coming_soon', }, ]; const CATEGORIES: { name: CategoryType; icon: string }[] = [ { name: 'All', icon: '📱' }, { name: 'Finance', icon: '💰' }, { name: 'Governance', icon: '🏛️' }, { name: 'Social', icon: '💬' }, { name: 'Education', icon: '📚' }, { name: 'Health', icon: '🏥' }, { name: 'Entertainment', icon: '🎬' }, { name: 'Tools', icon: '🛠️' }, { name: 'Gaming', icon: '🎮' }, ]; const AppsScreen: React.FC = () => { const navigation = useNavigation<{ navigate: (screen: string) => void }>(); const { selectedAccount, accounts, connectWallet } = usePezkuwi(); const isConnected = !!selectedAccount; const [searchQuery, setSearchQuery] = useState(''); const [selectedCategory, setSelectedCategory] = useState('All'); const [refreshing, setRefreshing] = useState(false); const [showSubmitModal, setShowSubmitModal] = useState(false); const [appName, setAppName] = useState(''); const [appDescription, setAppDescription] = useState(''); const [contactEmail, setContactEmail] = useState(''); const [contactName, setContactName] = useState(''); const [contactPhone, setContactPhone] = useState(''); const [projectDomain, setProjectDomain] = useState(''); const [githubRepo, setGithubRepo] = useState(''); const filteredApps = FEATURED_APPS.filter(app => { const matchesSearch = app.name.toLowerCase().includes(searchQuery.toLowerCase()) || app.description.toLowerCase().includes(searchQuery.toLowerCase()); const matchesCategory = selectedCategory === 'All' || app.category === selectedCategory; return matchesSearch && matchesCategory; }); const handleConnectWallet = async () => { // If no wallets exist, navigate to wallet setup first if (accounts.length === 0) { navigation.navigate('WalletSetup'); return; } try { await connectWallet(); Alert.alert('Girêdayî / Connected', 'Cîzdanê te bi serkeftî girêdayî bû!\nYour wallet has been connected successfully!'); } catch (error) { logger.error('Wallet connection error:', error); Alert.alert('Çewtî / Error', 'Cîzdan nehat girêdan. Dîsa biceribîne.\nFailed to connect wallet. Please try again.'); } }; const handleSubmitApp = () => { if (!appName.trim() || !appDescription.trim() || !contactEmail.trim() || !contactName.trim() || !contactPhone.trim()) { Alert.alert('Missing Information', 'Please fill in all required fields to submit your mini app.'); return; } setShowSubmitModal(false); setAppName(''); setAppDescription(''); setContactEmail(''); setContactName(''); setContactPhone(''); setProjectDomain(''); setGithubRepo(''); Alert.alert( 'Application Submitted ✅', 'Dijital Kurdistan Tech Inst officials will contact you as soon as possible.\n\nSpas bo xebata te!', [{ text: 'Temam' }] ); }; const renderMiniAppCard = (app: MiniApp) => ( { if (app.status === 'live') { if (app.id === 'bereketli') navigation.navigate('Bereketli'); else if (app.id === 'dapp-browser') navigation.navigate('DAppBrowser'); else if (app.id === 'governance') navigation.navigate('Governance'); else Alert.alert(app.name, app.description); } else { Alert.alert(app.name, `${app.description}\n\nby ${app.developer}\n\nStatus: Coming Soon`); } }} > {app.icon} {app.name} {app.status === 'coming_soon' ? ( Coming Soon ) : ( Live )} {app.description} by {app.developer} ); return ( { setRefreshing(true); setTimeout(() => setRefreshing(false), 1000); }} />}> {/* Header */} MiniApps Store Discover & Build on Pezkuwichain {!isConnected ? ( Connect ) : ( Connected )} {/* Search Bar */} 🔍 {searchQuery.length > 0 && ( setSearchQuery('')} accessibilityRole="button" accessibilityLabel="Clear search"> )} {/* Categories - Horizontal Scroll */} {CATEGORIES.map((cat) => ( setSelectedCategory(cat.name)} accessibilityRole="button" accessibilityLabel={`Filter by ${cat.name} category`} > {cat.icon} {cat.name} ))} {/* Build on Pezkuwichain Section */} Build on Pezkuwichain Submit your mini app to the ecosystem setShowSubmitModal(true)} activeOpacity={0.8} accessibilityRole="button" accessibilityLabel="Submit a new mini app" > + {/* Featured Apps */} {selectedCategory === 'All' ? 'Featured Mini Apps' : `${selectedCategory} Apps`} {filteredApps.length > 0 ? ( filteredApps.map(renderMiniAppCard) ) : ( 🔍 No apps found in this category yet Be the first to submit one! )} {/* Footer Note */} 💡 Access all other apps from Home screen {/* Submit App Modal */} setShowSubmitModal(false)} > Submit Your Mini App Join the Pezkuwichain ecosystem setShowSubmitModal(false)} accessibilityRole="button" accessibilityLabel="Close submit modal" > App Name * Description * Your Name * Contact Email * Contact Phone Number * Project Domain (optional) GitHub Repository (optional) 📧 Review Process Your submission will be reviewed by Dijital Kurdistan Tech Inst. We'll contact you within 5-7 business days. setShowSubmitModal(false)} accessibilityRole="button" accessibilityLabel="Cancel submission" > Cancel Submit Application ); }; const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#F5F5F5', paddingTop: Platform.OS === 'android' ? StatusBar.currentHeight : 0, }, header: { paddingHorizontal: 20, paddingTop: 16, paddingBottom: 12, }, headerTop: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'flex-start', }, headerTitle: { fontSize: 26, fontWeight: 'bold', color: KurdistanColors.reş, }, headerSubtitle: { fontSize: 13, color: '#666', marginTop: 2, }, connectButton: { backgroundColor: KurdistanColors.kesk, paddingHorizontal: 16, paddingVertical: 8, borderRadius: 20, }, connectButtonText: { color: KurdistanColors.spi, fontSize: 13, fontWeight: '600', }, connectedBadge: { flexDirection: 'row', alignItems: 'center', backgroundColor: '#E8F5E9', paddingHorizontal: 12, paddingVertical: 6, borderRadius: 20, gap: 4, }, connectedIcon: { fontSize: 12, color: KurdistanColors.kesk, }, connectedText: { fontSize: 12, fontWeight: '600', color: KurdistanColors.kesk, }, searchContainer: { paddingHorizontal: 20, marginBottom: 12, }, searchBar: { flexDirection: 'row', alignItems: 'center', backgroundColor: KurdistanColors.spi, borderRadius: 12, paddingHorizontal: 14, height: 46, shadowColor: '#000', shadowOffset: { width: 0, height: 1 }, shadowOpacity: 0.05, shadowRadius: 3, elevation: 2, }, searchIcon: { fontSize: 16, marginRight: 10, opacity: 0.5, }, searchInput: { flex: 1, fontSize: 15, color: '#333', }, clearIcon: { fontSize: 14, color: '#999', padding: 4, }, categoriesContainer: { marginBottom: 16, }, categoriesContent: { paddingHorizontal: 20, gap: 8, }, categoryChip: { flexDirection: 'row', alignItems: 'center', paddingHorizontal: 14, paddingVertical: 8, borderRadius: 20, backgroundColor: KurdistanColors.spi, marginRight: 8, shadowColor: '#000', shadowOffset: { width: 0, height: 1 }, shadowOpacity: 0.05, shadowRadius: 2, elevation: 1, }, categoryChipActive: { backgroundColor: KurdistanColors.kesk, }, categoryEmoji: { fontSize: 14, marginRight: 6, }, categoryText: { fontSize: 13, fontWeight: '600', color: '#555', }, categoryTextActive: { color: KurdistanColors.spi, }, buildSection: { marginHorizontal: 20, marginBottom: 20, backgroundColor: KurdistanColors.kesk, borderRadius: 16, padding: 18, shadowColor: KurdistanColors.kesk, shadowOffset: { width: 0, height: 4 }, shadowOpacity: 0.25, shadowRadius: 8, elevation: 5, }, buildContent: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', }, buildTextContainer: { flex: 1, }, buildTitle: { fontSize: 17, fontWeight: 'bold', color: KurdistanColors.spi, marginBottom: 3, }, buildSubtitle: { fontSize: 12, color: 'rgba(255,255,255,0.85)', }, addButton: { width: 44, height: 44, borderRadius: 22, backgroundColor: KurdistanColors.spi, justifyContent: 'center', alignItems: 'center', marginLeft: 12, }, addButtonText: { fontSize: 26, fontWeight: '600', color: KurdistanColors.kesk, marginTop: -2, }, section: { paddingHorizontal: 20, marginBottom: 16, }, sectionTitle: { fontSize: 17, fontWeight: 'bold', color: KurdistanColors.reş, marginBottom: 12, }, miniAppCard: { flexDirection: 'row', backgroundColor: KurdistanColors.spi, borderRadius: 14, padding: 14, marginBottom: 10, shadowColor: '#000', shadowOffset: { width: 0, height: 1 }, shadowOpacity: 0.05, shadowRadius: 3, elevation: 2, }, miniAppIconContainer: { width: 52, height: 52, borderRadius: 13, backgroundColor: '#F0F8F0', justifyContent: 'center', alignItems: 'center', marginRight: 12, }, miniAppIcon: { fontSize: 26, }, miniAppInfo: { flex: 1, justifyContent: 'center', }, miniAppHeader: { flexDirection: 'row', alignItems: 'center', marginBottom: 3, }, miniAppName: { fontSize: 15, fontWeight: 'bold', color: KurdistanColors.reş, }, comingSoonBadge: { backgroundColor: KurdistanColors.zer, paddingHorizontal: 7, paddingVertical: 2, borderRadius: 6, marginLeft: 8, }, comingSoonText: { fontSize: 9, fontWeight: '600', color: KurdistanColors.reş, }, miniAppDescription: { fontSize: 12, color: '#666', marginBottom: 2, }, miniAppDeveloper: { fontSize: 10, color: '#999', }, emptyState: { alignItems: 'center', paddingVertical: 32, backgroundColor: KurdistanColors.spi, borderRadius: 14, }, emptyIcon: { fontSize: 40, marginBottom: 12, opacity: 0.5, }, emptyText: { fontSize: 14, color: '#666', marginBottom: 4, }, emptySubtext: { fontSize: 12, color: '#999', }, footerNote: { flexDirection: 'row', alignItems: 'center', justifyContent: 'center', paddingVertical: 16, marginBottom: 16, }, footerIcon: { fontSize: 14, marginRight: 6, }, footerText: { fontSize: 12, color: '#888', }, modalOverlay: { flex: 1, backgroundColor: 'rgba(0,0,0,0.5)', justifyContent: 'flex-end', }, modalContent: { backgroundColor: KurdistanColors.spi, borderTopLeftRadius: 24, borderTopRightRadius: 24, maxHeight: '90%', }, modalHeader: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'flex-start', padding: 20, borderBottomWidth: 1, borderBottomColor: '#F0F0F0', }, modalTitle: { fontSize: 20, fontWeight: 'bold', color: KurdistanColors.reş, }, modalSubtitle: { fontSize: 13, color: '#666', marginTop: 2, }, modalCloseButton: { padding: 4, }, modalClose: { fontSize: 20, color: '#999', }, modalBody: { padding: 20, maxHeight: 400, }, inputGroup: { marginBottom: 16, }, inputLabel: { fontSize: 13, fontWeight: '600', color: KurdistanColors.reş, marginBottom: 6, }, input: { backgroundColor: '#F5F5F5', borderRadius: 10, padding: 12, fontSize: 14, color: KurdistanColors.reş, borderWidth: 1, borderColor: '#E8E8E8', }, textArea: { height: 90, paddingTop: 12, }, infoBox: { flexDirection: 'row', backgroundColor: '#F0F8F0', borderRadius: 12, padding: 14, marginTop: 8, }, infoIcon: { fontSize: 20, marginRight: 12, }, infoTextContainer: { flex: 1, }, infoTitle: { fontSize: 13, fontWeight: '600', color: KurdistanColors.kesk, marginBottom: 4, }, infoText: { fontSize: 12, color: '#666', lineHeight: 18, }, modalFooter: { flexDirection: 'row', padding: 20, paddingTop: 12, borderTopWidth: 1, borderTopColor: '#F0F0F0', gap: 12, }, cancelButton: { flex: 1, padding: 14, borderRadius: 12, backgroundColor: '#F0F0F0', alignItems: 'center', }, cancelButtonText: { fontSize: 15, fontWeight: '600', color: '#666', }, submitButton: { flex: 2, padding: 14, borderRadius: 12, backgroundColor: KurdistanColors.kesk, alignItems: 'center', }, submitButtonText: { fontSize: 15, fontWeight: '600', color: KurdistanColors.spi, }, }); export default AppsScreen;