File size: 9,766 Bytes
c61c730
 
 
 
 
 
 
 
 
 
 
 
 
f8f95a3
c61c730
 
 
f8f95a3
 
569161a
c61c730
 
f0ab918
 
 
 
 
 
 
37dbf5f
 
 
f0ab918
a4bedd0
f0ab918
 
 
 
 
 
 
a4bedd0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37dbf5f
 
 
f8f95a3
334eee7
 
 
f8f95a3
334eee7
 
 
 
 
 
 
 
 
 
 
f8f95a3
c61c730
 
 
 
 
 
 
 
 
 
 
f8f95a3
c61c730
 
 
f8f95a3
 
c61c730
 
 
 
f8f95a3
 
c61c730
 
 
 
 
 
334eee7
 
 
 
 
 
 
f8f95a3
 
c61c730
 
f8f95a3
c61c730
 
87ee313
2777a72
87ee313
 
 
f8f95a3
 
87ee313
c61c730
 
 
 
 
2777a72
f8f95a3
 
2777a72
 
 
 
 
87ee313
 
f8f95a3
37dbf5f
 
 
 
 
 
 
2777a72
c61c730
 
 
f8f95a3
 
 
 
c61c730
 
 
 
 
2777a72
 
 
 
 
 
 
 
 
f8f95a3
 
2777a72
 
 
 
 
 
c61c730
 
2777a72
c61c730
 
 
 
 
 
f8f95a3
 
c61c730
 
87ee313
 
 
 
 
a4bedd0
 
c61c730
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
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 = '<i data-feather="check-circle" class="mr-2"></i> 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 = '<li class="py-2 text-gray-600 italic">No payments recorded yet</li>';
        } else {
            attendanceData.history.forEach(entry => {
            const li = document.createElement('li');
            li.className = 'history-item group';
            li.innerHTML = `
                <div class="flex justify-between items-center">
                    <div class="flex items-center">
                        <div class="w-8 h-8 rounded-full flex items-center justify-center mr-3 ${entry.isFullDay ? 'bg-primary-500/10' : 'bg-yellow-500/10'}">
                            <i data-feather="${entry.isFullDay ? 'check' : 'clock'}" class="${entry.isFullDay ? 'text-primary-500' : 'text-yellow-500'} w-4 h-4"></i>
                        </div>
                        <div>
                            <span class="font-medium">${entry.date}</span>
                            <span class="text-gray-500 text-sm ml-2">${entry.time}</span>
                        </div>
                    </div>
                    <div class="flex items-center">
                        <span class="font-medium ${entry.isFullDay ? 'text-primary-500' : 'text-yellow-500'} mr-3">
                            +${entry.amount.toFixed(2)}
                        </span>
                        <button class="delete-btn opacity-0 group-hover:opacity-100 transition-opacity duration-200 text-red-500 hover:text-red-700" data-timestamp="${entry.timestamp}">
                            <i data-feather="trash-2" class="w-4 h-4"></i>
                        </button>
                    </div>
                </div>
            `;
historyList.appendChild(li);
        // Add event listener to delete button
        const deleteBtn = li.querySelector('.delete-btn');
        deleteBtn.addEventListener('click', (e) => {
            e.preventDefault();
            e.stopPropagation();
            deleteHistoryEntry(entry.timestamp);
        });
});
        }

        // Update goal progress
        updateGoalProgress(goal1, 10);
        updateGoalProgress(goal2, 20);
        updateGoalProgress(goal3, 40);
}

    function updateGoalProgress(progressBar, goalDays) {
        const progress = Math.min((attendanceData.totalDays / goalDays) * 100, 100);
        progressBar.style.width = `${progress}%`;
    }
    function deleteHistoryEntry(timestamp) {
        if (!confirm('Remove this attendance record? This will adjust your total days and earnings.')) return;
        
        // Find and remove the entry
        const entryIndex = attendanceData.history.findIndex(entry => entry.timestamp === timestamp);
        if (entryIndex === -1) return;
        
        // Subtract days from total
        const removedEntry = attendanceData.history[entryIndex];
        attendanceData.totalMoney -= removedEntry.amount;
// Remove from history
        attendanceData.history.splice(entryIndex, 1);
        
        // Save and update
        localStorage.setItem('attendanceData', JSON.stringify(attendanceData));
        updateUI();
    }

    // Add a reset button functionality (hidden by default, can be enabled if needed)
function addResetButton() {
        const resetBtn = document.createElement('button');
        resetBtn.textContent = 'Reset All Data';
        resetBtn.className = 'mt-4 text-sm text-red-500 hover:text-red-700';
        resetBtn.addEventListener('click', () => {
            if (confirm('Are you sure you want to reset all data? This cannot be undone.')) {
                localStorage.removeItem('attendanceData');
                attendanceData = { totalMoney: 0, history: [] };
updateUI();
            }
        });
        const resetBtnContainer = document.createElement('div');
        resetBtnContainer.className = 'text-center mt-8';
        resetBtnContainer.appendChild(resetBtn);
        document.querySelector('main').appendChild(resetBtnContainer);
}
    // Check for daily reminder and send SMS if needed
    checkDailyReminder();

    // Uncomment to enable reset button (for debugging)
    // addResetButton();
});