import React, { useState, useEffect, useMemo } from 'react'; import { initializeApp } from 'firebase/app'; import { getFirestore, collection, addDoc, doc, updateDoc, onSnapshot, query, deleteDoc, orderBy } from 'firebase/firestore'; import { getAuth, signInAnonymously, signInWithCustomToken, onAuthStateChanged, signOut } from 'firebase/auth'; import { MapPin, Calendar, User, Plus, Trash2, CheckCircle, XCircle, Package, Check, X, CreditCard, Mail, Smartphone, ShieldCheck, Image as ImageIcon, ChevronLeft, ChevronRight, Lock, LogOut, Upload, Search, ArrowRight, BarChart3, Users, Settings, Filter, Star, Clock, Globe, Briefcase, Info } from 'lucide-react'; const firebaseConfig = JSON.parse(__firebase_config); const app = initializeApp(firebaseConfig); const auth = getAuth(app); const db = getFirestore(app); const appId = typeof __app_id !== 'undefined' ? __app_id : 'aztur-enterprise-system'; const App = () => { const [user, setUser] = useState(null); const [isAdmin, setIsAdmin] = useState(false); const [view, setView] = useState('home'); // home, login, admin, tour-detail, policy, search const [loading, setLoading] = useState(true); // Data States const [tours, setTours] = useState([]); const [bookings, setBookings] = useState([]); const [selectedTour, setSelectedTour] = useState(null); const [searchTerm, setSearchTerm] = useState(""); const [activeTab, setActiveTab] = useState('overview'); // admin tabs // Form States const [loginForm, setLoginForm] = useState({ email: '', password: '' }); const [imagePreview, setImagePreview] = useState([]); const [tourForm, setTourForm] = useState({ title: '', basePrice: '', duration: '', locations: '', description: '', category: 'Xarici', included: '', notIncluded: '', images: [] }); // Auth Effect useEffect(() => { const initAuth = async () => { try { if (typeof __initial_auth_token !== 'undefined' && __initial_auth_token) { await signInWithCustomToken(auth, __initial_auth_token); } else { await signInAnonymously(auth); } } catch (err) { console.error(err); } }; initAuth(); const unsubscribe = onAuthStateChanged(auth, (u) => { setUser(u); setIsAdmin(u && !u.isAnonymous); setLoading(false); }); return () => unsubscribe(); }, []); // Real-time Data Listeners useEffect(() => { if (!user) return; const toursRef = query(collection(db, 'artifacts', appId, 'public', 'data', 'tours'), orderBy('createdAt', 'desc')); const unsubTours = onSnapshot(toursRef, (snap) => { setTours(snap.docs.map(d => ({ id: d.id, ...d.data() }))); }, (err) => console.log(err)); const bookingsRef = collection(db, 'artifacts', appId, 'public', 'data', 'all_bookings'); const unsubBookings = onSnapshot(bookingsRef, (snap) => { setBookings(snap.docs.map(d => ({ id: d.id, ...d.data() }))); }); return () => { unsubTours(); unsubBookings(); }; }, [user]); // Image Upload Logic const handleImageSelect = (e) => { const files = Array.from(e.target.files); files.forEach(file => { const reader = new FileReader(); reader.onloadend = () => { setTourForm(prev => ({ ...prev, images: [...prev.images, reader.result] })); setImagePreview(prev => [...prev, reader.result]); }; reader.readAsDataURL(file); }); }; const handleAdminLogin = (e) => { e.preventDefault(); // Simulate real auth - for CPanel/MySQL integration replace this with API call if (loginForm.email === 'admin@aztur.az' && loginForm.password === 'admin2026') { setIsAdmin(true); setView('admin'); } else { alert("Yanlış giriş məlumatları!"); } }; const handleBooking = async (tour) => { const name = prompt("Ad və Soyad:"); const phone = prompt("Əlaqə nömrəsi:"); if (!name || !phone) return; try { await addDoc(collection(db, 'artifacts', appId, 'public', 'data', 'all_bookings'), { tourId: tour.id, tourTitle: tour.title, customerName: name, customerPhone: phone, status: 'Yeni', price: tour.basePrice, createdAt: new Date().toISOString() }); alert("Rezervasiya uğurla tamamlandı. Menecerimiz sizinlə əlaqə saxlayacaq."); } catch (err) { console.error(err); } }; const filteredTours = useMemo(() => { return tours.filter(t => t.title.toLowerCase().includes(searchTerm.toLowerCase()) || t.locations.toLowerCase().includes(searchTerm.toLowerCase()) ); }, [tours, searchTerm]); const stats = useMemo(() => { const totalRevenue = bookings.filter(b => b.status === 'Təsdiqləndi').reduce((s, b) => s + Number(b.price), 0); return { revenue: totalRevenue, totalOrders: bookings.length, pending: bookings.filter(b => b.status === 'Yeni').length }; }, [bookings]); if (loading) return
AZTUR YÜKLƏNİR...
; return (
{/* Navigation */}
{/* HOME VIEW */} {view === 'home' && (
2026 Yay Mövsümü

Xəyallarınızdakı
Səyahəti Yaşayın.

Bütün xərclər daxil, professional bələdçi müşayiəti ilə unudulmaz anlar sizi gözləyir.

Populyar İstiqamətlər

Ən çox seçilən və bəyənilən turlarımız

{filteredTours.map((tour) => (
{setSelectedTour(tour); setView('tour-detail'); window.scrollTo(0,0)}}>
4.9 (120 rəy)
{tour.basePrice} AZN

{tour.title}

{tour.category}
{tour.locations.split(',')[0]} {tour.duration || '7 gün'}
{[1,2,3].map(i => )}
+15
))}
)} {/* TOUR DETAIL VIEW */} {view === 'tour-detail' && selectedTour && (

{selectedTour.title}

{selectedTour.locations}
Max 25 Nəfər
Tam Sığortalı
{/* Gallery */}
{selectedTour.images.slice(1,4).map((img, i) => (
))}
Müddət
10 GÜN / 9 GECƏ
Nəqliyyat
AVİABİLET DAXİL
Mətbəx
3 DƏFƏ QİDALANMA

Turun İcmalı

{selectedTour.description}

Qiymətə daxildir:

    {selectedTour.included.split(',').map((item, i) => (
  • {item.trim()}
  • ))}

Qiymətə daxil deyil:

    {selectedTour.notIncluded.split(',').map((item, i) => (
  • {item.trim()}
  • ))}

Səyahət Proqramı

{selectedTour.program.split('\n').map((line, i) => (

{line}

))}
)} {/* LOGIN VIEW */} {view === 'login' && (

Xoş gəldiniz

Yalnız səlahiyyətli şəxslər üçün

setLoginForm({...loginForm, email: e.target.value})} className="w-full p-5 bg-slate-50 border-none rounded-3xl outline-none focus:ring-2 focus:ring-blue-100 transition-all font-bold" placeholder="admin@aztur.az" />
setLoginForm({...loginForm, password: e.target.value})} className="w-full p-5 bg-slate-50 border-none rounded-3xl outline-none focus:ring-2 focus:ring-blue-100 transition-all font-bold" placeholder="••••••••" />
)} {/* ADMIN PANEL */} {view === 'admin' && isAdmin && (

İdarəetmə Paneli

Aztur Global Turizm Sistemləri

{/* STATS */} {activeTab === 'overview' && (
Ümumi Gəlir
{stats.revenue} AZN
Bütün Rezervlər
{stats.totalOrders}
Gözləyən Sorğu
{stats.pending}
)} {/* ADD TOUR TAB */} {activeTab === 'tours' && (

Yeni Tur Yerləşdir

{ e.preventDefault(); if (tourForm.images.length === 0) return alert("Şəkil yükləyin"); try { await addDoc(collection(db, 'artifacts', appId, 'public', 'data', 'tours'), { ...tourForm, createdAt: new Date().toISOString() }); alert("Tur uğurla əlavə edildi!"); setTourForm({ title: '', basePrice: '', duration: '', locations: '', description: '', category: 'Xarici', included: '', notIncluded: '', images: [] }); setImagePreview([]); } catch (err) { console.error(err); } }} className="space-y-8">
setTourForm({...tourForm, title: e.target.value})} className="w-full p-4 bg-slate-50 border-none rounded-2xl outline-none focus:ring-2 focus:ring-blue-100 font-bold" placeholder="Məs: Bali Turu" />
setTourForm({...tourForm, basePrice: e.target.value})} className="w-full p-4 bg-slate-50 border-none rounded-2xl outline-none focus:ring-2 focus:ring-blue-100 font-bold" placeholder="999" />

Faylları bura sürüşdürün və ya klikləyin

{imagePreview.map((src, i) => (
))}
setTourForm({...tourForm, duration: e.target.value})} className="w-full p-4 bg-slate-50 border-none rounded-2xl outline-none font-bold" />