"use strict";

Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.HeaderHighlightPlugin = void 0;

class HeaderHighlightPlugin {
    constructor(table, options) {
        this.table = table, this.options = options, this.registerStyle(), this.bindEvent();
    }
    registerStyle() {
        var _a, _b, _c, _d, _e, _f, _g, _h;
        this.table.registerCustomCellStyle("col-highlight", {
            bgColor: null !== (_b = null === (_a = this.options) || void 0 === _a ? void 0 : _a.colHighlightBGColor) && void 0 !== _b ? _b : "#82b2f5",
            color: null !== (_d = null === (_c = this.options) || void 0 === _c ? void 0 : _c.colHighlightColor) && void 0 !== _d ? _d : "#FFF"
        }), this.table.registerCustomCellStyle("row-highlight", {
            bgColor: null !== (_f = null === (_e = this.options) || void 0 === _e ? void 0 : _e.rowHighlightBGColor) && void 0 !== _f ? _f : "#82b2f5",
            color: null !== (_h = null === (_g = this.options) || void 0 === _g ? void 0 : _g.rowHighlightColor) && void 0 !== _h ? _h : "#FFF"
        });
    }
    bindEvent() {
        this.table.on("selected_cell", (() => {
            this.updateHighlight();
        })), this.table.on("selected_clear", (() => {
            this.clearHighlight();
        })), this.table.on("mousemove_table", (() => {
            this.table.stateManager.select.selecting && this.updateHighlight();
        }));
    }
    clearHighlight() {
        this.colHeaderRange && this.table.arrangeCustomCellStyle({
            range: this.colHeaderRange
        }, void 0), this.rowHeaderRange && this.table.arrangeCustomCellStyle({
            range: this.rowHeaderRange
        }, void 0), this.colHeaderRange = void 0, this.rowHeaderRange = void 0;
    }
    updateHighlight() {
        var _a, _b, _c, _d;
        if (!1 === (null === (_a = this.options) || void 0 === _a ? void 0 : _a.colHighlight) && !1 === (null === (_b = this.options) || void 0 === _b ? void 0 : _b.rowHighlight)) return;
        const selectRanges = this.table.getSelectedCellRanges();
        if (0 === selectRanges.length) return void this.clearHighlight();
        const selectRange = selectRanges[0], rowSelectRange = [ selectRange.start.row, selectRange.end.row ];
        rowSelectRange.sort(((a, b) => a - b));
        const colSelectRange = [ selectRange.start.col, selectRange.end.col ];
        let colHeaderRange, rowHeaderRange;
        colSelectRange.sort(((a, b) => a - b)), this.table.isPivotTable() ? (colHeaderRange = {
            start: {
                col: colSelectRange[0],
                row: 0
            },
            end: {
                col: colSelectRange[1],
                row: this.table.columnHeaderLevelCount - 1
            }
        }, rowHeaderRange = {
            start: {
                col: 0,
                row: rowSelectRange[0]
            },
            end: {
                col: this.table.rowHeaderLevelCount - 1,
                row: rowSelectRange[1]
            }
        }) : this.table.internalProps.transpose ? rowHeaderRange = {
            start: {
                col: 0,
                row: rowSelectRange[0]
            },
            end: {
                col: this.table.rowHeaderLevelCount - 1,
                row: rowSelectRange[1]
            }
        } : (colHeaderRange = {
            start: {
                col: colSelectRange[0],
                row: 0
            },
            end: {
                col: colSelectRange[1],
                row: this.table.columnHeaderLevelCount - 1
            }
        }, this.table.internalProps.rowSeriesNumber && (rowHeaderRange = {
            start: {
                col: 0,
                row: rowSelectRange[0]
            },
            end: {
                col: 0,
                row: rowSelectRange[1]
            }
        })), !1 === (null === (_c = this.options) || void 0 === _c ? void 0 : _c.colHighlight) || isSameRange(this.colHeaderRange, colHeaderRange) || (this.colHeaderRange && this.table.arrangeCustomCellStyle({
            range: this.colHeaderRange
        }, void 0), colHeaderRange && this.table.arrangeCustomCellStyle({
            range: colHeaderRange
        }, "col-highlight"), this.colHeaderRange = colHeaderRange), !1 === (null === (_d = this.options) || void 0 === _d ? void 0 : _d.rowHighlight) || isSameRange(this.rowHeaderRange, rowHeaderRange) || (this.rowHeaderRange && this.table.arrangeCustomCellStyle({
            range: this.rowHeaderRange
        }, void 0), rowHeaderRange && this.table.arrangeCustomCellStyle({
            range: rowHeaderRange
        }, "row-highlight"), this.rowHeaderRange = rowHeaderRange);
    }
}

function isSameRange(a, b) {
    return void 0 === a && void 0 === b || void 0 !== a && void 0 !== b && (a.start.col === b.start.col && a.start.row === b.start.row && a.end.col === b.end.col && a.end.row === b.end.row);
}

//# sourceMappingURL=header-highlight.js.map
exports.HeaderHighlightPlugin = HeaderHighlightPlugin;