import { Image as ExpoImage } from 'expo-image'; import { FileVideo, Image as ImageIcon, Plus } from 'lucide-react-native'; import { useState } from 'react'; import { Alert, FlatList, Modal, Pressable, ScrollView, StyleSheet, Text, TextInput, View, } from 'react-native'; import { useProfileData } from '../lib/ProfileDataContext'; const CATEGORIES = [ 'Qurilish', 'Savdo', 'IT', 'Dizayn', 'Transport', "Ta'lim", "Sog'liqni saqlash", 'Restoran', 'Turizm', 'Sport', ]; export function ProductServicesTab() { const { productServices, addProductService } = useProfileData(); const [modalVisible, setModalVisible] = useState(false); const [step, setStep] = useState<1 | 2>(1); const [title, setTitle] = useState(''); const [description, setDescription] = useState(''); const [mediaUrl, setMediaUrl] = useState(''); const [mediaType, setMediaType] = useState<'image' | 'video'>('image'); const [selectedCategories, setSelectedCategories] = useState([]); const resetForm = () => { setTitle(''); setDescription(''); setMediaUrl(''); setMediaType('image'); setSelectedCategories([]); setStep(1); }; const handleNext = () => { if (!title.trim() || !description.trim() || !mediaUrl.trim()) { Alert.alert('Xato', "Barcha maydonlarni to'ldiring"); return; } setStep(2); }; const handleAdd = () => { if (selectedCategories.length === 0) { Alert.alert('Xato', 'Kamida bitta kategoriya tanlang'); return; } addProductService({ title: title.trim(), description: description.trim(), mediaUrl: mediaUrl.trim(), mediaType, categories: selectedCategories, }); resetForm(); setModalVisible(false); Alert.alert('Muvaffaqiyat', "Xizmat muvaffaqiyatli qo'shildi"); }; const toggleCategory = (category: string) => { setSelectedCategories((prev) => prev.includes(category) ? prev.filter((c) => c !== category) : [...prev, category] ); }; return ( setModalVisible(true)} style={styles.addButton}> Xizmat qo'shish item.id} contentContainerStyle={styles.list} renderItem={({ item }) => ( {item.mediaType === 'image' ? ( ) : ( Video )} {item.title} {item.description} {item.categories.map((category, index) => ( {category} ))} )} ListEmptyComponent={ Hozircha xizmatlar yo'q Yangi xizmat qo'shish uchun yuqoridagi tugmani bosing } /> { resetForm(); setModalVisible(false); }} > {step === 1 ? "Xizmat ma'lumotlari" : 'Kategoriyalarni tanlang'} = 1 && styles.stepDotActive]} /> = 2 && styles.stepLineActive]} /> = 2 && styles.stepDotActive]} /> {step === 1 ? ( Nomi Tavsif Media turi setMediaType('image')} style={[ styles.mediaTypeButton, mediaType === 'image' && styles.mediaTypeButtonActive, ]} > Rasm setMediaType('video')} style={[ styles.mediaTypeButton, mediaType === 'video' && styles.mediaTypeButtonActive, ]} > Video Media URL { resetForm(); setModalVisible(false); }} style={[styles.modalButton, styles.cancelButton]} > Bekor qilish Keyingisi ) : ( <> {CATEGORIES.map((category) => ( toggleCategory(category)} style={[ styles.categoryOption, selectedCategories.includes(category) && styles.categoryOptionSelected, ]} > {category} ))} setStep(1)} style={[styles.modalButton, styles.backButton]} > Ortga Qo'shish )} ); } const styles = StyleSheet.create({ container: { flex: 1, padding: 16, paddingBottom: 100, }, addButton: { flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 8, backgroundColor: '#3b82f6', paddingVertical: 14, borderRadius: 12, marginBottom: 16, }, addButtonText: { fontSize: 16, fontWeight: '700' as const, color: '#ffffff', }, list: { gap: 16, flexGrow: 1 }, card: { backgroundColor: '#1e293b', borderRadius: 16, overflow: 'hidden', }, mediaContainer: { width: '100%', height: 200, backgroundColor: '#334155', }, media: { width: '100%', height: '100%', }, videoPlaceholder: { width: '100%', height: '100%', alignItems: 'center', justifyContent: 'center', gap: 8, }, videoText: { fontSize: 14, color: '#64748b', fontWeight: '600' as const, }, contentContainer: { padding: 16, gap: 8, }, title: { fontSize: 18, fontWeight: '700' as const, color: '#f8fafc', }, description: { fontSize: 14, color: '#94a3b8', lineHeight: 20, }, categoriesContainer: { flexDirection: 'row', flexWrap: 'wrap', gap: 8, marginTop: 4, }, categoryChip: { paddingHorizontal: 12, paddingVertical: 6, borderRadius: 12, backgroundColor: '#334155', }, categoryText: { fontSize: 12, color: '#94a3b8', fontWeight: '500' as const, }, emptyContainer: { flex: 1, alignItems: 'center', justifyContent: 'center', paddingVertical: 80, gap: 12, }, emptyText: { fontSize: 18, fontWeight: '600' as const, color: '#64748b', }, emptySubtext: { fontSize: 14, color: '#475569', textAlign: 'center', paddingHorizontal: 40, }, modalOverlay: { flex: 1, backgroundColor: '#00000090', justifyContent: 'flex-end', }, modalContent: { maxHeight: '90%', backgroundColor: '#1e293b', borderTopLeftRadius: 24, borderTopRightRadius: 24, padding: 24, gap: 20, }, modalHeader: { gap: 12, }, modalTitle: { fontSize: 22, fontWeight: '700' as const, color: '#f8fafc', }, stepIndicator: { flexDirection: 'row', alignItems: 'center', gap: 4, }, stepDot: { width: 10, height: 10, borderRadius: 5, backgroundColor: '#334155', }, stepDotActive: { backgroundColor: '#3b82f6', }, stepLine: { flex: 1, height: 2, backgroundColor: '#334155', }, stepLineActive: { backgroundColor: '#3b82f6', }, inputLabel: { fontSize: 14, fontWeight: '600' as const, color: '#94a3b8', marginBottom: 8, marginTop: 8, }, input: { backgroundColor: '#0f172a', borderRadius: 12, padding: 14, fontSize: 16, color: '#f8fafc', borderWidth: 1, borderColor: '#334155', }, textArea: { height: 100, paddingTop: 14, }, mediaTypeContainer: { flexDirection: 'row', gap: 12, }, mediaTypeButton: { flex: 1, flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 8, paddingVertical: 14, borderRadius: 12, backgroundColor: '#0f172a', borderWidth: 1, borderColor: '#334155', }, mediaTypeButtonActive: { borderColor: '#3b82f6', backgroundColor: '#1e40af20', }, mediaTypeText: { fontSize: 14, fontWeight: '600' as const, color: '#64748b', }, mediaTypeTextActive: { color: '#3b82f6', }, categoriesGrid: { flexDirection: 'row', flexWrap: 'wrap', gap: 12, }, categoryOption: { paddingHorizontal: 16, paddingVertical: 12, borderRadius: 12, backgroundColor: '#0f172a', borderWidth: 1, borderColor: '#334155', }, categoryOptionSelected: { backgroundColor: '#1e40af20', borderColor: '#3b82f6', }, categoryOptionText: { fontSize: 14, fontWeight: '600' as const, color: '#94a3b8', }, categoryOptionTextSelected: { color: '#3b82f6', }, modalButtons: { flexDirection: 'row', gap: 12, marginTop: 8, }, modalButton: { flex: 1, paddingVertical: 14, borderRadius: 12, alignItems: 'center', }, cancelButton: { backgroundColor: '#334155', }, backButton: { backgroundColor: '#334155', }, nextButton: { backgroundColor: '#3b82f6', }, saveButton: { backgroundColor: '#10b981', }, cancelButtonText: { fontSize: 16, fontWeight: '600' as const, color: '#f8fafc', }, backButtonText: { fontSize: 16, fontWeight: '600' as const, color: '#f8fafc', }, nextButtonText: { fontSize: 16, fontWeight: '600' as const, color: '#ffffff', }, saveButtonText: { fontSize: 16, fontWeight: '600' as const, color: '#ffffff', }, });