if (!customElements.get('lf-page-product')) {
  customElements.define('lf-page-product', class extends HTMLElement {
    connectedCallback() {
      if (this.dataset.ready) return;
      this.dataset.ready = 'true';
      const select = this.querySelector('[data-lf-variant]');
      if (!select) return;
      select.addEventListener('change', () => {
        const option = select.selectedOptions[0];
        this.querySelector('[data-lf-price]').textContent = option.dataset.price;
        const button = this.querySelector('[data-lf-add]');
        button.disabled = option.dataset.available !== 'true';
        button.textContent = button.disabled ? 'Sold out' : 'Add to cart';
        const image = this.querySelector('.lf-media img');
        if (image && option.dataset.image) { image.removeAttribute('srcset'); image.src = option.dataset.image; image.alt = option.dataset.imageAlt; }
      });
    }
  });
}
