export class CheckboxCellRenderer {
    init(params) {
        this.createCheckbox(params);
    }
    getGui() {
        return this.eGui;
    }
    refresh(params) {
        this.updateCheckbox(params);
        return true;
    }
    createCheckbox(params) {
        const config = params.data[params.colDef.field];
        const options = params.colDef.cellRendererParams || {};
        this.eGui = document.createElement('div');
        this.eGui.style.display = 'flex';
        this.eGui.style.alignItems = 'center';
        this.eGui.style.justifyContent = 'center';
        this.eCheckbox = document.createElement('ifx-checkbox');
        if (this.hasRequiredKeys(config)) {
            this.setCheckboxAttributes(config);
            this.eGui.appendChild(this.eCheckbox);
            this.attachEventListener(options, params);
        }
        else {
            this.eGui.textContent = config ? String(config) : 'No checkbox data';
        }
    }
    updateCheckbox(params) {
        const config = params.data[params.colDef.field];
        const options = params.colDef.cellRendererParams || {};
        if (this.hasRequiredKeys(config)) {
            this.setCheckboxAttributes(config);
            this.detachEventListener();
            this.attachEventListener(options, params);
        }
        else {
            this.eGui.textContent = config ? String(config) : '';
        }
    }
    setCheckboxAttributes(config) {
        this.eCheckbox.setAttribute('disabled', config.disabled.toString());
        this.eCheckbox.setAttribute('error', config.error.toString());
        this.eCheckbox.setAttribute('size', config.size);
        this.eCheckbox.setAttribute('checked', config.checked.toString());
        this.eCheckbox.setAttribute('indeterminate', config.indeterminate.toString());
    }
    attachEventListener(options, params) {
        this.eventListener = (event) => {
            if (options.onCheckboxClick) {
                options.onCheckboxClick(params, event);
            }
        };
        this.eCheckbox.addEventListener('click', this.eventListener);
    }
    detachEventListener() {
        if (this.eventListener) {
            this.eCheckbox.removeEventListener('click', this.eventListener);
        }
    }
    hasRequiredKeys(config) {
        return config && config.size !== '';
    }
}
//# sourceMappingURL=checkboxCellRenderer.js.map
