export class NotesTracker { constructor(containerId) { this.container = document.getElementById(containerId); this.STORAGE_KEY = 'hydroflux_notes'; this.notes = []; this.loadState(); this.render(); } loadState() { const saved = localStorage.getItem(this.STORAGE_KEY); if (saved) { this.notes = JSON.parse(saved); } else { this.notes = [ { id: 1, text: "Feeling hydrated today. Remember to add those gym sessions!", date: new Date().toISOString() } ]; this.saveState(); } } saveState() { localStorage.setItem(this.STORAGE_KEY, JSON.stringify(this.notes)); } addNote(text) { if (!text.trim()) return; this.notes.unshift({ id: Date.now(), text: text, date: new Date().toISOString() }); this.saveState(); this.render(); } deleteNote(id) { if (confirm("Delete this note?")) { this.notes = this.notes.filter(n => n.id !== id); this.saveState(); this.render(); } } render() { if (!this.container) return; this.container.innerHTML = `

NOTES

${this.notes.map(note => `

${note.text}

`).join('')}
`; this.attachEvents(); } attachEvents() { const btn = this.container.querySelector('#add-note-btn'); const input = this.container.querySelector('#new-note-text'); btn.addEventListener('click', () => { this.addNote(input.value); input.value = ''; }); this.container.querySelectorAll('.delete-note-btn').forEach(b => { b.addEventListener('click', (e) => { this.deleteNote(parseInt(e.currentTarget.dataset.id)); }); }); } }