class CustomCrewCard extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
}
connectedCallback() {
const title = this.getAttribute('title') || 'Crew Build';
const tank = this.getAttribute('tank') || 'Unknown Tank';
const rating = this.getAttribute('rating') || '0';
const perks = this.getAttribute('perks') || 'No perks specified';
const image = this.getAttribute('image') || 'http://static.photos/technology/320x240/10';
this.shadowRoot.innerHTML = `
${title}
${tank}
${this.renderStars(rating)}
${rating}
`;
// Initialize feather icons in shadow DOM
if (feather) {
const icons = this.shadowRoot.querySelectorAll('[data-feather]');
icons.forEach(icon => {
feather.replace(icon);
});
}
}
renderStars(rating) {
const numRating = parseFloat(rating);
const fullStars = Math.floor(numRating);
const hasHalfStar = numRating % 1 >= 0.5;
const emptyStars = 5 - fullStars - (hasHalfStar ? 1 : 0);
let stars = '';
// Full stars
for (let i = 0; i < fullStars; i++) {
stars += '';
}
// Half star
if (hasHalfStar) {
stars += '';
}
// Empty stars
for (let i = 0; i < emptyStars; i++) {
stars += '';
}
return stars;
}
}
customElements.define('custom-crew-card', CustomCrewCard);