export class LinkCellRenderer {
    init(params) {
        this.createLink(params);
    }
    getGui() {
        return this.eGui;
    }
    refresh(params) {
        this.updateLink(params);
        return true;
    }
    createLink(params) {
        var _a, _b, _c;
        const field = (_a = params.colDef) === null || _a === void 0 ? void 0 : _a.field;
        const config = ((_b = params.value) !== null && _b !== void 0 ? _b : (_c = params.data) === null || _c === void 0 ? void 0 : _c[field]);
        this.eGui = document.createElement('div');
        this.eLink = document.createElement('ifx-link');
        if (this.hasRequiredKeys(config)) {
            this.setLinkAttributes(config);
            this.eGui.appendChild(this.eLink);
        }
        else {
            this.eGui.textContent = config ? String(config) : '';
        }
    }
    updateLink(params) {
        var _a, _b, _c;
        const field = (_a = params.colDef) === null || _a === void 0 ? void 0 : _a.field;
        const config = ((_b = params.value) !== null && _b !== void 0 ? _b : (_c = params.data) === null || _c === void 0 ? void 0 : _c[field]);
        if (this.hasRequiredKeys(config)) {
            this.setLinkAttributes(config);
        }
        else {
            this.eGui.textContent = config ? String(config) : '';
        }
    }
    setLinkAttributes(config) {
        var _a;
        this.eLink.setAttribute('disabled', (_a = config.disabled) === null || _a === void 0 ? void 0 : _a.toString());
        this.eLink.setAttribute('variant', config.variant);
        this.eLink.setAttribute('size', config.size);
        this.eLink.setAttribute('target', config.target);
        this.eLink.setAttribute('href', config.href);
        if (config.download)
            this.eLink.setAttribute('download', config.download);
        this.eLink.textContent = config.text || '';
    }
    hasRequiredKeys(config) {
        return !!(config &&
            config.text &&
            config.variant &&
            config.size);
    }
}
//# sourceMappingURL=linkCellRenderer.js.map
