import React, { useState, useEffect } from 'react'; import { initializeApp } from 'firebase/app'; import { getFirestore, collection, getDocs, query, where } from 'firebase/firestore'; import { getAuth, onAuthStateChanged } from 'firebase/auth'; import { ChevronLeft, ChevronRight, Calendar, Bell, Settings, Info } from 'lucide-react'; // Firebase configuration const firebaseConfig = { apiKey: "IvKQMx", authDomain: "IvKQMx.firebaseapp.com", projectId: "IvKQMx", storageBucket: "IvKQMx.appspot.com", messagingSenderId: "IvKQMx", appId: "IvKQMx" }; // Initialize Firebase const app = initializeApp(firebaseConfig); const db = getFirestore(app); const auth = getAuth(app); // Mock data for development (will be replaced with Firebase data) const monthsNP = [ 'बैशाख', 'जेठ', 'असार', 'श्रावण', 'भदौ', 'असोज', 'कार्तिक', 'मंसिर', 'पुष', 'माघ', 'फागुन', 'चैत्र' ]; const monthsEN = [ 'Baisakh', 'Jestha', 'Asar', 'Shrawan', 'Bhadra', 'Ashwin', 'Kartik', 'Mangsir', 'Poush', 'Magh', 'Falgun', 'Chaitra' ]; const weekdaysNP = ['आइतवार', 'सोमवार', 'मङ्गलवार', 'बुधवार', 'बिहिवार', 'शुक्रवार', 'शनिवार']; const weekdaysEN = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']; const gregorianMonths = [ 'January-February', 'February-March', 'March-April', 'April-May', 'May-June', 'June-July', 'July-August', 'August-September', 'September-October', 'October-November', 'November-December', 'December-January' ]; // Convert English digits to Nepali digits const toNepaliDigits = (num) => { const nepaliDigits = ['०', '१', '२', '३', '४', '५', '६', '७', '८', '९']; return num.toString().split('').map(digit => isNaN(parseInt(digit)) ? digit : nepaliDigits[parseInt(digit)] ).join(''); }; // Mock calendar data for Baisakh 2082 const generateMockCalendarData = () => { const days = []; const startDay = 6; // Saturday (0-indexed, 6 = Saturday) const totalDays = 31; // Add empty cells for days before the 1st of the month for (let i = 0; i < startDay; i++) { days.push({ empty: true }); } // Generate days of the month for (let i = 1; i <= totalDays; i++) { const gregorianDate = i + 13; // Approximation for April-May const nepaliDate = i; let tithi = ''; let isSpecial = false; // Add some sample tithis and festivals if (i === 1) { tithi = 'नयाँ वर्ष'; isSpecial = true; } else if (i === 14) { tithi = 'मेष सङ्क्रान्ति'; isSpecial = true; } else if (i === 15) { tithi = 'पूर्णिमा'; } else if (i === 22) { tithi = 'एकादशी'; } else if (i === 30) { tithi = 'औंसी'; } days.push({ gregorianDate: gregorianDate > 30 ? gregorianDate - 30 : gregorianDate, nepaliDate, tithi, isSpecial }); } return days; }; const NepaliVedicCalendar = () => { const [currentYear, setCurrentYear] = useState(2082); const [currentMonth, setCurrentMonth] = useState(0); // 0-indexed (0 = Baisakh) const [calendarData, setCalendarData] = useState([]); const [language, setLanguage] = useState('np'); // 'np' for Nepali, 'en' for English const [loading, setLoading] = useState(true); const [user, setUser] = useState(null); // Check if user is authenticated useEffect(() => { const unsubscribe = onAuthStateChanged(auth, (user) => { setUser(user); }); return () => unsubscribe(); }, []); // Fetch calendar data from Firebase (mock for now) useEffect(() => { const fetchCalendarData = async () => { setLoading(true); try { // In a real implementation, we would fetch from Firebase // const calendarRef = collection(db, 'calendar'); // const q = query(calendarRef, where("year", "==", currentYear), where("month", "==", currentMonth)); // const querySnapshot = await getDocs(q); // const data = querySnapshot.docs.map(doc => doc.data()); // For now, use mock data const mockData = generateMockCalendarData(); setCalendarData(mockData); } catch (error) { console.error("Error fetching calendar data:", error); } finally { setLoading(false); } }; fetchCalendarData(); }, [currentYear, currentMonth]); const goToPreviousMonth = () => { if (currentMonth === 0) { setCurrentMonth(11); setCurrentYear(currentYear - 1); } else { setCurrentMonth(currentMonth - 1); } }; const goToNextMonth = () => { if (currentMonth === 11) { setCurrentMonth(0); setCurrentYear(currentYear + 1); } else { setCurrentMonth(currentMonth + 1); } }; const selectMonth = (monthIndex) => { setCurrentMonth(monthIndex); }; const toggleLanguage = () => { setLanguage(language === 'np' ? 'en' : 'np'); }; // Render calendar grid const renderCalendarGrid = () => { if (loading) { return (
); } return (
{/* Weekday headers */} {(language === 'np' ? weekdaysNP : weekdaysEN).map((day, index) => (
{day}
))} {/* Calendar days */} {calendarData.map((day, index) => { if (day.empty) { return
; } return (
{day.gregorianDate}
{language === 'np' ? toNepaliDigits(day.nepaliDate) : day.nepaliDate}
{day.tithi && (
{day.tithi}
)}
); })}
); }; // Render month thumbnails const renderMonthThumbnails = () => { return (
{(language === 'np' ? monthsNP : monthsEN).map((month, index) => (
selectMonth(index)} className={`flex-shrink-0 cursor-pointer p-2 rounded-md text-center min-w-[80px] ${ currentMonth === index ? 'bg-orange-500 text-white border-2 border-red-600' : 'bg-orange-100 text-orange-800' }`} > {month}
))}
); }; return (
{/* Header */}
{language === 'np' ? `वि.सं. ${toNepaliDigits(currentYear)}` : `B.S. ${currentYear}`}
{gregorianMonths[currentMonth]}

{language === 'np' ? 'वैदिक तिथि पत्रम्' : 'Vedic Calendar'}

{language === 'np' ? monthsNP[currentMonth] : monthsEN[currentMonth]}
{/* Main Calendar */}
{renderCalendarGrid()}
{/* Month Thumbnails */}
{renderMonthThumbnails()}
{/* Footer with actions */}
); }; export default NepaliVedicCalendar;