export class IconButtonCellRenderer {
    init(params) {
        this.createIconButton(params);
    }
    getGui() {
        return this.eGui;
    }
    refresh(params) {
        this.updateIconButton(params);
        return true;
    }
    createIconButton(params) {
        const config = params.data[params.colDef.field];
        const options = params.colDef.cellRendererParams || {};
        this.eGui = document.createElement('div');
        this.eIconButton = document.createElement('ifx-icon-button');
        if (this.hasRequiredKeys(config)) {
            this.setIconButtonAttributes(config);
            this.eGui.appendChild(this.eIconButton);
            this.attachEventListener(options, params);
        }
        else {
            this.eGui.textContent = config ? String(config) : '';
        }
    }
    updateIconButton(params) {
        const config = params.data[params.colDef.field];
        const options = params.colDef.cellRendererParams || {};
        if (this.hasRequiredKeys(config)) {
            this.setIconButtonAttributes(config);
            this.detachEventListener();
            this.attachEventListener(options, params);
        }
        else {
            this.eGui.textContent = config ? String(config) : '';
        }
    }
    setIconButtonAttributes(config) {
        this.eIconButton.setAttribute('disabled', config.disabled.toString());
        this.eIconButton.setAttribute('variant', config.variant);
        this.eIconButton.setAttribute('shape', config.shape);
        this.eIconButton.setAttribute('size', config.size);
        this.eIconButton.setAttribute('target', config.target);
        this.eIconButton.setAttribute('href', config.href);
        this.eIconButton.setAttribute('icon', config.icon);
    }
    attachEventListener(options, params) {
        this.eventListener = (event) => {
            if (options.onIconButtonClick) {
                options.onIconButtonClick(params, event);
            }
        };
        this.eIconButton.addEventListener('click', this.eventListener);
    }
    detachEventListener() {
        if (this.eventListener) {
            this.eIconButton.removeEventListener('click', this.eventListener);
        }
    }
    hasRequiredKeys(config) {
        return config && config.variant !== '' && config.size !== '' && config.shape !== '';
    }
}
//# sourceMappingURL=iconButtonCellRenderer.js.map
