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 */}
setView('home')} className={view === 'home' ? 'text-blue-600' : 'hover:text-blue-600'}>Turlar
Haqqımızda
setView('policy')} className={view === 'policy' ? 'text-blue-600' : 'hover:text-blue-600'}>Məxfilik
Əlaqə
setSearchTerm(e.target.value)}
/>
{isAdmin ? (
setView('admin')} className="flex items-center gap-2 bg-blue-50 text-blue-600 px-5 py-2.5 rounded-full font-bold text-sm">
Panel
setIsAdmin(false)} className="text-slate-400 hover:text-red-500 transition-colors">
) : (
setView('login')} className="bg-slate-900 text-white px-6 py-2.5 rounded-full font-bold text-sm hover:scale-105 transition-transform flex items-center gap-2 shadow-xl shadow-slate-200">
Admin
)}
{/* 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.
İndi Kəşf Et
Kampaniyalar
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
Ətraflı
))}
)}
{/* TOUR DETAIL VIEW */}
{view === 'tour-detail' && selectedTour && (
setView('home')} className="flex items-center gap-2 text-slate-400 font-bold hover:text-blue-600 transition-colors uppercase tracking-widest text-xs">
Turlara Qayıt
{selectedTour.title}
{selectedTour.locations}
Max 25 Nəfər
Tam Sığortalı
{/* Gallery */}
{selectedTour.images.slice(1,4).map((img, i) => (
))}
Nəqliyyat
AVİABİLET DAXİL
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) => (
))}
)}
{/* LOGIN VIEW */}
{view === 'login' && (
Xoş gəldiniz
Yalnız səlahiyyətli şəxslər üçün
)}
{/* ADMIN PANEL */}
{view === 'admin' && isAdmin && (
İdarəetmə Paneli
Aztur Global Turizm Sistemləri
setActiveTab('overview')} className={`px-6 py-2.5 rounded-xl text-xs font-black uppercase tracking-wider transition-all ${activeTab === 'overview' ? 'bg-blue-600 text-white shadow-lg shadow-blue-200' : 'text-slate-400 hover:bg-slate-50'}`}>İcmal
setActiveTab('tours')} className={`px-6 py-2.5 rounded-xl text-xs font-black uppercase tracking-wider transition-all ${activeTab === 'tours' ? 'bg-blue-600 text-white shadow-lg shadow-blue-200' : 'text-slate-400 hover:bg-slate-50'}`}>Turlar
setActiveTab('bookings')} className={`px-6 py-2.5 rounded-xl text-xs font-black uppercase tracking-wider transition-all ${activeTab === 'bookings' ? 'bg-blue-600 text-white shadow-lg shadow-blue-200' : 'text-slate-400 hover:bg-slate-50'}`}>Sifarişlər
{/* 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' && (
Yayımlanan Turlar
{tours.map(t => (
{t.title}
{t.basePrice} AZN
deleteDoc(doc(db, 'artifacts', appId, 'public', 'data', 'tours', t.id))} className="p-3 text-red-400 hover:bg-red-50 rounded-xl opacity-0 group-hover:opacity-100 transition-all">
))}
)}
{/* BOOKINGS TAB */}
{activeTab === 'bookings' && (
Müştəri
Tur
Qiymət
Status
Əməliyyat
{bookings.map(b => (
{b.customerName}
{b.customerPhone}
{b.tourTitle}
{b.price} AZN
{b.status}
updateDoc(doc(db, 'artifacts', appId, 'public', 'data', 'all_bookings', b.id), {status: 'Təsdiqləndi'})} className="p-2.5 bg-green-50 text-green-600 rounded-xl hover:bg-green-600 hover:text-white transition-all">
))}
)}
)}
{/* POLICY VIEW */}
{view === 'policy' && (
1. Məlumatların Qorunması
AZTUR olaraq biz sizin şəxsi məlumatlarınızın təhlükəsizliyinə tam zəmanət veririk. Toplanan bütün məlumatlar 256-bit SSL protokolu ilə şifrələnir.
2. Ödəniş və Maliyyə
Maliyyə əməliyyatları heç vaxt bizim sistemimizdə saxlanılmır. Bütün ödənişlər birbaşa rəsmi bank tərəfdaşlarımızın portalı vasitəsilə həyata keçirilir.
Son yenilənmə: Fevral 2026
setView('home')} className="bg-slate-900 text-white px-8 py-4 rounded-2xl font-black">Bağla
)}
);
};
export default App;