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

TableSheet.Cell = function (text, settings) {
    this.text = text;
    this.isHtml = false;
    this.moreText = null;
    this.data = {};
    this.customTemplate = null;
    this.cssClasses = "";
    this.custom = {};
    if (settings) {
        for(let propKey in settings) {
            let propValue = settings[propKey];
            if (propValue) {
                switch(propKey) {
                    case "sortValue":
                        this.data["value"] = propValue;
                        break;
                    case "cssClasses":
                        this.cssClasses = propValue;
                        break;
                    case "customTemplate":
                        this.customTemplate = propValue;
                        break;
                    case "isHtml":
                        this.isHtml = true;
                        break;
                    case "moreText":
                        this.moreText = propValue;
                        break;
                }
            }
        }
    }    
};

TableSheet.Cell.prototype.setSortValue = function (value) {
    setData("value",value);
    return this;
};

TableSheet.Cell.prototype.setData = function (key, value) {
    this.data[key] = value;
    return this;
};

TableSheet.Cell.prototype.setCustomTemplate = function (customTemplate, customContext) {
    this.customTemplate = customTemplate;
    this.custom = Object.assign(this.custom, customContext);
    return this;
};

TableSheet.Cell.prototype.addClass = function (className) {
    if (!this.cssClasses) {
        this.cssClasses = className;
    } else {
        this.cssClasses = this.cssClasses + " " + className;
    }
    return this;
};

TableSheet.Cell.prototype.getTemplate = function () {
    if (this.customTemplate) {
        return this.customTemplate;
    }
    return "tablesheet:cell";
};