class PostCard extends HTMLElement { connectedCallback() { this.attachShadow({ mode: 'open' }); // Get attributes const name = this.getAttribute('data-name') || 'Unknown User'; const avatar = this.getAttribute('data-avatar') || 'https://via.placeholder.com/40'; const time = this.getAttribute('data-time') || 'Just now'; const content = this.getAttribute('data-content') || ''; const image = this.getAttribute('data-image') || ''; const likes = this.getAttribute('data-likes') || '0'; const comments = this.getAttribute('data-comments') || '0'; const hasImage = image && image.length > 0; this.shadowRoot.innerHTML = `
${name}

${name}

${time} ยท
${content}
${hasImage ? `
Post content
` : ''}
${likes}
${comments} comments
`; } } customElements.define('post-card', PostCard);