document.addEventListener('DOMContentLoaded', function() { // DOM Elements const fullDayBtn = document.getElementById('fullDayBtn'); const halfDayBtn = document.getElementById('halfDayBtn'); const totalDaysDisplay = document.getElementById('totalDays'); const totalEarningsDisplay = document.getElementById('totalEarnings'); const historyList = document.getElementById('historyList'); const goal1 = document.getElementById('goal1'); const goal2 = document.getElementById('goal2'); const goal3 = document.getElementById('goal3'); // Initialize data from localStorage or set defaults let attendanceData = JSON.parse(localStorage.getItem('attendanceData')) || { totalMoney: 0, history: [] }; // Constants const FULL_DAY_RATE = 2.00; const HALF_DAY_RATE = 1.00; // Update the UI with current data updateUI(); // Event Listeners // Add empty dishwasher button functionality const emptyDishwasherBtn = document.createElement('button'); emptyDishwasherBtn.id = 'emptyDishwasherBtn'; emptyDishwasherBtn.className = 'w-full py-3 px-4 bg-secondary-500 hover:bg-secondary-600 text-black transition flex items-center justify-center mb-4'; emptyDishwasherBtn.innerHTML = ' Empty Dishwasher (+$1.00)'; document.querySelector('.bg-white.p-8').insertBefore(emptyDishwasherBtn, document.querySelector('.bg-white.p-8').firstChild); fullDayBtn.addEventListener('click', (e) => { e.preventDefault(); addAttendance(true); }); emptyDishwasherBtn.addEventListener('click', (e) => { e.preventDefault(); const questsElement = document.querySelector('custom-quests'); if (questsElement) { questsElement.updateQuestProgress('emptyDishwasher'); } }); // SMS Notification Functions async function sendSMS(phoneNumber, message) { // In a real implementation, you would call your backend API here // which would then use Twilio to send the SMS console.log(`Would send SMS to ${phoneNumber}: ${message}`); // This is just a simulation - in production you would: // 1. Create a backend endpoint (e.g., /api/send-sms) // 2. Call it with fetch(): /* try { const response = await fetch('/api/send-sms', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ phoneNumber, message }) }); const data = await response.json(); console.log('SMS sent:', data); } catch (error) { console.error('Error sending SMS:', error); } */ } function checkDailyReminder() { const settings = JSON.parse(localStorage.getItem('notificationSettings')) || {}; if (!settings.dailyReminder || !settings.phoneNumber) return; // Check current time const now = new Date(); const currentHour = now.getHours(); const currentMinute = now.getMinutes(); // If it's 14:00 (2PM) and user hasn't logged attendance today if (currentHour === 14 && currentMinute === 0) { const today = now.toLocaleDateString(); const attendanceData = JSON.parse(localStorage.getItem('attendanceData')) || { history: [] }; const hasLoggedToday = attendanceData.history.some(entry => { return entry.date === today; }); if (!hasLoggedToday) { const message = `Prestige School Rewards: Don't forget to log your attendance today!`; sendSMS(settings.phoneNumber, message); } } } // Check time every minute setInterval(checkDailyReminder, 60000); halfDayBtn.addEventListener('click', (e) => { e.preventDefault(); addAttendance(false); }); // Functions // Listen for UI update events from quests component document.addEventListener('updateUI', updateUI); function addAttendance(isFullDay) { // Update quest progress const questsElement = document.querySelector('custom-quests'); if (questsElement) { questsElement.updateQuestProgress(isFullDay ? 'attendFullDay' : 'attendHalfDay'); // Check for perfect week progress if (isFullDay) { questsElement.updateQuestProgress('perfectWeek'); } } const now = new Date(); const dateString = now.toLocaleDateString('en-US', { weekday: 'short', month: 'short', day: 'numeric' }); const timeString = now.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' }); // Add to history const amount = isFullDay ? FULL_DAY_RATE : HALF_DAY_RATE; const entry = { date: dateString, time: timeString, amount: amount, isFullDay: isFullDay, timestamp: now.getTime() }; attendanceData.history.unshift(entry); attendanceData.totalMoney += amount; // Save to localStorage localStorage.setItem('attendanceData', JSON.stringify(attendanceData)); // Update UI updateUI(); } function updateUI() { // Update quests display if it exists const questsElement = document.querySelector('custom-quests'); if (questsElement) { questsElement.renderQuests(); } // Update total days and earnings totalEarningsDisplay.textContent = `${attendanceData.totalMoney.toFixed(2)}`; // Update history list historyList.innerHTML = ''; if (attendanceData.history.length === 0) { historyList.innerHTML = '