ko.components.register('ko-rgborder', {
    viewModel: function (params) {
        var self = this;
        self.tableTemplateId = params.tableTemplateId;
        self.id = "rg-" + self.tableTemplateId();
        self.scope = null;
        self.hasTrueShape = false;
        self.borderWidths = ko.observableArray([
            { id: 1, value: "1px" },
            { id: 2, value: "3px" },
            { id: 3, value: "5px" }
        ]);
        self.borders = {
            right: { enable: ko.observable(false), value: ko.observable("") },
            top: { enable: ko.observable(false), value: ko.observable("") },
            bottom: { enable: ko.observable(false), value: ko.observable("") },
            left: { enable: ko.observable(false), value: ko.observable("") },
            insideVert: { enable: ko.observable(false), value: ko.observable("") },
            insideHorz: { enable: ko.observable(false), value: ko.observable("") }
        };
        self.borderColorList = ko.observableArray(["c00000", "ff0000", "ff842d", "ffc000", "ffff00", "92d050", "00b050", "00b0f0", "0070c0", "002060", "7030a0", "000000", "808080"]);
        self.borderStyles = ko.observableArray([
            { id: 1, style: "2px solid black", value: "solid" },
            { id: 2, style: "2px dashed black", value: "dashed" },
            { id: 3, style: "3px double black", value: "double" }
        ]);
        self.borderStyleVal = ko.observable("").extend({ deferred: true });
        self.borderWidthVal = ko.observable("").extend({ deferred: true });
        self.borderColorVal = ko.observable("").extend({ deferred: true });
        self.hasBorder = function (cell, side) {
            var borderStyles = cell.style.borderStyle.split(" ");
            borderStyles = _h.cleanArray(borderStyles);
            var borderWidths = cell.style.borderWidth.split(" ");
            borderWidths = _h.cleanArray(borderWidths);
            switch (side) {
                case "top":
                    return !borderWidths[0].startsWith("0") && !borderStyles[0].startsWith("none");
                case "bottom":
                    return !borderWidths[2].startsWith("0") && !borderStyles[2].startsWith("none");
                case "left":
                    return !borderWidths[3].startsWith("0") && !borderStyles[3].startsWith("none");
                case "right":
                    return !borderWidths[1].startsWith("0") && !borderStyles[1].startsWith("none");
                case "any":
                    if (borderWidths.length === 0 || borderStyles.length === 0)
                        return false;
                    return (borderWidths[0] && !borderWidths[0].startsWith("0") && !borderStyles[0].startsWith("none")) ||
                        (borderWidths[2] && !borderWidths[2].startsWith("0") && !borderStyles[2].startsWith("none")) ||
                        (borderWidths[3] && !borderWidths[3].startsWith("0") && !borderStyles[3].startsWith("none")) ||
                        (borderWidths[1] && !borderWidths[1].startsWith("0") && !borderStyles[1].startsWith("none"));
            }
        }
        self.getAllSideBorders = function (cell) {
            var borderStyles = cell.style.borderStyle.split(" ");
            borderStyles = _h.cleanArray(borderStyles);
            var borderWidths = cell.style.borderWidth.split(" ");
            borderWidths = _h.cleanArray(borderWidths);
            var borderColors = cell.style.borderColor.split(" ");
            borderColors = _h.cleanArray(borderColors);
            if (_h.any(borderColors))
                for (var i = 0; i < borderColors.length; i++) {
                    if (borderColors[i].indexOf("undefined") !== -1) {
                        borderColors[i] = "#000000";
                    }
                }
            return [borderStyles, borderWidths, borderColors];
        }
        self.bordersBind = function () {
            var data = self.scope.find(".rp-gen").rg("getSelectedCellsData");
            self.selectedCells = data.cells;
            self.hasTrueShape = data.shapeData[4];

            if (self.selectedCells.length === 0 || (self.selectedCells.length > 1 && !self.hasTrueShape)) {
                self.borders.top.value("");
                self.borders.right.value("");
                self.borders.bottom.value("");
                self.borders.left.value("");
                self.borders.insideVert.value("");
                self.borders.insideHorz.value("");
                self.borders.top.enable(false);
                self.borders.right.enable(false);
                self.borders.bottom.enable(false);
                self.borders.left.enable(false);
                self.borders.insideVert.enable(false);
                self.borders.insideHorz.enable(false);
                self.borderStyleVal("solid");
                self.borderWidthVal("1px");
                if (_h.isNullOrEmpty(self.borderColorVal()) || self.borderColorVal() === "")
                    self.borderColorVal("#000000");
            }
            if (self.selectedCells.length === 1) {
                self.oneSideBind(self.selectedCells[0]);
            }
            if (self.selectedCells.length > 1 && self.hasTrueShape) {
                var vertexes = self.scope.find(".rp-gen").rg("getBorder");
                var rightSide = true;
                var leftSide = true;
                var topSide = true;
                var bottomSide = true;
                var insideVertSide = true;
                var insideHorzSide = true;
                var rightSideItem = null;
                var leftSideItem = null;
                var topSideItem = null;
                var bottomSideItem = null;
                var insideVertSideItem = null;
                var insideHorzSideItem = null;
                var borderStyle = "";
                var borderWidth = "";
                var borderColor = "";
                for (var i = 0; i < self.selectedCells.length; i++) {
                    var target = self.selectedCells[i];
                    if (target.col === vertexes.sCol) {
                        if (!self.hasBorder(target, "right"))
                            rightSide = false;
                        if (rightSide && rightSideItem === null)
                            rightSideItem = target;
                    }
                    if (target.col === vertexes.bCol) {
                        if (!self.hasBorder(target, "left"))
                            leftSide = false;
                        if (leftSide && leftSideItem === null)
                            leftSideItem = target;
                    }
                    if (target.row === vertexes.sRow) {
                        if (!self.hasBorder(target, "top"))
                            topSide = false;
                        if (topSide && topSideItem === null)
                            topSideItem = target;
                    }
                    if (target.row === vertexes.bRow) {
                        if (!self.hasBorder(target, "bottom"))
                            bottomSide = false;
                        if (bottomSide && bottomSideItem === null)
                            bottomSideItem = target;
                    }
                    if (target.col < vertexes.bCol) {
                        if (!self.hasBorder(target, "left"))
                            insideVertSide = false;
                        if (insideVertSide && insideVertSideItem === null)
                            insideVertSideItem = target;
                    }
                    if (target.row < vertexes.bRow) {
                        if (!self.hasBorder(target, "bottom"))
                            insideHorzSide = false;
                        if (insideHorzSide && insideHorzSideItem === null)
                            insideHorzSideItem = target;
                    }

                    if (target.col === vertexes.bCol && vertexes.bCol === vertexes.sCol) {
                        insideVertSide = false;
                        if (insideVertSide && insideVertSideItem === null)
                            insideVertSideItem = target;
                    }
                    if (target.row === vertexes.bRow && vertexes.bRow === vertexes.sRow) {
                        insideHorzSide = false;
                        if (insideHorzSide && insideHorzSideItem === null)
                            insideHorzSideItem = target;
                    }
                }
                self.borders.top.value("");
                self.borders.right.value("");
                self.borders.bottom.value("");
                self.borders.left.value("");
                self.borders.insideVert.value("");
                self.borders.insideHorz.value("");
                if (rightSide) {
                    var rightbordersData = self.getAllSideBorders(rightSideItem);
                    self.borders.right.value("border-width: " +
                        rightbordersData[1][1] +
                        ";border-style: " +
                        rightbordersData[0][1] +
                        ";border-color: " + rightbordersData[2][1] + ";");
                    borderStyle = rightbordersData[0][1];
                    borderWidth = rightbordersData[1][1];
                    borderColor = rightbordersData[2][1];
                }
                if (leftSide) {
                    var leftbordersData = self.getAllSideBorders(leftSideItem);
                    self.borders.left.value("border-width: " +
                        leftbordersData[1][3] +
                        ";border-style: " +
                        leftbordersData[0][3] +
                        ";border-color: " + leftbordersData[2][3] + ";");
                    borderStyle = leftbordersData[0][3];
                    borderWidth = leftbordersData[1][3];
                    borderColor = leftbordersData[2][3];
                }
                if (topSide) {
                    var topbordersData = self.getAllSideBorders(topSideItem);
                    self.borders.top.value("border-width: " +
                        topbordersData[1][0] +
                        ";border-style: " +
                        topbordersData[0][0] +
                        ";border-color: " + topbordersData[2][0] + ";");
                    borderStyle = topbordersData[0][0];
                    borderWidth = topbordersData[1][0];
                    borderColor = topbordersData[2][0];
                }
                if (bottomSide) {
                    var bottombordersData = self.getAllSideBorders(bottomSideItem);
                    self.borders.bottom.value("border-width: " +
                        bottombordersData[1][2] +
                        ";border-style: " +
                        bottombordersData[0][2] +
                        ";border-color: " + bottombordersData[2][2] + ";");
                    borderStyle = bottombordersData[0][2];
                    borderWidth = bottombordersData[1][2];
                    borderColor = bottombordersData[2][2];
                }
                if (insideVertSide) {
                    var insideVertbordersData = self.getAllSideBorders(insideVertSideItem);
                    self.borders.insideVert.value("border-width: " +
                        insideVertbordersData[1][3] +
                        ";border-style: " +
                        insideVertbordersData[0][3] +
                        ";border-color: " + insideVertbordersData[2][3] + ";");
                    borderStyle = insideVertbordersData[0][3];
                    borderWidth = insideVertbordersData[1][3];
                    borderColor = insideVertbordersData[2][3];
                }
                if (insideHorzSide) {
                    var insideHorzbordersData = self.getAllSideBorders(insideHorzSideItem);
                    self.borders.insideHorz.value("border-width: " +
                        insideHorzbordersData[1][2] +
                        ";border-style: " +
                        insideHorzbordersData[0][2] +
                        ";border-color: " + insideHorzbordersData[2][2] + ";");
                    borderStyle = insideHorzbordersData[0][2];
                    borderWidth = insideHorzbordersData[1][2];
                    borderColor = insideHorzbordersData[2][2];
                }
                self.borders.top.enable(topSide);
                self.borders.right.enable(rightSide);
                self.borders.bottom.enable(bottomSide);
                self.borders.left.enable(leftSide);
                self.borders.insideVert.enable(insideVertSide);
                self.borders.insideHorz.enable(insideHorzSide);
                self.borderStyleVal(borderStyle);
                self.borderWidthVal(borderWidth);
                self.borderColorVal(borderColor);
                if (!topSide && !rightSide && !bottomSide && !leftSide && !insideVertSide && !insideHorzSide) {
                    self.borderStyleVal("solid");
                    self.borderWidthVal("1px");
                    if (_h.isNullOrEmpty(self.borderColorVal()) || self.borderColorVal() === "")
                        self.borderColorVal("#000000");
                }
            }
        };
        self.oneSideBind = function (cell) {
            var bordersData = self.getAllSideBorders(cell);
            var borderStyles = bordersData[0];
            var borderWidths = bordersData[1];
            var borderColors = bordersData[2];
            self.borders.top.enable(!borderWidths[0].startsWith("0") && !borderStyles[0].startsWith("none"));
            self.borders.right.enable(!borderWidths[1].startsWith("0") && !borderStyles[1].startsWith("none"));
            self.borders.bottom.enable(!borderWidths[2].startsWith("0") && !borderStyles[2].startsWith("none"));
            self.borders.left.enable(!borderWidths[3].startsWith("0") && !borderStyles[3].startsWith("none"));
            self.borders.insideVert.enable(false);
            self.borders.insideHorz.enable(false);
            var top = self.borders.top.enable();
            var right = self.borders.right.enable();
            var bottom = self.borders.bottom.enable();
            var left = self.borders.left.enable();
            self.borders.top.value("");
            self.borders.right.value("");
            self.borders.bottom.value("");
            self.borders.left.value("");
            self.borders.insideVert.value("");
            self.borders.insideHorz.value("");
            if (top) {
                self.borders.top.value("border-width: " +
                    borderWidths[0] +
                    ";border-style: " +
                    borderStyles[0] +
                    ";border-color: " +
                    borderColors[0] + ";");
                self.borderWidthVal(borderWidths[0]);
                self.borderStyleVal(borderStyles[0]);
                self.borderColorVal(borderColors[0]);
            }
            if (right) {
                self.borders.right.value("border-width: " +
                    borderWidths[1] +
                    ";border-style: " +
                    borderStyles[1] +
                    ";border-color: " +
                    borderColors[1] + ";");
                self.borderWidthVal(borderWidths[1]);
                self.borderStyleVal(borderStyles[1]);
                self.borderColorVal(borderColors[1]);
            }
            if (bottom) {
                self.borders.bottom.value("border-width: " +
                    borderWidths[2] +
                    ";border-style: " +
                    borderStyles[2] +
                    ";border-color: " +
                    borderColors[2] + ";");
                self.borderWidthVal(borderWidths[2]);
                self.borderStyleVal(borderStyles[2]);
                self.borderColorVal(borderColors[2]);
            }
            if (left) {
                self.borders.left.value("border-width: " +
                    borderWidths[3] +
                    ";border-style: " +
                    borderStyles[3] +
                    ";border-color: " +
                    borderColors[3] + ";");
                self.borderWidthVal(borderWidths[3]);
                self.borderStyleVal(borderStyles[3]);
                self.borderColorVal(borderColors[3]);
            }

            if (!top && !right && !bottom && !left) {
                self.borderStyleVal("solid");
                self.borderWidthVal("1px");
                if (_h.isNullOrEmpty(self.borderColorVal()) || self.borderColorVal() === "")
                    self.borderColorVal("#000000");
            }
        }
        self.changeBorderColor = function (color) {
            self.borderColorVal(color);
        }
        self.changeBorderStyle = function (m, v) {
            self.borderStyleVal(v.value);
        }
        self.changeBorderWidth = function (m, v) {
            self.borderWidthVal(v.value);
        }
        self.toggleBorderCells = function (model, command, val) {
            if (self.selectedCells.length > 1 && self.hasTrueShape) {
                var list = [];
                switch (command) {
                    case "bottom":
                    case "top":
                    case "right":
                    case "left":
                        list = self.getSurroundingsBorder(command);
                        self.setOneSideBorders(command, list);
                        break;
                    case "outside":
                        if (!_h.isEmpty(self.borderStyleVal()) &&
                            !_h.isEmpty(self.borderWidthVal())) {
                            var listRight = self.getSurroundingsBorder("right");
                            self.setOneSideBorders("right", listRight);

                            var listTop = self.getSurroundingsBorder("top");
                            self.setOneSideBorders("top", listTop);

                            var listLeft = self.getSurroundingsBorder("left");
                            self.setOneSideBorders("left", listLeft);

                            var listBottom = self.getSurroundingsBorder("bottom");
                            self.setOneSideBorders("bottom", listBottom);
                        }
                        break;
                    case "none":
                        for (var i = 0; i < self.selectedCells.length; i++) {
                            self.sendJqrgCommand({
                                id: "border", color: "#000000",
                                cell: self.selectedCells[i],
                                style: "none", width: "0", side: command
                            });
                        }
                        self.borders.left.value("");
                        self.borders.right.value("");
                        self.borders.top.value("");
                        self.borders.bottom.value("");
                        break;
                    case "inside":
                        self.toggleInsideBorder("both");
                        break;
                    case "inside-vert":
                        self.toggleInsideBorder("vert");
                        break;
                    case "inside-horz":
                        self.toggleInsideBorder("horz");
                        break;
                }
            }
            if (self.selectedCells.length === 1 || (self.selectedCells.length > 1 && !self.hasTrueShape)) {
                for (var j = 0; j < self.selectedCells.length; j++) {
                    switch (command) {
                        case "bottom":
                        case "top":
                        case "right":
                        case "left":
                            self.setOneSideBorder(command, self.selectedCells[j]);
                            break;
                        case "outside":
                            if (!_h.isEmpty(self.borderStyleVal()) && !_h.isEmpty(self.borderWidthVal())) {
                                self.setOneSideBorder("bottom", self.selectedCells[j]);
                                self.setOneSideBorder("top", self.selectedCells[j]);
                                self.setOneSideBorder("right", self.selectedCells[j]);
                                self.setOneSideBorder("left", self.selectedCells[j]);
                            }
                            break;
                        case "none":
                            self.sendJqrgCommand({
                                id: "border", color: "#000000",
                                cell: self.selectedCells[i],
                                style: "none", width: "0", side: command
                            });
                            self.borders.left.value("");
                            self.borders.right.value("");
                            self.borders.top.value("");
                            self.borders.bottom.value("");
                            break;
                    }
                }

            }
            self.bordersBind();
        }
        self.setOneSideBorders = function (command, list) {
            var zero = list[0];
            var bordersData = self.getAllSideBorders(zero);
            var borderStyles = bordersData[0];
            var borderWidths = bordersData[1];
            var borderColors = bordersData[2];
            var bStyle = "";
            var bWidth = "";
            var action = "add";
            switch (command) {
                case "left":
                    bStyle = borderStyles[3];
                    bWidth = borderWidths[3];
                    break;
                case "top":
                    bStyle = borderStyles[0];
                    bWidth = borderWidths[0];
                    break;
                case "right":
                    bStyle = borderStyles[1];
                    bWidth = borderWidths[1];
                    break;
                case "bottom":
                    bStyle = borderStyles[2];
                    bWidth = borderWidths[2];
                    break;
            }
            if (bStyle !== "none" && bWidth !== "0")
                action = "remove";

            for (var i = 0; i < list.length; i++) {
                var cell = list[i];
                if (action === "remove") {
                    self.sendJqrgCommand({
                        id: "border", color: "#000000",
                        cell: cell,
                        style: "none", width: "0", side: command
                    });
                } else {
                    if (self.borderStyleVal() || self.borderWidthVal())
                        self.sendJqrgCommand({
                            id: "border", color: self.borderColorVal(),
                            cell: cell,
                            style: self.borderStyleVal(), width: self.borderWidthVal(), side: command
                        });
                }
            }
            if (action === "remove") {
                self.borders[command].value("");
            } else {
                var line = "";
                line = "border-width: " + self.borderWidthVal() + ";";
                line += "border-style: " + self.borderStyleVal() + ";";
                line += "border-color: " + self.borderColorVal() + ";";
                self.borders[command].value(line);
            }
        }
        self.setOneSideBorder = function (command, item) {
            var cell = self.selectedCells[0];
            if (item)
                cell = item;
            var bordersData = self.getAllSideBorders(cell);
            var borderStyles = bordersData[0];
            var borderWidths = bordersData[1];
            if (self.hasBorder(cell, command)) {
                self.sendJqrgCommand({
                    id: "border", color: "#000000",
                    cell: cell,
                    style: "none", width: "0", side: command
                });
                self.borders[command].value("");
            } else {
                switch (command) {
                    case "left":
                        borderStyles = borderStyles[3];
                        borderWidths = borderWidths[3];
                        break;
                    case "top":
                        borderStyles = borderStyles[0];
                        borderWidths = borderWidths[0];
                        break;
                    case "right":
                        borderStyles = borderStyles[1];
                        borderWidths = borderWidths[1];
                        break;
                    case "bottom":
                        borderStyles = borderStyles[2];
                        borderWidths = borderWidths[2];
                        break;
                }
                var line = "";
                var isChanged = false;
                if (self.borderWidthVal()) {
                    line = "border-width: " + self.borderWidthVal() + ";";
                    isChanged = true;
                } else {
                    line = "border-width: " + borderWidths + ";";
                }
                if (self.borderStyleVal()) {
                    line += "border-style: " + self.borderStyleVal() + ";border-color: " + self.borderColorVal() + ";";
                    isChanged = true;
                } else {
                    line += "border-style: " + borderStyles + ";border-color: " + self.borderColorVal() + ";";
                }
                if (isChanged)
                    self.sendJqrgCommand({
                        id: "border", color: self.borderColorVal(),
                        cell: cell,
                        style: self.borderStyleVal(), width: self.borderWidthVal(), side: command
                    });
                self.borders[command].value(line);
            }
        }
        self.getSurroundingsBorder = function (command) {
            var vertexes = self.scope.find(".rp-gen").rg("getBorder");
            var array = [];
            switch (command) {
                case "bottom":
                    for (var b = vertexes.sCol; b < vertexes.bCol + 1; b++) {
                        array.push(_h.numberToAlphabet(b) + vertexes.bRow);
                    }
                    break;
                case "top":
                    for (var t = vertexes.sCol; t < vertexes.bCol + 1; t++) {
                        array.push(_h.numberToAlphabet(t) + vertexes.sRow);
                    }
                    break;
                case "right":
                    for (var r = vertexes.sRow; r < vertexes.bRow + 1; r++) {
                        array.push(_h.numberToAlphabet(vertexes.sCol) + r);
                    }
                    break;
                case "left":
                    for (var l = vertexes.sRow; l < vertexes.bRow + 1; l++) {
                        array.push(_h.numberToAlphabet(vertexes.bCol) + l);
                    }
                    break;
            }
            var cellArray = [];
            for (var i = 0; i < self.selectedCells.length; i++) {
                var cell = self.selectedCells[i];
                if (array.indexOf(cell.address) !== -1)
                    cellArray.push(cell);
            }
            return cellArray;
        }
        self.toggleInsideBorder = function (side) {
            var vertexes = self.scope.find(".rp-gen").rg("getBorder");
            var model = self.scope.find(".rp-gen").rg("getModel");
            var zero = model.cells.filter(a => a.col === vertexes.sCol && a.row === vertexes.sRow)[0];
            var bordersData = self.getAllSideBorders(zero);
            var borderStyles = bordersData[0];
            var borderWidths = bordersData[1];
            var leftHasBorder = borderStyles[3] !== "none" && borderWidths[3] !== "0";
            var bottomHasBorder = borderStyles[2] !== "none" && borderWidths[2] !== "0";
            var targetCol = "";
            var targetRow = "";
            var cell = "";
            var line = "";
            if (side === "horz" || side === "both") {
                for (var i = 0; i < vertexes.bRow - vertexes.sRow; i++) {
                    targetRow = vertexes.sRow + i;
                    for (var j = 0; j < (vertexes.bCol - vertexes.sCol + 1); j++) {
                        targetCol = vertexes.sCol + j;
                        cell = model.cells.filter(a => a.col === targetCol && a.row === targetRow)[0];
                        if (bottomHasBorder) {
                            self.sendJqrgCommand({
                                id: "border", color: "#000000",
                                cell: cell,
                                style: "none", width: "0", side: "bottom"
                            });
                        } else {
                            if (self.borderWidthVal() || self.borderStyleVal())
                                self.sendJqrgCommand({
                                    id: "border", color: self.borderColorVal(),
                                    cell: cell,
                                    style: self.borderStyleVal(), width: self.borderWidthVal(), side: "bottom"
                                });
                        }
                    }
                }
                if (bottomHasBorder) {
                    self.borders.insideHorz.value("");
                } else {
                    line = "border-width: " + self.borderWidthVal() + ";";
                    line += "border-style: " + self.borderStyleVal() + ";";
                    line += "border-color: " + self.borderColorVal() + ";";
                    self.borders.insideHorz.value(line);
                }
            }
            if (side === "vert" || side === "both") {
                for (var k = 0; k < vertexes.bCol - vertexes.sCol; k++) {
                    targetCol = vertexes.sCol + k;
                    for (var l = 0; l < (vertexes.bRow - vertexes.sRow + 1); l++) {
                        targetRow = vertexes.sRow + l;
                        cell = model.cells.filter(a => a.col === targetCol && a.row === targetRow)[0];
                        if (leftHasBorder) {
                            self.sendJqrgCommand({
                                id: "border", color: "#000000",
                                cell: cell,
                                style: "none", width: "0", side: "left"
                            });
                        } else {
                            if (self.borderWidthVal() || self.borderStyleVal())
                                self.sendJqrgCommand({
                                    id: "border", color: self.borderColorVal(),
                                    cell: cell,
                                    style: self.borderStyleVal(), width: self.borderWidthVal(), side: "left"
                                });
                        }
                    }
                }
                if (leftHasBorder) {
                    self.borders.insideVert.value("");
                } else {
                    line = "";
                    line = "border-width: " + self.borderWidthVal() + ";";
                    line += "border-style: " + self.borderStyleVal() + ";";
                    line += "border-color: " + self.borderColorVal() + ";";
                    self.borders.insideVert.value(line);
                }
            }
        }
        self.sendJqrgCommand = function (obj) {
            var defaultVal = self.getDefault();
            obj.defaultVal = defaultVal;
            obj.type = obj.id;
            obj.value = obj;
            var res = self.scope.find(".rp-gen").rg("command", obj);
            return res;
        }      
        self.config = function (data) {
            var baseSelector = "#" + self.id;
            $(document).on("click", baseSelector + " .border-box", function (e) {
                e.stopPropagation();
                self.bordersBind(true);
            });
        }
        self.init = function () {
            self.scope = $('#' + self.id);
            self.config();
           
        }
        self.getDefault = function () {
            var model = {};
            var data = clientStorage.getSetting("DefaultTemplateStyle");
            if (!_h.isEmpty(data)) {
                model = JSON.parse(data);
                if (!model.textFontSize)
                    model.textFontSize = "12px";
                if (!model.textFontFamily)
                    model.textFontFamily = "Nazanin";

            } else {
                return {
                    textColor: "",
                    backColor: "",
                    textFontSize: "12px",
                    textFontFamily: "Nazanin",
                    align: undefined
                };
            }
            return model;
        }
        self.init();
    },
    template: '<!-- ko template: { name: "rgborder-component-t" } --><!-- /ko -->'
}); 
