class ReviewCard extends HTMLElement {
connectedCallback() {
const name = this.getAttribute('name') || 'Anonymous';
const rating = parseInt(this.getAttribute('rating')) || 5;
const text = this.getAttribute('text') || 'Great service!';
const service = this.getAttribute('service') || 'Service';
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
"${text}"
${this.generateDate()}
`;
}
generateStars(rating) {
let stars = '';
for (let i = 0; i < 5; i++) {
if (i < rating) {
stars += '';
} else {
stars += '';
}
}
return stars;
}
generateDate() {
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
const date = new Date();
const month = months[date.getMonth()];
const year = date.getFullYear();
return `${month} ${year}`;
}
}
customElements.define('review-card', ReviewCard);