class TaskCard extends HTMLElement { connectedCallback() { this.attachShadow({ mode: 'open' }); const id = this.getAttribute('id'); const text = this.getAttribute('text'); const email = this.getAttribute('email'); const completed = this.getAttribute('completed') === 'true'; const hasReminder = this.getAttribute('has-reminder') === 'true'; const reminderStopped = this.getAttribute('reminder-stopped') === 'true'; const reminderFrequency = this.getAttribute('reminder-frequency'); const createdAt = this.getAttribute('created-at'); const createdDate = new Date(createdAt).toLocaleDateString(); const timeAgo = this.getTimeAgo(createdAt); this.shadowRoot.innerHTML = `

${text}

${email}
${timeAgo}
${hasReminder && !reminderStopped ? `Active (${reminderFrequency || 'daily'})` : ''} ${reminderStopped ? 'Reminder Stopped' : ''}
${!completed ? ` ` : ''}
`; } getTimeAgo(dateString) { const date = new Date(dateString); const seconds = Math.floor((new Date() - date) / 1000); let interval = seconds / 31536000; if (interval > 1) return Math.floor(interval) + 'y ago'; interval = seconds / 2592000; if (interval > 1) return Math.floor(interval) + 'mo ago'; interval = seconds / 86400; if (interval > 1) return Math.floor(interval) + 'd ago'; interval = seconds / 3600; if (interval > 1) return Math.floor(interval) + 'h ago'; interval = seconds / 60; if (interval > 1) return Math.floor(interval) + 'm ago'; return 'Just now'; } } customElements.define('task-card', TaskCard);