import * as tslib_1 from "tslib";
import Column from './Column';
/**
 * a column having an accessor to get the cell value
 */
var ValueColumn = /** @class */ (function (_super) {
    tslib_1.__extends(ValueColumn, _super);
    function ValueColumn(id, desc) {
        var _this = _super.call(this, id, desc) || this;
        //find accessor
        _this.accessor = desc.accessor || (function () { return null; });
        _this.loaded = desc.lazyLoaded !== true;
        return _this;
    }
    ValueColumn.prototype.createEventList = function () {
        return _super.prototype.createEventList.call(this).concat([ValueColumn.EVENT_DATA_LOADED]);
    };
    ValueColumn.prototype.on = function (type, listener) {
        return _super.prototype.on.call(this, type, listener);
    };
    ValueColumn.prototype.getLabel = function (row) {
        if (!this.isLoaded()) {
            return '';
        }
        var v = this.getValue(row);
        return v == null ? '' : String(v);
    };
    ValueColumn.prototype.getRaw = function (row) {
        if (!this.isLoaded()) {
            return null;
        }
        return this.accessor(row, this.desc);
    };
    ValueColumn.prototype.getValue = function (row) {
        return this.getRaw(row);
    };
    ValueColumn.prototype.isLoaded = function () {
        return this.loaded;
    };
    ValueColumn.prototype.setLoaded = function (loaded) {
        if (this.loaded === loaded) {
            return;
        }
        this.fire([ValueColumn.EVENT_DATA_LOADED, Column.EVENT_DIRTY_HEADER, Column.EVENT_DIRTY_VALUES, Column.EVENT_DIRTY_CACHES, Column.EVENT_DIRTY], this.loaded, this.loaded = loaded);
    };
    ValueColumn.prototype.getRenderer = function () {
        if (!this.isLoaded()) {
            return ValueColumn.RENDERER_LOADING;
        }
        return _super.prototype.getRenderer.call(this);
    };
    /**
     * patch the dump such that the loaded attribute is defined (for lazy loading columns)
     * @param toDescRef
     * @returns {any}
     */
    ValueColumn.prototype.dump = function (toDescRef) {
        var r = _super.prototype.dump.call(this, toDescRef);
        r.loaded = this.loaded;
        if (!this.loaded && r.renderer === ValueColumn.RENDERER_LOADING) {
            delete r.renderer;
        }
        return r;
    };
    ValueColumn.prototype.restore = function (dump, factory) {
        if (dump.loaded !== undefined) {
            this.loaded = dump.loaded;
        }
        _super.prototype.restore.call(this, dump, factory);
    };
    ValueColumn.EVENT_DATA_LOADED = 'dataLoaded';
    ValueColumn.RENDERER_LOADING = 'loading';
    return ValueColumn;
}(Column));
export default ValueColumn;
//# sourceMappingURL=ValueColumn.js.map