"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var _ = require("lodash");
var default_1 = /** @class */ (function () {
    function default_1(columns) {
        var _this = this;
        this.trigger = new Map();
        this.stroge = new Map();
        this.columns = [];
        this.trigger.clear();
        this.stroge.clear();
        this.columns = _.concat([], columns);
        columns.map(function (col) {
            if (_.has(col, 'link')) {
                _this.trigger.set(col.dataIndex, col.link);
            }
        });
    }
    default_1.prototype.init = function (data) {
        var it = this.trigger.keys();
        var field = it.next().value;
        while (field) {
            var link = this.trigger.get(field);
            var options = [];
            if (data == null) {
                var column = _.find(this.columns, { dataIndex: field });
                if (column && column.options && column.options.length) {
                    options = link.call(column.options[0].value + '');
                }
            }
            else {
                options = link.call(data[field]);
            }
            this.stroge.set(link.field, options);
            field = it.next().value;
        }
    };
    default_1.prototype.getOptions = function (column) {
        // console.log(column)
        if (this.stroge.has(column.dataIndex)) {
            // console.log(this.stroge)
            return this.stroge.get(column.dataIndex);
        }
        return column.options;
    };
    default_1.prototype.call = function (column, value, callBack) {
        if (!this.trigger.has(column.dataIndex)) {
            return;
        }
        var link = this.trigger.get(column.dataIndex);
        var options = link.call(value);
        this.stroge.set(link.field, options);
        if (callBack) {
            callBack();
        }
    };
    return default_1;
}());
exports.default = default_1;
