
export class ProductAddOption extends HTMLButtonElement {
    constructor() {
        super();
        this.addEventListener('click', this.handleClick.bind(this));
    }

    handleClick(e) {
        e.preventDefault();
        
        const inputId = this.getAttribute('data-input-id');
        const baseUrl = this.getAttribute('data-url');
        const input = document.getElementById(inputId);

        if (input && input.value) {
            // The base URL comes from Twig path() which includes ?act=addOption
            // We safely append the idOption parameter
            window.location.href = `${baseUrl}&idOption=${input.value}`;
        } else {
            // Visual feedback could be added here (e.g., shake effect or border color)
            alert("Veuillez sélectionner une option avant d'ajouter.");
        }
    }
}
