import React, { useState, useEffect } from 'react';
import {
Plus,
Trash2,
Layout,
User,
Palette,
Share2,
Cat,
GripVertical,
Eye,
Instagram,
Facebook,
Twitter,
Globe,
Smartphone,
Check,
LogOut,
Mail,
Lock,
ArrowRight
} from 'lucide-react';
// --- FIREBASE IMPORTS ---
import { initializeApp } from 'firebase/app';
import { getAuth, signInWithPopup, GoogleAuthProvider, signOut, onAuthStateChanged } from 'firebase/auth';
// --- FIREBASE CONFIGURATION ---
const firebaseConfig = {
apiKey: "AIzaSyAqndpG932fb8RfOUBDAf_Q4R-9llpUJlI",
authDomain: "biolink-6e6ee.firebaseapp.com",
projectId: "biolink-6e6ee",
storageBucket: "biolink-6e6ee.firebasestorage.app",
messagingSenderId: "232844523779",
appId: "1:232844523779:web:a0bdf6e804892ca5c41136",
measurementId: "G-2DSTF8HF5P"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
const provider = new GoogleAuthProvider();
// --- 1. CÁC COMPONENT PHỤ TRỢ (ĐỊNH NGHĨA TRƯỚC KHI DÙNG) ---
// Nút chuyển đổi (Toggle Switch)
// FIX: Dùng span thay vì div bên trong button để tránh lỗi HTML nesting
const Toggle = ({ checked, onChange }) => (
);
// Component Menu Item trong Sidebar
// FIX: Dùng span bọc icon thay vì div
const NavItem = ({ icon, label, active, onClick }) => {
return (
);
};
// Component lựa chọn Theme
// FIX: Chuyển từ button sang div để chứa được các div con phức tạp bên trong
const ThemeOption = ({ label, bg, btn, textColor, active, onClick }) => {
return (
)
};
// Component lựa chọn kiểu nút
const ButtonStyleOption = ({ label, shape, active, onClick }) => {
return (
)
};
// --- 2. TRANG ĐĂNG NHẬP / ĐĂNG KÝ (AUTH PAGE) ---
const AuthPage = () => {
const [isLogin, setIsLogin] = useState(true);
const [isLoading, setIsLoading] = useState(false);
const [errorMsg, setErrorMsg] = useState("");
const handleGoogleLogin = async () => {
setIsLoading(true);
setErrorMsg("");
try {
await signInWithPopup(auth, provider);
// Auth state change sẽ được bắt ở App component
} catch (error) {
console.error("Login Failed:", error);
setErrorMsg(error.message);
setIsLoading(false);
}
};
const handleTraditionalSubmit = (e) => {
e.preventDefault();
alert("Vui lòng sử dụng Đăng nhập bằng Google trong phiên bản Demo này!");
};
return (
{/* Form Container */}
{/* Logo */}
{isLogin ? 'Chào mừng trở lại! 👋' : 'Tạo tài khoản mới 🚀'}
{isLogin ? 'Đăng nhập để quản lý Bio Link của bạn.' : 'Bắt đầu xây dựng trang Bio Link miễn phí.'}
{/* Google Login Button */}
{errorMsg && (
{errorMsg}
)}
{/* Traditional Inputs */}
{isLogin ? 'Chưa có tài khoản?' : 'Đã có tài khoản?'}
);
};
// --- 3. ỨNG DỤNG CHÍNH (MAIN APP) - ĐƯỢC ĐỊNH NGHĨA CUỐI CÙNG ---
const App = () => {
// --- STATE (DỮ LIỆU) ---
const [currentUser, setCurrentUser] = useState(null); // Trạng thái đăng nhập
const [authLoading, setAuthLoading] = useState(true); // Trạng thái tải auth ban đầu
const [activeTab, setActiveTab] = useState('links');
const [mobilePreviewMode, setMobilePreviewMode] = useState(false);
// Dữ liệu Profile (sẽ được cập nhật khi login)
const [profile, setProfile] = useState({
username: 'user',
displayName: 'User',
bio: '',
avatar: '',
});
// Dữ liệu Giao diện (Theme)
const [theme, setTheme] = useState({
background: 'bg-slate-50',
buttonStyle: 'rounded-xl',
buttonColor: 'bg-white',
textColor: 'text-slate-800',
accentColor: 'text-orange-500',
});
// Danh sách Links
const [links, setLinks] = useState([
{ id: 1, title: 'Ghé thăm Mewo Website', url: 'https://mewo.life', active: true, icon: 'shop' },
{ id: 2, title: 'Đặt lịch tư vấn (Book me)', url: 'https://cal.com', active: true, icon: 'calendar' },
{ id: 3, title: 'Nhận Ebook Miễn Phí', url: 'https://gumroad.com', active: false, icon: 'book' },
]);
// --- HÀM XỬ LÝ AUTH (FIREBASE LISTENER) ---
useEffect(() => {
// Lắng nghe sự thay đổi trạng thái đăng nhập
const unsubscribe = onAuthStateChanged(auth, (user) => {
if (user) {
// User is signed in
setCurrentUser(user);
setProfile(prev => ({
...prev,
username: user.email ? user.email.split('@')[0] : 'user',
displayName: user.displayName || 'Mewo Friend',
avatar: user.photoURL || 'https://api.dicebear.com/7.x/avataaars/svg?seed=Felix',
bio: prev.bio || 'Chuyên gia bắt chuột & Marketing 🐟 | CEO @Mewo'
}));
} else {
// User is signed out
setCurrentUser(null);
}
setAuthLoading(false);
});
return () => unsubscribe(); // Cleanup subscription
}, []);
const handleLogout = async () => {
try {
await signOut(auth);
} catch (error) {
console.error("Logout Error:", error);
}
};
// --- CÁC HÀM XỬ LÝ LINK (ACTIONS) ---
const handleAddLink = () => {
const newLink = {
id: Date.now(),
title: '',
url: '',
active: true,
icon: 'link'
};
setLinks([newLink, ...links]);
};
const handleUpdateLink = (id, field, value) => {
setLinks(links.map(link => link.id === id ? { ...link, [field]: value } : link));
};
const handleDeleteLink = (id) => {
setLinks(links.filter(link => link.id !== id));
};
const handleToggleLink = (id) => {
setLinks(links.map(link => link.id === id ? { ...link, active: !link.active } : link));
};
// --- RENDERING ---
// Màn hình chờ khi đang kiểm tra đăng nhập
if (authLoading) {
return (
);
}
// Nếu chưa đăng nhập -> Hiển thị AuthPage
if (!currentUser) {
return ;
}
// Nếu đã đăng nhập -> Hiển thị Dashboard
return (
{/* --- SIDEBAR MENU (DESKTOP) --- */}
{/* --- MAIN EDITOR AREA --- */}
{/* Header Mobile */}
{activeTab === 'links' && 'Quản lý Liên kết'}
{activeTab === 'appearance' && 'Tùy chỉnh Giao diện'}
{activeTab === 'settings' && 'Cài đặt Tài khoản'}
{/* Scrollable Content */}
{/* TAB: LINKS */}
{activeTab === 'links' && (
{/* Profile Quick Edit */}
{/* Add Link Button */}
{/* Links List */}
{links.length === 0 && (
Chưa có liên kết nào. Hãy thêm cái đầu tiên! 🐾
)}
{links.map((link, index) => (
))}
)}
{/* TAB: APPEARANCE */}
{activeTab === 'appearance' && (
Themes (Chủ đề)
{/* Theme 1: Default */}
setTheme({...theme, background: 'bg-slate-50', buttonColor: 'bg-white', textColor: 'text-slate-800'})}
/>
{/* Theme 2: Dark Cat */}
setTheme({...theme, background: 'bg-gray-900', buttonColor: 'bg-gray-800', textColor: 'text-white'})}
/>
{/* Theme 3: Orange Paw */}
setTheme({...theme, background: 'bg-orange-50', buttonColor: 'bg-white', textColor: 'text-orange-900'})}
/>
{/* Theme 4: Purple Dream */}
setTheme({...theme, background: 'bg-indigo-900', buttonColor: 'bg-indigo-800', textColor: 'text-indigo-100'})}
/>
Kiểu dáng nút
setTheme({...theme, buttonStyle: 'rounded-none'})} />
setTheme({...theme, buttonStyle: 'rounded-xl'})} />
setTheme({...theme, buttonStyle: 'rounded-full'})} />
)}
{/* TAB: SETTINGS */}
{activeTab === 'settings' && (
Tài khoản của bạn
Email
{currentUser.email}
Gói thành viên
Mèo Con (Free)
)}
{/* --- PREVIEW SECTION (DESKTOP: RIGHT SIDE / MOBILE: OVERLAY) --- */}
);
};
export default App;