import { useTheme } from '@/components/ThemeContext'; import { products_api } from '@/screens/home/lib/api'; import { businessAboutDetailResData } from '@/screens/home/lib/types'; import { useMutation } from '@tanstack/react-query'; import { ChevronLeft, FileText, Phone, User } from 'lucide-react-native'; import React, { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { ActivityIndicator, FlatList, Image, Linking, ScrollView, StyleSheet, Text, TouchableOpacity, View, } from 'react-native'; interface FilteredItemsProps { data: { id: number; company_name: string }[]; back: () => void; } export default function FilteredItems({ data, back }: FilteredItemsProps) { const { isDark } = useTheme(); const { t } = useTranslation(); const [selectedItem, setSelectedItem] = useState(null); const { mutate, isPending } = useMutation({ mutationFn: (id: number) => products_api.businessAboutDetail(id), onSuccess: (data) => setSelectedItem(data.data.data), }); if (isPending) { return ( ); } if (selectedItem) { return ( {/* Back Button */} setSelectedItem(null)} style={[styles.backButton, isDark ? styles.darkBackButton : styles.lightBackButton]} > {/* Company Name */} {selectedItem.company_name} {/* Company Image */} {selectedItem.company_image && ( )} {/* Info Card */} {selectedItem.director_full_name && ( {t('Rahbar')} {selectedItem.director_full_name} )} {selectedItem.phone && ( Linking.openURL(`tel:+${selectedItem.phone}`)} > {t('Telefon raqami')} +{selectedItem.phone} )} {selectedItem.product_service_company?.length > 0 && ( {t('Mahsulot va xizmatlar')} {selectedItem.product_service_company.map((item, index) => ( {item.title} {item.description && ( {item.description} )} {item.category?.length > 0 && ( {item.category.map((cat) => ( {cat.name} ))} )} {item.files?.length > 0 && ( {t('Fayllar')}: {item.files.map((file, idx) => ( Linking.openURL(file.file)} style={styles.fileLink} > {t('Fayl')} {idx + 1} {t('ochish')} ))} )} ))} )} ); } // List view return ( {data && data.length > 0 ? ( item.id.toString()} renderItem={({ item }) => ( mutate(item.id)} > {item.company_name} )} contentContainerStyle={styles.listContainer} /> ) : ( {t('Natija topilmadi')} )} ); } const styles = StyleSheet.create({ container: { flex: 1 }, darkBg: { backgroundColor: '#0f172a', }, lightBg: { backgroundColor: '#f8fafc', }, content: { padding: 16, maxWidth: 500, width: '100%', alignSelf: 'center', }, center: { flex: 1, justifyContent: 'center', alignItems: 'center' }, backButton: { flexDirection: 'row', alignItems: 'center', marginBottom: 16, padding: 10, borderRadius: 12, alignSelf: 'flex-start', gap: 8, }, darkBackButton: { backgroundColor: '#1e293b', }, lightBackButton: { backgroundColor: '#ffffff', }, backText: { fontSize: 16, color: '#3b82f6', fontWeight: '600' }, listContainer: { gap: 12 }, itemCard: { borderRadius: 12, padding: 16, borderWidth: 1, shadowColor: '#000', shadowOffset: { width: 0, height: 1 }, shadowOpacity: 0.05, shadowRadius: 2, elevation: 2, }, darkItemCard: { backgroundColor: '#1e293b', borderColor: '#334155', }, lightItemCard: { backgroundColor: '#ffffff', borderColor: '#e2e8f0', }, itemTitle: { fontSize: 17, fontWeight: '600' }, darkText: { color: '#f1f5f9', }, lightText: { color: '#0f172a', }, emptyContainer: { flex: 1, alignItems: 'center', justifyContent: 'center', padding: 40 }, emptyText: { fontSize: 16, textAlign: 'center' }, darkSubText: { color: '#64748b', }, lightSubText: { color: '#94a3b8', }, // Detail detailTitle: { fontSize: 26, fontWeight: '700', marginBottom: 16 }, companyImage: { width: '100%', height: 220, borderRadius: 16, marginBottom: 20, }, darkImageBg: { backgroundColor: '#1e293b', }, lightImageBg: { backgroundColor: '#f1f5f9', }, infoCard: { borderRadius: 16, padding: 20, borderWidth: 1, gap: 16, }, darkCard: { backgroundColor: '#1e293b', borderColor: '#334155', }, lightCard: { backgroundColor: '#ffffff', borderColor: '#e2e8f0', }, infoRow: { flexDirection: 'row', alignItems: 'center', gap: 12, paddingVertical: 8 }, infoTextContainer: { flex: 1 }, infoLabel: { fontSize: 14, marginBottom: 4 }, infoValue: { fontSize: 16, fontWeight: '500' }, section: { marginTop: 8 }, sectionHeader: { flexDirection: 'row', alignItems: 'center', gap: 10, marginBottom: 12 }, sectionTitle: { fontSize: 18, fontWeight: '700' }, serviceItem: { borderRadius: 12, padding: 16, marginBottom: 12, }, darkServiceItem: { backgroundColor: '#0f172a', }, lightServiceItem: { backgroundColor: '#f8fafc', }, serviceTitle: { fontSize: 17, fontWeight: '600', marginBottom: 8 }, serviceDescription: { fontSize: 15, lineHeight: 22, marginBottom: 12 }, tagsContainer: { flexDirection: 'row', flexWrap: 'wrap', gap: 8, marginTop: 8 }, tag: { flexDirection: 'row', alignItems: 'center', gap: 6, paddingHorizontal: 12, paddingVertical: 6, borderRadius: 20, }, darkTag: { backgroundColor: '#1e293b', }, lightTag: { backgroundColor: '#ffffff', }, tagText: { fontSize: 13, fontWeight: '500' }, filesContainer: { marginTop: 12 }, filesTitle: { fontSize: 14, fontWeight: '600', marginBottom: 8 }, fileLink: { paddingVertical: 6 }, fileLinkText: { color: '#3b82f6', fontSize: 15, textDecorationLine: 'underline' }, });