// Sample data - in a real app, this would come from a database let transactions = [ { id: 1, date: '2023-11-15', time: '10:30 AM', description: 'Vegetables for home', amount: 350, type: 'expense', person: 'Mother', balance: 4650 }, { id: 2, date: '2023-11-14', time: '5:45 PM', description: 'Grocery shopping', amount: 1200, type: 'expense', person: 'Father', balance: 5000 }, { id: 3, date: '2023-11-12', time: '12:15 PM', description: 'Received money', amount: 2000, type: 'income', person: 'Brother', balance: 6200 } ]; let familyMembers = [ { id: 1, name: 'Anubhav', balance: 0, avatar: 'http://static.photos/people/200x200/1' }, { id: 2, name: 'Anidhya', balance: 0, avatar: 'http://static.photos/people/200x200/2' }, { id: 3, name: 'Mumma', balance: 0, avatar: 'http://static.photos/people/200x200/3' }, { id: 4, name: 'Papa Ji', balance: 0, avatar: 'http://static.photos/people/200x200/4' } ]; // Calculate current balance function calculateBalance() { return transactions.reduce((total, transaction) => { return transaction.type === 'income' ? total + transaction.amount : total - transaction.amount; }, 0); } // Load initial data function loadInitialData() { setupDarkMode(); // Update balance const balance = calculateBalance(); document.getElementById('current-balance').textContent = `₹${balance.toFixed(2)}`; // Load recent transactions (last 3) const recentTransactions = transactions.slice(0, 3); const transactionsContainer = document.getElementById('recent-transactions'); recentTransactions.forEach(transaction => { const transactionEl = document.createElement('div'); transactionEl.className = 'transaction-card bg-gray-50 p-4 rounded-md'; transactionEl.innerHTML = `

${transaction.description}

${transaction.person} • ${transaction.date} ${transaction.time}

${transaction.type === 'income' ? '+' : '-'}₹${transaction.amount.toFixed(2)}

`; transactionsContainer.appendChild(transactionEl); }); // Load family members const familyContainer = document.getElementById('family-members'); familyMembers.forEach(member => { const memberEl = document.createElement('div'); memberEl.className = 'family-member-card bg-gray-50 p-4 rounded-md text-center'; memberEl.innerHTML = ` ${member.name}

${member.name}

${member.balance > 0 ? 'You owe' : member.balance < 0 ? 'Owes you' : 'Settled'} ${member.balance !== 0 ? '₹' + Math.abs(member.balance).toFixed(2) : ''}

`; familyContainer.appendChild(memberEl); }); } // Dark mode toggle function setupDarkMode() { const themeToggle = document.getElementById('theme-toggle'); const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches; const currentTheme = localStorage.getItem('theme') || (prefersDark ? 'dark' : 'light'); if (currentTheme === 'dark') { document.documentElement.setAttribute('data-theme', 'dark'); themeToggle.innerHTML = ''; } else { document.documentElement.removeAttribute('data-theme'); themeToggle.innerHTML = ''; } feather.replace(); themeToggle.addEventListener('click', () => { const currentTheme = document.documentElement.getAttribute('data-theme'); if (currentTheme === 'dark') { document.documentElement.removeAttribute('data-theme'); localStorage.setItem('theme', 'light'); themeToggle.innerHTML = ''; } else { document.documentElement.setAttribute('data-theme', 'dark'); localStorage.setItem('theme', 'dark'); themeToggle.innerHTML = ''; } feather.replace(); }); } // Shared functions function formatDate(dateString) { const options = { year: 'numeric', month: 'short', day: 'numeric' }; return new Date(dateString).toLocaleDateString('en-US', options); }