class ScoreCard extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: 'open' });
this.score = this.getAttribute('score') || 85;
this.title = this.getAttribute('title') || 'Score';
this.icon = this.getAttribute('icon') || 'star';
this.status = this.getAttribute('status') || 'Good';
this.color = this.getAttribute('color') || 'green';
this.shadowRoot.innerHTML = `
`;
}
static get observedAttributes() {
return ['score', 'status', 'color'];
}
attributeChangedCallback(name, oldValue, newValue) {
if (name === 'score' && this.shadowRoot) {
const ring = this.shadowRoot.querySelector('.score-ring');
const value = this.shadowRoot.querySelector('.score-value');
const radius = 54;
const circumference = 2 * Math.PI * radius;
if (ring) {
ring.style.strokeDashoffset = circumference * (1 - newValue / 100);
}
if (value) {
value.textContent = newValue;
}
}
if (name === 'status' && this.shadowRoot) {
const badge = this.shadowRoot.querySelector('.status-badge');
if (badge) {
badge.textContent = newValue;
badge.className = `status-badge status-${newValue.toLowerCase().replace(' ', '-')}`;
}
}
if (name === 'color' && this.shadowRoot) {
const ring = this.shadowRoot.querySelector('.score-ring');
if (ring) {
ring.className = `score-ring color-${newValue}`;
}
}
}
}
customElements.define('score-card', ScoreCard);