import * as tslib_1 from "tslib";
import { toolbar } from './annotations';
import { patternFunction } from './internal';
import MapColumn from './MapColumn';
import LinkColumn from './LinkColumn';
import { EAlignment } from './StringColumn';
/**
 * a string column with optional alignment
 */
var LinkMapColumn = /** @class */ (function (_super) {
    tslib_1.__extends(LinkMapColumn, _super);
    function LinkMapColumn(id, desc) {
        var _this = _super.call(this, id, desc) || this;
        _this.patternFunction = null;
        _this.setDefaultWidth(200); //by default 200
        _this.alignment = desc.alignment || EAlignment.left;
        _this.escape = desc.escape !== false;
        _this.pattern = desc.pattern || '';
        _this.patternTemplates = desc.patternTemplates || [];
        _this.setDefaultRenderer('map');
        return _this;
    }
    LinkMapColumn.prototype.setPattern = function (pattern) {
        LinkColumn.prototype.setPattern.call(this, pattern);
    };
    LinkMapColumn.prototype.getPattern = function () {
        return this.pattern;
    };
    LinkMapColumn.prototype.createEventList = function () {
        return _super.prototype.createEventList.call(this).concat([LinkColumn.EVENT_PATTERN_CHANGED]);
    };
    LinkMapColumn.prototype.on = function (type, listener) {
        return _super.prototype.on.call(this, type, listener);
    };
    LinkMapColumn.prototype.getValue = function (row) {
        var r = this.getLinkMap(row);
        return r.every(function (d) { return d.value == null; }) ? null : r.map(function (_a) {
            var key = _a.key, value = _a.value;
            return ({
                key: key,
                value: value ? value.href : ''
            });
        });
    };
    LinkMapColumn.prototype.getLabels = function (row) {
        return this.getLinkMap(row).map(function (_a) {
            var key = _a.key, value = _a.value;
            return ({
                key: key,
                value: value ? value.alt : ''
            });
        });
    };
    LinkMapColumn.prototype.getLinkMap = function (row) {
        var _this = this;
        return _super.prototype.getMap.call(this, row).map(function (_a) {
            var key = _a.key, value = _a.value;
            return ({
                key: key,
                value: _this.transformValue(value, row, key)
            });
        });
    };
    LinkMapColumn.prototype.transformValue = function (v, row, key) {
        if (v == null || v === '') {
            return null;
        }
        if (typeof v === 'string') {
            if (!this.pattern) {
                return {
                    alt: v,
                    href: v
                };
            }
            if (!this.patternFunction) {
                this.patternFunction = patternFunction(this.pattern, 'item', 'key');
            }
            return {
                alt: v,
                href: this.patternFunction.call(this, v, row.v, key)
            };
        }
        return v;
    };
    LinkMapColumn.prototype.dump = function (toDescRef) {
        var r = _super.prototype.dump.call(this, toDescRef);
        if (this.pattern !== this.desc.pattern) {
            r.pattern = this.pattern;
        }
        return r;
    };
    LinkMapColumn.prototype.restore = function (dump, factory) {
        if (dump.pattern) {
            this.pattern = dump.pattern;
        }
        _super.prototype.restore.call(this, dump, factory);
    };
    LinkMapColumn.EVENT_PATTERN_CHANGED = LinkColumn.EVENT_PATTERN_CHANGED;
    LinkMapColumn = tslib_1.__decorate([
        toolbar('search', 'editPattern')
    ], LinkMapColumn);
    return LinkMapColumn;
}(MapColumn));
export default LinkMapColumn;
//# sourceMappingURL=LinkMapColumn.js.map