/* global Bdf,$$,Intl,TableSheet */

TableSheet.CssResolver = function (settings) {
    this.functions = {
        defaultCssClass: null,
        cssClass: null
    };
    if (settings) {
        if (settings.functions) {
            for(let prop in settings.functions) {
                this.functions[prop] = settings.functions[prop];
            }
        }
    }
        
};

TableSheet.CssResolver.prototype.getDefaultCssClass = function(columnName) {
    if (this.functions.defaultCssClass) {
        let defaultCssClass = this.functions.defaultCssClass(columnName);
        if (!defaultCssClass) {
            return defaultCssClass;
        }
    }
    return "tablesheet-column-Medium";
};

TableSheet.CssResolver.prototype.resolveCss = function(columnName, valueArray) {
    var cssClassArray = new Array();
    for(let value of valueArray) {
        let resolved = null;
        if (this.functions.cssClass) {
            resolved = this.cssClass(columnName, value);
        }
        if (!resolved) {
            resolved = _checkShortcut(value);
        }
        if (!resolved) {
            if (!value.startsWith("od:")) {
                resolved = value;
            }
        }
        if (resolved) {
            cssClassArray.push(resolved);
        }
    }
    return cssClassArray.join(" ");
    
    function _checkShortcut(val) {
        switch(val) {
            case "small":
                return "tablesheet-column-Small";
            case "medium":
                return "tablesheet-column-Medium";
            case "large":
                return "tablesheet-column-Large";
            default:
                return null;
        }
    }
};
