(function(paw){
    function PawExcelStyle(){

    }

    PawExcelStyle.prototype.HTMLStyleToExcel = function($elt, cell, excel){
        if(!excel.settings.ignoreBackgrounds){
            var bgc = paw.utils.color.rgbaToARGB($elt.css('background-color'));
            // not fully transparent
            if(bgc !== '00000000'){
                cell.fill = {
                    type: 'pattern',
                    pattern:'solid',
                    fgColor:{argb: bgc} 
                };
            }
        }

        if(!excel.settings.ignoreFont){
            cell.font = {
                color: { 
                    argb: paw.utils.color.rgbaToARGB($elt.css('color'))
                },
                bold: paw.utils.value.strToNum($elt.css('font-weight')) >= 700
            };
        }

        if(!excel.settings.ignoreBorders){
            cell.border = this.HTMLEltBorderToExcel(
                this.getHTMLBorder($elt)
            );
        }
    };

    PawExcelStyle.prototype.getHTMLBorderComputed = function(computedStyle, borderId){
        return {
            width: computedStyle.getPropertyValue('border-' + borderId + '-width'),
            style: computedStyle.getPropertyValue('border-' + borderId + '-style'),
            color: computedStyle.getPropertyValue('border-' + borderId + '-color')
        };
    };

    PawExcelStyle.prototype.getHTMLBorder = function($elt){
        var computedStyle = window.getComputedStyle($elt[0]);
        return {
            top: this.getHTMLBorderComputed(computedStyle, 'top'),
            bottom: this.getHTMLBorderComputed(computedStyle, 'bottom'),
            left: this.getHTMLBorderComputed(computedStyle, 'left'),
            right: this.getHTMLBorderComputed(computedStyle, 'right')
        };
    };

    PawExcelStyle.prototype.HTMLBorderToExcel = function(cssBorder){
        let borderStyle = this.cssBorderStyleToExcel(cssBorder.style);        
        if(borderStyle === 'none'){
            return { style: 'thin', color: {argb: 'FFD9D9D9'} };
        }
        return { 
            style: borderStyle, 
            color: 
            { 
                argb: paw.utils.color.rgbaToARGB(cssBorder.color) 
            } 
        };
    }

    PawExcelStyle.prototype.HTMLEltBorderToExcel = function(eltBorder){
        return {
            top: this.HTMLBorderToExcel(eltBorder.top),
            bottom: this.HTMLBorderToExcel(eltBorder.bottom),
            left: this.HTMLBorderToExcel(eltBorder.left),
            right: this.HTMLBorderToExcel(eltBorder.right)
        }
    }

    PawExcelStyle.prototype.cssBorderStyleToExcel = function(borderStyle){
        var excelBorderStyle;
        switch (borderStyle) {
            case 'none':
                excelBorderStyle = 'none';
                break;
            case 'solid':
                excelBorderStyle = 'thin'; // You can adjust this to match Excel's thin border style
                break;
            case 'dashed':
                excelBorderStyle = 'dashed';
                break;
            // Add more cases as needed to handle other CSS border styles
            default:
                excelBorderStyle = 'thin'; // Fallback to a default ExcelJS border style
        }
        return excelBorderStyle;
    };

    paw.mod.excel.excelStyle = new PawExcelStyle();
})(paw);