// pages/home/ui/HomeScreen.tsx import { useTheme } from '@/components/ThemeContext'; import CompanyList from '@/components/ui/CompanyList'; import CountriesList from '@/components/ui/CountriesList'; import FilteredItems from '@/components/ui/FilteredItems'; import FilterUI from '@/components/ui/FilterUI'; import ProductList from '@/components/ui/ProductList'; import SearchTabs from '@/components/ui/SearchTabs'; import { useTabSearch } from '@/hooks/useSearch'; import { TabKey } from '@/types'; import { useQueryClient } from '@tanstack/react-query'; import { Stack } from 'expo-router'; import { Filter, Search } from 'lucide-react-native'; import React, { useCallback, useMemo, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { ActivityIndicator, ScrollView, StyleSheet, Text, TextInput, TouchableOpacity, View, } from 'react-native'; import { RefreshControl } from 'react-native-gesture-handler'; function Loading() { return ( ); } export default function HomeScreen() { const { isDark } = useTheme(); const [activeTab, setActiveTab] = useState('products'); const [step, setStep] = useState<'filter' | 'items'>('filter'); const [query, setQuery] = useState(''); const [showFilter, setShowFilter] = useState(false); const [refreshing, setRefreshing] = useState(false); const [filtered, setFiltered] = useState<{ id: number; company_name: string }[]>([]); const { t } = useTranslation(); const queryClient = useQueryClient(); const { isLoading, error } = useTabSearch(activeTab, query); const onRefresh = useCallback(async () => { setRefreshing(true); try { if (activeTab === 'products') { await queryClient.invalidateQueries({ queryKey: ['products-list'] }); } await queryClient.refetchQueries(); } catch (err) { console.error('Refresh error:', err); } finally { setRefreshing(false); } }, [queryClient, activeTab]); const placeholderText = useMemo(() => { switch (activeTab) { case 'products': return 'Mahsulot qidirish...'; case 'companies': return 'Korxona qidirish...'; case 'countries': return 'Davlat qidirish...'; default: return 'Qidiruv...'; } }, [activeTab]); const RenderedView = useMemo(() => { switch (activeTab) { case 'products': return ; case 'companies': return ; case 'countries': return ; } }, [activeTab, query]); if (showFilter && step === 'filter') { return ( setShowFilter(false)} setStep={setStep} setFiltered={setFiltered} /> ); } if (showFilter && step === 'items') { return ( { setShowFilter(false); setStep('filter'); }} /> ); } return ( } > {/* Qidiruv va filter */} setShowFilter(true)} activeOpacity={0.7} > {error && ( {t("Ma'lumot yuklashda xatolik")} {t('Qayta urinish')} )} {isLoading && !refreshing && } {!isLoading && RenderedView} ); } const styles = StyleSheet.create({ darkBg: { flex: 1, backgroundColor: '#0f172a', }, lightBg: { flex: 1, backgroundColor: '#f8fafc', }, content: { padding: 16, maxWidth: 768, width: '100%', alignSelf: 'center', gap: 20, }, searchSection: { flexDirection: 'row', gap: 12, alignItems: 'center', }, searchInputContainer: { flex: 1, flexDirection: 'row', alignItems: 'center', borderRadius: 16, borderWidth: 1.5, paddingHorizontal: 16, shadowColor: '#3b82f6', shadowOffset: { width: 0, height: 2 }, shadowOpacity: 0.05, shadowRadius: 8, elevation: 2, }, darkSearchInput: { backgroundColor: '#1e293b', borderColor: '#334155', }, lightSearchInput: { backgroundColor: '#ffffff', borderColor: '#e2e8f0', }, searchIcon: { marginRight: 10, }, searchInput: { flex: 1, paddingVertical: 14, fontSize: 15, fontWeight: '500', }, darkInputText: { color: '#f1f5f9', }, lightInputText: { color: '#0f172a', }, filterButton: { backgroundColor: '#3b82f6', width: 48, height: 48, borderRadius: 16, alignItems: 'center', justifyContent: 'center', shadowColor: '#3b82f6', shadowOffset: { width: 0, height: 4 }, shadowOpacity: 0.3, shadowRadius: 8, elevation: 4, }, loadingContainer: { padding: 60, alignItems: 'center', justifyContent: 'center', }, errorContainer: { padding: 32, alignItems: 'center', borderRadius: 16, }, darkError: { backgroundColor: '#1e293b', }, lightError: { backgroundColor: '#ffffff', borderWidth: 1, borderColor: '#fee2e2', }, errorText: { fontSize: 16, fontWeight: '600', color: '#f87171', marginBottom: 12, }, retryButton: { backgroundColor: '#3b82f6', paddingHorizontal: 20, paddingVertical: 10, borderRadius: 10, }, retryButtonText: { color: '#ffffff', fontWeight: '700', fontSize: 14, }, });