export class ButtonCellRenderer {
    init(params) {
        this.createButton(params);
    }
    getGui() {
        return this.eGui;
    }
    refresh(params) {
        this.updateButton(params);
        return true;
    }
    createButton(params) {
        const config = params.data[params.colDef.field];
        const options = params.colDef.cellRendererParams || {};
        this.eGui = document.createElement('div');
        this.eButton = document.createElement('ifx-button');
        if (this.hasRequiredKeys(config)) {
            this.setButtonAttributes(config);
            this.eGui.appendChild(this.eButton);
            this.attachEventListener(options, params);
        }
        else {
            this.eGui.textContent = config ? String(config) : '';
        }
    }
    updateButton(params) {
        const config = params.data[params.colDef.field];
        const options = params.colDef.cellRendererParams || {};
        if (this.hasRequiredKeys(config)) {
            this.setButtonAttributes(config);
            this.detachEventListener();
            this.attachEventListener(options, params);
        }
        else {
            this.eGui.textContent = config ? String(config) : '';
        }
    }
    setButtonAttributes(config) {
        this.eButton.setAttribute('disabled', config.disabled.toString());
        this.eButton.setAttribute('variant', config.variant);
        this.eButton.setAttribute('theme', config.theme);
        this.eButton.setAttribute('type', config.type);
        this.eButton.setAttribute('size', config.size);
        this.eButton.setAttribute('full-width', config.fullWidth.toString());
        this.eButton.setAttribute('target', config.target);
        this.eButton.setAttribute('href', config.href);
        this.eButton.textContent = config.text;
    }
    attachEventListener(options, params) {
        this.eventListener = (event) => {
            if (options.onButtonClick) {
                options.onButtonClick(params, event);
            }
        };
        this.eButton.addEventListener('click', this.eventListener);
    }
    detachEventListener() {
        if (this.eventListener) {
            this.eButton.removeEventListener('click', this.eventListener);
        }
    }
    hasRequiredKeys(config) {
        return config && config.text !== '' && config.variant !== '' && config.size !== '' && config.type !== '';
    }
}
//# sourceMappingURL=buttonCellRenderer.js.map
